Files
CustomNPC-Plus/src/main/java/noppes/npcs/PacketHandlerServer.java
T

610 lines
26 KiB
Java
Raw Normal View History

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;
2023-01-12 21:33:06 -05:00
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent.ServerCustomPacketEvent;
2022-11-07 01:49:54 -05:00
import cpw.mods.fml.relauncher.Side;
2018-09-13 12:03:28 -04:00
import foxz.utils.Market;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.network.packets.data.ScrollSelectedPacket;
import kamkeel.npcs.network.packets.data.large.GuiDataPacket;
import kamkeel.npcs.network.packets.data.large.PartyDataPacket;
import kamkeel.npcs.network.packets.data.large.ScrollDataPacket;
import kamkeel.npcs.network.packets.data.large.ScrollListPacket;
2025-01-30 12:44:39 -05:00
import kamkeel.npcs.util.ByteBufUtils;
2018-09-13 12:03:28 -04:00
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.passive.EntityVillager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.PacketBuffer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChunkCoordinates;
import net.minecraft.village.MerchantRecipeList;
import net.minecraft.world.WorldServer;
2024-01-21 22:17:24 +03:00
import noppes.npcs.blocks.tiles.TileScripted;
2023-01-07 00:21:08 -05:00
import noppes.npcs.config.ConfigDebug;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.config.ConfigScript;
2023-01-12 21:33:06 -05:00
import noppes.npcs.constants.*;
2018-09-13 12:03:28 -04:00
import noppes.npcs.containers.ContainerMail;
2022-01-12 04:44:08 -06:00
import noppes.npcs.controllers.*;
2018-09-13 12:03:28 -04:00
import noppes.npcs.controllers.LinkedNpcController.LinkedData;
import noppes.npcs.controllers.data.*;
2018-09-13 12:03:28 -04:00
import noppes.npcs.entity.EntityCustomNpc;
import noppes.npcs.entity.EntityNPCInterface;
import noppes.npcs.roles.JobSpawner;
import noppes.npcs.roles.RoleCompanion;
import noppes.npcs.roles.RoleTrader;
import noppes.npcs.roles.RoleTransporter;
import noppes.npcs.scripted.NpcAPI;
2022-05-11 01:10:31 -05:00
import noppes.npcs.scripted.item.ScriptCustomItem;
2018-09-13 12:03:28 -04:00
2023-01-12 21:33:06 -05:00
import java.io.IOException;
import java.util.*;
2023-01-12 21:33:06 -05:00
2018-09-13 12:03:28 -04:00
public class PacketHandlerServer{
@SubscribeEvent
public void onServerPacket(ServerCustomPacketEvent event) {
EntityPlayerMP player = ((NetHandlerPlayServer)event.handler).playerEntity;
2023-01-07 00:21:08 -05:00
if(ConfigMain.OpsOnly && !NoppesUtilServer.isOp(player)){
2018-09-13 12:03:28 -04:00
warn(player, "tried to use custom npcs without being an op");
return;
}
2025-01-31 01:58:54 -05:00
ByteBuf in = event.packet.payload();
2018-09-13 12:03:28 -04:00
EnumPacketServer type = null;
try {
2025-01-31 01:58:54 -05:00
type = EnumPacketServer.values()[in.readInt()];
2018-09-13 12:03:28 -04:00
ItemStack item = player.inventory.getCurrentItem();
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
2025-02-01 21:44:22 -05:00
if(item == null && (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave || type == EnumPacketServer.ScriptGlobalNPCGet || type == EnumPacketServer.ScriptGlobalNPCSave || type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave))
2018-09-13 12:03:28 -04:00
warn(player, "tried to use custom npcs without a tool in hand, probably a hacker");
2022-01-12 04:44:08 -06:00
else {
if (item != null) {
if (item.getItem() == CustomItems.wand)
2025-01-31 01:58:54 -05:00
wandPackets(type, in, player, npc);
2022-01-12 04:44:08 -06:00
else if (item.getItem() == CustomItems.moving)
2025-01-31 01:58:54 -05:00
movingPackets(type, in, player, npc);
2022-01-12 04:44:08 -06:00
else if (item.getItem() == CustomItems.mount)
2025-01-31 01:58:54 -05:00
mountPackets(type, in, player);
2022-01-12 04:44:08 -06:00
else if (item.getItem() == CustomItems.cloner)
2025-01-31 01:58:54 -05:00
clonePackets(type, in, player);
2022-01-12 04:44:08 -06:00
else if (item.getItem() == CustomItems.teleporter)
2025-01-31 01:58:54 -05:00
featherPackets(type, in, player);
2022-01-12 04:44:08 -06:00
else if (item.getItem() == Item.getItemFromBlock(CustomItems.waypoint) || item.getItem() == Item.getItemFromBlock(CustomItems.border) || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock))
2025-01-31 01:58:54 -05:00
blockPackets(type, in, player);
2024-03-07 19:34:25 -05:00
else if (ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT)) {
2023-03-16 04:27:19 -05:00
if (type == EnumPacketServer.EventScriptDataGet || type == EnumPacketServer.EventScriptDataSave)
2025-01-31 01:58:54 -05:00
npcEventScriptPackets(type, in, player, npc);
2023-03-16 04:27:19 -05:00
else if (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave)
2025-01-31 01:58:54 -05:00
playerScriptPackets(type, in, player);
2023-03-16 04:27:19 -05:00
else if (type == EnumPacketServer.ScriptGlobalNPCGet || type == EnumPacketServer.ScriptGlobalNPCSave)
2025-01-31 01:58:54 -05:00
npcGlobalScriptPackets(type, in, player);
2022-07-07 16:22:50 -05:00
else if (type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave)
2025-01-31 01:58:54 -05:00
forgeScriptPackets(type, in, player);
2022-07-07 16:22:50 -05:00
else if (type == EnumPacketServer.ScriptItemDataGet || type == EnumPacketServer.ScriptItemDataSave)
2025-01-31 01:58:54 -05:00
itemScriptPackets(type, in, player);
2024-01-21 22:17:24 +03:00
else if (type == EnumPacketServer.ScriptBlockDataGet || type == EnumPacketServer.ScriptBlockDataSave)
2025-01-31 01:58:54 -05:00
blockScriptPackets(type, in, player);
2022-07-07 16:22:50 -05:00
else if (type == EnumPacketServer.ScriptGlobalGuiDataGet || type == EnumPacketServer.ScriptGlobalGuiDataSave)
2025-01-31 01:58:54 -05:00
getScriptsEnabled(type, in, player);
2022-07-07 16:22:50 -05:00
else if (item.getItem() == CustomItems.scripter)
2025-01-31 01:58:54 -05:00
scriptPackets(type, in, player, npc);
2022-07-07 16:22:50 -05:00
}
2022-01-12 04:44:08 -06:00
}
}
2018-09-13 12:03:28 -04:00
} catch (Exception e) {
LogWriter.error("Error with EnumPacketServer." + type, e);
}
}
public static void sendPartyData(EntityPlayerMP player) {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
if (playerData.partyUUID != null) {
Party party = PartyController.Instance().getParty(playerData.partyUUID);
2024-02-18 01:30:34 -06:00
NBTTagCompound compound = party.writeToNBT();
if (party.getQuest() != null) {
Quest quest = (Quest) party.getQuest();
2024-03-15 15:43:29 -04:00
compound.setString("QuestName", quest.getCategory().getName() + ":" + quest.getName());
2024-03-02 17:13:50 -05:00
Vector<String> vector = quest.questInterface.getPartyQuestLogStatus(party);
2024-02-18 01:30:34 -06:00
NBTTagList list = new NBTTagList();
for (String s : vector) {
list.appendTag(new NBTTagString(s));
}
compound.setTag("QuestProgress", list);
2024-03-02 17:13:50 -05:00
if(quest.completion == EnumQuestCompletion.Npc && quest.questInterface.isPartyCompleted(party)) {
2024-02-18 01:30:34 -06:00
compound.setString("QuestCompleteWith", quest.completerNpc);
}
}
PartyDataPacket.sendPartyData(player, compound);
2025-01-30 12:44:39 -05:00
} else {
sendInviteData(player);
}
}
public static void sendInviteData(EntityPlayerMP player) {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
if (playerData.partyUUID == null) {
NBTTagCompound compound = new NBTTagCompound();
NBTTagList list = new NBTTagList();
HashSet<UUID> partyInvites = playerData.getPartyInvites();
for (UUID uuid : partyInvites) {
Party party = PartyController.Instance().getParty(uuid);
NBTTagCompound partyCompound = new NBTTagCompound();
partyCompound.setString("PartyLeader", party.getPartyLeaderName());
partyCompound.setString("PartyUUID", party.getPartyUUID().toString());
list.appendTag(partyCompound);
}
compound.setTag("PartyInvites", list);
PartyDataPacket.sendPartyData(player, compound);
2025-01-30 12:44:39 -05:00
}
}
private void isGuiOpenPacket(ByteBuf buffer, EntityPlayerMP player) throws IOException {
NoppesUtilServer.isGUIOpen(buffer, player);
}
2022-05-16 00:42:40 -05:00
private void getScriptsEnabled(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
if (type == EnumPacketServer.ScriptGlobalGuiDataGet) {
NBTTagCompound compound = new NBTTagCompound();
2023-01-07 00:21:08 -05:00
compound.setBoolean("ScriptsEnabled", ConfigScript.ScriptingEnabled);
compound.setBoolean("PlayerScriptsEnabled", ConfigScript.GlobalPlayerScripts);
compound.setBoolean("GlobalNPCScriptsEnabled", ConfigScript.GlobalNPCScripts);
compound.setBoolean("ForgeScriptsEnabled", ConfigScript.GlobalForgeScripts);
GuiDataPacket.sendGuiData(player, compound);
2022-05-16 00:42:40 -05:00
}
else if (type == EnumPacketServer.ScriptGlobalGuiDataSave) {
2025-01-30 12:44:39 -05:00
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
2023-01-07 00:21:08 -05:00
ConfigScript.ScriptingEnabled = compound.getBoolean("ScriptsEnabled");
ConfigScript.GlobalPlayerScripts = compound.getBoolean("PlayerScriptsEnabled");
ConfigScript.GlobalNPCScripts = compound.getBoolean("GlobalNPCScriptsEnabled");
ConfigScript.GlobalForgeScripts = compound.getBoolean("ForgeScriptsEnabled");
2022-05-16 00:42:40 -05:00
}
}
2018-09-13 12:03:28 -04:00
private void scriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception {
if(type == EnumPacketServer.ScriptDataSave){
2025-01-30 12:44:39 -05:00
npc.script.readFromNBT(ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
npc.updateAI = true;
npc.script.hasInited = false;
2023-01-07 00:21:08 -05:00
if(ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
2022-11-07 01:49:54 -05:00
LogWriter.script(String.format("[%s] (Player) %s SAVED NPC %s (%s, %s, %s) [%s]", "SCRIPTER", player.getCommandSenderName(), npc.display.getName(), (int)npc.posX, (int)(npc).posY, (int)npc.posZ, npc.worldObj.getWorldInfo().getWorldName()));
}
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.ScriptDataGet){
NBTTagCompound compound = npc.script.writeToNBT(new NBTTagCompound());
compound.setTag("Languages", ScriptController.Instance.nbtLanguages());
GuiDataPacket.sendGuiData(player, compound);
2018-09-13 12:03:28 -04:00
}
}
public static void getScripts(IScriptHandler data, ByteBuf buffer, EntityPlayerMP player) {
NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("ScriptEnabled", data.getEnabled());
compound.setString("ScriptLanguage", data.getLanguage());
compound.setTag("Languages", ScriptController.Instance.nbtLanguages());
compound.setTag("ScriptConsole", NBTTags.NBTLongStringMap(data.getConsoleText()));
GuiDataPacket.sendGuiData(player, compound);
List<ScriptContainer> containers = data.getScripts();
for (int i = 0; i < containers.size(); i++) {
ScriptContainer container = containers.get(i);
NBTTagCompound tabCompound = new NBTTagCompound();
tabCompound.setInteger("Tab",i);
tabCompound.setTag("Script",container.writeToNBT(new NBTTagCompound()));
tabCompound.setInteger("TotalScripts",containers.size());
GuiDataPacket.sendGuiData(player, tabCompound);
}
}
public static void saveScripts(IScriptHandler data, ByteBuf buffer, EntityPlayerMP player) throws IOException {
int tab = buffer.readInt();
2023-03-16 04:27:19 -05:00
int totalScripts = buffer.readInt();
if (totalScripts == 0) {
data.getScripts().clear();
}
if (tab >= 0) {
if (data.getScripts().size() > totalScripts) {
data.setScripts(data.getScripts().subList(0,totalScripts));
} else while (data.getScripts().size() < totalScripts) {
data.getScripts().add(new ScriptContainer(data));
}
2025-01-30 12:44:39 -05:00
NBTTagCompound tabCompound = ByteBufUtils.readNBT(buffer);
2023-05-26 00:22:14 -05:00
ScriptContainer script = new ScriptContainer(data);
script.readFromNBT(tabCompound);
data.getScripts().set(tab,script);
} else {
2025-01-30 12:44:39 -05:00
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
data.setLanguage(compound.getString("ScriptLanguage"));
if (!ScriptController.Instance.languages.containsKey(data.getLanguage())) {
if (!ScriptController.Instance.languages.isEmpty()) {
data.setLanguage((String) ScriptController.Instance.languages.keySet().toArray()[0]);
} else {
data.setLanguage("ECMAScript");
}
}
data.setEnabled(compound.getBoolean("ScriptEnabled"));
}
}
2023-03-16 04:27:19 -05:00
private void npcEventScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws Exception {
DataScript data = npc.script;
if(type == EnumPacketServer.EventScriptDataGet) {
getScripts(data,buffer,player);
2023-03-16 04:27:19 -05:00
} else if(type == EnumPacketServer.EventScriptDataSave) {
saveScripts(data,buffer,player);
2023-03-16 04:27:19 -05:00
npc.updateAI = true;
npc.script.hasInited = false;
if(ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
LogWriter.script(String.format("[%s] (Player) %s SAVED NPC %s (%s, %s, %s) [%s]", "SCRIPTER", player.getCommandSenderName(), npc.display.getName(), (int)npc.posX, (int)(npc).posY, (int)npc.posZ, npc.worldObj.getWorldInfo().getWorldName()));
}
}
}
private void playerScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
PlayerDataScript data = ScriptController.Instance.playerScripts;
if(type == EnumPacketServer.ScriptPlayerGet) {
getScripts(data,buffer,player);
} else if(type == EnumPacketServer.ScriptPlayerSave) {
2024-04-04 18:53:53 -04:00
int tab = buffer.getInt(buffer.readerIndex());
saveScripts(data,buffer,player);
ScriptController.Instance.lastPlayerUpdate = System.currentTimeMillis();
2024-04-04 18:53:53 -04:00
if(tab == -1)
ScriptController.Instance.savePlayerScriptsSync();
}
}
private void forgeScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
ForgeDataScript data = ScriptController.Instance.forgeScripts;
if (type == EnumPacketServer.ScriptForgeGet) {
getScripts(data,buffer,player);
} else if (type == EnumPacketServer.ScriptForgeSave) {
2024-04-04 18:53:53 -04:00
int tab = buffer.getInt(buffer.readerIndex());
saveScripts(data,buffer,player);
ScriptController.Instance.lastForgeUpdate = System.currentTimeMillis();
2024-04-04 18:53:53 -04:00
if(tab == -1)
ScriptController.Instance.saveForgeScriptsSync();
}
}
2023-03-16 04:27:19 -05:00
private void npcGlobalScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
GlobalNPCDataScript data = ScriptController.Instance.globalNpcScripts;
if(type == EnumPacketServer.ScriptGlobalNPCGet) {
getScripts(data,buffer,player);
2023-03-16 04:27:19 -05:00
} else if(type == EnumPacketServer.ScriptGlobalNPCSave) {
2024-04-04 18:53:53 -04:00
int tab = buffer.getInt(buffer.readerIndex());
saveScripts(data,buffer,player);
2023-03-16 04:27:19 -05:00
ScriptController.Instance.lastGlobalNpcUpdate = System.currentTimeMillis();
2024-04-04 18:53:53 -04:00
if(tab == -1)
ScriptController.Instance.saveGlobalScriptsSync();
2022-03-23 03:54:06 -05:00
}
}
2022-05-11 01:10:31 -05:00
private void itemScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
if (type == EnumPacketServer.ScriptItemDataGet) {
2022-07-03 09:46:40 -05:00
ScriptCustomItem iw = (ScriptCustomItem) NpcAPI.Instance().getIItemStack(player.getHeldItem());
2023-05-30 00:56:39 -05:00
iw.loadScriptData();
2022-05-11 01:10:31 -05:00
NBTTagCompound compound = iw.getMCNbt();
compound.setTag("Languages", ScriptController.Instance.nbtLanguages());
GuiDataPacket.sendGuiData(player, compound);
2022-05-11 01:10:31 -05:00
} else if (type == EnumPacketServer.ScriptItemDataSave) {
if (!player.capabilities.isCreativeMode) {
return;
}
2025-01-30 12:44:39 -05:00
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
2022-07-03 09:46:40 -05:00
ScriptCustomItem wrapper = (ScriptCustomItem) NpcAPI.Instance().getIItemStack(player.getHeldItem());
2022-05-11 01:10:31 -05:00
wrapper.setMCNbt(compound);
wrapper.saveScriptData();
2023-06-01 17:53:08 -05:00
wrapper.loaded = false;
2024-05-25 18:07:41 -04:00
wrapper.lastInited = -1;
2022-05-11 01:10:31 -05:00
player.sendContainerToPlayer(player.inventoryContainer);
}
}
2024-01-21 22:17:24 +03:00
private void blockScriptPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws Exception {
if (type == EnumPacketServer.ScriptBlockDataGet) {
TileEntity tile = player.worldObj.getTileEntity(buffer.readInt(), buffer.readInt(), buffer.readInt());
if(!(tile instanceof TileScripted))
return;
NBTTagCompound compound = ((TileScripted) tile).getNBT(new NBTTagCompound());
compound.setTag("Languages", ScriptController.Instance.nbtLanguages());
GuiDataPacket.sendGuiData(player, compound);
2024-01-21 22:17:24 +03:00
} else if (type == EnumPacketServer.ScriptBlockDataSave) {
if (!player.capabilities.isCreativeMode) {
return;
}
TileEntity tile = player.worldObj.getTileEntity(buffer.readInt(), buffer.readInt(), buffer.readInt());
if(!(tile instanceof TileScripted))
return;
TileScripted script = (TileScripted) tile;
2025-01-30 12:44:39 -05:00
script.setNBT(ByteBufUtils.readNBT(buffer));
2024-01-21 22:17:24 +03:00
script.lastInited = -1;
}
}
2018-09-13 12:03:28 -04:00
private void featherPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
if(type == EnumPacketServer.DimensionTeleport){
2018-09-13 12:03:28 -04:00
int dimension = buffer.readInt();
WorldServer world = MinecraftServer.getServer().worldServerForDimension(dimension);
ChunkCoordinates coords = world.getEntrancePortalLocation();
if(coords == null){
coords = world.getSpawnPoint();
if(!world.isAirBlock(coords.posX, coords.posY, coords.posZ))
coords.posY = world.getTopSolidOrLiquidBlock(coords.posX, coords.posZ);
else{
while(world.isAirBlock(coords.posX, coords.posY - 1, coords.posZ) && coords.posY > 0){
coords.posY--;
}
if(coords.posY == 0)
coords.posY = world.getTopSolidOrLiquidBlock(coords.posX, coords.posZ);
}
}
NoppesUtilPlayer.teleportPlayer(player, coords.posX, coords.posY, coords.posZ, dimension);
}
}
2022-11-07 01:49:54 -05:00
2018-09-13 12:03:28 -04:00
private void movingPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws IOException {
if(type == EnumPacketServer.MovingPathGet){
GuiDataPacket.sendGuiData(player, npc.ai.writeToNBT(new NBTTagCompound()));
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.MovingPathSave){
2025-01-30 12:44:39 -05:00
npc.ai.setMovingPath(NBTTags.getIntegerArraySet(ByteBufUtils.readNBT(buffer).getTagList("MovingPathNew",10)));
2018-09-13 12:03:28 -04:00
}
}
private void blockPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
2025-02-02 17:03:45 -05:00
if(type == EnumPacketServer.DialogCategoriesGet){
ScrollDataPacket.sendScrollData(player, DialogController.Instance.getScroll());
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.DialogsGetFromDialog){
2023-06-05 22:12:48 -04:00
Dialog dialog = DialogController.Instance.dialogs.get(buffer.readInt());
2018-09-13 12:03:28 -04:00
if(dialog == null)
return;
NoppesUtilServer.sendDialogData(player,dialog.category);
}
else if(type == EnumPacketServer.DialogsGet){
2023-06-07 22:49:54 -04:00
int catID = buffer.readInt();
boolean sendGroup = buffer.readBoolean();
if(sendGroup){
NoppesUtilServer.sendDialogGroup(player,DialogController.Instance.categories.get(catID));
}
else {
NoppesUtilServer.sendDialogData(player,DialogController.Instance.categories.get(catID));
}
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.QuestsGetFromQuest){
2023-06-05 22:12:48 -04:00
Quest quest = QuestController.Instance.quests.get(buffer.readInt());
2018-09-13 12:03:28 -04:00
if(quest == null)
return;
NoppesUtilServer.sendQuestData(player,quest.category);
}
else if(type == EnumPacketServer.QuestCategoriesGet){
NoppesUtilServer.sendQuestCategoryData(player);
}
else if(type == EnumPacketServer.QuestsGet){
2023-06-05 22:12:48 -04:00
QuestCategory category = QuestController.Instance.categories.get(buffer.readInt());
2023-06-11 16:05:15 -04:00
boolean sendGroup = buffer.readBoolean();
if(sendGroup){
NoppesUtilServer.sendQuestGroup(player,category);
}
else {
NoppesUtilServer.sendQuestData(player,category);
}
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.FactionsGet){
NoppesUtilServer.sendFactionDataAll(player);
}
else if(type == EnumPacketServer.DialogGet){
2023-06-05 22:12:48 -04:00
Dialog dialog = DialogController.Instance.dialogs.get(buffer.readInt());
2018-09-13 12:03:28 -04:00
if(dialog != null){
NBTTagCompound compound = dialog.writeToNBT(new NBTTagCompound());
2023-06-05 22:12:48 -04:00
Quest quest = QuestController.Instance.quests.get(dialog.quest);
2018-09-13 12:03:28 -04:00
if(quest != null)
compound.setString("DialogQuestName", quest.title);
GuiDataPacket.sendGuiData(player, compound);
2018-09-13 12:03:28 -04:00
}
}
else if(type == EnumPacketServer.QuestGet){
2023-06-05 22:12:48 -04:00
Quest quest = QuestController.Instance.quests.get(buffer.readInt());
2018-09-13 12:03:28 -04:00
if(quest != null){
NBTTagCompound compound = new NBTTagCompound();
if(quest.hasNewQuest())
compound.setString("NextQuestTitle", quest.getNextQuest().title);
GuiDataPacket.sendGuiData(player, quest.writeToNBT(compound));
2018-09-13 12:03:28 -04:00
}
}
else if(type == EnumPacketServer.FactionGet){
NBTTagCompound compound = new NBTTagCompound();
2022-01-10 15:21:48 -06:00
Faction faction = FactionController.getInstance().get(buffer.readInt());
2018-09-13 12:03:28 -04:00
faction.writeNBT(compound);
GuiDataPacket.sendGuiData(player, compound);
2018-09-13 12:03:28 -04:00
}
2023-01-10 17:17:15 -05:00
else if(type == EnumPacketServer.TagGet){
NBTTagCompound compound = new NBTTagCompound();
Tag tag = TagController.getInstance().get(buffer.readInt());
tag.writeNBT(compound);
GuiDataPacket.sendGuiData(player, compound);
2023-01-10 17:17:15 -05:00
}
2018-09-13 12:03:28 -04:00
}
private void wandPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player, EntityNPCInterface npc) throws IOException{
2025-02-02 17:00:32 -05:00
blockPackets(type, buffer, player);
2018-09-13 12:03:28 -04:00
}
private void mountPackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException{
2022-11-07 01:49:54 -05:00
if(type == EnumPacketServer.SpawnRider){
2025-01-30 12:44:39 -05:00
Entity entity = EntityList.createEntityFromNBT(ByteBufUtils.readNBT(buffer), player.worldObj);
2018-09-13 12:03:28 -04:00
player.worldObj.spawnEntityInWorld(entity);
entity.mountEntity(ServerEventsHandler.mounted);
}
else if(type == EnumPacketServer.PlayerRider){
player.mountEntity(ServerEventsHandler.mounted);
}
else if(type == EnumPacketServer.CloneList){
2022-11-07 01:49:54 -05:00
NBTTagList list = new NBTTagList();
int tab = buffer.readInt();
for(String name : ServerCloneController.Instance.getClones(tab))
2022-11-07 01:49:54 -05:00
list.appendTag(new NBTTagString(name));
NBTTagList listDate = new NBTTagList();
for(String name : ServerCloneController.Instance.getClonesDate(tab))
listDate.appendTag(new NBTTagString(name));
2022-11-07 01:49:54 -05:00
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("List", list);
compound.setTag("ListDate", listDate);
2022-11-07 01:49:54 -05:00
GuiDataPacket.sendGuiData(player, compound);
2018-09-13 12:03:28 -04:00
}
else
2023-03-22 19:14:13 -04:00
warn(player,"WE 1 tried todo something with the wrong tool, probably a hacker");
2018-09-13 12:03:28 -04:00
}
private void clonePackets(EnumPacketServer type, ByteBuf buffer, EntityPlayerMP player) throws IOException {
if(type == EnumPacketServer.SpawnMob){
boolean server = buffer.readBoolean();
int x = buffer.readInt();
int y = buffer.readInt();
int z = buffer.readInt();
NBTTagCompound compound;
if(server)
2025-01-30 12:44:39 -05:00
compound = ServerCloneController.Instance.getCloneData(player, ByteBufUtils.readString(buffer), buffer.readInt());
2018-09-13 12:03:28 -04:00
else
2025-01-30 12:44:39 -05:00
compound = ByteBufUtils.readNBT(buffer);
2018-09-13 12:03:28 -04:00
if(compound == null)
return;
Entity entity = NoppesUtilServer.spawnClone(compound, x, y, z, player.worldObj);
if(entity == null){
player.addChatMessage(new ChatComponentText("Failed to create an entity out of your clone"));
return;
}
if (entity instanceof EntityNPCInterface && !ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT)) {
EntityNPCInterface npc = (EntityNPCInterface) entity;
npc.script.setEnabled(false);
}
2023-01-07 00:21:08 -05:00
if(ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
2022-11-07 01:49:54 -05:00
LogWriter.script(String.format("[%s] (Player) %s SPAWNED ENTITY %s", "CLONER", player.getCommandSenderName(), entity));
}
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.MobSpawner){
boolean server = buffer.readBoolean();
int x = buffer.readInt();
int y = buffer.readInt();
int z = buffer.readInt();
NBTTagCompound compound;
if(server)
2025-01-30 12:44:39 -05:00
compound = ServerCloneController.Instance.getCloneData(player, ByteBufUtils.readString(buffer), buffer.readInt());
2018-09-13 12:03:28 -04:00
else
2025-01-30 12:44:39 -05:00
compound = ByteBufUtils.readNBT(buffer);
if (!ConfigScript.canScript(player, CustomNpcsPermissions.SCRIPT)) {
return;
}
2018-09-13 12:03:28 -04:00
if(compound != null)
NoppesUtilServer.createMobSpawner(x, y, z, compound, player);
}
else if(type == EnumPacketServer.ClonePreSave){
2025-01-30 12:44:39 -05:00
boolean bo = ServerCloneController.Instance.getCloneData(null, ByteBufUtils.readString(buffer), buffer.readInt()) != null;
2018-09-13 12:03:28 -04:00
NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("NameExists", bo);
GuiDataPacket.sendGuiData(player, compound);
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.CloneSave){
2023-06-05 19:35:06 -04:00
PlayerData data = PlayerDataController.Instance.getPlayerData(player);
2018-09-13 12:03:28 -04:00
if(data.cloned == null)
return;
2025-01-30 12:44:39 -05:00
String name = ByteBufUtils.readString(buffer);
int tab = buffer.readInt();
2025-01-30 12:44:39 -05:00
NBTTagCompound tagExtra = ByteBufUtils.readNBT(buffer);
NBTTagCompound tagCompound = ByteBufUtils.readNBT(buffer);
NBTTagList tagList = tagCompound.getTagList("TagUUIDs", 8);
data.cloned.setTag("TagUUIDs", tagList);
ServerCloneController.Instance.addClone(data.cloned, name, tab, tagExtra);
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.CloneRemove){
int tab = buffer.readInt();
2025-01-30 12:44:39 -05:00
ServerCloneController.Instance.removeClone(ByteBufUtils.readString(buffer), tab);
2018-09-13 12:03:28 -04:00
2022-11-07 01:49:54 -05:00
NBTTagList list = new NBTTagList();
for(String name : ServerCloneController.Instance.getClones(tab))
list.appendTag(new NBTTagString(name));
NBTTagList listDate = new NBTTagList();
for(String name : ServerCloneController.Instance.getClonesDate(tab))
listDate.appendTag(new NBTTagString(name));
2022-11-07 01:49:54 -05:00
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("List", list);
compound.setTag("ListDate", listDate);
2022-11-07 01:49:54 -05:00
GuiDataPacket.sendGuiData(player, compound);
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.CloneList){
2022-11-07 01:49:54 -05:00
NBTTagList list = new NBTTagList();
int tab = buffer.readInt();
for(String name : ServerCloneController.Instance.getClones(tab))
2022-11-07 01:49:54 -05:00
list.appendTag(new NBTTagString(name));
NBTTagList listDate = new NBTTagList();
for(String name : ServerCloneController.Instance.getClonesDate(tab))
listDate.appendTag(new NBTTagString(name));
2022-11-07 01:49:54 -05:00
NBTTagCompound compound = new NBTTagCompound();
compound.setTag("List", list);
compound.setTag("ListDate", listDate);
2022-11-07 01:49:54 -05:00
GuiDataPacket.sendGuiData(player, compound);
2018-09-13 12:03:28 -04:00
}
2023-03-21 03:16:52 -05:00
else if (type == EnumPacketServer.CloneTagList) {
int tab = buffer.readInt();
2023-03-22 16:07:09 -04:00
TagMap tagMap = ServerTagMapController.Instance.getTagMap(tab);
2023-03-21 03:16:52 -05:00
NBTTagCompound compound = new NBTTagCompound();
2023-03-22 16:07:09 -04:00
compound.setTag("CloneTags", tagMap.writeNBT());
GuiDataPacket.sendGuiData(player, compound);
}
else if (type == EnumPacketServer.CloneAllTags) {
NBTTagCompound compound = new NBTTagCompound();
2023-03-22 20:13:36 -04:00
HashSet<Tag> validTags = TagController.getInstance().getAllTags();
NBTTagList validTagList = new NBTTagList();
for(Tag tag : validTags){
NBTTagCompound tagCompound = new NBTTagCompound();
tag.writeNBT(tagCompound);
validTagList.appendTag(tagCompound);
}
2023-03-22 20:13:36 -04:00
compound.setTag("AllTags", validTagList);
GuiDataPacket.sendGuiData(player, compound);
}
else if (type == EnumPacketServer.CloneAllTagsShort) {
NBTTagCompound compound = new NBTTagCompound();
HashSet<Tag> validTags = TagController.getInstance().getAllTags();
NBTTagList validTagList = new NBTTagList();
for(Tag tag : validTags){
NBTTagCompound tagCompound = new NBTTagCompound();
tag.writeShortNBT(tagCompound);
validTagList.appendTag(tagCompound);
}
compound.setTag("ShortTags", validTagList);
GuiDataPacket.sendGuiData(player, compound);
2023-03-21 03:16:52 -05:00
}
2018-09-13 12:03:28 -04:00
}
private void warn(EntityPlayer player, String warning){
MinecraftServer.getServer().logWarning(player.getCommandSenderName() + ": " + warning);
}
}