2021-09-30 00:56:49 -05:00
|
|
|
//
|
|
|
|
|
// Source code recreated from a .class file by IntelliJ IDEA
|
|
|
|
|
// (powered by Fernflower decompiler)
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
package noppes.npcs;
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
import cpw.mods.fml.common.eventhandler.Event;
|
2021-09-30 00:56:49 -05:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
|
import net.minecraft.entity.item.EntityItem;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
|
import net.minecraft.util.DamageSource;
|
2021-10-11 06:49:30 -05:00
|
|
|
import net.minecraft.world.WorldServer;
|
|
|
|
|
import net.minecraftforge.event.entity.EntityEvent;
|
|
|
|
|
import net.minecraftforge.event.world.WorldEvent;
|
|
|
|
|
import noppes.npcs.controllers.IScriptHandler;
|
|
|
|
|
import noppes.npcs.controllers.ScriptController;
|
|
|
|
|
import noppes.npcs.controllers.data.ForgeDataScript;
|
|
|
|
|
import noppes.npcs.controllers.data.PlayerDataScript;
|
|
|
|
|
import noppes.npcs.scripted.IEntity;
|
|
|
|
|
import noppes.npcs.scripted.IWorld;
|
2021-09-30 21:44:30 -05:00
|
|
|
import noppes.npcs.scripted.NpcAPI;
|
2021-10-11 06:49:30 -05:00
|
|
|
import noppes.npcs.scripted.ScriptPlayer;
|
|
|
|
|
import noppes.npcs.scripted.event.ForgeEvent;
|
2021-09-30 00:56:49 -05:00
|
|
|
import noppes.npcs.scripted.event.PlayerEvent.AttackEvent;
|
|
|
|
|
import noppes.npcs.scripted.event.PlayerEvent.ChatEvent;
|
|
|
|
|
import noppes.npcs.scripted.event.PlayerEvent.ContainerClosed;
|
|
|
|
|
import noppes.npcs.scripted.event.PlayerEvent.ContainerOpen;
|
|
|
|
|
import noppes.npcs.scripted.event.PlayerEvent.DamagedEntityEvent;
|
|
|
|
|
import noppes.npcs.scripted.event.PlayerEvent.KeyPressedEvent;
|
|
|
|
|
import noppes.npcs.scripted.event.PlayerEvent.LevelUpEvent;
|
|
|
|
|
import noppes.npcs.scripted.event.PlayerEvent.LoginEvent;
|
|
|
|
|
import noppes.npcs.scripted.event.PlayerEvent.LogoutEvent;
|
|
|
|
|
import noppes.npcs.scripted.event.PlayerEvent.PickUpEvent;
|
|
|
|
|
import noppes.npcs.scripted.event.PlayerEvent.TossEvent;
|
|
|
|
|
import noppes.npcs.scripted.wrapper.WrapperNpcAPI;
|
|
|
|
|
import noppes.npcs.constants.EnumScriptType;
|
2021-09-30 21:44:30 -05:00
|
|
|
import noppes.npcs.controllers.PlayerData;
|
2021-10-11 06:49:30 -05:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2021-09-30 00:56:49 -05:00
|
|
|
|
|
|
|
|
public class EventHooks {
|
|
|
|
|
public EventHooks() {
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static void onForgeInit(IScriptHandler handler) {
|
2021-09-30 00:56:49 -05:00
|
|
|
noppes.npcs.scripted.event.ForgeEvent.InitEvent event = new noppes.npcs.scripted.event.ForgeEvent.InitEvent();
|
2021-10-11 06:49:30 -05:00
|
|
|
handler.callScript(EnumScriptType.INIT, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static void onPlayerInit(PlayerDataScript handler) {
|
2021-09-30 00:56:49 -05:00
|
|
|
noppes.npcs.scripted.event.PlayerEvent.InitEvent event = new noppes.npcs.scripted.event.PlayerEvent.InitEvent(handler.getPlayer());
|
2021-10-11 06:49:30 -05:00
|
|
|
handler.callScript(EnumScriptType.INIT, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static void onPlayerTick(PlayerDataScript handler) {
|
2021-09-30 00:56:49 -05:00
|
|
|
noppes.npcs.scripted.event.PlayerEvent.UpdateEvent event = new noppes.npcs.scripted.event.PlayerEvent.UpdateEvent(handler.getPlayer());
|
2021-10-11 06:49:30 -05:00
|
|
|
handler.callScript(EnumScriptType.TICK, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static boolean onPlayerInteract(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.InteractEvent event) {
|
|
|
|
|
handler.callScript(EnumScriptType.INTERACT, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
return WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static boolean onPlayerAttack(PlayerDataScript handler, AttackEvent event) {
|
|
|
|
|
handler.callScript(EnumScriptType.ATTACK, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
return WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static boolean onPlayerToss(PlayerDataScript handler, EntityItem entityItem) {
|
2021-09-30 21:44:30 -05:00
|
|
|
TossEvent event = new TossEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.getEntityItem()));
|
2021-10-11 06:49:30 -05:00
|
|
|
handler.callScript(EnumScriptType.TOSS, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
return WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static void onPlayerLevelUp(PlayerDataScript handler, int change) {
|
2021-09-30 00:56:49 -05:00
|
|
|
LevelUpEvent event = new LevelUpEvent(handler.getPlayer(), change);
|
2021-10-11 06:49:30 -05:00
|
|
|
handler.callScript(EnumScriptType.LEVEL_UP, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static boolean onPlayerPickUp(PlayerDataScript handler, EntityItem entityItem) {
|
2021-09-30 21:44:30 -05:00
|
|
|
PickUpEvent event = new PickUpEvent(handler.getPlayer(), NpcAPI.Instance().getIItemStack(entityItem.getEntityItem()));
|
2021-10-11 06:49:30 -05:00
|
|
|
handler.callScript(EnumScriptType.PICKUP, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
return WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static void onPlayerContainerOpen(PlayerDataScript handler, Container container) {
|
2021-09-30 00:56:49 -05:00
|
|
|
ContainerOpen event = new ContainerOpen(handler.getPlayer(), NpcAPI.Instance().getIContainer(container));
|
2021-10-11 06:49:30 -05:00
|
|
|
handler.callScript(EnumScriptType.CONTAINER_OPEN, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static void onPlayerContainerClose(PlayerDataScript handler, Container container) {
|
2021-09-30 00:56:49 -05:00
|
|
|
ContainerClosed event = new ContainerClosed(handler.getPlayer(), NpcAPI.Instance().getIContainer(container));
|
2021-10-11 06:49:30 -05:00
|
|
|
handler.callScript(EnumScriptType.CONTAINER_CLOSED, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static void onPlayerDeath(PlayerDataScript handler, DamageSource source, Entity entity) {
|
2021-09-30 00:56:49 -05:00
|
|
|
noppes.npcs.scripted.event.PlayerEvent.DiedEvent event = new noppes.npcs.scripted.event.PlayerEvent.DiedEvent(handler.getPlayer(), source, entity);
|
2021-10-11 06:49:30 -05:00
|
|
|
handler.callScript(EnumScriptType.KILLED, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static void onPlayerKills(PlayerDataScript handler, EntityLivingBase entityLiving) {
|
2021-09-30 00:56:49 -05:00
|
|
|
noppes.npcs.scripted.event.PlayerEvent.KilledEntityEvent event = new noppes.npcs.scripted.event.PlayerEvent.KilledEntityEvent(handler.getPlayer(), entityLiving);
|
2021-10-11 06:49:30 -05:00
|
|
|
handler.callScript(EnumScriptType.KILLS, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static boolean onPlayerDamaged(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.DamagedEvent event) {
|
|
|
|
|
handler.callScript(EnumScriptType.DAMAGED, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
return WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static void onPlayerLogin(PlayerDataScript handler) {
|
2021-09-30 00:56:49 -05:00
|
|
|
LoginEvent event = new LoginEvent(handler.getPlayer());
|
2021-10-11 06:49:30 -05:00
|
|
|
handler.callScript(EnumScriptType.LOGIN, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static void onPlayerLogout(PlayerDataScript handler) {
|
2021-09-30 00:56:49 -05:00
|
|
|
LogoutEvent event = new LogoutEvent(handler.getPlayer());
|
2021-10-11 06:49:30 -05:00
|
|
|
handler.callScript(EnumScriptType.LOGOUT, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static void onPlayerChat(PlayerDataScript handler, ChatEvent event) {
|
|
|
|
|
handler.callScript(EnumScriptType.CHAT, event, "message", event.message);
|
2021-09-30 00:56:49 -05:00
|
|
|
WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static boolean onPlayerRanged(PlayerDataScript handler, noppes.npcs.scripted.event.PlayerEvent.RangedLaunchedEvent event) {
|
|
|
|
|
handler.callScript(EnumScriptType.RANGED_LAUNCHED, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
return WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-11 06:49:30 -05:00
|
|
|
public static boolean onPlayerDamagedEntity(PlayerDataScript handler, DamagedEntityEvent event) {
|
|
|
|
|
handler.callScript(EnumScriptType.DAMAGED_ENTITY, event);
|
2021-09-30 00:56:49 -05:00
|
|
|
return WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void onPlayerKeyPressed(EntityPlayerMP player, int button, boolean isCtrlPressed, boolean isShiftPressed, boolean isAltPressed, boolean isMetaPressed) {
|
2021-10-11 06:49:30 -05:00
|
|
|
PlayerDataScript handler = PlayerData.get(player).scriptData;
|
2021-09-30 00:56:49 -05:00
|
|
|
KeyPressedEvent event = new KeyPressedEvent(handler.getPlayer(), button, isCtrlPressed, isAltPressed, isShiftPressed, isMetaPressed);
|
2021-10-11 07:16:10 -05:00
|
|
|
handler.callScript(EnumScriptType.KEY_PRESSED, event, "key", button, "isCtrlPressed", isCtrlPressed, "isAltPressed", isAltPressed, "isShiftPressed", isShiftPressed, "isMetaPressed", isMetaPressed);
|
2021-09-30 00:56:49 -05:00
|
|
|
WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
2021-10-11 06:49:30 -05:00
|
|
|
|
|
|
|
|
public static void onPlayerTimer(PlayerData data, int id) {
|
|
|
|
|
PlayerDataScript handler = data.scriptData;
|
|
|
|
|
noppes.npcs.scripted.event.PlayerEvent.TimerEvent event = new noppes.npcs.scripted.event.PlayerEvent.TimerEvent(handler.getPlayer(), id);
|
|
|
|
|
handler.callScript(EnumScriptType.TIMER, event);
|
|
|
|
|
WrapperNpcAPI.EVENT_BUS.post(event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void onForgeEntityEvent(EntityEvent event) {
|
|
|
|
|
IEntity e = NpcAPI.Instance().getIEntity(event.entity);
|
|
|
|
|
onForgeEvent(new noppes.npcs.scripted.event.ForgeEvent.EntityEvent(event, e), event);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void onForgeEvent(ForgeEvent ev, Event event) {
|
|
|
|
|
ForgeDataScript data = ScriptController.Instance.forgeScripts;
|
|
|
|
|
if(data.isEnabled()) {
|
|
|
|
|
String eventName = event.getClass().getName();
|
|
|
|
|
int i = eventName.lastIndexOf(".");
|
|
|
|
|
eventName = StringUtils.uncapitalize(eventName.substring(i + 1).replace("$", ""));
|
|
|
|
|
if(event.isCancelable()) {
|
|
|
|
|
ev.setCanceled(event.isCanceled());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
data.callScript(eventName, event);
|
|
|
|
|
WrapperNpcAPI.EVENT_BUS.post(ev);
|
|
|
|
|
if(event.isCancelable()) {
|
|
|
|
|
event.setCanceled(ev.isCanceled());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void onForgeWorldEvent(WorldEvent event) {
|
|
|
|
|
if(ScriptController.Instance.forgeScripts.isEnabled()) {
|
|
|
|
|
IWorld e = NpcAPI.Instance().getIWorld((WorldServer)event.world);
|
|
|
|
|
onForgeEvent(new noppes.npcs.scripted.event.ForgeEvent.WorldEvent(event, e), event);
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-30 00:56:49 -05:00
|
|
|
}
|