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

1401 lines
62 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.WorldProvider;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.DimensionManager;
2023-01-12 21:33:06 -05:00
import noppes.npcs.api.entity.IPlayer;
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.*;
2022-01-12 04:44:08 -06:00
import noppes.npcs.containers.ContainerCustomGui;
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;
import noppes.npcs.scripted.event.PartyEvent;
2022-01-12 04:44:08 -06:00
import noppes.npcs.scripted.gui.ScriptGui;
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;
}
ByteBuf buffer = event.packet.payload();
EnumPacketServer type = null;
try {
type = EnumPacketServer.values()[buffer.readInt()];
ItemStack item = player.inventory.getCurrentItem();
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
if (type == EnumPacketServer.IsGuiOpen) {
isGuiOpenPacket(buffer, player);
return;
} else if (type == EnumPacketServer.CustomGuiButton && player.openContainer instanceof ContainerCustomGui) {
2025-01-30 12:44:39 -05:00
((ContainerCustomGui) player.openContainer).customGui.fromNBT(ByteBufUtils.readNBT(buffer));
EventHooks.onCustomGuiButton((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui) player.openContainer).customGui, buffer.readInt());
2022-01-14 16:09:27 -06:00
return;
} else if (type == EnumPacketServer.CustomGuiUnfocused && player.openContainer instanceof ContainerCustomGui) {
2025-01-30 12:44:39 -05:00
((ContainerCustomGui) player.openContainer).customGui.fromNBT(ByteBufUtils.readNBT(buffer));
EventHooks.onCustomGuiUnfocused((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui) player.openContainer).customGui, buffer.readInt());
2022-01-14 16:09:27 -06:00
return;
2022-01-12 04:44:08 -06:00
} else if (type == EnumPacketServer.CustomGuiScrollClick && player.openContainer instanceof ContainerCustomGui) {
2025-01-30 12:44:39 -05:00
((ContainerCustomGui) player.openContainer).customGui.fromNBT(ByteBufUtils.readNBT(buffer));
EventHooks.onCustomGuiScrollClick((IPlayer) NpcAPI.Instance().getIEntity(player), ((ContainerCustomGui) player.openContainer).customGui, buffer.readInt(), buffer.readInt(), CustomGuiController.readScrollSelection(buffer), buffer.readBoolean());
2022-01-12 04:44:08 -06:00
return;
} else if (type == EnumPacketServer.CustomGuiClose) {
2025-01-30 12:44:39 -05:00
EventHooks.onCustomGuiClose((IPlayer) NpcAPI.Instance().getIEntity(player), (new ScriptGui()).fromNBT(ByteBufUtils.readNBT(buffer)));
2022-01-14 16:09:27 -06:00
return;
} else if (type == EnumPacketServer.QuestLogToServer) {
NoppesUtilPlayer.updateQuestLogData(buffer, player);
return;
2024-03-15 15:43:29 -04:00
} else if (type == EnumPacketServer.PartyLogToServer) {
NoppesUtilPlayer.updatePartyQuestLogData(buffer, player);
return;
2024-03-15 16:40:43 -04:00
} else if (type == EnumPacketServer.UntrackQuest) {
NoppesUtilPlayer.clearTrackQuest(player);
return;
2024-03-15 15:43:29 -04:00
} else if(type == EnumPacketServer.DimensionsGet){
HashMap<String,Integer> map = new HashMap<String,Integer>();
for(int id : DimensionManager.getStaticDimensionIDs()){
WorldProvider provider = DimensionManager.createProviderFor(id);
map.put(provider.getDimensionName(), id);
}
ScrollDataPacket.sendScrollData(player, map);
} else if(type == EnumPacketServer.TagsGet){
NoppesUtilServer.sendTagDataAll(player);
} else if (type == EnumPacketServer.NpcTagsGet) {
NBTTagCompound compound = new NBTTagCompound();
NBTTagList tagList = new NBTTagList();
for (UUID uuid : npc.advanced.tagUUIDs) {
Tag tag = TagController.getInstance().getTagFromUUID(uuid);
if (tag != null) {
tagList.appendTag(new NBTTagString(tag.name));
}
}
compound.setTag("TagNames",tagList);
GuiDataPacket.sendGuiData(player, compound);
2023-12-13 14:32:09 -06:00
} else if (type == EnumPacketServer.CacheAnimation) {
PlayerDataController.Instance.getPlayerData(player).animationData.cacheAnimation(buffer.readInt());
return;
} else if (type == EnumPacketServer.GetPartyData || type == EnumPacketServer.CreateParty) {
2024-03-17 16:08:07 -04:00
if(!ConfigMain.PartiesEnabled)
return;
if (type == EnumPacketServer.CreateParty) {
Party party = PartyController.Instance().createParty();
party.addPlayer(player);
party.setLeader(player);
}
sendPartyData(player);
} else if (type == EnumPacketServer.DisbandParty) {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
if (playerData.partyUUID != null) {
PartyController.Instance().disbandParty(playerData.partyUUID);
}
NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("Disband", true);
PartyDataPacket.sendPartyData(player, compound);
} else if (type == EnumPacketServer.KickPlayer) {
2025-01-30 12:44:39 -05:00
String kickPlayerName = ByteBufUtils.readString(buffer);
2024-03-06 05:23:45 -05:00
EntityPlayer kickPlayer = NoppesUtilServer.getPlayerByName(kickPlayerName);
PlayerData playerData = null;
UUID playerUUID = null;
if (kickPlayer != null) {
2024-03-06 05:23:45 -05:00
playerData = PlayerDataController.Instance.getPlayerData(player);
} else {
String uuid = PlayerDataController.Instance.getPlayerUUIDFromName(kickPlayerName);
if(!uuid.isEmpty()){
playerData = PlayerDataController.Instance.getPlayerDataCache(uuid);
playerUUID = UUID.fromString(uuid);
}
}
if(playerData != null){
if (playerData.partyUUID != null) {
Party party = PartyController.Instance().getParty(playerData.partyUUID);
if (!party.getIsLocked()) {
PartyEvent.PartyKickEvent partyEvent = new PartyEvent.PartyKickEvent(party, party.getQuest(), (IPlayer) NpcAPI.Instance().getIEntity(kickPlayer));
EventHooks.onPartyKick(partyEvent);
if (!partyEvent.isCancelled()){
boolean successful = party.removePlayer(kickPlayer);
2024-03-06 05:23:45 -05:00
if(!successful)
successful = party.removePlayer(playerUUID);
if(successful){
2024-03-06 05:23:45 -05:00
if(kickPlayer != null){
sendInviteData((EntityPlayerMP) kickPlayer);
}
PartyController.Instance().pingPartyUpdate(party);
2024-03-06 05:25:33 -05:00
PartyController.Instance().sendKickMessages(party, kickPlayer, kickPlayerName);
}
}
}
2024-03-06 05:23:45 -05:00
}
}
2024-03-01 20:00:09 -05:00
} else if (type == EnumPacketServer.LeavePlayer) {
2025-01-30 12:44:39 -05:00
EntityPlayer leavingPlayer = NoppesUtilServer.getPlayerByName(ByteBufUtils.readString(buffer));
2024-03-01 20:00:09 -05:00
if (leavingPlayer != null) {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
if (playerData.partyUUID != null) {
Party party = PartyController.Instance().getParty(playerData.partyUUID);
boolean successful = party.removePlayer(leavingPlayer);
if(successful){
PartyEvent.PartyLeaveEvent partyEvent = new PartyEvent.PartyLeaveEvent(party, party.getQuest(), (IPlayer) NpcAPI.Instance().getIEntity(leavingPlayer));
EventHooks.onPartyLeave(partyEvent);
sendInviteData((EntityPlayerMP) leavingPlayer);
PartyController.Instance().pingPartyUpdate(party);
2024-03-01 20:00:09 -05:00
PartyController.Instance().sendLeavingMessages(party, leavingPlayer);
}
}
}
} else if (type == EnumPacketServer.SavePartyData) {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
if (playerData.partyUUID != null) {
Party party = PartyController.Instance().getParty(playerData.partyUUID);
2025-01-30 12:44:39 -05:00
party.readClientNBT(ByteBufUtils.readNBT(buffer));
}
} else if (type == EnumPacketServer.SetPartyLeader) {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
if (playerData.partyUUID != null) {
Party party = PartyController.Instance().getParty(playerData.partyUUID);
if (!party.getIsLocked()) {
2025-01-30 12:44:39 -05:00
party.setLeader(NoppesUtilServer.getPlayerByName(ByteBufUtils.readString(buffer)));
PartyController.Instance().pingPartyUpdate(party);
}
}
} else if (type == EnumPacketServer.PartyInvite) {
2025-01-30 12:44:39 -05:00
EntityPlayer invitedPlayer = NoppesUtilServer.getPlayerByName(ByteBufUtils.readString(buffer));
if (invitedPlayer != null) {
PlayerData senderData = PlayerDataController.Instance.getPlayerData(player);
PlayerData invitedData = PlayerDataController.Instance.getPlayerData(invitedPlayer);
if (senderData.partyUUID != null && invitedData.partyUUID == null) {//only send invite if player is not in a party
Party party = PartyController.Instance().getParty(senderData.partyUUID);
if (!party.getIsLocked()) {
PartyEvent.PartyInviteEvent partyEvent = new PartyEvent.PartyInviteEvent(party, party.getQuest(), (IPlayer) NpcAPI.Instance().getIEntity(invitedPlayer));
EventHooks.onPartyInvite(partyEvent);
if (!partyEvent.isCancelled()){
invitedData.inviteToParty(party);
sendInviteData((EntityPlayerMP) invitedPlayer);
}
}
}
}
} else if (type == EnumPacketServer.GetPartyInviteList) {
sendInviteData(player);
} else if (type == EnumPacketServer.AcceptInvite) {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
2025-01-30 12:44:39 -05:00
String uuidString = ByteBufUtils.readString(buffer);
if (uuidString != null) {
UUID uuid = UUID.fromString(uuidString);
playerData.acceptInvite(uuid);
}
} else if (type == EnumPacketServer.IgnoreInvite) {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
2025-01-30 12:44:39 -05:00
String uuidString = ByteBufUtils.readString(buffer);
if (uuidString != null) {
UUID uuid = UUID.fromString(uuidString);
playerData.ignoreInvite(uuid);
}
2024-02-12 23:56:55 -06:00
} else if (type == EnumPacketServer.SetPartyQuest) {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
if(playerData.partyUUID != null){
Party party = PartyController.Instance().getParty(playerData.partyUUID);
if (party != null) {
2024-03-05 17:33:56 -05:00
if (party.getLeaderUUID().equals(player.getUniqueID())) {
int questID = buffer.readInt();
party.setQuest(null);
if(questID != -1){
Quest foundQuest = QuestController.Instance.quests.get(questID);
if(foundQuest != null){
if (foundQuest.partyOptions.allowParty) {
if(party.validateQuest(questID, true)){
PartyEvent.PartyQuestSetEvent partyEvent = new PartyEvent.PartyQuestSetEvent(party, foundQuest);
EventHooks.onPartyQuestSet(partyEvent);
if (!partyEvent.isCancelled()){
if(playerData.questData.hasActiveQuest(questID)){
QuestData questdata = new QuestData(foundQuest);
playerData.questData.activeQuests.put(questID, questdata);
}
party.setQuest(foundQuest);
PartyController.Instance().sendQuestChat(party, "party.setChat", " ", foundQuest.title);
2024-03-05 17:33:56 -05:00
}
2024-03-04 05:29:48 -05:00
}
}
}
}
2024-03-05 17:33:56 -05:00
PartyController.Instance().pingPartyUpdate(party);
}
}
}
}
2018-09-13 12:03:28 -04:00
if(type.needsNpc && npc == null){
2022-11-07 01:49:54 -05:00
2018-09-13 12:03:28 -04:00
}
2022-07-05 22:55:38 -07:00
else if(type.hasPermission() && !CustomNpcsPermissions.hasPermission(player, type.permission)){
//player doesnt have permission to do this
2022-11-07 01:49:54 -05:00
}
2023-03-16 04:27:19 -05:00
else 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)
wandPackets(type, buffer, player, npc);
else if (item.getItem() == CustomItems.moving)
movingPackets(type, buffer, player, npc);
else if (item.getItem() == CustomItems.mount)
mountPackets(type, buffer, player);
else if (item.getItem() == CustomItems.cloner)
clonePackets(type, buffer, player);
else if (item.getItem() == CustomItems.teleporter)
featherPackets(type, buffer, player);
else if (item.getItem() == Item.getItemFromBlock(CustomItems.waypoint) || item.getItem() == Item.getItemFromBlock(CustomItems.border) || item.getItem() == Item.getItemFromBlock(CustomItems.redstoneBlock))
blockPackets(type, buffer, 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)
npcEventScriptPackets(type, buffer, player, npc);
else if (type == EnumPacketServer.ScriptPlayerGet || type == EnumPacketServer.ScriptPlayerSave)
2022-07-07 16:22:50 -05:00
playerScriptPackets(type, buffer, player);
2023-03-16 04:27:19 -05:00
else if (type == EnumPacketServer.ScriptGlobalNPCGet || type == EnumPacketServer.ScriptGlobalNPCSave)
npcGlobalScriptPackets(type, buffer, player);
2022-07-07 16:22:50 -05:00
else if (type == EnumPacketServer.ScriptForgeGet || type == EnumPacketServer.ScriptForgeSave)
forgeScriptPackets(type, buffer, player);
else if (type == EnumPacketServer.ScriptItemDataGet || type == EnumPacketServer.ScriptItemDataSave)
itemScriptPackets(type, buffer, player);
2024-01-21 22:17:24 +03:00
else if (type == EnumPacketServer.ScriptBlockDataGet || type == EnumPacketServer.ScriptBlockDataSave)
blockScriptPackets(type, buffer, player);
2022-07-07 16:22:50 -05:00
else if (type == EnumPacketServer.ScriptGlobalGuiDataGet || type == EnumPacketServer.ScriptGlobalGuiDataSave)
getScriptsEnabled(type, buffer, player);
else if (item.getItem() == CustomItems.scripter)
scriptPackets(type, buffer, player, npc);
}
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 {
if (type == EnumPacketServer.SaveTileEntity) {
2025-01-30 12:44:39 -05:00
NoppesUtilServer.saveTileEntity(player, ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.GetTileEntity){
TileEntity tile = player.worldObj.getTileEntity(buffer.readInt(), buffer.readInt(), buffer.readInt());
NBTTagCompound compound = new NBTTagCompound();
tile.writeToNBT(compound);
GuiDataPacket.sendGuiData(player, compound);
2018-09-13 12:03:28 -04:00
}
2022-11-07 01:49:54 -05:00
else 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{
if(type == EnumPacketServer.Delete){
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 DELETE NPC %s (%s, %s, %s) [%s]", "WAND", 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
npc.delete();
NoppesUtilServer.deleteNpc(npc,player);
}
else if(type == EnumPacketServer.LinkedAdd){
2025-01-30 12:44:39 -05:00
LinkedNpcController.Instance.addData(ByteBufUtils.readString(buffer));
2018-09-13 12:03:28 -04:00
List<String> list = new ArrayList<String>();
for(LinkedData data : LinkedNpcController.Instance.list)
list.add(data.name);
ScrollListPacket.sendList((EntityPlayerMP)player, list);
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.LinkedRemove){
2025-01-30 12:44:39 -05:00
LinkedNpcController.Instance.removeData(ByteBufUtils.readString(buffer));
2018-09-13 12:03:28 -04:00
List<String> list = new ArrayList<String>();
for(LinkedData data : LinkedNpcController.Instance.list)
list.add(data.name);
ScrollListPacket.sendList((EntityPlayerMP)player, list);
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.LinkedGetAll){
List<String> list = new ArrayList<String>();
for(LinkedData data : LinkedNpcController.Instance.list)
list.add(data.name);
ScrollListPacket.sendList((EntityPlayerMP)player, list);
2018-09-13 12:03:28 -04:00
if(npc != null)
ScrollSelectedPacket.setSelectedList(player, npc.linkedName);
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.LinkedSet){
2025-01-30 12:44:39 -05:00
npc.linkedName = ByteBufUtils.readString(buffer);
2018-09-13 12:03:28 -04:00
LinkedNpcController.Instance.loadNpcData(npc);
}
else if(type == EnumPacketServer.NpcMenuClose){
npc.reset();
if(npc.linkedData != null)
LinkedNpcController.Instance.saveNpcData(npc);
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 CLOSE NPC %s (%s, %s, %s) [%s]", "WAND", 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
NoppesUtilServer.setEditingNpc(player, null);
}
else if(type == EnumPacketServer.BanksGet){
NoppesUtilServer.sendBankDataAll(player);
}
else if(type == EnumPacketServer.BankGet){
Bank bank = BankController.getInstance().getBank(buffer.readInt());
NoppesUtilServer.sendBank(player,bank);
}
else if(type == EnumPacketServer.BankSave){
Bank bank = new Bank();
2025-01-30 12:44:39 -05:00
bank.readEntityFromNBT(ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
BankController.getInstance().saveBank(bank);
NoppesUtilServer.sendBankDataAll(player);
NoppesUtilServer.sendBank(player,bank);
}
else if(type == EnumPacketServer.BankRemove){
2022-11-07 01:49:54 -05:00
BankController.getInstance().removeBank(buffer.readInt());
2018-09-13 12:03:28 -04:00
NoppesUtilServer.sendBankDataAll(player);
NoppesUtilServer.sendBank(player,new Bank());
}
else if(type == EnumPacketServer.RemoteMainMenu){
Entity entity = player.worldObj.getEntityByID(buffer.readInt());
if(entity == null || !(entity instanceof EntityNPCInterface))
return;
NoppesUtilServer.sendOpenGui(player, EnumGuiType.MainMenuDisplay, (EntityNPCInterface) entity);
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 OPEN NPC %s (%s, %s, %s) [%s]", "WAND", player.getCommandSenderName(), ((EntityNPCInterface)entity).display.getName(), entity.posX, entity.posY, entity.posZ, entity.worldObj.getWorldInfo().getWorldName()));
}
2018-09-13 12:03:28 -04:00
}
2024-02-19 19:14:51 -05:00
else if(type == EnumPacketServer.RemoteGlobalMenu){
NoppesUtilServer.sendOpenGui(player, EnumGuiType.GlobalRemote, null);
if(ConfigDebug.PlayerLogging && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER){
LogWriter.script(String.format("[%s] (Player) %s OPEN GLOBAL MENU", "WAND", player.getCommandSenderName()));
}
}
2018-09-13 12:03:28 -04:00
else if(type == EnumPacketServer.RemoteDelete){
Entity entity = player.worldObj.getEntityByID(buffer.readInt());
if(entity == null || !(entity instanceof EntityNPCInterface))
return;
npc = (EntityNPCInterface) entity;
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 DELETE NPC %s (%s, %s, %s) [%s]", "WAND", 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
npc.delete();
NoppesUtilServer.deleteNpc(npc,player);
NoppesUtilServer.sendNearbyNpcs(player);
}
else if(type == EnumPacketServer.RemoteNpcsGet){
NoppesUtilServer.sendNearbyNpcs(player);
}
else if(type == EnumPacketServer.RemoteFreeze){
CustomNpcs.FreezeNPCs = !CustomNpcs.FreezeNPCs;
ScrollSelectedPacket.setSelectedList(player, CustomNpcs.FreezeNPCs?"Unfreeze NPCs":"Freeze NPCs");
2018-09-13 12:03:28 -04:00
}
2024-03-11 16:10:23 -04:00
else if(type == EnumPacketServer.RemoteFreezeGet){
ScrollSelectedPacket.setSelectedList(player, CustomNpcs.FreezeNPCs?"Unfreeze NPCs":"Freeze NPCs");
2024-03-11 16:10:23 -04:00
}
2018-09-13 12:03:28 -04:00
else if(type == EnumPacketServer.RemoteReset){
Entity entity = player.worldObj.getEntityByID(buffer.readInt());
if(entity == null || !(entity instanceof EntityNPCInterface))
return;
npc = (EntityNPCInterface) entity;
npc.reset();
}
else if(type == EnumPacketServer.RemoteTpToNpc){
Entity entity = player.worldObj.getEntityByID(buffer.readInt());
if(entity == null || !(entity instanceof EntityNPCInterface))
return;
npc = (EntityNPCInterface) entity;
player.playerNetServerHandler.setPlayerLocation(npc.posX, npc.posY, npc.posZ, 0, 0);
}
else if(type == EnumPacketServer.Gui){
EnumGuiType gui = EnumGuiType.values()[buffer.readInt()];
int i = buffer.readInt();
int j = buffer.readInt();
int k = buffer.readInt();
NoppesUtilServer.sendOpenGui(player, gui, npc, i, j, k);
}
else if(type == EnumPacketServer.RecipesGet){
NoppesUtilServer.sendRecipeData(player,buffer.readInt());
}
else if(type == EnumPacketServer.RecipeGet){
2023-06-05 22:12:48 -04:00
RecipeCarpentry recipe = RecipeController.Instance.getRecipe(buffer.readInt());
2018-09-13 12:03:28 -04:00
NoppesUtilServer.setRecipeGui(player,recipe);
}
else if(type == EnumPacketServer.RecipeRemove){
2023-06-05 22:12:48 -04:00
RecipeCarpentry recipe = RecipeController.Instance.delete(buffer.readInt());
2018-09-13 12:03:28 -04:00
NoppesUtilServer.sendRecipeData(player, recipe.isGlobal?3:4);
NoppesUtilServer.setRecipeGui(player,new RecipeCarpentry(""));
}
else if(type == EnumPacketServer.RecipeSave){
2025-01-30 12:44:39 -05:00
RecipeCarpentry recipe = RecipeController.Instance.saveRecipe(ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
NoppesUtilServer.sendRecipeData(player, recipe.isGlobal?3:4);
NoppesUtilServer.setRecipeGui(player,recipe);
}
else if(type == EnumPacketServer.NaturalSpawnGetAll){
ScrollDataPacket.sendScrollData(player, SpawnController.Instance.getScroll());
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.NaturalSpawnGet){
2023-06-05 22:12:48 -04:00
SpawnData spawn = SpawnController.Instance.getSpawnData(buffer.readInt());
2018-09-13 12:03:28 -04:00
if(spawn != null){
GuiDataPacket.sendGuiData(player, spawn.writeNBT(new NBTTagCompound()));
2018-09-13 12:03:28 -04:00
}
}
else if(type == EnumPacketServer.NaturalSpawnSave){
SpawnData data = new SpawnData();
2025-01-30 12:44:39 -05:00
data.readNBT(ByteBufUtils.readNBT(buffer));
2023-06-05 22:12:48 -04:00
SpawnController.Instance.saveSpawnData(data);
2018-09-13 12:03:28 -04:00
ScrollDataPacket.sendScrollData(player, SpawnController.Instance.getScroll());
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.NaturalSpawnRemove){
2023-06-05 22:12:48 -04:00
SpawnController.Instance.removeSpawnData(buffer.readInt());
ScrollDataPacket.sendScrollData(player, SpawnController.Instance.getScroll());
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.DialogCategorySave){
DialogCategory category = new DialogCategory();
2025-01-30 12:44:39 -05:00
category.readNBT(ByteBufUtils.readNBT(buffer));
2023-06-05 22:12:48 -04:00
DialogController.Instance.saveCategory(category);
ScrollDataPacket.sendScrollData(player, DialogController.Instance.getScroll());
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.DialogCategoryRemove){
2023-06-05 22:12:48 -04:00
DialogController.Instance.removeCategory(buffer.readInt());
ScrollDataPacket.sendScrollData(player, DialogController.Instance.getScroll());
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.DialogCategoryGet){
2023-06-05 22:12:48 -04:00
DialogCategory category = DialogController.Instance.categories.get(buffer.readInt());
2018-09-13 12:03:28 -04:00
if(category != null){
NBTTagCompound comp = category.writeNBT(new NBTTagCompound());
comp.removeTag("Dialogs");
GuiDataPacket.sendGuiData(player, comp);
2018-09-13 12:03:28 -04:00
}
}
else if(type == EnumPacketServer.DialogSave){
int category = buffer.readInt();
Dialog dialog = new Dialog();
2025-01-30 12:44:39 -05:00
dialog.readNBT(ByteBufUtils.readNBT(buffer));
2023-06-07 22:49:54 -04:00
boolean sendGroup = buffer.readBoolean();
2023-06-05 22:12:48 -04:00
DialogController.Instance.saveDialog(category,dialog);
2023-06-07 22:49:54 -04:00
if(dialog.category != null){
if(sendGroup){
NoppesUtilServer.sendDialogGroup(player,dialog.category);
}
else {
NoppesUtilServer.sendDialogData(player,dialog.category);
}
}
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.QuestOpenGui){
Quest quest = new Quest();
int gui = buffer.readInt();
2025-01-30 12:44:39 -05:00
quest.readNBT(ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
NoppesUtilServer.setEditingQuest(player,quest);
player.openGui(CustomNpcs.instance, gui , player.worldObj, 0, 0, 0);
}
else if(type == EnumPacketServer.DialogRemove){
2023-06-07 22:49:54 -04:00
int diagId = buffer.readInt();
boolean sendGroup = buffer.readBoolean();
Dialog dialog = DialogController.Instance.dialogs.get(diagId);
2018-09-13 12:03:28 -04:00
if(dialog != null && dialog.category != null){
2023-06-05 22:12:48 -04:00
DialogController.Instance.removeDialog(dialog);
2023-06-07 22:49:54 -04:00
if(sendGroup){
NoppesUtilServer.sendDialogGroup(player,dialog.category);
}
else {
NoppesUtilServer.sendDialogData(player,dialog.category);
}
2018-09-13 12:03:28 -04:00
}
}
else if(type == EnumPacketServer.DialogNpcGet){
NoppesUtilServer.sendNpcDialogs(player);
}
else if(type == EnumPacketServer.DialogNpcSet){
int slot = buffer.readInt();
int dialog = buffer.readInt();
DialogOption option = NoppesUtilServer.setNpcDialog(slot,dialog,player);
if(option != null && option.hasDialog()){
NBTTagCompound compound = option.writeNBT();
compound.setInteger("Position", slot);
GuiDataPacket.sendGuiData(player, compound);
2018-09-13 12:03:28 -04:00
}
}
else if(type == EnumPacketServer.DialogNpcRemove){
npc.dialogs.remove(buffer.readInt());
}
else if(type == EnumPacketServer.QuestCategoryGet){
2023-06-05 22:12:48 -04:00
QuestCategory category = QuestController.Instance.categories.get(buffer.readInt());
2018-09-13 12:03:28 -04:00
if(category != null){
NBTTagCompound comp = category.writeNBT(new NBTTagCompound());
comp.removeTag("Dialogs");
GuiDataPacket.sendGuiData(player, comp);
2018-09-13 12:03:28 -04:00
}
}
else if(type == EnumPacketServer.QuestCategorySave){
QuestCategory category = new QuestCategory();
2025-01-30 12:44:39 -05:00
category.readNBT(ByteBufUtils.readNBT(buffer));
2023-06-05 22:12:48 -04:00
QuestController.Instance.saveCategory(category);
2018-09-13 12:03:28 -04:00
NoppesUtilServer.sendQuestCategoryData(player);
}
else if(type == EnumPacketServer.QuestCategoryRemove){
2023-06-05 22:12:48 -04:00
QuestController.Instance.removeCategory(buffer.readInt());
2018-09-13 12:03:28 -04:00
NoppesUtilServer.sendQuestCategoryData(player);
}
else if(type == EnumPacketServer.QuestSave){
int category = buffer.readInt();
Quest quest = new Quest();
2025-01-30 12:44:39 -05:00
quest.readNBT(ByteBufUtils.readNBT(buffer));
2023-06-11 16:05:15 -04:00
boolean sendGroup = buffer.readBoolean();
2023-06-05 22:12:48 -04:00
QuestController.Instance.saveQuest(category, quest);
2023-06-11 16:05:15 -04:00
if(quest.category != null){
if(sendGroup){
NoppesUtilServer.sendQuestGroup(player, quest.category);
}
else {
NoppesUtilServer.sendQuestData(player, quest.category);
}
}
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.QuestDialogGetTitle){
2023-06-05 22:12:48 -04:00
Dialog quest = DialogController.Instance.dialogs.get(buffer.readInt());
Dialog quest2 = DialogController.Instance.dialogs.get(buffer.readInt());
Dialog quest3 = DialogController.Instance.dialogs.get(buffer.readInt());
2018-09-13 12:03:28 -04:00
NBTTagCompound compound = new NBTTagCompound();
if(quest != null)
compound.setString("1", quest.title);
if(quest2 != null)
compound.setString("2", quest2.title);
if(quest3 != null)
compound.setString("3", quest3.title);
GuiDataPacket.sendGuiData(player, compound);
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.QuestRemove){
2023-06-05 22:12:48 -04:00
Quest quest = QuestController.Instance.quests.get(buffer.readInt());
2023-06-11 16:05:15 -04:00
boolean sendGroup = buffer.readBoolean();
2018-09-13 12:03:28 -04:00
if(quest != null){
2023-06-05 22:12:48 -04:00
QuestController.Instance.removeQuest(quest);
2023-06-11 16:05:15 -04:00
if(sendGroup){
NoppesUtilServer.sendQuestGroup(player,quest.category);
}
else {
NoppesUtilServer.sendQuestData(player,quest.category);
}
2018-09-13 12:03:28 -04:00
}
}
else if(type == EnumPacketServer.TransportCategoriesGet){
NoppesUtilServer.sendTransportCategoryData(player);
}
else if(type == EnumPacketServer.TransportCategorySave){
2025-01-30 12:44:39 -05:00
TransportController.getInstance().saveCategory(ByteBufUtils.readString(buffer), buffer.readInt());
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.TransportCategoryRemove){
TransportController.getInstance().removeCategory(buffer.readInt());
NoppesUtilServer.sendTransportCategoryData(player);
}
else if(type == EnumPacketServer.TransportRemove){
int id = buffer.readInt();
TransportLocation loc = TransportController.getInstance().removeLocation(id);
if(loc != null)
NoppesUtilServer.sendTransportData(player,loc.category.id);
}
else if(type == EnumPacketServer.TransportsGet){
NoppesUtilServer.sendTransportData(player,buffer.readInt());
}
else if(type == EnumPacketServer.TransportSave){
int cat = buffer.readInt();
2025-01-30 12:44:39 -05:00
TransportLocation location = TransportController.getInstance().saveLocation(cat, ByteBufUtils.readNBT(buffer), npc);
2018-09-13 12:03:28 -04:00
if(location != null){
if(npc.advanced.role != EnumRoleType.Transporter)
return;
RoleTransporter role = (RoleTransporter) npc.roleInterface;
role.setTransport(location);
}
}
else if(type == EnumPacketServer.TransportGetLocation){
if(npc.advanced.role != EnumRoleType.Transporter)
return;
RoleTransporter role = (RoleTransporter) npc.roleInterface;
if(role.hasTransport()){
GuiDataPacket.sendGuiData(player, role.getLocation().writeNBT());
ScrollSelectedPacket.setSelectedList(player, role.getLocation().category.title);
2018-09-13 12:03:28 -04:00
}
}
else if(type == EnumPacketServer.FactionSet){
npc.setFaction(buffer.readInt());
}
else if(type == EnumPacketServer.FactionSave){
Faction faction = new Faction();
2025-01-30 12:44:39 -05:00
faction.readNBT(ByteBufUtils.readNBT(buffer));
2022-01-15 15:14:55 -06:00
FactionController.getInstance().saveFaction(faction);
2018-09-13 12:03:28 -04:00
NoppesUtilServer.sendFactionDataAll(player);
NBTTagCompound compound = new NBTTagCompound();
faction.writeNBT(compound);
GuiDataPacket.sendGuiData(player, compound);
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.FactionRemove){
2022-01-10 15:21:48 -06:00
FactionController.getInstance().delete(buffer.readInt());
2018-09-13 12:03:28 -04:00
NoppesUtilServer.sendFactionDataAll(player);
NBTTagCompound compound = new NBTTagCompound();
(new 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.TagSet){
this.setTags(npc,buffer);
2023-01-10 17:17:15 -05:00
}
else if(type == EnumPacketServer.TagSave){
Tag tag = new Tag();
2025-01-30 12:44:39 -05:00
tag.readNBT(ByteBufUtils.readNBT(buffer));
2023-01-10 17:17:15 -05:00
TagController.getInstance().saveTag(tag);
NoppesUtilServer.sendTagDataAll(player);
NBTTagCompound compound = new NBTTagCompound();
tag.writeNBT(compound);
GuiDataPacket.sendGuiData(player, compound);
2023-01-10 17:17:15 -05:00
}
else if(type == EnumPacketServer.TagRemove){
TagController.getInstance().delete(buffer.readInt());
NoppesUtilServer.sendTagDataAll(player);
NBTTagCompound compound = new NBTTagCompound();
(new Tag()).writeNBT(compound);
GuiDataPacket.sendGuiData(player, compound);
2023-01-10 17:17:15 -05:00
}
2018-09-13 12:03:28 -04:00
else if(type == EnumPacketServer.PlayerDataGet){
int id = buffer.readInt();
if(EnumPlayerData.values().length <= id)
return;
String name = null;
EnumPlayerData datatype = EnumPlayerData.values()[id];
if(datatype != EnumPlayerData.Players)
2025-01-30 12:44:39 -05:00
name = ByteBufUtils.readString(buffer);
2018-09-13 12:03:28 -04:00
NoppesUtilServer.sendPlayerData(datatype,player,name);
}
else if(type == EnumPacketServer.PlayerDataRemove){
NoppesUtilServer.removePlayerData(buffer,player);
}
2024-02-19 19:14:51 -05:00
else if(type == EnumPacketServer.PlayerDataMapRegen){
NoppesUtilServer.regenPlayerData(player);
}
2018-09-13 12:03:28 -04:00
else if(type == EnumPacketServer.MainmenuDisplayGet){
GuiDataPacket.sendGuiData(player, npc.display.writeToNBT(new NBTTagCompound()));
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.MainmenuDisplaySave){
2025-01-30 12:44:39 -05:00
npc.display.readToNBT(ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
npc.updateClient = true;
}
else if(type == EnumPacketServer.MainmenuStatsGet){
GuiDataPacket.sendGuiData(player, npc.stats.writeToNBT(new NBTTagCompound()));
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.MainmenuStatsSave){
2025-01-30 12:44:39 -05:00
npc.stats.readToNBT(ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
npc.updateClient = true;
}
else if(type == EnumPacketServer.MainmenuInvGet){
GuiDataPacket.sendGuiData(player, npc.inventory.writeEntityToNBT(new NBTTagCompound()));
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.MainmenuInvSave){
2025-01-30 12:44:39 -05:00
npc.inventory.readEntityFromNBT(ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
npc.updateAI = true;
npc.updateClient = true;
}
else if(type == EnumPacketServer.MainmenuAIGet){
GuiDataPacket.sendGuiData(player, npc.ai.writeToNBT(new NBTTagCompound()));
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.MainmenuAISave){
2025-01-30 12:44:39 -05:00
npc.ai.readToNBT(ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
npc.setHealth(npc.getMaxHealth());
npc.updateAI = true;
npc.updateClient = true;
}
else if(type == EnumPacketServer.MainmenuAdvancedGet){
GuiDataPacket.sendGuiData(player, npc.advanced.writeToNBT(new NBTTagCompound()));
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.MainmenuAdvancedSave){
2025-01-30 12:44:39 -05:00
npc.advanced.readToNBT(ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
npc.updateAI = true;
npc.updateClient = true;
}
2024-02-21 03:02:39 -05:00
else if(type == EnumPacketServer.MainmenuAdvancedMarkData){
MarkData data = MarkData.get(npc);
2025-01-30 12:44:39 -05:00
data.setNBT(ByteBufUtils.readNBT(buffer));
2024-02-21 03:02:39 -05:00
data.syncClients();
}
2018-09-13 12:03:28 -04:00
else if(type == EnumPacketServer.JobSave){
2022-11-07 01:49:54 -05:00
NBTTagCompound original = npc.jobInterface.writeToNBT(new NBTTagCompound());
2025-01-30 12:44:39 -05:00
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
2018-09-13 12:03:28 -04:00
Set<String> names = compound.func_150296_c();
for(String name : names)
original.setTag(name, compound.getTag(name));
npc.jobInterface.readFromNBT(original);
npc.updateClient = true;
}
else if(type == EnumPacketServer.JobGet){
if(npc.jobInterface == null)
return;
NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("JobData", true);
npc.jobInterface.writeToNBT(compound);
2022-11-07 01:49:54 -05:00
2018-09-13 12:03:28 -04:00
if(npc.advanced.job == EnumJobType.Spawner)
((JobSpawner)npc.jobInterface).cleanCompound(compound);
2022-11-07 01:49:54 -05:00
GuiDataPacket.sendGuiData(player, compound);
2018-09-13 12:03:28 -04:00
if(npc.advanced.job == EnumJobType.Spawner)
GuiDataPacket.sendGuiData(player, ((JobSpawner)npc.jobInterface).getTitles());
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.JobSpawnerAdd){
if(npc.advanced.job != EnumJobType.Spawner)
return;
JobSpawner job = (JobSpawner) npc.jobInterface;
if(buffer.readBoolean()){
2025-01-30 12:44:39 -05:00
NBTTagCompound compound = ServerCloneController.Instance.getCloneData(null, ByteBufUtils.readString(buffer), buffer.readInt());
2018-09-13 12:03:28 -04:00
job.setJobCompound(buffer.readInt(), compound);
}
else{
2025-01-30 12:44:39 -05:00
job.setJobCompound(buffer.readInt(), ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
}
GuiDataPacket.sendGuiData(player, job.getTitles());
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.RoleCompanionUpdate){
if(npc.advanced.role != EnumRoleType.Companion)
return;
((RoleCompanion)npc.roleInterface).matureTo(EnumCompanionStage.values()[buffer.readInt()]);
npc.updateClient = true;
}
else if(type == EnumPacketServer.JobSpawnerRemove){
if(npc.advanced.job != EnumJobType.Spawner)
return;
2023-07-30 17:29:06 -04:00
JobSpawner job = (JobSpawner) npc.jobInterface;
job.setJobCompound(buffer.readInt(), null);
GuiDataPacket.sendGuiData(player, job.getTitles());
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.RoleSave){
2025-01-30 12:44:39 -05:00
npc.roleInterface.readFromNBT(ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
npc.updateClient = true;
}
else if(type == EnumPacketServer.RoleGet){
if(npc.roleInterface == null)
return;
NBTTagCompound compound = new NBTTagCompound();
compound.setBoolean("RoleData", true);
GuiDataPacket.sendGuiData(player, npc.roleInterface.writeToNBT(compound));
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.MerchantUpdate){
Entity entity = player.worldObj.getEntityByID(buffer.readInt());
if(entity == null || !(entity instanceof EntityVillager))
return;
MerchantRecipeList list = MerchantRecipeList.func_151390_b(new PacketBuffer(buffer));
((EntityVillager)entity).setRecipes(list);
}
else if(type == EnumPacketServer.ModelDataSave){
if(npc instanceof EntityCustomNpc)
2025-01-30 12:44:39 -05:00
((EntityCustomNpc)npc).modelData.readFromNBT(ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.MailOpenSetup){
PlayerMail mail = new PlayerMail();
2025-01-30 12:44:39 -05:00
mail.readNBT(ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
ContainerMail.staticmail = mail;
player.openGui(CustomNpcs.instance, EnumGuiType.PlayerMailman.ordinal(), player.worldObj, 1, 0, 0);
}
else if(type == EnumPacketServer.TransformSave){
boolean isValid = npc.transform.isValid();
2025-01-30 12:44:39 -05:00
npc.transform.readOptions(ByteBufUtils.readNBT(buffer));
2018-09-13 12:03:28 -04:00
if(isValid != npc.transform.isValid())
npc.updateAI = true;
}
else if(type == EnumPacketServer.TransformGet){
GuiDataPacket.sendGuiData(player, npc.transform.writeOptions(new NBTTagCompound()));
2018-09-13 12:03:28 -04:00
}
else if(type == EnumPacketServer.TransformLoad){
if(npc.transform.isValid())
npc.transform.transform(buffer.readBoolean());
}
else if(type == EnumPacketServer.TraderMarketSave){
2025-01-30 12:44:39 -05:00
String market = ByteBufUtils.readString(buffer);
if(market == null)
return;
2018-09-13 12:03:28 -04:00
boolean bo = buffer.readBoolean();
if(npc.roleInterface instanceof RoleTrader){
if(bo)
Market.setMarket(npc, market);
else
Market.save((RoleTrader)npc.roleInterface, market);
}
}
else if(type == EnumPacketServer.AnimationsGet){
NoppesUtilServer.sendAnimationDataAll(player);
2023-02-06 23:17:05 -06:00
}
else if(type == EnumPacketServer.AnimationGet){
Animation animation = (Animation) AnimationController.getInstance().get(buffer.readInt());
NBTTagCompound compound = animation.writeToNBT();
GuiDataPacket.sendGuiData(player, compound);
}
else if(type == EnumPacketServer.AnimationRemove){
AnimationController.getInstance().delete(buffer.readInt());
NoppesUtilServer.sendAnimationDataAll(player);
NBTTagCompound compound = (new Animation()).writeToNBT();
GuiDataPacket.sendGuiData(player, compound);
2023-02-06 23:17:05 -06:00
}
else if(type == EnumPacketServer.AnimationSave){
2023-02-06 23:17:05 -06:00
Animation animation = new Animation();
2025-01-30 12:44:39 -05:00
animation.readFromNBT(ByteBufUtils.readNBT(buffer));
AnimationController.getInstance().saveAnimation(animation);
NoppesUtilServer.sendAnimationDataAll(player);
GuiDataPacket.sendGuiData(player, animation.writeToNBT());
2023-02-06 23:17:05 -06:00
}
2018-09-13 12:03:28 -04:00
else
blockPackets(type, buffer, player);
2022-11-07 01:49:54 -05:00
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
}
else if (type == EnumPacketServer.TagSet) {
EntityNPCInterface npc = NoppesUtilServer.getEditingNpc(player);
this.setTags(npc,buffer);
}
else if (type != EnumPacketServer.NpcTagsGet && type != EnumPacketServer.TagsGet) {
warn(player, "WE 2 tried todo something with the wrong tool, probably a hacker");
}
}
private void setTags(EntityNPCInterface npc, ByteBuf buffer) throws IOException {
npc.advanced.tagUUIDs.removeIf(uuid -> TagController.getInstance().getTagFromUUID(uuid) != null);
2025-01-30 12:44:39 -05:00
NBTTagCompound compound = ByteBufUtils.readNBT(buffer);
NBTTagList list = compound.getTagList("TagNames",8);
for (int i = 0; i < list.tagCount(); i++) {
String tagName = list.getStringTagAt(i);
npc.advanced.tagUUIDs.add(((Tag)TagController.getInstance().getTagFromName(tagName)).uuid);
}
2018-09-13 12:03:28 -04:00
}
private void warn(EntityPlayer player, String warning){
MinecraftServer.getServer().logWarning(player.getCommandSenderName() + ": " + warning);
}
}