2018-09-13 12:03:28 -04:00
|
|
|
package noppes.npcs;
|
|
|
|
|
|
2022-11-07 01:49:54 -05:00
|
|
|
import cpw.mods.fml.common.FMLCommonHandler;
|
2018-09-13 12:03:28 -04:00
|
|
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
2022-11-07 01:49:54 -05:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
2025-01-30 09:26:10 -05:00
|
|
|
import kamkeel.npcs.controllers.SyncController;
|
2025-01-30 01:35:48 -05:00
|
|
|
import kamkeel.npcs.network.PacketHandler;
|
|
|
|
|
import kamkeel.npcs.network.enums.EnumSoundOperation;
|
2025-01-30 09:22:43 -05:00
|
|
|
import kamkeel.npcs.network.enums.EnumSyncAction;
|
|
|
|
|
import kamkeel.npcs.network.enums.EnumSyncType;
|
2025-02-12 12:15:33 -06:00
|
|
|
import kamkeel.npcs.network.packets.data.ClonerPacket;
|
2025-01-30 13:54:49 -05:00
|
|
|
import kamkeel.npcs.network.packets.data.MarkDataPacket;
|
|
|
|
|
import kamkeel.npcs.network.packets.data.SoundManagementPacket;
|
|
|
|
|
import kamkeel.npcs.network.packets.data.VillagerListPacket;
|
|
|
|
|
import kamkeel.npcs.network.packets.data.gui.GuiOpenPacket;
|
|
|
|
|
import kamkeel.npcs.network.packets.data.large.SyncPacket;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraft.block.Block;
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
|
import net.minecraft.entity.EntityList;
|
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
|
import net.minecraft.entity.passive.EntityVillager;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
|
import net.minecraft.server.MinecraftServer;
|
|
|
|
|
import net.minecraft.util.ChatComponentTranslation;
|
|
|
|
|
import net.minecraft.util.MathHelper;
|
|
|
|
|
import net.minecraft.util.StatCollector;
|
|
|
|
|
import net.minecraft.village.MerchantRecipeList;
|
|
|
|
|
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
|
2026-02-20 18:16:52 -05:00
|
|
|
import kamkeel.npcs.entity.EntityEnergyBarrier;
|
2024-01-22 12:04:09 -06:00
|
|
|
import net.minecraftforge.event.entity.living.LivingAttackEvent;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraftforge.event.entity.living.LivingDeathEvent;
|
2025-02-12 12:15:33 -06:00
|
|
|
import net.minecraftforge.event.entity.living.LivingEvent;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraftforge.event.entity.living.LivingHurtEvent;
|
|
|
|
|
import net.minecraftforge.event.entity.player.EntityInteractEvent;
|
2022-11-11 15:15:42 -03:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
2018-09-13 12:03:28 -04:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
|
|
|
|
import net.minecraftforge.event.terraingen.PopulateChunkEvent;
|
2025-02-14 17:00:22 -05:00
|
|
|
import noppes.npcs.blocks.tiles.ITileIcon;
|
2023-01-07 00:21:08 -05:00
|
|
|
import noppes.npcs.config.ConfigDebug;
|
|
|
|
|
import noppes.npcs.config.ConfigMain;
|
2025-02-20 21:40:39 -05:00
|
|
|
import noppes.npcs.constants.EnumGuiType;
|
|
|
|
|
import noppes.npcs.constants.EnumPartyObjectives;
|
|
|
|
|
import noppes.npcs.constants.EnumQuestType;
|
|
|
|
|
import noppes.npcs.constants.EnumRoleType;
|
2024-03-02 21:06:42 -05:00
|
|
|
import noppes.npcs.controllers.PartyController;
|
2023-01-12 21:33:06 -05:00
|
|
|
import noppes.npcs.controllers.ServerCloneController;
|
2025-07-23 14:22:52 -04:00
|
|
|
import noppes.npcs.controllers.data.Animation;
|
|
|
|
|
import noppes.npcs.controllers.data.AnimationData;
|
|
|
|
|
import noppes.npcs.controllers.data.Line;
|
|
|
|
|
import noppes.npcs.controllers.data.MarkData;
|
|
|
|
|
import noppes.npcs.controllers.data.Party;
|
|
|
|
|
import noppes.npcs.controllers.data.PlayerData;
|
|
|
|
|
import noppes.npcs.controllers.data.PlayerQuestData;
|
|
|
|
|
import noppes.npcs.controllers.data.Quest;
|
|
|
|
|
import noppes.npcs.controllers.data.QuestData;
|
2018-09-13 12:03:28 -04:00
|
|
|
import noppes.npcs.entity.EntityNPCInterface;
|
|
|
|
|
import noppes.npcs.items.ItemExcalibur;
|
|
|
|
|
import noppes.npcs.items.ItemShield;
|
|
|
|
|
import noppes.npcs.items.ItemSoulstoneEmpty;
|
|
|
|
|
import noppes.npcs.quests.QuestKill;
|
|
|
|
|
import noppes.npcs.roles.RoleFollower;
|
|
|
|
|
|
2023-01-12 21:33:06 -05:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
2018-09-13 12:03:28 -04:00
|
|
|
public class ServerEventsHandler {
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
public static EntityVillager Merchant;
|
|
|
|
|
public static Entity mounted;
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void invoke(EntityInteractEvent event) {
|
|
|
|
|
ItemStack item = event.entityPlayer.getCurrentEquippedItem();
|
|
|
|
|
if (item == null)
|
|
|
|
|
return;
|
|
|
|
|
boolean isRemote = event.entityPlayer.worldObj.isRemote;
|
|
|
|
|
boolean npcInteracted = event.target instanceof EntityNPCInterface;
|
|
|
|
|
|
|
|
|
|
if (!isRemote && ConfigMain.OpsOnly && !MinecraftServer.getServer().getConfigurationManager().func_152596_g(event.entityPlayer.getGameProfile())) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isRemote && item.getItem() == CustomItems.soulstoneEmpty) {
|
|
|
|
|
if (event.target instanceof EntityLivingBase) {
|
|
|
|
|
((ItemSoulstoneEmpty) item.getItem()).store((EntityLivingBase) event.target, item, event.entityPlayer);
|
|
|
|
|
if (ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
2025-03-12 20:03:08 -04:00
|
|
|
LogWriter.script(String.format("[%s] (Player) %s PICKED ENTITY %s", "SOULSTONE", event.entityPlayer.getCommandSenderName(), event.target));
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (item.getItem() == CustomItems.wand && npcInteracted && !isRemote) {
|
|
|
|
|
if (!CustomNpcsPermissions.hasPermission(event.entityPlayer, CustomNpcsPermissions.NPC_GUI)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
NoppesUtilServer.sendOpenGui(event.entityPlayer, EnumGuiType.MainMenuDisplay, (EntityNPCInterface) event.target);
|
|
|
|
|
if (ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
|
|
|
|
LogWriter.script(String.format("[%s] (Player) %s OPEN NPC %s (%s, %s, %s) [%s]", "WAND", event.entityPlayer.getCommandSenderName(), ((EntityNPCInterface) (event.target)).display.getName(), (int) (event.target).posX, (int) (event.target).posY, (int) (event.target).posZ, (event.target).worldObj.getWorldInfo().getWorldName()));
|
|
|
|
|
}
|
|
|
|
|
} else if (item.getItem() == CustomItems.cloner && !isRemote && !(event.target instanceof EntityPlayer)) {
|
|
|
|
|
if (!CustomNpcsPermissions.hasPermission(event.entityPlayer, CustomNpcsPermissions.TOOL_CLONER))
|
|
|
|
|
return;
|
|
|
|
|
NBTTagCompound compound = new NBTTagCompound();
|
|
|
|
|
if (!event.target.writeToNBTOptional(compound))
|
|
|
|
|
return;
|
2025-04-08 22:48:32 -04:00
|
|
|
PlayerData data = PlayerData.get(event.entityPlayer);
|
2025-03-13 17:14:45 -04:00
|
|
|
ServerCloneController.Instance.cleanTags(compound);
|
|
|
|
|
PacketHandler.Instance.sendToPlayer(new ClonerPacket(compound), (EntityPlayerMP) event.entityPlayer);
|
|
|
|
|
data.cloned = compound;
|
|
|
|
|
if (event.target instanceof EntityNPCInterface) {
|
|
|
|
|
NoppesUtilServer.setEditingNpc(event.entityPlayer, (EntityNPCInterface) event.target);
|
|
|
|
|
}
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
} else if (item.getItem() == CustomItems.scripter && !isRemote && npcInteracted) {
|
|
|
|
|
if (!CustomNpcsPermissions.hasPermission(event.entityPlayer, CustomNpcsPermissions.TOOL_SCRIPTER))
|
|
|
|
|
return;
|
|
|
|
|
NoppesUtilServer.setEditingNpc(event.entityPlayer, (EntityNPCInterface) event.target);
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
GuiOpenPacket.openGUI((EntityPlayerMP) event.entityPlayer, EnumGuiType.Script, 0, 0, 0);
|
|
|
|
|
if (ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
|
|
|
|
|
LogWriter.script(String.format("[%s] (Player) %s OPEN NPC %s (%s, %s, %s) [%s]", "SCRIPTER", event.entityPlayer.getCommandSenderName(), ((EntityNPCInterface) (event.target)).display.getName(), (int) (event.target).posX, (int) (event.target).posY, (int) (event.target).posZ, (event.target).worldObj.getWorldInfo().getWorldName()));
|
|
|
|
|
}
|
|
|
|
|
} else if (item.getItem() == CustomItems.mount) {
|
|
|
|
|
if (!CustomNpcsPermissions.hasPermission(event.entityPlayer, CustomNpcsPermissions.TOOL_MOUNTER))
|
2024-02-19 19:14:51 -05:00
|
|
|
return;
|
2025-03-13 17:14:45 -04:00
|
|
|
event.setCanceled(true);
|
|
|
|
|
mounted = event.target;
|
|
|
|
|
if (isRemote)
|
|
|
|
|
CustomNpcs.proxy.openGui(MathHelper.floor_double(mounted.posX), MathHelper.floor_double(mounted.posY), MathHelper.floor_double(mounted.posZ), EnumGuiType.MobSpawnerMounter, event.entityPlayer);
|
|
|
|
|
} else if (item.getItem() == CustomItems.wand && !isRemote && event.target instanceof EntityVillager) {
|
|
|
|
|
if (!CustomNpcsPermissions.hasPermission(event.entityPlayer, CustomNpcsPermissions.EDIT_VILLAGER))
|
|
|
|
|
return;
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
Merchant = (EntityVillager) event.target;
|
|
|
|
|
|
|
|
|
|
if (!isRemote) {
|
|
|
|
|
EntityPlayerMP player = (EntityPlayerMP) event.entityPlayer;
|
|
|
|
|
player.openGui(CustomNpcs.instance, EnumGuiType.MerchantAdd.ordinal(), player.worldObj, 0, 0, 0);
|
|
|
|
|
MerchantRecipeList merchantrecipelist = Merchant.getRecipes(player);
|
|
|
|
|
|
|
|
|
|
if (merchantrecipelist != null) {
|
2025-01-30 12:16:11 -05:00
|
|
|
PacketHandler.Instance.sendToPlayer(new VillagerListPacket(merchantrecipelist), player);
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-22 12:04:09 -06:00
|
|
|
|
2026-02-20 18:16:52 -05:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void barrierDamageProtection(LivingAttackEvent event) {
|
|
|
|
|
if (event.entityLiving == null || event.entityLiving.worldObj == null || event.entityLiving.worldObj.isRemote)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
EntityEnergyBarrier barrier = EntityEnergyBarrier.getProtectingBarrier(event.entityLiving);
|
|
|
|
|
if (barrier != null && barrier.isDamageFromOutside(event.source)) {
|
|
|
|
|
// Redirect the damage to the barrier instead of preventing it
|
|
|
|
|
barrier.absorbDamage(event.ammount);
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void domeItemBlacklist(PlayerInteractEvent event) {
|
|
|
|
|
if (event.action == PlayerInteractEvent.Action.LEFT_CLICK_BLOCK) return;
|
|
|
|
|
EntityPlayer player = event.entityPlayer;
|
|
|
|
|
if (player == null || player.worldObj == null || player.worldObj.isRemote) return;
|
|
|
|
|
|
|
|
|
|
ItemStack held = player.getHeldItem();
|
|
|
|
|
if (held == null) return;
|
|
|
|
|
|
|
|
|
|
String itemId = net.minecraft.item.Item.itemRegistry.getNameForObject(held.getItem());
|
|
|
|
|
if (itemId == null) return;
|
|
|
|
|
|
|
|
|
|
String[] blacklist = noppes.npcs.config.ConfigEnergy.DomeItemBlacklist;
|
|
|
|
|
if (blacklist == null) return;
|
|
|
|
|
|
|
|
|
|
boolean blacklisted = false;
|
|
|
|
|
for (String banned : blacklist) {
|
|
|
|
|
if (banned.equals(itemId)) {
|
|
|
|
|
blacklisted = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!blacklisted) return;
|
|
|
|
|
|
|
|
|
|
List<EntityEnergyBarrier> barriers = EntityEnergyBarrier.getActiveBarriers(player.worldObj);
|
|
|
|
|
for (EntityEnergyBarrier barrier : barriers) {
|
|
|
|
|
if (barrier instanceof kamkeel.npcs.entity.EntityEnergyDome && barrier.isEntityInside(player)) {
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void partyDamagedEvent(LivingAttackEvent event) {
|
|
|
|
|
if (!(event.source != null && event.source.getEntity() instanceof EntityPlayer) || !(event.entityLiving instanceof EntityPlayer) || FMLCommonHandler.instance().getEffectiveSide().isClient())
|
|
|
|
|
return;
|
2024-03-07 22:24:00 -05:00
|
|
|
|
2024-03-07 22:23:44 -05:00
|
|
|
// Check for Friendly Fire
|
2025-03-13 17:14:45 -04:00
|
|
|
if (ConfigMain.PartyFriendlyFireEnabled) {
|
2024-03-17 16:08:19 -04:00
|
|
|
EntityPlayer sourcePlayer = (EntityPlayer) event.source.getEntity();
|
2025-04-08 22:48:32 -04:00
|
|
|
PlayerData playerData = PlayerData.get(sourcePlayer);
|
|
|
|
|
PlayerData targetData = PlayerData.get((EntityPlayer) event.entityLiving);
|
2024-03-17 16:08:19 -04:00
|
|
|
if (playerData.partyUUID != null && playerData.partyUUID.equals(targetData.partyUUID)) {
|
|
|
|
|
Party party = PartyController.Instance().getParty(playerData.partyUUID);
|
2025-03-13 17:14:45 -04:00
|
|
|
if (party != null && !party.friendlyFire())
|
2024-03-17 16:08:19 -04:00
|
|
|
event.setCanceled(true);
|
|
|
|
|
}
|
2024-03-07 22:23:44 -05:00
|
|
|
}
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void invoke(LivingHurtEvent event) {
|
|
|
|
|
if (!(event.entityLiving instanceof EntityPlayer))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
EntityPlayer player = (EntityPlayer) event.entityLiving;
|
|
|
|
|
if (event.source.isUnblockable() || event.source.isFireDamage())
|
|
|
|
|
return;
|
|
|
|
|
if (!player.isBlocking())
|
|
|
|
|
return;
|
|
|
|
|
ItemStack item = player.getCurrentEquippedItem();
|
|
|
|
|
if (item == null || !(item.getItem() instanceof ItemShield))
|
|
|
|
|
return;
|
|
|
|
|
if (((ItemShield) item.getItem()).material.getDamageVsEntity() < player.getRNG().nextInt(9))
|
|
|
|
|
return;
|
|
|
|
|
float damage = item.getItemDamage() + event.ammount;
|
|
|
|
|
|
|
|
|
|
item.damageItem((int) event.ammount, player);
|
|
|
|
|
|
|
|
|
|
if (damage > item.getMaxDamage())
|
|
|
|
|
event.ammount = damage - item.getMaxDamage();
|
|
|
|
|
else {
|
|
|
|
|
event.ammount = 0;
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void invoke(PlayerInteractEvent event) {
|
|
|
|
|
EntityPlayer player = event.entityPlayer;
|
|
|
|
|
Block block = player.worldObj.getBlock(event.x, event.y, event.z);
|
|
|
|
|
if (event.action == Action.LEFT_CLICK_BLOCK && player.getHeldItem() != null && player.getHeldItem().getItem() == CustomItems.teleporter) {
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (block == Blocks.crafting_table && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) {
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
2025-01-30 09:22:43 -05:00
|
|
|
EnumSyncType.WORKBENCH_RECIPES,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
2025-10-19 22:06:11 -04:00
|
|
|
SyncController.getCurrentRevision(EnumSyncType.WORKBENCH_RECIPES),
|
2025-01-30 09:26:10 -05:00
|
|
|
SyncController.workbenchNBT()
|
2025-01-30 09:22:43 -05:00
|
|
|
), (EntityPlayerMP) player);
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
if (block == CustomItems.carpentyBench && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) {
|
2025-01-30 13:54:49 -05:00
|
|
|
PacketHandler.Instance.sendToPlayer(new SyncPacket(
|
2025-01-30 09:22:43 -05:00
|
|
|
EnumSyncType.CARPENTRY_RECIPES,
|
|
|
|
|
EnumSyncAction.RELOAD,
|
|
|
|
|
-1,
|
2025-10-19 22:06:11 -04:00
|
|
|
SyncController.getCurrentRevision(EnumSyncType.CARPENTRY_RECIPES),
|
2025-01-30 09:26:10 -05:00
|
|
|
SyncController.carpentryNBT()
|
2025-01-30 09:22:43 -05:00
|
|
|
), (EntityPlayerMP) player);
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
if ((block == CustomItems.banner || block == CustomItems.wallBanner || block == CustomItems.sign) && event.action == Action.RIGHT_CLICK_BLOCK) {
|
|
|
|
|
ItemStack item = player.inventory.getCurrentItem();
|
|
|
|
|
if (item == null || item.getItem() == null)
|
|
|
|
|
return;
|
|
|
|
|
int y = event.y;
|
|
|
|
|
int meta = player.worldObj.getBlockMetadata(event.x, event.y, event.z);
|
|
|
|
|
if (meta >= 7)
|
|
|
|
|
y--;
|
|
|
|
|
ITileIcon tile = (ITileIcon) player.worldObj.getTileEntity(event.x, y, event.z);
|
|
|
|
|
if (!tile.canEdit()) {
|
|
|
|
|
if (item.getItem() == CustomItems.wand && CustomNpcsPermissions.hasPermission(player, CustomNpcsPermissions.EDIT_BLOCKS)) {
|
|
|
|
|
tile.setTime(System.currentTimeMillis());
|
|
|
|
|
if (player.worldObj.isRemote)
|
|
|
|
|
player.addChatComponentMessage(new ChatComponentTranslation("availability.editIcon"));
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!player.worldObj.isRemote) {
|
|
|
|
|
tile.setIcon(item.copy());
|
|
|
|
|
player.worldObj.markBlockForUpdate(event.x, y, event.z);
|
|
|
|
|
event.setCanceled(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void invoke(LivingDeathEvent event) {
|
|
|
|
|
if (event.entityLiving.worldObj.isRemote)
|
|
|
|
|
return;
|
|
|
|
|
if (event.source.getEntity() != null) {
|
|
|
|
|
if (event.source.getEntity() instanceof EntityPlayer) {
|
|
|
|
|
doExcalibur((EntityPlayer) event.source.getEntity(), event.entityLiving);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.source.getEntity() instanceof EntityNPCInterface) {
|
|
|
|
|
EntityNPCInterface npc = (EntityNPCInterface) event.source.getEntity();
|
|
|
|
|
Line line = npc.advanced.getKillLine();
|
|
|
|
|
if (line != null)
|
|
|
|
|
npc.saySurrounding(line.formatTarget(event.entityLiving));
|
|
|
|
|
|
|
|
|
|
EventHooks.onNPCKilledEntity(npc, event.entityLiving);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EntityPlayer player = null;
|
|
|
|
|
if (event.source.getEntity() instanceof EntityPlayer)
|
|
|
|
|
player = (EntityPlayer) event.source.getEntity();
|
|
|
|
|
else if (event.source.getEntity() instanceof EntityNPCInterface && ((EntityNPCInterface) event.source.getEntity()).advanced.role == EnumRoleType.Follower)
|
|
|
|
|
player = ((RoleFollower) ((EntityNPCInterface) event.source.getEntity()).roleInterface).owner;
|
|
|
|
|
if (player != null) {
|
|
|
|
|
doQuest(player, event.entityLiving, true);
|
|
|
|
|
|
|
|
|
|
if (event.entityLiving instanceof EntityNPCInterface)
|
|
|
|
|
doFactionPoints(player, (EntityNPCInterface) event.entityLiving);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (event.entityLiving instanceof EntityPlayer) {
|
2025-04-08 22:48:32 -04:00
|
|
|
PlayerData data = PlayerData.get((EntityPlayer) event.entityLiving);
|
2025-03-13 17:14:45 -04:00
|
|
|
data.save();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void onPlayerClone(PlayerEvent.Clone event) {
|
|
|
|
|
if (event.entity.worldObj.isRemote)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
NBTTagCompound storedData = event.original.getEntityData().getCompoundTag("CNPCStoredData");
|
|
|
|
|
if (!storedData.hasNoTags()) {
|
|
|
|
|
event.entityPlayer.getEntityData().setTag("CNPCStoredData", storedData);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-07 05:22:49 -04:00
|
|
|
@SubscribeEvent
|
2025-07-07 05:58:38 -04:00
|
|
|
public void onPlayerRespawn(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerRespawnEvent event) {
|
2025-07-07 05:22:49 -04:00
|
|
|
if (event.player == null || event.player.worldObj == null || event.player.worldObj.isRemote)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
PlayerData data = PlayerData.get(event.player);
|
|
|
|
|
data.setGUIOpen(false);
|
|
|
|
|
data.editingNpc = null;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
private void doExcalibur(EntityPlayer player, EntityLivingBase entity) {
|
|
|
|
|
ItemStack item = player.getCurrentEquippedItem();
|
|
|
|
|
if (item == null || item.getItem() != CustomItems.excalibur)
|
|
|
|
|
return;
|
|
|
|
|
PacketHandler.Instance.sendToPlayer(new SoundManagementPacket(EnumSoundOperation.PLAY_MUSIC, "customnpcs:songs.excalibur"), (EntityPlayerMP) player);
|
|
|
|
|
player.addChatMessage(new ChatComponentTranslation("<" + StatCollector.translateToLocal(item.getItem().getUnlocalizedName() + ".name") + "> " + ItemExcalibur.quotes[player.getRNG().nextInt(ItemExcalibur.quotes.length)]));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void doFactionPoints(EntityPlayer player, EntityNPCInterface npc) {
|
|
|
|
|
npc.advanced.factions.addPoints(player);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void doQuest(EntityPlayer player, EntityLivingBase entity, boolean all) {
|
2024-03-07 22:22:39 -05:00
|
|
|
PlayerData playerData = PlayerData.get(player);
|
2024-10-12 14:01:49 -04:00
|
|
|
if (playerData == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PlayerQuestData questData = playerData.questData;
|
|
|
|
|
if (questData == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
boolean checkCompletion = false;
|
2024-03-02 21:06:42 -05:00
|
|
|
String entityName = EntityList.getEntityString(entity);
|
2025-03-13 17:14:45 -04:00
|
|
|
if (entity instanceof EntityPlayer)
|
2024-12-21 15:51:37 -05:00
|
|
|
entityName = "Player";
|
2024-03-02 21:06:42 -05:00
|
|
|
|
2024-03-04 03:03:23 -05:00
|
|
|
Party party = playerData.getPlayerParty();
|
|
|
|
|
Quest partyQuest = null;
|
2025-03-13 17:14:45 -04:00
|
|
|
if (party != null) {
|
|
|
|
|
if (party.getQuestData() != null) {
|
2024-03-04 03:03:23 -05:00
|
|
|
partyQuest = party.getQuestData().quest;
|
2025-03-13 17:14:45 -04:00
|
|
|
if (partyQuest != null && (partyQuest.type == EnumQuestType.Kill || partyQuest.type == EnumQuestType.AreaKill))
|
2024-03-04 03:03:23 -05:00
|
|
|
doPartyQuest(player, party, entity);
|
|
|
|
|
else
|
|
|
|
|
partyQuest = null;
|
2024-03-02 21:06:42 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-04 03:03:23 -05:00
|
|
|
ArrayList<QuestData> activeQuestValues = new ArrayList<>(questData.activeQuests.values());
|
2025-03-13 17:14:45 -04:00
|
|
|
for (QuestData data : activeQuestValues) {
|
2024-10-12 14:01:49 -04:00
|
|
|
if (data.quest == null) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (data.quest.type != EnumQuestType.Kill && data.quest.type != EnumQuestType.AreaKill)
|
|
|
|
|
continue;
|
2023-03-16 23:37:57 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (partyQuest != null && partyQuest.getId() == data.quest.getId())
|
2024-03-04 03:03:23 -05:00
|
|
|
continue;
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (data.quest.partyOptions.allowParty && data.quest.partyOptions.onlyParty)
|
2024-03-04 05:17:27 -05:00
|
|
|
continue;
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (data.quest.type == EnumQuestType.AreaKill && all) {
|
2024-03-04 03:04:38 -05:00
|
|
|
List<EntityPlayer> list = player.worldObj.getEntitiesWithinAABB(EntityPlayer.class, entity.boundingBox.expand(10, 10, 10));
|
2025-03-13 17:14:45 -04:00
|
|
|
for (EntityPlayer pl : list)
|
|
|
|
|
if (pl != player)
|
2024-03-04 03:04:38 -05:00
|
|
|
doQuest(pl, entity, false);
|
|
|
|
|
|
|
|
|
|
}
|
2024-03-03 05:53:54 -05:00
|
|
|
|
2024-10-12 14:01:49 -04:00
|
|
|
String name = entityName;
|
2025-03-13 17:14:45 -04:00
|
|
|
QuestKill quest = (QuestKill) data.quest.questInterface;
|
|
|
|
|
Class entityType = EntityNPCInterface.class;
|
|
|
|
|
if (quest.targetType == 2) {
|
|
|
|
|
try {
|
|
|
|
|
entityType = Class.forName(quest.customTargetType);
|
|
|
|
|
} catch (ClassNotFoundException notFoundException) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (quest.targetType > 0 && !(entityType.isInstance(entity)))
|
|
|
|
|
continue;
|
2023-03-16 23:37:57 -05:00
|
|
|
|
2024-10-12 14:01:49 -04:00
|
|
|
if (entity.getCommandSenderName() != null && quest.targets != null && quest.targets.containsKey(entity.getCommandSenderName())) {
|
|
|
|
|
name = entity.getCommandSenderName();
|
|
|
|
|
} else if (entity.getCommandSenderName() == null || quest.targets == null || !quest.targets.containsKey(name)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2023-03-16 23:37:57 -05:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
checkCompletion = true;
|
2023-03-16 23:37:57 -05:00
|
|
|
|
2024-10-12 14:01:49 -04:00
|
|
|
HashMap<String, Integer> killed = quest.getKilled(data);
|
2025-03-13 17:14:45 -04:00
|
|
|
if (!killed.containsKey(name)) {
|
|
|
|
|
killed.put(name, 1);
|
|
|
|
|
} else if (killed.get(name) < quest.targets.get(name)) {
|
|
|
|
|
int amount = killed.get(name);
|
|
|
|
|
killed.put(name, amount + 1);
|
|
|
|
|
}
|
|
|
|
|
quest.setKilled(data, killed);
|
2024-03-07 22:22:39 -05:00
|
|
|
playerData.updateClient = true;
|
2025-03-13 17:14:45 -04:00
|
|
|
}
|
|
|
|
|
if (!checkCompletion)
|
|
|
|
|
return;
|
2021-12-22 03:33:50 -06:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
questData.checkQuestCompletion(playerData, EnumQuestType.Kill);
|
|
|
|
|
}
|
2018-09-13 12:03:28 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
private void doPartyQuest(EntityPlayer player, Party party, EntityLivingBase entity) {
|
2024-03-07 22:22:39 -05:00
|
|
|
PlayerData pdata = PlayerData.get(player);
|
2024-03-04 03:03:23 -05:00
|
|
|
QuestData data = party.getQuestData();
|
2025-03-13 17:14:45 -04:00
|
|
|
if (data == null)
|
2024-03-04 03:03:23 -05:00
|
|
|
return;
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (pdata == null)
|
2024-03-07 22:22:39 -05:00
|
|
|
return;
|
|
|
|
|
|
2024-03-04 03:03:23 -05:00
|
|
|
if (data.quest.type != EnumQuestType.Kill && data.quest.type != EnumQuestType.AreaKill)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
String name = EntityList.getEntityString(entity);
|
2025-12-19 20:39:54 +01:00
|
|
|
if (entity instanceof EntityPlayer)
|
|
|
|
|
name = "Player";
|
2024-03-04 03:03:23 -05:00
|
|
|
QuestKill quest = (QuestKill) data.quest.questInterface;
|
2025-03-13 17:14:45 -04:00
|
|
|
if (data.quest.partyOptions.objectiveRequirement == EnumPartyObjectives.Leader && !party.getLeaderUUID().equals(player.getUniqueID()))
|
2024-03-04 03:59:11 -05:00
|
|
|
return;
|
2024-03-04 03:03:23 -05:00
|
|
|
|
|
|
|
|
Class entityType = EntityNPCInterface.class;
|
|
|
|
|
if (quest.targetType == 2) {
|
|
|
|
|
try {
|
|
|
|
|
entityType = Class.forName(quest.customTargetType);
|
|
|
|
|
} catch (ClassNotFoundException notFoundException) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (quest.targetType > 0 && !(entityType.isInstance(entity)))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (quest.targets.containsKey(entity.getCommandSenderName()))
|
|
|
|
|
name = entity.getCommandSenderName();
|
|
|
|
|
else if (!quest.targets.containsKey(name))
|
|
|
|
|
return;
|
|
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
if (data.quest.partyOptions.objectiveRequirement == EnumPartyObjectives.All) {
|
2024-03-04 03:03:23 -05:00
|
|
|
HashMap<String, Integer> killed = quest.getPlayerKilled(data, player.getCommandSenderName());
|
|
|
|
|
if (!killed.containsKey(name)) {
|
|
|
|
|
killed.put(name, 1);
|
2025-03-13 17:14:45 -04:00
|
|
|
} else if (killed.get(name) < quest.targets.get(name)) {
|
2024-03-04 03:03:23 -05:00
|
|
|
int amount = killed.get(name);
|
|
|
|
|
killed.put(name, amount + 1);
|
|
|
|
|
}
|
|
|
|
|
quest.setPlayerKilled(data, killed, player.getCommandSenderName());
|
2025-03-13 17:14:45 -04:00
|
|
|
} else {
|
2024-03-04 03:03:23 -05:00
|
|
|
HashMap<String, Integer> killed = quest.getKilled(data);
|
|
|
|
|
if (!killed.containsKey(name)) {
|
|
|
|
|
killed.put(name, 1);
|
2025-03-13 17:14:45 -04:00
|
|
|
} else if (killed.get(name) < quest.targets.get(name)) {
|
2024-03-04 03:03:23 -05:00
|
|
|
int amount = killed.get(name);
|
|
|
|
|
killed.put(name, amount + 1);
|
|
|
|
|
}
|
|
|
|
|
quest.setKilled(data, killed);
|
2024-03-07 22:22:39 -05:00
|
|
|
pdata.updateClient = true;
|
2024-03-04 03:03:23 -05:00
|
|
|
}
|
|
|
|
|
|
2024-03-06 05:05:16 -05:00
|
|
|
PartyController.Instance().pingPartyQuestObjectiveUpdate(party);
|
2024-03-04 03:03:23 -05:00
|
|
|
PartyController.Instance().checkQuestCompletion(party, EnumQuestType.Kill);
|
|
|
|
|
}
|
2024-05-24 16:56:56 -04:00
|
|
|
|
2025-03-13 17:14:45 -04:00
|
|
|
@SubscribeEvent
|
|
|
|
|
public void world(PlayerEvent.SaveToFile event) {
|
2025-04-08 22:48:32 -04:00
|
|
|
PlayerData data = PlayerData.get((EntityPlayer) event.entity);
|
2025-03-13 17:14:45 -04:00
|
|
|
data.save();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void world(EntityJoinWorldEvent event) {
|
|
|
|
|
if (event.world.isRemote || !(event.entity instanceof EntityPlayer))
|
|
|
|
|
return;
|
2025-04-08 22:48:32 -04:00
|
|
|
PlayerData data = PlayerData.get((EntityPlayer) event.entity);
|
2025-03-13 17:14:45 -04:00
|
|
|
data.updateCompanion(event.world);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void populateChunk(PopulateChunkEvent.Post event) {
|
|
|
|
|
NPCSpawning.performWorldGenSpawning(event.world, event.chunkX, event.chunkZ, event.rand);
|
|
|
|
|
}
|
2024-02-21 03:02:39 -05:00
|
|
|
|
|
|
|
|
@SubscribeEvent
|
2025-03-13 17:14:45 -04:00
|
|
|
public void playerTracking(PlayerEvent.StartTracking event) {
|
|
|
|
|
if (!(event.target instanceof EntityPlayerMP || event.target instanceof EntityNPCInterface) || event.target.worldObj.isRemote)
|
2024-08-22 16:47:45 -04:00
|
|
|
return;
|
2024-02-21 03:02:39 -05:00
|
|
|
|
2025-01-23 00:35:25 -06:00
|
|
|
AnimationData animationData = AnimationData.getData(event.target);
|
2025-02-12 12:15:33 -06:00
|
|
|
if (animationData != null && animationData.isClientAnimating()) {
|
2025-01-23 00:35:25 -06:00
|
|
|
AnimationData playerAnimData = AnimationData.getData(event.entityPlayer);
|
2025-02-12 12:15:33 -06:00
|
|
|
if (playerAnimData != null) {
|
|
|
|
|
Animation currentAnimation = animationData.currentClientAnimation;
|
|
|
|
|
NBTTagCompound compound = currentAnimation.writeToNBT();
|
|
|
|
|
playerAnimData.viewAnimation(currentAnimation, animationData, compound,
|
|
|
|
|
animationData.isClientAnimating(), currentAnimation.currentFrame, currentAnimation.currentFrameTime);
|
2025-01-23 00:35:25 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (event.target instanceof EntityNPCInterface) {
|
|
|
|
|
MarkData data = MarkData.get((EntityNPCInterface) event.target);
|
|
|
|
|
if (data.marks.isEmpty())
|
|
|
|
|
return;
|
2025-03-13 17:14:45 -04:00
|
|
|
PacketHandler.Instance.sendToPlayer(new MarkDataPacket(event.target.getEntityId(), data.getNBT()), (EntityPlayerMP) event.entityPlayer);
|
2025-01-23 00:35:25 -06:00
|
|
|
}
|
2024-02-21 03:02:39 -05:00
|
|
|
}
|
2025-02-12 12:15:33 -06:00
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
|
public void entityTick(LivingEvent.LivingUpdateEvent event) {
|
|
|
|
|
AnimationData data = AnimationData.getData(event.entityLiving);
|
|
|
|
|
if (data != null) {
|
|
|
|
|
data.increaseTime();
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-19 19:14:51 -05:00
|
|
|
}
|