Syncing and Large Packet Completion

This commit is contained in:
Kam committed 2025-01-29 18:25:34 -05:00
1 parent dcf3a0d8b0
commit de56032118
39 files changed
+648 -862

No files matched your search

+4 -2
View File
@@ -17,7 +17,7 @@ import noppes.npcs.containers.*;
import noppes.npcs.controllers.data.PlayerData;
import noppes.npcs.entity.EntityNPCInterface;
public abstract class CommonProxy implements IGuiHandler {
public class CommonProxy implements IGuiHandler {
public boolean newVersionAvailable = false;
public int revision = 1;
@@ -159,7 +159,9 @@ public abstract class CommonProxy implements IGuiHandler {
}
public abstract void generateBigSmokeParticles(World world, int x, int y, int z, boolean signalFire);
public void generateBigSmokeParticles(World world, int x, int y, int z, boolean signalFire){
}
public String getAchievementDesc(Achievement achievement) {
return "";
+2 -6
View File
@@ -90,6 +90,8 @@ public class CustomNpcs {
Channel = NetworkRegistry.INSTANCE.newEventDrivenChannel("CustomNPCs");
ChannelPlayer = NetworkRegistry.INSTANCE.newEventDrivenChannel("CustomNPCsPlayer");
PacketHandler.Instance = new PacketHandler();
MinecraftServer server = MinecraftServer.getServer();
String dir = "";
if (server != null) {
@@ -250,12 +252,6 @@ public class CustomNpcs {
ServerTagMapController.Instance = new ServerTagMapController();
}
//Loading items in the about to start event was corrupting items with a damage value
@EventHandler
public void postInit(FMLPostInitializationEvent event) {
PacketHandler.Instance = new PacketHandler();
}
@EventHandler
public void stopped(FMLServerStoppedEvent event){
@@ -1,6 +1,7 @@
package noppes.npcs;
import io.netty.buffer.ByteBuf;
import kamkeel.npcs.controllers.SyncMaster;
import net.minecraft.command.server.CommandBlockLogic;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
@@ -572,7 +573,7 @@ public class NoppesUtilServer {
playerdata.save();
}
if(pl != null) {
SyncController.syncPlayer((EntityPlayerMP) pl);
SyncMaster.syncPlayer((EntityPlayerMP) pl);
}
sendPlayerData(type, player, name);
}
@@ -847,48 +848,6 @@ public class NoppesUtilServer {
return entity;
}
}
public static void sendPlayerDataCompound(EntityPlayerMP player, NBTTagCompound compound, boolean sync) {
try {
byte[] bytes = CompressedStreamTools.compress(compound);
// Split byte array into chunks and send each chunk
int chunkSize = 16000;
int totalChunks = (int) Math.ceil((double) bytes.length / chunkSize);
for (int i = 0; i < totalChunks; i++) {
int start = i * chunkSize;
int length = Math.min(bytes.length - start, chunkSize);
byte[] chunk = new byte[length];
System.arraycopy(bytes, start, chunk, 0, length);
Server.sendData(player, EnumPacketClient.LARGE_NBT_PART, (Object) chunk);
}
// Send end packet
Server.sendData(player, EnumPacketClient.SYNC_PLAYER, sync);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void sendDBCCompound(EntityPlayerMP player, NBTTagCompound compound) {
try {
byte[] bytes = CompressedStreamTools.compress(compound);
// Split byte array into chunks and send each chunk
int chunkSize = 16000;
int totalChunks = (int) Math.ceil((double) bytes.length / chunkSize);
for (int i = 0; i < totalChunks; i++) {
int start = i * chunkSize;
int length = Math.min(bytes.length - start, chunkSize);
byte[] chunk = new byte[length];
System.arraycopy(bytes, start, chunk, 0, length);
Server.sendData(player, EnumPacketClient.LARGE_NBT_PART, (Object) chunk);
}
// Send end packet
Server.sendData(player, EnumPacketClient.DBC_FORM);
} catch (IOException e) {
e.printStackTrace();
}
}
public static boolean isOp(EntityPlayer player) {
return MinecraftServer.getServer().getConfigurationManager().func_152596_g(player.getGameProfile());
@@ -5,6 +5,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.relauncher.Side;
import kamkeel.npcs.controllers.SyncMaster;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@@ -62,7 +63,7 @@ public class ScriptPlayerEventHandler {
PlayerData playerData = PlayerDataController.Instance.getPlayerData(player);
if(playerData.updateClient) {
NoppesUtilServer.sendPlayerDataCompound((EntityPlayerMP)player, playerData.getSyncNBT(), true);
SyncMaster.syncPlayerData((EntityPlayerMP)player, true);
playerData.updateClient = false;
}
@@ -5,6 +5,7 @@ import cpw.mods.fml.common.gameevent.PlayerEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import kamkeel.npcs.controllers.ProfileController;
import kamkeel.npcs.controllers.SyncMaster;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.WorldServer;
@@ -52,7 +53,7 @@ public class ServerTickHandler {
playerData.onLogin();
}
SyncController.syncPlayer(player);
SyncMaster.syncPlayer(player);
ProfileController.login(player);
}
@@ -19,8 +19,6 @@ import org.lwjgl.opengl.GL11;
import java.util.Random;
import static noppes.npcs.client.ClientProxy.RAND;
public class BlockCampfire extends BlockLightable{
public BlockCampfire(boolean lit) {
@@ -329,51 +329,4 @@ public class NoppesUtil {
public static void isGUIOpen(boolean isGUIOpen) {
Client.sendData(EnumPacketServer.IsGuiOpen, isGUIOpen);
}
private static byte[] accumulatedData = new byte[0];
public static void handleLargeData(byte[] chunk) {
// Append the chunk to the accumulated data
accumulatedData = concatByteArrays(accumulatedData, chunk);
}
public static void handlePlayerDataEnd(boolean sync) {
NBTTagCompound compound;
try {
compound = CompressedStreamTools.func_152457_a(accumulatedData, new NBTSizeTracker(2097152L));
if(sync){
ClientCacheHandler.playerData.setSyncNBT(compound);
}
else {
ClientCacheHandler.playerData.setSyncNBTFull(compound);
}
} catch (IOException e) {
e.printStackTrace();
return;
} finally {
// Reset the accumulated data after processing
accumulatedData = new byte[0];
}
}
public static void handleFormEnd() {
NBTTagCompound compound;
try {
compound = CompressedStreamTools.func_152457_a(accumulatedData, new NBTSizeTracker(2097152L));
ClientCacheHandler.playerData.setDBCSync(compound);
} catch (IOException e) {
e.printStackTrace();
return;
} finally {
accumulatedData = new byte[0];
}
}
// Utility method to concatenate two byte arrays
private static byte[] concatByteArrays(byte[] a, byte[] b) {
byte[] result = new byte[a.length + b.length];
System.arraycopy(a, 0, result, 0, a.length);
System.arraycopy(b, 0, result, a.length, b.length);
return result;
}
}
@@ -111,31 +111,6 @@ public class PacketHandlerClient extends PacketHandlerServer{
RecipeController.Instance.anvilRecipes = RecipeController.syncRecipes;
RecipeController.syncRecipes = new HashMap<Integer, RecipeCarpentry>();
}
else if(type == EnumPacketClient.LARGE_NBT_PART){
byte[] chunk = new byte[buffer.readShort()];
buffer.readBytes(chunk);
NoppesUtil.handleLargeData(chunk);
}
else if(type == EnumPacketClient.SYNC_PLAYER){
boolean sync = buffer.readBoolean();
NoppesUtil.handlePlayerDataEnd(sync);
}
else if(type == EnumPacketClient.SYNC_ADD || type == EnumPacketClient.SYNC_END){
int synctype = buffer.readInt();
NBTTagCompound compound = Server.readNBT(buffer);
SyncController.clientSync(synctype, compound, type == EnumPacketClient.SYNC_END);
}
else if(type == EnumPacketClient.SYNC_UPDATE){
int synctype = buffer.readInt();
NBTTagCompound compound = Server.readNBT(buffer);
SyncController.clientSyncUpdate(synctype, compound, buffer);
}
else if(type == EnumPacketClient.SYNC_REMOVE){
int synctype = buffer.readInt();
int id = buffer.readInt();
SyncController.clientSyncRemove(synctype, id);
}
else if(type == EnumPacketClient.SYNC_CONFIG){
NBTTagCompound configNBT = Server.readNBT(buffer);
SyncController.receiveConfigs(configNBT);
@@ -450,8 +425,5 @@ public class PacketHandlerClient extends PacketHandlerServer{
if(gui instanceof IPartyData)
((IPartyData)gui).setPartyData(Server.readNBT(buffer));
}
else if(type == EnumPacketClient.DBC_FORM){
NoppesUtil.handleFormEnd();
}
}
}
@@ -55,9 +55,6 @@ public enum EnumPacketClient {
STOP_SOUNDS,
SYNC_WEAPON,
MARK_DATA,
SYNC_ADD, SYNC_END, SYNC_UPDATE, SYNC_REMOVE, SYNC_PLAYER,
SYNC_CONFIG,
DBC_FORM,
LARGE_NBT_PART, LARGE_NBT_END,
PARTY_DATA
}
@@ -1,11 +0,0 @@
package noppes.npcs.constants;
public class SyncType {
public static final int FACTION = 1;
public static final int QUEST = 2;
public static final int QUEST_CATEGORY = 3;
public static final int DIALOG = 4;
public static final int DIALOG_CATEGORY = 5;
public static final int PLAYER_DATA = 6;
public static final int MAGIC = 7;
}
@@ -1,18 +1,17 @@
package noppes.npcs.controllers;
import kamkeel.npcs.controllers.SyncMaster;
import kamkeel.npcs.network.enums.EnumSyncType;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.NoppesStringUtils;
import noppes.npcs.Server;
import noppes.npcs.api.handler.IDialogHandler;
import noppes.npcs.api.handler.data.IDialog;
import noppes.npcs.api.handler.data.IDialogCategory;
import noppes.npcs.constants.EnumOptionType;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.SyncType;
import noppes.npcs.controllers.data.Dialog;
import noppes.npcs.controllers.data.DialogCategory;
import noppes.npcs.controllers.data.DialogOption;
@@ -230,7 +229,7 @@ public class DialogController implements IDialogHandler {
dir.mkdirs();
}
categories.put(category.id, category);
SyncController.updateDialogCat(category);
SyncMaster.syncUpdate(EnumSyncType.DIALOG_CATEGORY, -1, SyncMaster.updateDialogCat(category));
}
public void removeCategory(int category){
@@ -243,8 +242,8 @@ public class DialogController implements IDialogHandler {
for(int dia : cat.dialogs.keySet())
dialogs.remove(dia);
categories.remove(category);
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.DIALOG_CATEGORY, category);
}
SyncMaster.syncRemove(EnumSyncType.DIALOG_CATEGORY, category);
}
private boolean containsCategoryName(String name) {
name = name.toLowerCase();
@@ -291,7 +290,7 @@ public class DialogController implements IDialogHandler {
if(file2.exists())
file2.delete();
file.renameTo(file2);
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.DIALOG, dialog.writeToNBT(new NBTTagCompound()), category.id);
SyncMaster.syncUpdate(EnumSyncType.DIALOG, category.id, dialog.writeToNBT(new NBTTagCompound()));
} catch (Exception e) {
LogWriter.except(e);
}
@@ -305,7 +304,7 @@ public class DialogController implements IDialogHandler {
return;
category.dialogs.remove(dialog.id);
dialogs.remove(dialog.id);
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.DIALOG, dialog.id);
SyncMaster.syncRemove(EnumSyncType.DIALOG, dialog.id);
}
private File getDir(){
@@ -1,15 +1,14 @@
package noppes.npcs.controllers;
import kamkeel.npcs.controllers.SyncMaster;
import kamkeel.npcs.network.enums.EnumSyncType;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.Server;
import noppes.npcs.api.handler.IFactionHandler;
import noppes.npcs.api.handler.data.IFaction;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.SyncType;
import noppes.npcs.controllers.data.Faction;
import java.io.*;
@@ -158,7 +157,7 @@ public class FactionController implements IFactionHandler {
NBTTagCompound facCompound = new NBTTagCompound();
faction.writeNBT(facCompound);
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.FACTION, facCompound);
SyncMaster.syncUpdate(EnumSyncType.FACTION, -1, facCompound);
saveFactions();
}
@@ -193,7 +192,7 @@ public class FactionController implements IFactionHandler {
} else {
this.saveFactions();
faction.id = -1;
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.FACTION, id);
SyncMaster.syncRemove(EnumSyncType.FACTION, id);
return faction;
}
} else {
@@ -5,10 +5,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.Server;
import noppes.npcs.api.handler.data.IMagic;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.SyncType;
import noppes.npcs.controllers.data.Magic;
import java.io.*;
@@ -160,7 +157,7 @@ public class MagicController {
NBTTagCompound facCompound = new NBTTagCompound();
mag.writeNBT(facCompound);
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.MAGIC, facCompound);
// Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.MAGIC, facCompound);
saveFactions();
}
@@ -1,17 +1,16 @@
package noppes.npcs.controllers;
import kamkeel.npcs.controllers.SyncMaster;
import kamkeel.npcs.network.enums.EnumSyncType;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import noppes.npcs.NoppesStringUtils;
import noppes.npcs.Server;
import noppes.npcs.api.handler.IQuestHandler;
import noppes.npcs.api.handler.data.IQuest;
import noppes.npcs.api.handler.data.IQuestCategory;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.SyncType;
import noppes.npcs.controllers.data.Quest;
import noppes.npcs.controllers.data.QuestCategory;
import noppes.npcs.util.NBTJsonUtil;
@@ -146,7 +145,7 @@ public class QuestController implements IQuestHandler {
for(int dia : cat.quests.keySet())
quests.remove(dia);
categories.remove(category);
Server.sendToAll(EnumPacketClient.SYNC_REMOVE, SyncType.QUEST_CATEGORY, category);
SyncMaster.syncRemove(EnumSyncType.QUEST_CATEGORY, category);
}
public void saveCategory(QuestCategory category){
@@ -177,7 +176,7 @@ public class QuestController implements IQuestHandler {
dir.mkdirs();
}
categories.put(category.id, category);
SyncController.updateQuestCat(category);
SyncMaster.syncUpdate(EnumSyncType.QUEST_CATEGORY, -1, SyncMaster.updateQuestCat(category));
}
private boolean containsCategoryName(String name) {
name = name.toLowerCase();
@@ -225,7 +224,7 @@ public class QuestController implements IQuestHandler {
if(file2.exists())
file2.delete();
file.renameTo(file2);
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.QUEST, quest.writeToNBT(new NBTTagCompound()), category.id);
SyncMaster.syncUpdate(EnumSyncType.QUEST, category.id, quest.writeToNBT(new NBTTagCompound()));
} catch (Exception e) {
e.printStackTrace();
}
@@ -9,10 +9,6 @@ import noppes.npcs.NoppesUtilServer;
import noppes.npcs.Server;
import noppes.npcs.config.ConfigMain;
import noppes.npcs.constants.EnumPacketClient;
import noppes.npcs.constants.SyncType;
import noppes.npcs.controllers.data.*;
import java.util.HashMap;
public class SyncController {
@@ -26,332 +22,4 @@ public class SyncController {
ConfigMain.EnableProfiles = compound.getBoolean("Profiles");
}
public static void syncPlayer(EntityPlayerMP player){
NBTTagList list = new NBTTagList();
NBTTagCompound compound = new NBTTagCompound();
////////////////////////////////////////////////////////////////////////////////
// Faction Sync
for(Faction faction : FactionController.getInstance().factions.values()){
NBTTagCompound factioNBT = new NBTTagCompound();
faction.writeNBT(factioNBT);
list.appendTag(factioNBT);
if(list.tagCount() > 10){
compound = new NBTTagCompound();
compound.setTag("Data", list);
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.FACTION, compound);
list = new NBTTagList();
}
}
compound = new NBTTagCompound();
compound.setTag("Data", list);
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.FACTION, compound);
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Quest Sync
for(QuestCategory category : QuestController.Instance.categories.values()){
NBTTagCompound questCompound;
NBTTagList questList = new NBTTagList();
for(int questID : category.quests.keySet()){
Quest quest = category.quests.get(questID);
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
if(questList.tagCount() > 20){
questCompound = new NBTTagCompound();
questCompound.setTag("Data", questList);
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, questCompound);
questList = new NBTTagList();
}
}
questCompound = new NBTTagCompound();
questCompound.setTag("Data", questList);
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, questCompound);
}
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.QUEST_CATEGORY, new NBTTagCompound());
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// Dialog Sync
for(DialogCategory category : DialogController.Instance.categories.values()){
NBTTagCompound dialogCompound;
NBTTagList dialogList = new NBTTagList();
for(int dialogID : category.dialogs.keySet()){
Dialog dialog = category.dialogs.get(dialogID);
dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound()));
if(dialogList.tagCount() > 20){
dialogCompound = new NBTTagCompound();
dialogCompound.setTag("Data", dialogList);
dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, dialogCompound);
dialogList = new NBTTagList();
}
}
dialogCompound = new NBTTagCompound();
dialogCompound.setTag("Data", dialogList);
dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
Server.sendData(player, EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, dialogCompound);
}
Server.sendData(player, EnumPacketClient.SYNC_END, SyncType.DIALOG_CATEGORY, new NBTTagCompound());
////////////////////////////////////////////////////////////////////////////////
DBCAddon.instance.syncPlayer(player);
PlayerData data = PlayerData.get(player);
if(data != null){
NoppesUtilServer.sendPlayerDataCompound(player, data.getSyncNBTFull(), false);
}
}
public static void syncAllDialogs() {
for(DialogCategory category : DialogController.Instance.categories.values()){
NBTTagCompound dialogCompound;
NBTTagList dialogList = new NBTTagList();
for(int dialogID : category.dialogs.keySet()){
Dialog dialog = category.dialogs.get(dialogID);
dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound()));
if(dialogList.tagCount() > 20){
dialogCompound = new NBTTagCompound();
dialogCompound.setTag("Data", dialogList);
dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, dialogCompound);
dialogList = new NBTTagList();
}
}
dialogCompound = new NBTTagCompound();
dialogCompound.setTag("Data", dialogList);
dialogCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.DIALOG_CATEGORY, dialogCompound);
}
Server.sendToAll(EnumPacketClient.SYNC_END, SyncType.DIALOG_CATEGORY, new NBTTagCompound());
}
public static void syncAllQuests() {
for(QuestCategory category : QuestController.Instance.categories.values()){
NBTTagCompound questCompound;
NBTTagList questList = new NBTTagList();
for(int questID : category.quests.keySet()){
Quest quest = category.quests.get(questID);
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
if(questList.tagCount() > 20){
questCompound = new NBTTagCompound();
questCompound.setTag("Data", questList);
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, questCompound);
questList = new NBTTagList();
}
}
questCompound = new NBTTagCompound();
questCompound.setTag("Data", questList);
questCompound.setTag("CatNBT", category.writeSmallNBT(new NBTTagCompound()));
Server.sendToAll(EnumPacketClient.SYNC_ADD, SyncType.QUEST_CATEGORY, questCompound);
}
Server.sendToAll(EnumPacketClient.SYNC_END, SyncType.QUEST_CATEGORY, new NBTTagCompound());
}
public static void updateQuestCat(QuestCategory questCategory) {
NBTTagCompound questCompound;
NBTTagList questList = new NBTTagList();
for(int questID : questCategory.quests.keySet()){
Quest quest = questCategory.quests.get(questID);
questList.appendTag(quest.writeToNBT(new NBTTagCompound()));
if(questList.tagCount() > 20){
questCompound = new NBTTagCompound();
questCompound.setTag("Data", questList);
questCompound.setTag("CatNBT", questCategory.writeSmallNBT(new NBTTagCompound()));
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.QUEST_CATEGORY, questCompound);
questList = new NBTTagList();
}
}
questCompound = new NBTTagCompound();
questCompound.setTag("Data", questList);
questCompound.setTag("CatNBT", questCategory.writeSmallNBT(new NBTTagCompound()));
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.QUEST_CATEGORY, questCompound);
}
public static void updateDialogCat(DialogCategory dialogCategory) {
NBTTagCompound dialogCompound;
NBTTagList dialogList = new NBTTagList();
for(int questID : dialogCategory.dialogs.keySet()){
Dialog dialog = dialogCategory.dialogs.get(questID);
dialogList.appendTag(dialog.writeToNBT(new NBTTagCompound()));
if(dialogList.tagCount() > 20){
dialogCompound = new NBTTagCompound();
dialogCompound.setTag("Data", dialogList);
dialogCompound.setTag("CatNBT", dialogCategory.writeSmallNBT(new NBTTagCompound()));
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.DIALOG_CATEGORY, dialogCompound);
dialogList = new NBTTagList();
}
}
dialogCompound = new NBTTagCompound();
dialogCompound.setTag("Data", dialogList);
dialogCompound.setTag("CatNBT", dialogCategory.writeSmallNBT(new NBTTagCompound()));
Server.sendToAll(EnumPacketClient.SYNC_UPDATE, SyncType.DIALOG_CATEGORY, dialogCompound);
}
public static void clientSync(int synctype, NBTTagCompound compound, boolean syncEnd) {
if(synctype == SyncType.FACTION){
NBTTagList list = compound.getTagList("Data", 10);
for(int i = 0; i < list.tagCount(); i++)
{
Faction faction = new Faction();
faction.readNBT(list.getCompoundTagAt(i));
FactionController.getInstance().factionsSync.put(faction.id, faction);
}
if(syncEnd){
FactionController.getInstance().factions = FactionController.getInstance().factionsSync;
FactionController.getInstance().factionsSync = new HashMap<Integer, Faction>();
}
}
else if(synctype == SyncType.QUEST_CATEGORY){
if(!compound.hasNoTags()){
QuestCategory category = new QuestCategory();
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
NBTTagList list = compound.getTagList("Data", 10);
if(QuestController.Instance.categoriesSync.containsKey(category.id)){
category = QuestController.Instance.categoriesSync.get(category.id);
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
}
for(int i = 0; i < list.tagCount(); i++)
{
Quest quest = new Quest();
quest.readNBT(list.getCompoundTagAt(i));
quest.category = category;
category.quests.put(quest.id, quest);
}
QuestController.Instance.categoriesSync.put(category.id, category);
}
if(syncEnd){
HashMap<Integer,Quest> quests = new HashMap<Integer, Quest>();
for(QuestCategory category : QuestController.Instance.categoriesSync.values()){
for(Quest quest : category.quests.values()){
quests.put(quest.id, quest);
}
}
QuestController.Instance.categories = QuestController.Instance.categoriesSync;
QuestController.Instance.quests = quests;
QuestController.Instance.categoriesSync = new HashMap<Integer, QuestCategory>();
}
}
else if(synctype == SyncType.DIALOG_CATEGORY){
if(!compound.hasNoTags()){
DialogCategory category = new DialogCategory();
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
NBTTagList list = compound.getTagList("Data", 10);
if(DialogController.Instance.categoriesSync.containsKey(category.id)){
category = DialogController.Instance.categoriesSync.get(category.id);
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
}
for(int i = 0; i < list.tagCount(); i++)
{
Dialog dialog = new Dialog();
dialog.readNBT(list.getCompoundTagAt(i));
dialog.category = category;
category.dialogs.put(dialog.id, dialog);
}
DialogController.Instance.categoriesSync.put(category.id, category);
}
if(syncEnd){
HashMap<Integer,Dialog> dialogs = new HashMap<Integer, Dialog>();
for(DialogCategory category : DialogController.Instance.categoriesSync.values()){
for(Dialog dialog : category.dialogs.values()){
dialogs.put(dialog.id, dialog);
}
}
DialogController.Instance.categories = DialogController.Instance.categoriesSync;
DialogController.Instance.dialogs = dialogs;
DialogController.Instance.categoriesSync = new HashMap<Integer, DialogCategory>();
}
}
}
public static void clientSyncUpdate(int synctype, NBTTagCompound compound, ByteBuf buffer) {
if(synctype == SyncType.FACTION){
Faction faction = new Faction();
faction.readNBT(compound);
FactionController.getInstance().factions.put(faction.id, faction);
}
else if(synctype == SyncType.DIALOG){
DialogCategory category = DialogController.Instance.categories.get(buffer.readInt());
Dialog dialog = new Dialog();
dialog.category = category;
dialog.readNBT(compound);
DialogController.Instance.dialogs.put(dialog.id, dialog);
category.dialogs.put(dialog.id, dialog);
}
else if(synctype == SyncType.DIALOG_CATEGORY){
DialogCategory category = new DialogCategory();
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
NBTTagList list = compound.getTagList("Data", 10);
if(DialogController.Instance.categoriesSync.containsKey(category.id)){
category = DialogController.Instance.categoriesSync.get(category.id);
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
}
for(int i = 0; i < list.tagCount(); i++)
{
Dialog dialog = new Dialog();
dialog.readNBT(list.getCompoundTagAt(i));
dialog.category = category;
category.dialogs.put(dialog.id, dialog);
}
DialogController.Instance.categories.put(category.id, category);
}
else if(synctype == SyncType.QUEST){
QuestCategory category = QuestController.Instance.categories.get(buffer.readInt());
Quest quest = new Quest();
quest.category = category;
quest.readNBT(compound);
QuestController.Instance.quests.put(quest.id, quest);
category.quests.put(quest.id, quest);
}
else if(synctype == SyncType.QUEST_CATEGORY){
QuestCategory category = new QuestCategory();
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
NBTTagList list = compound.getTagList("Data", 10);
if(QuestController.Instance.categoriesSync.containsKey(category.id)){
category = QuestController.Instance.categoriesSync.get(category.id);
category.readSmallNBT(compound.getCompoundTag("CatNBT"));
}
for(int i = 0; i < list.tagCount(); i++)
{
Quest quest = new Quest();
quest.readNBT(list.getCompoundTagAt(i));
quest.category = category;
category.quests.put(quest.id, quest);
}
QuestController.Instance.categories.put(category.id, category);
}
}
public static void clientSyncRemove(int synctype, int id) {
if(synctype == SyncType.FACTION){
FactionController.getInstance().factions.remove(id);
}
else if(synctype == SyncType.DIALOG){
Dialog dialog = DialogController.Instance.dialogs.remove(id);
if(dialog != null) {
dialog.category.dialogs.remove(id);
}
}
else if(synctype == SyncType.DIALOG_CATEGORY){
DialogCategory category = DialogController.Instance.categories.remove(id);
if(category != null) {
DialogController.Instance.dialogs.keySet().removeAll(category.dialogs.keySet());
}
}
else if(synctype == SyncType.QUEST){
Quest quest = QuestController.Instance.quests.remove(id);
if(quest != null) {
quest.category.quests.remove(id);
}
}
else if(synctype == SyncType.QUEST_CATEGORY){
QuestCategory category = QuestController.Instance.categories.remove(id);
if(category != null) {
QuestController.Instance.quests.keySet().removeAll(category.quests.keySet());
}
}
}
}