diff --git a/src/main/java/kamkeel/npcs/controllers/SyncController.java b/src/main/java/kamkeel/npcs/controllers/SyncController.java index 57b111404..ca2171461 100644 --- a/src/main/java/kamkeel/npcs/controllers/SyncController.java +++ b/src/main/java/kamkeel/npcs/controllers/SyncController.java @@ -10,7 +10,7 @@ import kamkeel.npcs.controllers.data.ability.data.ChainedAbility; import kamkeel.npcs.network.LargeAbstractPacket; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumSyncAction; -import kamkeel.npcs.network.enums.EnumSyncType; +import kamkeel.npcs.network.enums.SyncType; import kamkeel.npcs.network.packets.data.LoginPacket; import kamkeel.npcs.network.packets.data.ProfileSharedQuestPacket; import kamkeel.npcs.network.packets.data.ability.AbilityCooldownSyncPacket; @@ -47,11 +47,12 @@ import noppes.npcs.controllers.data.RecipeAnvil; import noppes.npcs.controllers.data.RecipeCarpentry; import java.io.IOException; -import java.util.EnumMap; -import java.util.EnumSet; +import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Supplier; @@ -60,7 +61,7 @@ public class SyncController { public static boolean DEBUG_SYNC_LOGGING = false; - private static final EnumMap cacheEntries = new EnumMap<>(EnumSyncType.class); + private static final Map cacheEntries = new LinkedHashMap<>(); private static final ConcurrentHashMap playerSyncState = new ConcurrentHashMap<>(); @@ -70,35 +71,35 @@ public class SyncController { } } - private static final EnumSyncType[] LOGIN_SYNC_TYPES = new EnumSyncType[]{ - EnumSyncType.FACTION, - EnumSyncType.DIALOG_CATEGORY, - EnumSyncType.QUEST_CATEGORY, - EnumSyncType.WORKBENCH_RECIPES, - EnumSyncType.CARPENTRY_RECIPES, - EnumSyncType.ANVIL_RECIPES, - EnumSyncType.CUSTOM_EFFECTS, - EnumSyncType.MAGIC, - EnumSyncType.MAGIC_CYCLE, - EnumSyncType.CUSTOM_ABILITY, - EnumSyncType.CHAINED_ABILITY + private static final SyncType[] LOGIN_SYNC_TYPES = new SyncType[]{ + SyncType.FACTION, + SyncType.DIALOG_CATEGORY, + SyncType.QUEST_CATEGORY, + SyncType.WORKBENCH_RECIPES, + SyncType.CARPENTRY_RECIPES, + SyncType.ANVIL_RECIPES, + SyncType.CUSTOM_EFFECTS, + SyncType.MAGIC, + SyncType.MAGIC_CYCLE, + SyncType.CUSTOM_ABILITY, + SyncType.CHAINED_ABILITY }; public static void load() { cacheEntries.clear(); playerSyncState.clear(); - registerCache(EnumSyncType.FACTION, SyncController::factionsNBT); - registerCache(EnumSyncType.DIALOG_CATEGORY, SyncController::dialogCategoriesNBT); - registerCache(EnumSyncType.QUEST_CATEGORY, SyncController::questCategoriesNBT); - registerCache(EnumSyncType.WORKBENCH_RECIPES, SyncController::workbenchNBT); - registerCache(EnumSyncType.CARPENTRY_RECIPES, SyncController::carpentryNBT); - registerCache(EnumSyncType.ANVIL_RECIPES, SyncController::anvilNBT); - registerCache(EnumSyncType.CUSTOM_EFFECTS, SyncController::customEffectsNBT); - registerCache(EnumSyncType.MAGIC, SyncController::magicsNBT); - registerCache(EnumSyncType.MAGIC_CYCLE, SyncController::magicCyclesNBT); - registerCache(EnumSyncType.CUSTOM_ABILITY, SyncController::customAbilitiesNBT); - registerCache(EnumSyncType.CHAINED_ABILITY, SyncController::chainedAbilitiesNBT); + registerCache(SyncType.FACTION, SyncController::factionsNBT); + registerCache(SyncType.DIALOG_CATEGORY, SyncController::dialogCategoriesNBT); + registerCache(SyncType.QUEST_CATEGORY, SyncController::questCategoriesNBT); + registerCache(SyncType.WORKBENCH_RECIPES, SyncController::workbenchNBT); + registerCache(SyncType.CARPENTRY_RECIPES, SyncController::carpentryNBT); + registerCache(SyncType.ANVIL_RECIPES, SyncController::anvilNBT); + registerCache(SyncType.CUSTOM_EFFECTS, SyncController::customEffectsNBT); + registerCache(SyncType.MAGIC, SyncController::magicsNBT); + registerCache(SyncType.MAGIC_CYCLE, SyncController::magicCyclesNBT); + registerCache(SyncType.CUSTOM_ABILITY, SyncController::customAbilitiesNBT); + registerCache(SyncType.CHAINED_ABILITY, SyncController::chainedAbilitiesNBT); } public static void syncPlayer(EntityPlayerMP player) { @@ -108,7 +109,7 @@ public class SyncController { private static void syncPlayerInternal(EntityPlayerMP player, boolean includePostPackets) { PlayerSyncState state = playerSyncState.computeIfAbsent(player.getUniqueID(), PlayerSyncState::new); - for (EnumSyncType type : LOGIN_SYNC_TYPES) { + for (SyncType type : LOGIN_SYNC_TYPES) { SyncCacheEntry entry = cacheEntries.get(type); if (entry == null) { continue; @@ -149,7 +150,7 @@ public class SyncController { EntityPlayerMP player, String serverKey, String previousServerKey, - Map clientRevisions + Map clientRevisions ) { String currentServerKey = getServerCacheKey(); PlayerSyncState state = playerSyncState.computeIfAbsent(player.getUniqueID(), PlayerSyncState::new); @@ -196,9 +197,9 @@ public class SyncController { } } - private static EnumMap getServerRevisionSnapshot() { - EnumMap snapshot = new EnumMap<>(EnumSyncType.class); - for (EnumSyncType type : LOGIN_SYNC_TYPES) { + private static Map getServerRevisionSnapshot() { + Map snapshot = new LinkedHashMap<>(); + for (SyncType type : LOGIN_SYNC_TYPES) { SyncCacheEntry entry = cacheEntries.get(type); if (entry != null) { snapshot.put(type, entry.getRevisionValue()); @@ -222,7 +223,7 @@ public class SyncController { return SERVER_IDENTITY_KEY; } - public static int getCurrentRevision(EnumSyncType type) { + public static int getCurrentRevision(SyncType type) { SyncCacheEntry entry = cacheEntries.get(type); return entry == null ? -1 : entry.getRevisionValue(); } @@ -356,12 +357,12 @@ public class SyncController { } public static void syncAllCustomAbilities() { - CachedSyncPayload payload = rebuildNow(EnumSyncType.CUSTOM_ABILITY); + CachedSyncPayload payload = rebuildNow(SyncType.CUSTOM_ABILITY); if (payload == null) { return; } - PacketHandler.Instance.sendToAll(new SyncPacket(EnumSyncType.CUSTOM_ABILITY, payload)); - updateAllPlayerRevisions(EnumSyncType.CUSTOM_ABILITY, payload.getRevision()); + PacketHandler.Instance.sendToAll(new SyncPacket(SyncType.CUSTOM_ABILITY, payload)); + updateAllPlayerRevisions(SyncType.CUSTOM_ABILITY, payload.getRevision()); } public static NBTTagCompound chainedAbilitiesNBT() { @@ -377,12 +378,12 @@ public class SyncController { } public static void syncAllChainedAbilities() { - CachedSyncPayload payload = rebuildNow(EnumSyncType.CHAINED_ABILITY); + CachedSyncPayload payload = rebuildNow(SyncType.CHAINED_ABILITY); if (payload == null) { return; } - PacketHandler.Instance.sendToAll(new SyncPacket(EnumSyncType.CHAINED_ABILITY, payload)); - updateAllPlayerRevisions(EnumSyncType.CHAINED_ABILITY, payload.getRevision()); + PacketHandler.Instance.sendToAll(new SyncPacket(SyncType.CHAINED_ABILITY, payload)); + updateAllPlayerRevisions(SyncType.CHAINED_ABILITY, payload.getRevision()); } public static void syncPlayerData(EntityPlayerMP player, boolean update) { @@ -390,14 +391,14 @@ public class SyncController { if (data != null) { if (update) { PacketHandler.Instance.sendToPlayer(new SyncPacket( - EnumSyncType.PLAYERDATA, + SyncType.PLAYERDATA, EnumSyncAction.UPDATE, -1, data.getSyncNBT()) , player); } else { PacketHandler.Instance.sendToPlayer(new SyncPacket( - EnumSyncType.PLAYERDATA, + SyncType.PLAYERDATA, EnumSyncAction.RELOAD, -1, data.getSyncNBTFull()), player); @@ -405,11 +406,11 @@ public class SyncController { } } - public static void syncRemove(EnumSyncType enumSyncType, int id) { - Map revisions = invalidateCaches(enumSyncType); - int revision = revisions.getOrDefault(enumSyncType, getCurrentRevision(enumSyncType)); + public static void syncRemove(SyncType syncType, int id) { + Map revisions = invalidateCaches(syncType); + int revision = revisions.getOrDefault(syncType, getCurrentRevision(syncType)); PacketHandler.Instance.sendToAll(new SyncPacket( - enumSyncType, + syncType, EnumSyncAction.REMOVE, id, revision, @@ -419,373 +420,326 @@ public class SyncController { } public static void syncAllDialogs() { - CachedSyncPayload payload = rebuildNow(EnumSyncType.DIALOG_CATEGORY); + CachedSyncPayload payload = rebuildNow(SyncType.DIALOG_CATEGORY); if (payload == null) { return; } - PacketHandler.Instance.sendToAll(new SyncPacket(EnumSyncType.DIALOG_CATEGORY, payload)); - updateAllPlayerRevisions(EnumSyncType.DIALOG_CATEGORY, payload.getRevision()); + PacketHandler.Instance.sendToAll(new SyncPacket(SyncType.DIALOG_CATEGORY, payload)); + updateAllPlayerRevisions(SyncType.DIALOG_CATEGORY, payload.getRevision()); } public static void syncAllQuests() { - CachedSyncPayload payload = rebuildNow(EnumSyncType.QUEST_CATEGORY); + CachedSyncPayload payload = rebuildNow(SyncType.QUEST_CATEGORY); if (payload == null) { return; } - PacketHandler.Instance.sendToAll(new SyncPacket(EnumSyncType.QUEST_CATEGORY, payload)); - updateAllPlayerRevisions(EnumSyncType.QUEST_CATEGORY, payload.getRevision()); + PacketHandler.Instance.sendToAll(new SyncPacket(SyncType.QUEST_CATEGORY, payload)); + updateAllPlayerRevisions(SyncType.QUEST_CATEGORY, payload.getRevision()); } public static void syncAllWorkbenchRecipes() { - CachedSyncPayload payload = rebuildNow(EnumSyncType.WORKBENCH_RECIPES); + CachedSyncPayload payload = rebuildNow(SyncType.WORKBENCH_RECIPES); if (payload == null) { return; } - PacketHandler.Instance.sendToAll(new SyncPacket(EnumSyncType.WORKBENCH_RECIPES, payload)); - updateAllPlayerRevisions(EnumSyncType.WORKBENCH_RECIPES, payload.getRevision()); + PacketHandler.Instance.sendToAll(new SyncPacket(SyncType.WORKBENCH_RECIPES, payload)); + updateAllPlayerRevisions(SyncType.WORKBENCH_RECIPES, payload.getRevision()); } public static void syncAllCarpentryRecipes() { - CachedSyncPayload payload = rebuildNow(EnumSyncType.CARPENTRY_RECIPES); + CachedSyncPayload payload = rebuildNow(SyncType.CARPENTRY_RECIPES); if (payload == null) { return; } - PacketHandler.Instance.sendToAll(new SyncPacket(EnumSyncType.CARPENTRY_RECIPES, payload)); - updateAllPlayerRevisions(EnumSyncType.CARPENTRY_RECIPES, payload.getRevision()); + PacketHandler.Instance.sendToAll(new SyncPacket(SyncType.CARPENTRY_RECIPES, payload)); + updateAllPlayerRevisions(SyncType.CARPENTRY_RECIPES, payload.getRevision()); } public static void syncAllAnvilRecipes() { - CachedSyncPayload payload = rebuildNow(EnumSyncType.ANVIL_RECIPES); + CachedSyncPayload payload = rebuildNow(SyncType.ANVIL_RECIPES); if (payload == null) { return; } - PacketHandler.Instance.sendToAll(new SyncPacket(EnumSyncType.ANVIL_RECIPES, payload)); - updateAllPlayerRevisions(EnumSyncType.ANVIL_RECIPES, payload.getRevision()); + PacketHandler.Instance.sendToAll(new SyncPacket(SyncType.ANVIL_RECIPES, payload)); + updateAllPlayerRevisions(SyncType.ANVIL_RECIPES, payload.getRevision()); } public static void syncAllCustomEffects() { - CachedSyncPayload payload = rebuildNow(EnumSyncType.CUSTOM_EFFECTS); + CachedSyncPayload payload = rebuildNow(SyncType.CUSTOM_EFFECTS); if (payload == null) { return; } - PacketHandler.Instance.sendToAll(new SyncPacket(EnumSyncType.CUSTOM_EFFECTS, payload)); - updateAllPlayerRevisions(EnumSyncType.CUSTOM_EFFECTS, payload.getRevision()); + PacketHandler.Instance.sendToAll(new SyncPacket(SyncType.CUSTOM_EFFECTS, payload)); + updateAllPlayerRevisions(SyncType.CUSTOM_EFFECTS, payload.getRevision()); } @SideOnly(Side.CLIENT) - public static void clientSync(EnumSyncType enumSyncType, int revision, NBTTagCompound fullCompound) { - switch (enumSyncType) { - case FACTION: { - NBTTagList list = fullCompound.getTagList("Factions", 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); - } - FactionController.getInstance().factions = FactionController.getInstance().factionsSync; - FactionController.getInstance().factionsSync = new HashMap(); - break; - } - case DIALOG_CATEGORY: { - if (!fullCompound.hasNoTags()) { - NBTTagList categories = fullCompound.getTagList("DialogCategories", 10); - for (int j = 0; j < fullCompound.getTagList("DialogCategories", 10).tagCount(); j++) { - NBTTagCompound categoryCompound = categories.getCompoundTagAt(j); - if (categoryCompound.hasNoTags()) - continue; - - DialogCategory category = new DialogCategory(); - category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT")); - NBTTagList dialogList = categoryCompound.getTagList("Data", 10); - if (DialogController.Instance.categoriesSync.containsKey(category.id)) { - category = DialogController.Instance.categoriesSync.get(category.id); - category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT")); - } - for (int i = 0; i < dialogList.tagCount(); i++) { - Dialog dialog = new Dialog(); - dialog.readNBT(dialogList.getCompoundTagAt(i)); - dialog.category = category; - category.dialogs.put(dialog.id, dialog); - } - DialogController.Instance.categoriesSync.put(category.id, category); - } - } - - HashMap dialogs = new HashMap(); - 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(); - break; - } - case QUEST_CATEGORY: { - if (!fullCompound.hasNoTags()) { - NBTTagList categories = fullCompound.getTagList("QuestCategories", 10); - for (int j = 0; j < fullCompound.getTagList("QuestCategories", 10).tagCount(); j++) { - NBTTagCompound categoryCompound = categories.getCompoundTagAt(j); - if (categoryCompound.hasNoTags()) - continue; - - QuestCategory category = new QuestCategory(); - category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT")); - NBTTagList questList = categoryCompound.getTagList("Data", 10); - if (QuestController.Instance.categoriesSync.containsKey(category.id)) { - category = QuestController.Instance.categoriesSync.get(category.id); - category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT")); - } - for (int i = 0; i < questList.tagCount(); i++) { - Quest quest = new Quest(); - quest.readNBT(questList.getCompoundTagAt(i)); - quest.category = category; - category.quests.put(quest.id, quest); - } - QuestController.Instance.categoriesSync.put(category.id, category); - } - } - - HashMap quests = new HashMap(); - 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(); - break; - } - case PLAYERDATA: { - ClientCacheHandler.playerData.setSyncNBTFull(fullCompound); - break; - } - case MAGIC: { - NBTTagList list = fullCompound.getTagList("Data", 10); - MagicController mc = MagicController.getInstance(); - mc.magicSync.clear(); - for (int i = 0; i < list.tagCount(); i++) { - Magic magic = new Magic(); - magic.readNBT(list.getCompoundTagAt(i)); - mc.magicSync.put(magic.id, magic); - } - - mc.magics.clear(); - mc.magics.putAll(mc.magicSync); - mc.magicSync.clear(); - break; - } - case MAGIC_CYCLE: { - NBTTagList list = fullCompound.getTagList("Data", 10); - MagicController mc = MagicController.getInstance(); - mc.cyclesSync.clear(); - for (int i = 0; i < list.tagCount(); i++) { - MagicCycle cycle = new MagicCycle(); - cycle.readNBT(list.getCompoundTagAt(i)); - mc.cyclesSync.put(cycle.id, cycle); - } - - mc.cycles.clear(); - mc.cycles.putAll(mc.cyclesSync); - mc.cyclesSync.clear(); - break; - } - case WORKBENCH_RECIPES: { - NBTTagList list = fullCompound.getTagList("recipes", 10); - if (list == null) - return; - - for (int i = 0; i < list.tagCount(); i++) { - NBTTagCompound recipeCompound = list.getCompoundTagAt(i); - RecipeCarpentry recipe = RecipeCarpentry.create(recipeCompound); - recipe.readNBT(recipeCompound); - RecipeController.syncRecipes.put(recipe.id, recipe); - } - - RecipeController.reloadGlobalRecipes(RecipeController.syncRecipes); - RecipeController.syncRecipes = new HashMap(); - break; - } - case CARPENTRY_RECIPES: { - NBTTagList list = fullCompound.getTagList("recipes", 10); - if (list == null) - return; - - for (int i = 0; i < list.tagCount(); i++) { - NBTTagCompound recipeCompound = list.getCompoundTagAt(i); - RecipeCarpentry recipe = RecipeCarpentry.create(recipeCompound); - recipe.readNBT(recipeCompound); - RecipeController.syncRecipes.put(recipe.id, recipe); - } - - RecipeController.Instance.carpentryRecipes = RecipeController.syncRecipes; - RecipeController.syncRecipes = new HashMap(); - break; - } - case ANVIL_RECIPES: { - NBTTagList list = fullCompound.getTagList("recipes", 10); - if (list == null) - return; - - for (int i = 0; i < list.tagCount(); i++) { - RecipeAnvil recipe = new RecipeAnvil(); - recipe.readNBT(list.getCompoundTagAt(i)); - RecipeController.syncAnvilRecipes.put(recipe.id, recipe); - } - - RecipeController.Instance.anvilRecipes = RecipeController.syncAnvilRecipes; - RecipeController.syncAnvilRecipes = new HashMap(); - break; - } - case CUSTOM_EFFECTS: { - NBTTagList list = fullCompound.getTagList("Data", 10); - CustomEffectController ce = CustomEffectController.getInstance(); - ce.customEffectsSync.clear(); - for (int i = 0; i < list.tagCount(); i++) { - CustomEffect effect = new CustomEffect(); - effect.readFromNBT(list.getCompoundTagAt(i)); - ClientCacheHandler.getImageData(effect.icon); - ce.customEffectsSync.put(effect.id, effect); - } - - ce.getCustomEffects().clear(); - ce.getCustomEffects().putAll(ce.customEffectsSync); - ce.customEffectsSync.clear(); - break; - } - case CUSTOM_ABILITY: { - NBTTagList list = fullCompound.getTagList("Data", 10); - LinkedHashMap sync = new LinkedHashMap<>(); - for (int i = 0; i < list.tagCount(); i++) { - NBTTagCompound nbt = list.getCompoundTagAt(i); - String name = nbt.getString("CustomAbilityId"); - Ability ability = AbilityController.Instance.fromNBT(nbt); - if (ability != null) { - ability.setName(name); - sync.put(name, ability); - } - } - AbilityController.Instance.setCustomAbilities(sync); - break; - } - case CHAINED_ABILITY: { - NBTTagList list = fullCompound.getTagList("Data", 10); - LinkedHashMap sync = new LinkedHashMap<>(); - for (int i = 0; i < list.tagCount(); i++) { - NBTTagCompound nbt = list.getCompoundTagAt(i); - String id = nbt.getString("ChainedAbilityId"); - ChainedAbility chain = new ChainedAbility(); - chain.readNBT(nbt); - chain.setName(id); - sync.put(id, chain); - } - AbilityController.Instance.setChainedAbilities(sync); - break; - } - } - - ClientCacheHandler.updateClientRevision(enumSyncType, revision); - } - - /** - * Update Related Tasks - */ - @SideOnly(Side.CLIENT) - public static void clientUpdate(EnumSyncType enumSyncType, int category_id, int revision, NBTTagCompound compound) { - switch (enumSyncType) { - case FACTION: { + public static void clientSync(SyncType syncType, int revision, NBTTagCompound fullCompound) { + if (syncType == SyncType.FACTION) { + NBTTagList list = fullCompound.getTagList("Factions", 10); + for (int i = 0; i < list.tagCount(); i++) { Faction faction = new Faction(); - faction.readNBT(compound); - FactionController.getInstance().factions.put(faction.id, faction); - break; + faction.readNBT(list.getCompoundTagAt(i)); + FactionController.getInstance().factionsSync.put(faction.id, faction); } - case DIALOG: { - DialogCategory category = DialogController.Instance.categories.get(category_id); - Dialog dialog = new Dialog(); - dialog.category = category; - dialog.readNBT(compound); - DialogController.Instance.dialogs.put(dialog.id, dialog); - category.dialogs.put(dialog.id, dialog); - break; - } - case QUEST: { - QuestCategory category = QuestController.Instance.categories.get(category_id); - Quest quest = new Quest(); - quest.category = category; - quest.readNBT(compound); - QuestController.Instance.quests.put(quest.id, quest); - category.quests.put(quest.id, quest); - break; - } - case 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); - break; - } - case 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); - break; - } - case MAGIC_CYCLE: { - MagicCycle cycle = new MagicCycle(); - cycle.readNBT(compound); - MagicController.getInstance().cycles.put(cycle.id, cycle); - break; - } - case MAGIC: { - Magic magic = new Magic(); - magic.readNBT(compound); - MagicController.getInstance().magics.put(magic.id, magic); - break; - } - case PLAYERDATA: { - ClientCacheHandler.playerData.setSyncNBT(compound); - break; - } - case CUSTOM_EFFECTS: { - CustomEffect effect = new CustomEffect(); - effect.readFromNBT(compound); - ClientCacheHandler.getImageData(effect.icon); + FactionController.getInstance().factions = FactionController.getInstance().factionsSync; + FactionController.getInstance().factionsSync = new HashMap(); + } else if (syncType == SyncType.DIALOG_CATEGORY) { + if (!fullCompound.hasNoTags()) { + NBTTagList categories = fullCompound.getTagList("DialogCategories", 10); + for (int j = 0; j < fullCompound.getTagList("DialogCategories", 10).tagCount(); j++) { + NBTTagCompound categoryCompound = categories.getCompoundTagAt(j); + if (categoryCompound.hasNoTags()) + continue; - CustomEffectController.Instance.getCustomEffects().put(effect.id, effect); - break; + DialogCategory category = new DialogCategory(); + category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT")); + NBTTagList dialogList = categoryCompound.getTagList("Data", 10); + if (DialogController.Instance.categoriesSync.containsKey(category.id)) { + category = DialogController.Instance.categoriesSync.get(category.id); + category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT")); + } + for (int i = 0; i < dialogList.tagCount(); i++) { + Dialog dialog = new Dialog(); + dialog.readNBT(dialogList.getCompoundTagAt(i)); + dialog.category = category; + category.dialogs.put(dialog.id, dialog); + } + DialogController.Instance.categoriesSync.put(category.id, category); + } } + + HashMap dialogs = new HashMap(); + 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(); + } else if (syncType == SyncType.QUEST_CATEGORY) { + if (!fullCompound.hasNoTags()) { + NBTTagList categories = fullCompound.getTagList("QuestCategories", 10); + for (int j = 0; j < fullCompound.getTagList("QuestCategories", 10).tagCount(); j++) { + NBTTagCompound categoryCompound = categories.getCompoundTagAt(j); + if (categoryCompound.hasNoTags()) + continue; + + QuestCategory category = new QuestCategory(); + category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT")); + NBTTagList questList = categoryCompound.getTagList("Data", 10); + if (QuestController.Instance.categoriesSync.containsKey(category.id)) { + category = QuestController.Instance.categoriesSync.get(category.id); + category.readSmallNBT(categoryCompound.getCompoundTag("CatNBT")); + } + for (int i = 0; i < questList.tagCount(); i++) { + Quest quest = new Quest(); + quest.readNBT(questList.getCompoundTagAt(i)); + quest.category = category; + category.quests.put(quest.id, quest); + } + QuestController.Instance.categoriesSync.put(category.id, category); + } + } + + HashMap quests = new HashMap(); + 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(); + } else if (syncType == SyncType.PLAYERDATA) { + ClientCacheHandler.playerData.setSyncNBTFull(fullCompound); + } else if (syncType == SyncType.MAGIC) { + NBTTagList list = fullCompound.getTagList("Data", 10); + MagicController mc = MagicController.getInstance(); + mc.magicSync.clear(); + for (int i = 0; i < list.tagCount(); i++) { + Magic magic = new Magic(); + magic.readNBT(list.getCompoundTagAt(i)); + mc.magicSync.put(magic.id, magic); + } + + mc.magics.clear(); + mc.magics.putAll(mc.magicSync); + mc.magicSync.clear(); + } else if (syncType == SyncType.MAGIC_CYCLE) { + NBTTagList list = fullCompound.getTagList("Data", 10); + MagicController mc = MagicController.getInstance(); + mc.cyclesSync.clear(); + for (int i = 0; i < list.tagCount(); i++) { + MagicCycle cycle = new MagicCycle(); + cycle.readNBT(list.getCompoundTagAt(i)); + mc.cyclesSync.put(cycle.id, cycle); + } + + mc.cycles.clear(); + mc.cycles.putAll(mc.cyclesSync); + mc.cyclesSync.clear(); + } else if (syncType == SyncType.WORKBENCH_RECIPES) { + NBTTagList list = fullCompound.getTagList("recipes", 10); + if (list == null) + return; + + for (int i = 0; i < list.tagCount(); i++) { + NBTTagCompound recipeCompound = list.getCompoundTagAt(i); + RecipeCarpentry recipe = RecipeCarpentry.create(recipeCompound); + recipe.readNBT(recipeCompound); + RecipeController.syncRecipes.put(recipe.id, recipe); + } + + RecipeController.reloadGlobalRecipes(RecipeController.syncRecipes); + RecipeController.syncRecipes = new HashMap(); + } else if (syncType == SyncType.CARPENTRY_RECIPES) { + NBTTagList list = fullCompound.getTagList("recipes", 10); + if (list == null) + return; + + for (int i = 0; i < list.tagCount(); i++) { + NBTTagCompound recipeCompound = list.getCompoundTagAt(i); + RecipeCarpentry recipe = RecipeCarpentry.create(recipeCompound); + recipe.readNBT(recipeCompound); + RecipeController.syncRecipes.put(recipe.id, recipe); + } + + RecipeController.Instance.carpentryRecipes = RecipeController.syncRecipes; + RecipeController.syncRecipes = new HashMap(); + } else if (syncType == SyncType.ANVIL_RECIPES) { + NBTTagList list = fullCompound.getTagList("recipes", 10); + if (list == null) + return; + + for (int i = 0; i < list.tagCount(); i++) { + RecipeAnvil recipe = new RecipeAnvil(); + recipe.readNBT(list.getCompoundTagAt(i)); + RecipeController.syncAnvilRecipes.put(recipe.id, recipe); + } + + RecipeController.Instance.anvilRecipes = RecipeController.syncAnvilRecipes; + RecipeController.syncAnvilRecipes = new HashMap(); + } else if (syncType == SyncType.CUSTOM_EFFECTS) { + NBTTagList list = fullCompound.getTagList("Data", 10); + CustomEffectController ce = CustomEffectController.getInstance(); + ce.customEffectsSync.clear(); + for (int i = 0; i < list.tagCount(); i++) { + CustomEffect effect = new CustomEffect(); + effect.readFromNBT(list.getCompoundTagAt(i)); + ClientCacheHandler.getImageData(effect.icon); + ce.customEffectsSync.put(effect.id, effect); + } + + ce.getCustomEffects().clear(); + ce.getCustomEffects().putAll(ce.customEffectsSync); + ce.customEffectsSync.clear(); + } else if (syncType == SyncType.CUSTOM_ABILITY) { + NBTTagList list = fullCompound.getTagList("Data", 10); + LinkedHashMap sync = new LinkedHashMap<>(); + for (int i = 0; i < list.tagCount(); i++) { + NBTTagCompound nbt = list.getCompoundTagAt(i); + String name = nbt.getString("CustomAbilityId"); + Ability ability = AbilityController.Instance.fromNBT(nbt); + if (ability != null) { + ability.setName(name); + sync.put(name, ability); + } + } + AbilityController.Instance.setCustomAbilities(sync); + } else if (syncType == SyncType.CHAINED_ABILITY) { + NBTTagList list = fullCompound.getTagList("Data", 10); + LinkedHashMap sync = new LinkedHashMap<>(); + for (int i = 0; i < list.tagCount(); i++) { + NBTTagCompound nbt = list.getCompoundTagAt(i); + String id = nbt.getString("ChainedAbilityId"); + ChainedAbility chain = new ChainedAbility(); + chain.readNBT(nbt); + chain.setName(id); + sync.put(id, chain); + } + AbilityController.Instance.setChainedAbilities(sync); } - ClientCacheHandler.updateClientRevision(enumSyncType, revision); + ClientCacheHandler.updateClientRevision(syncType, revision); } - public static void syncUpdate(EnumSyncType type, int cat, NBTTagCompound compound) { - Map revisions = invalidateCaches(type); + @SideOnly(Side.CLIENT) + public static void clientUpdate(SyncType syncType, int category_id, int revision, NBTTagCompound compound) { + 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(category_id); + 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.QUEST) { + QuestCategory category = QuestController.Instance.categories.get(category_id); + 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); + } 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.MAGIC_CYCLE) { + MagicCycle cycle = new MagicCycle(); + cycle.readNBT(compound); + MagicController.getInstance().cycles.put(cycle.id, cycle); + } else if (syncType == SyncType.MAGIC) { + Magic magic = new Magic(); + magic.readNBT(compound); + MagicController.getInstance().magics.put(magic.id, magic); + } else if (syncType == SyncType.PLAYERDATA) { + ClientCacheHandler.playerData.setSyncNBT(compound); + } else if (syncType == SyncType.CUSTOM_EFFECTS) { + CustomEffect effect = new CustomEffect(); + effect.readFromNBT(compound); + ClientCacheHandler.getImageData(effect.icon); + + CustomEffectController.Instance.getCustomEffects().put(effect.id, effect); + } + + ClientCacheHandler.updateClientRevision(syncType, revision); + } + + public static void syncUpdate(SyncType type, int cat, NBTTagCompound compound) { + Map revisions = invalidateCaches(type); int revision = revisions.getOrDefault(type, getCurrentRevision(type)); PacketHandler.Instance.sendToAll(new SyncPacket( type, @@ -823,50 +777,41 @@ public class SyncController { } @SideOnly(Side.CLIENT) - public static void clientSyncRemove(EnumSyncType enumSyncType, int id, int revision) { - switch (enumSyncType) { - case FACTION: - FactionController.getInstance().factions.remove(id); - break; - case DIALOG: - Dialog dialog = DialogController.Instance.dialogs.remove(id); - if (dialog != null) { - dialog.category.dialogs.remove(id); - } - break; - case DIALOG_CATEGORY: - DialogCategory dialogCategory = DialogController.Instance.categories.remove(id); - if (dialogCategory != null) { - DialogController.Instance.dialogs.keySet().removeAll(dialogCategory.dialogs.keySet()); - } - break; - case QUEST: - Quest quest = QuestController.Instance.quests.remove(id); - if (quest != null) { - quest.category.quests.remove(id); - } - break; - case QUEST_CATEGORY: - QuestCategory questCategory = QuestController.Instance.categories.remove(id); - if (questCategory != null) { - QuestController.Instance.quests.keySet().removeAll(questCategory.quests.keySet()); - } - break; - case MAGIC: - for (MagicCycle cycle : MagicController.getInstance().cycles.values()) { - cycle.associations.remove(id); - } - MagicController.getInstance().cycles.remove(id); - break; - case MAGIC_CYCLE: - MagicController.getInstance().cycles.remove(id); - break; - case CUSTOM_EFFECTS: - CustomEffectController.Instance.getCustomEffects().remove(id); - break; + public static void clientSyncRemove(SyncType syncType, int id, int revision) { + 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 dialogCategory = DialogController.Instance.categories.remove(id); + if (dialogCategory != null) { + DialogController.Instance.dialogs.keySet().removeAll(dialogCategory.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 questCategory = QuestController.Instance.categories.remove(id); + if (questCategory != null) { + QuestController.Instance.quests.keySet().removeAll(questCategory.quests.keySet()); + } + } else if (syncType == SyncType.MAGIC) { + for (MagicCycle cycle : MagicController.getInstance().cycles.values()) { + cycle.associations.remove(id); + } + MagicController.getInstance().cycles.remove(id); + } else if (syncType == SyncType.MAGIC_CYCLE) { + MagicController.getInstance().cycles.remove(id); + } else if (syncType == SyncType.CUSTOM_EFFECTS) { + CustomEffectController.Instance.getCustomEffects().remove(id); } - ClientCacheHandler.updateClientRevision(enumSyncType, revision); + ClientCacheHandler.updateClientRevision(syncType, revision); } public static void syncEffects(EntityPlayerMP playerMP) { @@ -912,11 +857,11 @@ public class SyncController { } } - private static void registerCache(EnumSyncType type, Supplier supplier) { - cacheEntries.put(type, new SyncCacheEntry(type, supplier)); + private static void registerCache(SyncType type, Supplier supplier) { + cacheEntries.put(type, new SyncCacheEntry(supplier)); } - private static CachedSyncPayload rebuildNow(EnumSyncType type) { + private static CachedSyncPayload rebuildNow(SyncType type) { SyncCacheEntry entry = cacheEntries.get(type); if (entry == null) { return null; @@ -925,10 +870,10 @@ public class SyncController { return entry.getPayload(type); } - public static Map invalidateCaches(EnumSyncType type) { - EnumSet targets = getInvalidationTargets(type); - EnumMap revisions = new EnumMap<>(EnumSyncType.class); - for (EnumSyncType target : targets) { + public static Map invalidateCaches(SyncType type) { + Set targets = getInvalidationTargets(type); + Map revisions = new LinkedHashMap<>(); + for (SyncType target : targets) { SyncCacheEntry entry = cacheEntries.get(target); if (entry != null) { int newRevision = entry.invalidate(); @@ -938,38 +883,56 @@ public class SyncController { return revisions; } - private static EnumSet getInvalidationTargets(EnumSyncType type) { - switch (type) { - case DIALOG: - case DIALOG_CATEGORY: - return EnumSet.of(EnumSyncType.DIALOG_CATEGORY); - case QUEST: - case QUEST_CATEGORY: - return EnumSet.of(EnumSyncType.QUEST_CATEGORY); - case FACTION: - return EnumSet.of(EnumSyncType.FACTION); - case MAGIC: - return EnumSet.of(EnumSyncType.MAGIC); - case MAGIC_CYCLE: - return EnumSet.of(EnumSyncType.MAGIC_CYCLE); - case WORKBENCH_RECIPES: - return EnumSet.of(EnumSyncType.WORKBENCH_RECIPES); - case CARPENTRY_RECIPES: - return EnumSet.of(EnumSyncType.CARPENTRY_RECIPES); - case ANVIL_RECIPES: - return EnumSet.of(EnumSyncType.ANVIL_RECIPES); - case CUSTOM_EFFECTS: - return EnumSet.of(EnumSyncType.CUSTOM_EFFECTS); - case CUSTOM_ABILITY: - return EnumSet.of(EnumSyncType.CUSTOM_ABILITY); - case CHAINED_ABILITY: - return EnumSet.of(EnumSyncType.CHAINED_ABILITY); - default: - return EnumSet.noneOf(EnumSyncType.class); + private static Set getInvalidationTargets(SyncType type) { + if (type == SyncType.DIALOG || type == SyncType.DIALOG_CATEGORY) { + Set set = new HashSet<>(); + set.add(SyncType.DIALOG_CATEGORY); + return set; + } else if (type == SyncType.QUEST || type == SyncType.QUEST_CATEGORY) { + Set set = new HashSet<>(); + set.add(SyncType.QUEST_CATEGORY); + return set; + } else if (type == SyncType.FACTION) { + Set set = new HashSet<>(); + set.add(SyncType.FACTION); + return set; + } else if (type == SyncType.MAGIC) { + Set set = new HashSet<>(); + set.add(SyncType.MAGIC); + return set; + } else if (type == SyncType.MAGIC_CYCLE) { + Set set = new HashSet<>(); + set.add(SyncType.MAGIC_CYCLE); + return set; + } else if (type == SyncType.WORKBENCH_RECIPES) { + Set set = new HashSet<>(); + set.add(SyncType.WORKBENCH_RECIPES); + return set; + } else if (type == SyncType.CARPENTRY_RECIPES) { + Set set = new HashSet<>(); + set.add(SyncType.CARPENTRY_RECIPES); + return set; + } else if (type == SyncType.ANVIL_RECIPES) { + Set set = new HashSet<>(); + set.add(SyncType.ANVIL_RECIPES); + return set; + } else if (type == SyncType.CUSTOM_EFFECTS) { + Set set = new HashSet<>(); + set.add(SyncType.CUSTOM_EFFECTS); + return set; + } else if (type == SyncType.CUSTOM_ABILITY) { + Set set = new HashSet<>(); + set.add(SyncType.CUSTOM_ABILITY); + return set; + } else if (type == SyncType.CHAINED_ABILITY) { + Set set = new HashSet<>(); + set.add(SyncType.CHAINED_ABILITY); + return set; } + return Collections.emptySet(); } - private static void updateAllPlayerRevisions(EnumSyncType type, int revision) { + private static void updateAllPlayerRevisions(SyncType type, int revision) { if (revision < 0) { return; } @@ -978,12 +941,12 @@ public class SyncController { } } - private static void updateAllPlayerRevisions(Map revisions) { + private static void updateAllPlayerRevisions(Map revisions) { if (revisions.isEmpty()) { return; } for (PlayerSyncState state : playerSyncState.values()) { - for (Map.Entry entry : revisions.entrySet()) { + for (Map.Entry entry : revisions.entrySet()) { state.updateRevision(entry.getKey(), entry.getValue()); } } @@ -1019,11 +982,11 @@ public class SyncController { private int revision = 0; private boolean dirty = true; - private SyncCacheEntry(EnumSyncType type, Supplier supplier) { + private SyncCacheEntry(Supplier supplier) { this.supplier = supplier; } - private synchronized CachedSyncPayload getPayload(EnumSyncType requestedType) { + private synchronized CachedSyncPayload getPayload(SyncType requestedType) { if (!dirty && payload != null) { return payload; } @@ -1089,21 +1052,21 @@ public class SyncController { } private static final class PlayerSyncState { - private final EnumMap revisions = new EnumMap<>(EnumSyncType.class); + private final Map revisions = new HashMap<>(); private PlayerSyncState(UUID ignored) { } - private synchronized int getRevision(EnumSyncType type) { + private synchronized int getRevision(SyncType type) { Integer value = revisions.get(type); return value == null ? -1 : value; } - private synchronized void updateRevision(EnumSyncType type, int revision) { + private synchronized void updateRevision(SyncType type, int revision) { revisions.put(type, revision); } - private synchronized void applyHandshake(Map incoming) { + private synchronized void applyHandshake(Map incoming) { if (incoming == null || incoming.isEmpty()) { return; } diff --git a/src/main/java/kamkeel/npcs/network/enums/EnumSyncType.java b/src/main/java/kamkeel/npcs/network/enums/EnumSyncType.java deleted file mode 100644 index ee6cf352f..000000000 --- a/src/main/java/kamkeel/npcs/network/enums/EnumSyncType.java +++ /dev/null @@ -1,18 +0,0 @@ -package kamkeel.npcs.network.enums; - -public enum EnumSyncType { - FACTION, - DIALOG, - DIALOG_CATEGORY, - QUEST, - QUEST_CATEGORY, - PLAYERDATA, - MAGIC, - MAGIC_CYCLE, - WORKBENCH_RECIPES, - CARPENTRY_RECIPES, - ANVIL_RECIPES, - CUSTOM_EFFECTS, - CUSTOM_ABILITY, - CHAINED_ABILITY -} diff --git a/src/main/java/kamkeel/npcs/network/enums/SyncType.java b/src/main/java/kamkeel/npcs/network/enums/SyncType.java new file mode 100644 index 000000000..2623038ac --- /dev/null +++ b/src/main/java/kamkeel/npcs/network/enums/SyncType.java @@ -0,0 +1,178 @@ +package kamkeel.npcs.network.enums; + +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Immutable, object-based sync-type identity for the CNPC+ sync backend. + * + *

Each {@code SyncType} has a canonical namespaced string ID ({@code modid:path}) + * and is registered via the static {@link #register} factory. Built-in CNPC+ + * families are exposed as {@code public static final} constants.

+ * + *

Identity is based on the canonical {@link #id} string, which is unique + * across all registered types. Two references with the same {@code id} + * are always the same object (identity == equality for registered types).

+ * + *

The {@code ordinal} field provides a stable integer identity for + * wire encoding during the migration period. It is assigned at registration + * time in declaration order and must NOT be used as a protocol identifier + * once string-on-wire migration is complete.

+ */ +public final class SyncType { + + // ──────────────────── Registry ──────────────────── + private static final Map REGISTRY = new LinkedHashMap<>(); + private static int nextOrdinal = 0; + private static boolean frozen = false; + + // ──────────────────── CNPC+ families ──────────────────── + public static final SyncType FACTION = register("cnpc:faction"); + public static final SyncType DIALOG = register("cnpc:dialog"); + public static final SyncType DIALOG_CATEGORY = register("cnpc:dialog_category"); + public static final SyncType QUEST = register("cnpc:quest"); + public static final SyncType QUEST_CATEGORY = register("cnpc:quest_category"); + public static final SyncType PLAYERDATA = register("cnpc:playerdata"); + public static final SyncType MAGIC = register("cnpc:magic"); + public static final SyncType MAGIC_CYCLE = register("cnpc:magic_cycle"); + public static final SyncType WORKBENCH_RECIPES = register("cnpc:workbench_recipes"); + public static final SyncType CARPENTRY_RECIPES = register("cnpc:carpentry_recipes"); + public static final SyncType ANVIL_RECIPES = register("cnpc:anvil_recipes"); + public static final SyncType CUSTOM_EFFECTS = register("cnpc:custom_effects"); + public static final SyncType CUSTOM_ABILITY = register("cnpc:custom_ability"); + public static final SyncType CHAINED_ABILITY = register("cnpc:chained_ability"); + + // ──────────────────── Instance fields ──────────────────── + private final String id; + private final int ordinal; + + private SyncType(String id, int ordinal) { + this.id = id; + this.ordinal = ordinal; + } + + // ──────────────────── Public API ──────────────────── + + /** + * The canonical namespaced identifier, e.g. {@code "cnpc:faction"}. + */ + public String getId() { + return id; + } + + /** + * Stable integer ordinal assigned at registration time. + * Used for wire encoding during the migration period only. + */ + public int ordinal() { + return ordinal; + } + + // ──────────────────── Registration ──────────────────── + + /** + * Register a new {@code SyncType} with the given canonical ID. + * + * @param id namespaced identifier ({@code modid:path}) + * @return the newly created and registered {@code SyncType} + * @throws IllegalArgumentException if the ID is null, empty, or lacks a colon + * @throws IllegalStateException if a type with the same ID is already registered + * @throws IllegalStateException if the registry has been frozen + */ + public static SyncType register(String id) { + if (id == null || id.isEmpty()) { + throw new IllegalArgumentException("SyncType id must not be null or empty"); + } + if (!id.contains(":")) { + throw new IllegalArgumentException("SyncType id must be namespaced (modid:path): " + id); + } + if (frozen) { + throw new IllegalStateException("SyncType registry is frozen; cannot register: " + id); + } + if (REGISTRY.containsKey(id)) { + throw new IllegalStateException("Duplicate SyncType registration: " + id); + } + SyncType type = new SyncType(id, nextOrdinal++); + REGISTRY.put(id, type); + return type; + } + + /** + * Look up a registered SyncType by its canonical string ID. + * + * @return the registered type, or {@code null} if not found + */ + public static SyncType byId(String id) { + return id == null ? null : REGISTRY.get(id); + } + + /** + * Look up a registered SyncType by its ordinal. + * Used during migration for decoding ordinal-based wire traffic. + * + * @return the registered type, or {@code null} if ordinal is out of range + */ + public static SyncType byOrdinal(int ordinal) { + if (ordinal < 0) { + return null; + } + for (SyncType type : REGISTRY.values()) { + if (type.ordinal == ordinal) { + return type; + } + } + return null; + } + + /** + * Returns all registered SyncType instances in registration order. + */ + public static Collection values() { + return Collections.unmodifiableCollection(REGISTRY.values()); + } + + /** + * Freeze the registry. After freezing, no new types can be registered. + * Should be called after all mods have had a chance to register types. + */ + public static void freeze() { + frozen = true; + } + + /** + * Whether the registry has been frozen. + */ + public static boolean isFrozen() { + return frozen; + } + + /** + * Unfreeze the registry. Called during world reload to allow addon + * re-registration. Does NOT clear existing registrations — built-in + * constants stay stable. + */ + public static void unfreeze() { + frozen = false; + } + + // ──────────────────── Object overrides ──────────────────── + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SyncType)) return false; + return id.equals(((SyncType) o).id); + } + + @Override + public int hashCode() { + return id.hashCode(); + } + + @Override + public String toString() { + return id; + } +} diff --git a/src/main/java/kamkeel/npcs/network/packets/data/LoginPacket.java b/src/main/java/kamkeel/npcs/network/packets/data/LoginPacket.java index da9eb9aa2..103c2e5fa 100644 --- a/src/main/java/kamkeel/npcs/network/packets/data/LoginPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/data/LoginPacket.java @@ -8,7 +8,7 @@ import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketClient; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumDataPacket; -import kamkeel.npcs.network.enums.EnumSyncType; +import kamkeel.npcs.network.enums.SyncType; import kamkeel.npcs.network.packets.player.SyncRevisionInfoPacket; import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; @@ -21,19 +21,20 @@ import noppes.npcs.controllers.AuctionConfigSync; import noppes.npcs.controllers.ScriptConfigSync; import java.io.IOException; -import java.util.EnumMap; +import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; public final class LoginPacket extends AbstractPacket { public static final String packetName = "CNPC+|Login"; private String serverCacheKey = ""; - private final EnumMap revisionSnapshot = new EnumMap<>(EnumSyncType.class); + private final Map revisionSnapshot = new LinkedHashMap<>(); public LoginPacket() { } - public LoginPacket(String serverCacheKey, EnumMap revisionSnapshot) { + public LoginPacket(String serverCacheKey, Map revisionSnapshot) { if (serverCacheKey != null) { this.serverCacheKey = serverCacheKey; } @@ -58,17 +59,15 @@ public final class LoginPacket extends AbstractPacket { out.writeBoolean(ConfigMain.ProfilesEnabled); ByteBufUtils.writeString(out, serverCacheKey); out.writeShort(revisionSnapshot.size()); - for (Map.Entry entry : revisionSnapshot.entrySet()) { + for (Map.Entry entry : revisionSnapshot.entrySet()) { out.writeInt(entry.getKey().ordinal()); out.writeInt(entry.getValue()); } - // Send auction config (server-side sync) NBTTagCompound auctionConfig = new NBTTagCompound(); AuctionConfigSync.writeToNBT(auctionConfig); ByteBufUtils.writeNBT(out, auctionConfig); - // Send script config (server-side sync) NBTTagCompound scriptConfig = new NBTTagCompound(); ScriptConfigSync.writeToNBT(scriptConfig); ByteBufUtils.writeNBT(out, scriptConfig); @@ -82,20 +81,20 @@ public final class LoginPacket extends AbstractPacket { String serverKey = ByteBufUtils.readString(in); int revisionCount = in.readUnsignedShort(); - EnumMap serverRevisions = new EnumMap<>(EnumSyncType.class); + Map serverRevisions = new LinkedHashMap<>(); for (int i = 0; i < revisionCount; i++) { - EnumSyncType type = EnumSyncType.values()[in.readInt()]; + SyncType type = SyncType.byOrdinal(in.readInt()); int revision = in.readInt(); - serverRevisions.put(type, revision); + if (type != null) { + serverRevisions.put(type, revision); + } } ClientCacheHandler.setActiveServer(serverKey, serverRevisions); - // Read auction config NBTTagCompound auctionConfig = ByteBufUtils.readNBT(in); AuctionClientConfig.readFromNBT(auctionConfig); - // Read script config NBTTagCompound scriptConfig = ByteBufUtils.readNBT(in); ScriptClientConfig.readFromNBT(scriptConfig); diff --git a/src/main/java/kamkeel/npcs/network/packets/data/large/SyncPacket.java b/src/main/java/kamkeel/npcs/network/packets/data/large/SyncPacket.java index 77b2122b4..322f6c976 100644 --- a/src/main/java/kamkeel/npcs/network/packets/data/large/SyncPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/data/large/SyncPacket.java @@ -10,7 +10,7 @@ import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumDataPacket; import kamkeel.npcs.network.enums.EnumSyncAction; -import kamkeel.npcs.network.enums.EnumSyncType; +import kamkeel.npcs.network.enums.SyncType; import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.NBTTagCompound; @@ -22,13 +22,9 @@ import java.util.ArrayList; import java.util.List; import java.util.UUID; -/** - * A large sync packet that sends chunked data to the client for a given SyncType - * along with a SyncAction (RELOAD, UPDATE, REMOVE). - */ public final class SyncPacket extends LargeAbstractPacket { - private EnumSyncType enumSyncType; + private SyncType syncType; private EnumSyncAction enumSyncAction; private NBTTagCompound syncData; private int operationID; @@ -39,23 +35,20 @@ public final class SyncPacket extends LargeAbstractPacket { public SyncPacket() { } - /** - * Constructs a new LargeSyncPacket. - */ - public SyncPacket(EnumSyncType enumSyncType, EnumSyncAction enumSyncAction, int catId, NBTTagCompound syncData) { - this(enumSyncType, enumSyncAction, catId, -1, syncData); + public SyncPacket(SyncType syncType, EnumSyncAction enumSyncAction, int catId, NBTTagCompound syncData) { + this(syncType, enumSyncAction, catId, -1, syncData); } - public SyncPacket(EnumSyncType enumSyncType, EnumSyncAction enumSyncAction, int catId, int revision, NBTTagCompound syncData) { - this.enumSyncType = enumSyncType; + public SyncPacket(SyncType syncType, EnumSyncAction enumSyncAction, int catId, int revision, NBTTagCompound syncData) { + this.syncType = syncType; this.enumSyncAction = enumSyncAction; this.syncData = syncData; this.operationID = catId; this.revision = revision; } - public SyncPacket(EnumSyncType enumSyncType, SyncController.CachedSyncPayload payload) { - this.enumSyncType = enumSyncType; + public SyncPacket(SyncType syncType, SyncController.CachedSyncPayload payload) { + this.syncType = syncType; this.enumSyncAction = EnumSyncAction.RELOAD; this.operationID = -1; this.revision = payload.getRevision(); @@ -81,7 +74,7 @@ public final class SyncPacket extends LargeAbstractPacket { ByteBuf buffer = Unpooled.buffer(); try { - buffer.writeInt(enumSyncType.ordinal()); + buffer.writeInt(syncType.ordinal()); buffer.writeInt(enumSyncAction.ordinal()); buffer.writeInt(operationID); buffer.writeInt(revision); @@ -131,17 +124,19 @@ public final class SyncPacket extends LargeAbstractPacket { if (CustomNpcs.side() != Side.CLIENT) return; - // Reconstruct everything from the ByteBuf int syncTypeOrdinal = data.readInt(); int syncActionOrdinal = data.readInt(); int categoryID = data.readInt(); int incomingRevision = data.readInt(); - EnumSyncType type = EnumSyncType.values()[syncTypeOrdinal]; + SyncType type = SyncType.byOrdinal(syncTypeOrdinal); + if (type == null) { + LogWriter.error("[SyncPacket] Unknown sync type ordinal: " + syncTypeOrdinal + "; skipping"); + return; + } EnumSyncAction action = EnumSyncAction.values()[syncActionOrdinal]; try { NBTTagCompound tag = ByteBufUtils.readBigNBT(data); - // Now do your client-side logic (similar to your old clientSync() or clientSyncUpdate() approach) handleSyncPacketClient(type, action, categoryID, incomingRevision, tag); } catch (RuntimeException e) { LogWriter.error(String.format("Attempted to Sync %s but it was too big", type.toString())); @@ -149,7 +144,7 @@ public final class SyncPacket extends LargeAbstractPacket { } private void handleSyncPacketClient( - EnumSyncType enumSyncType, + SyncType syncType, EnumSyncAction enumSyncAction, int id, int incomingRevision, @@ -157,13 +152,13 @@ public final class SyncPacket extends LargeAbstractPacket { ) { switch (enumSyncAction) { case RELOAD: - SyncController.clientSync(enumSyncType, incomingRevision, data); + SyncController.clientSync(syncType, incomingRevision, data); break; case UPDATE: - SyncController.clientUpdate(enumSyncType, id, incomingRevision, data); + SyncController.clientUpdate(syncType, id, incomingRevision, data); break; case REMOVE: - SyncController.clientSyncRemove(enumSyncType, id, incomingRevision); + SyncController.clientSyncRemove(syncType, id, incomingRevision); break; } } diff --git a/src/main/java/kamkeel/npcs/network/packets/player/SyncRevisionInfoPacket.java b/src/main/java/kamkeel/npcs/network/packets/player/SyncRevisionInfoPacket.java index 769b086b7..25824e15a 100644 --- a/src/main/java/kamkeel/npcs/network/packets/player/SyncRevisionInfoPacket.java +++ b/src/main/java/kamkeel/npcs/network/packets/player/SyncRevisionInfoPacket.java @@ -8,13 +8,13 @@ import kamkeel.npcs.network.AbstractPacket; import kamkeel.npcs.network.PacketChannel; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumPlayerPacket; -import kamkeel.npcs.network.enums.EnumSyncType; +import kamkeel.npcs.network.enums.SyncType; import kamkeel.npcs.util.ByteBufUtils; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import java.io.IOException; -import java.util.EnumMap; +import java.util.LinkedHashMap; import java.util.Map; public class SyncRevisionInfoPacket extends AbstractPacket { @@ -23,12 +23,12 @@ public class SyncRevisionInfoPacket extends AbstractPacket { private String serverKey = ""; private String previousServerKey = ""; - private final EnumMap revisions = new EnumMap<>(EnumSyncType.class); + private final Map revisions = new LinkedHashMap<>(); public SyncRevisionInfoPacket() { } - public SyncRevisionInfoPacket(String serverKey, String previousServerKey, EnumMap revisions) { + public SyncRevisionInfoPacket(String serverKey, String previousServerKey, Map revisions) { if (serverKey != null) { this.serverKey = serverKey; } @@ -56,7 +56,7 @@ public class SyncRevisionInfoPacket extends AbstractPacket { ByteBufUtils.writeString(out, serverKey); ByteBufUtils.writeString(out, previousServerKey); out.writeShort(revisions.size()); - for (Map.Entry entry : revisions.entrySet()) { + for (Map.Entry entry : revisions.entrySet()) { out.writeInt(entry.getKey().ordinal()); out.writeInt(entry.getValue()); } @@ -71,11 +71,13 @@ public class SyncRevisionInfoPacket extends AbstractPacket { String incomingServerKey = ByteBufUtils.readString(in); String incomingPreviousKey = ByteBufUtils.readString(in); int revisionCount = in.readUnsignedShort(); - EnumMap incomingRevisions = new EnumMap<>(EnumSyncType.class); + Map incomingRevisions = new LinkedHashMap<>(); for (int i = 0; i < revisionCount; i++) { - EnumSyncType type = EnumSyncType.values()[in.readInt()]; + SyncType type = SyncType.byOrdinal(in.readInt()); int revision = in.readInt(); - incomingRevisions.put(type, revision); + if (type != null) { + incomingRevisions.put(type, revision); + } } SyncController.handleClientRevisionReport((EntityPlayerMP) player, incomingServerKey, incomingPreviousKey, incomingRevisions); diff --git a/src/main/java/noppes/npcs/ServerEventsHandler.java b/src/main/java/noppes/npcs/ServerEventsHandler.java index 04e0406d8..a8c5f2b4a 100644 --- a/src/main/java/noppes/npcs/ServerEventsHandler.java +++ b/src/main/java/noppes/npcs/ServerEventsHandler.java @@ -10,7 +10,7 @@ import kamkeel.npcs.entity.EntityEnergyDome; import kamkeel.npcs.network.PacketHandler; import kamkeel.npcs.network.enums.EnumSoundOperation; import kamkeel.npcs.network.enums.EnumSyncAction; -import kamkeel.npcs.network.enums.EnumSyncType; +import kamkeel.npcs.network.enums.SyncType; import kamkeel.npcs.network.packets.data.ClonerPacket; import kamkeel.npcs.network.packets.data.MarkDataPacket; import kamkeel.npcs.network.packets.data.SoundManagementPacket; @@ -255,19 +255,19 @@ public class ServerEventsHandler { if (block == Blocks.crafting_table && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) { PacketHandler.Instance.sendToPlayer(new SyncPacket( - EnumSyncType.WORKBENCH_RECIPES, + SyncType.WORKBENCH_RECIPES, EnumSyncAction.RELOAD, -1, - SyncController.getCurrentRevision(EnumSyncType.WORKBENCH_RECIPES), + SyncController.getCurrentRevision(SyncType.WORKBENCH_RECIPES), SyncController.workbenchNBT() ), (EntityPlayerMP) player); } if (block == CustomItems.carpentyBench && event.action == Action.RIGHT_CLICK_BLOCK && !player.worldObj.isRemote) { PacketHandler.Instance.sendToPlayer(new SyncPacket( - EnumSyncType.CARPENTRY_RECIPES, + SyncType.CARPENTRY_RECIPES, EnumSyncAction.RELOAD, -1, - SyncController.getCurrentRevision(EnumSyncType.CARPENTRY_RECIPES), + SyncController.getCurrentRevision(SyncType.CARPENTRY_RECIPES), SyncController.carpentryNBT() ), (EntityPlayerMP) player); } diff --git a/src/main/java/noppes/npcs/client/ClientCacheHandler.java b/src/main/java/noppes/npcs/client/ClientCacheHandler.java index 3386ffb43..53dfb9959 100644 --- a/src/main/java/noppes/npcs/client/ClientCacheHandler.java +++ b/src/main/java/noppes/npcs/client/ClientCacheHandler.java @@ -1,6 +1,6 @@ package noppes.npcs.client; -import kamkeel.npcs.network.enums.EnumSyncType; +import kamkeel.npcs.network.enums.SyncType; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.ResourceLocation; import noppes.npcs.client.controllers.MusicController; @@ -18,8 +18,8 @@ import noppes.npcs.controllers.data.PlayerData; import noppes.npcs.controllers.data.SkinOverlay; import noppes.npcs.util.CacheHashMap; -import java.util.EnumMap; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.Map; import java.util.UUID; @@ -32,14 +32,14 @@ public class ClientCacheHandler { private static String activeServerKey = ""; private static String lastServerKey = ""; - private static final Map> clientRevisionCache = new HashMap<>(); + private static final Map> clientRevisionCache = new HashMap<>(); public static Party party; public static boolean allowProfiles = true; public static boolean allowParties = true; - public static void setActiveServer(String serverKey, EnumMap serverRevisions) { + public static void setActiveServer(String serverKey, Map serverRevisions) { String normalizedKey = serverKey == null ? "" : serverKey; String previousKey = activeServerKey == null ? "" : activeServerKey; lastServerKey = previousKey; @@ -54,9 +54,9 @@ public class ClientCacheHandler { return; } - EnumMap cached = clientRevisionCache.computeIfAbsent( + Map cached = clientRevisionCache.computeIfAbsent( activeServerKey, - ignored -> new EnumMap<>(EnumSyncType.class) + ignored -> new LinkedHashMap<>() ); if (serverRevisions != null && !serverRevisions.isEmpty()) { cached.keySet().retainAll(serverRevisions.keySet()); @@ -67,19 +67,19 @@ public class ClientCacheHandler { return lastServerKey == null ? "" : lastServerKey; } - public static EnumMap getCachedRevisionsForServer(String serverKey) { + public static Map getCachedRevisionsForServer(String serverKey) { String key = serverKey == null ? "" : serverKey; if (key.isEmpty()) { - return new EnumMap<>(EnumSyncType.class); + return new LinkedHashMap<>(); } - EnumMap revisions = clientRevisionCache.get(key); + Map revisions = clientRevisionCache.get(key); if (revisions == null) { - return new EnumMap<>(EnumSyncType.class); + return new LinkedHashMap<>(); } - return new EnumMap<>(revisions); + return new LinkedHashMap<>(revisions); } - public static void updateClientRevision(EnumSyncType type, int revision) { + public static void updateClientRevision(SyncType type, int revision) { if (revision < 0) { return; } @@ -87,9 +87,9 @@ public class ClientCacheHandler { if (key.isEmpty()) { return; } - EnumMap revisions = clientRevisionCache.computeIfAbsent( + Map revisions = clientRevisionCache.computeIfAbsent( key, - ignored -> new EnumMap<>(EnumSyncType.class) + ignored -> new LinkedHashMap<>() ); revisions.put(type, revision); } @@ -126,14 +126,11 @@ public class ClientCacheHandler { ClientCacheHandler.playerAnimations.clear(); ProfileClientConfig.reset(); - // Clear Texture Caches GuiSoundSelection.cachedDomains.clear(); GuiTextureSelection.cachedTextures.clear(); - // Clear music/bard sounds MusicController.Instance.stopAllSounds(); - // Clear Quest Tracker HudComponent component = ClientHudManager.getInstance().getHudComponents().get(EnumHudComponent.QuestTracker); if (component != null) { component.loadData(new NBTTagCompound()); @@ -146,7 +143,6 @@ public class ClientCacheHandler { ClientCacheHandler.customOverlays.clear(); ClientCacheHandler.skinOverlays.clear(); - // Clear Texture Caches GuiSoundSelection.cachedDomains.clear(); GuiTextureSelection.cachedTextures.clear(); } diff --git a/src/main/java/noppes/npcs/controllers/CustomEffectController.java b/src/main/java/noppes/npcs/controllers/CustomEffectController.java index 640f544c4..6a465b0ee 100644 --- a/src/main/java/noppes/npcs/controllers/CustomEffectController.java +++ b/src/main/java/noppes/npcs/controllers/CustomEffectController.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers; import kamkeel.npcs.controllers.SyncController; -import kamkeel.npcs.network.enums.EnumSyncType; +import kamkeel.npcs.network.enums.SyncType; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; @@ -128,7 +128,7 @@ public class CustomEffectController implements ICustomEffectHandler { file.delete(); } categoryManager.removeItem(id); - SyncController.syncRemove(EnumSyncType.CUSTOM_EFFECTS, foundEffect.getID()); + SyncController.syncRemove(SyncType.CUSTOM_EFFECTS, foundEffect.getID()); saveEffectLoadMap(); } } @@ -700,7 +700,7 @@ public class CustomEffectController implements ICustomEffectHandler { file2.delete(); file.renameTo(file2); nbtTagCompound.removeTag("ScriptData"); - SyncController.syncUpdate(EnumSyncType.CUSTOM_EFFECTS, -1, nbtTagCompound); + SyncController.syncUpdate(SyncType.CUSTOM_EFFECTS, -1, nbtTagCompound); } catch (Exception e) { LogWriter.except(e); } diff --git a/src/main/java/noppes/npcs/controllers/DialogController.java b/src/main/java/noppes/npcs/controllers/DialogController.java index 3490735f3..0e2df3d84 100644 --- a/src/main/java/noppes/npcs/controllers/DialogController.java +++ b/src/main/java/noppes/npcs/controllers/DialogController.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers; import kamkeel.npcs.controllers.SyncController; -import kamkeel.npcs.network.enums.EnumSyncType; +import kamkeel.npcs.network.enums.SyncType; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -239,7 +239,7 @@ public class DialogController implements IDialogHandler { dir.mkdirs(); } categories.put(category.id, category); - SyncController.syncUpdate(EnumSyncType.DIALOG_CATEGORY, -1, SyncController.updateDialogCat(category)); + SyncController.syncUpdate(SyncType.DIALOG_CATEGORY, -1, SyncController.updateDialogCat(category)); } public void removeCategory(int category) { @@ -252,7 +252,7 @@ public class DialogController implements IDialogHandler { for (int dia : cat.dialogs.keySet()) dialogs.remove(dia); categories.remove(category); - SyncController.syncRemove(EnumSyncType.DIALOG_CATEGORY, category); + SyncController.syncRemove(SyncType.DIALOG_CATEGORY, category); } private boolean containsCategoryName(String name) { @@ -302,7 +302,7 @@ public class DialogController implements IDialogHandler { if (file2.exists()) file2.delete(); file.renameTo(file2); - SyncController.syncUpdate(EnumSyncType.DIALOG, category.id, dialog.writeToNBT(new NBTTagCompound())); + SyncController.syncUpdate(SyncType.DIALOG, category.id, dialog.writeToNBT(new NBTTagCompound())); } catch (Exception e) { LogWriter.except(e); } @@ -316,7 +316,7 @@ public class DialogController implements IDialogHandler { return; category.dialogs.remove(dialog.id); dialogs.remove(dialog.id); - SyncController.syncRemove(EnumSyncType.DIALOG, dialog.id); + SyncController.syncRemove(SyncType.DIALOG, dialog.id); } private File getDir() { diff --git a/src/main/java/noppes/npcs/controllers/FactionController.java b/src/main/java/noppes/npcs/controllers/FactionController.java index 9ddf860ea..7da2ebe67 100644 --- a/src/main/java/noppes/npcs/controllers/FactionController.java +++ b/src/main/java/noppes/npcs/controllers/FactionController.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers; import kamkeel.npcs.controllers.SyncController; -import kamkeel.npcs.network.enums.EnumSyncType; +import kamkeel.npcs.network.enums.SyncType; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -159,7 +159,7 @@ public class FactionController implements IFactionHandler { NBTTagCompound facCompound = new NBTTagCompound(); faction.writeNBT(facCompound); - SyncController.syncUpdate(EnumSyncType.FACTION, -1, facCompound); + SyncController.syncUpdate(SyncType.FACTION, -1, facCompound); saveFactions(); } @@ -195,7 +195,7 @@ public class FactionController implements IFactionHandler { } else { this.saveFactions(); faction.id = -1; - SyncController.syncRemove(EnumSyncType.FACTION, id); + SyncController.syncRemove(SyncType.FACTION, id); return faction; } } else { diff --git a/src/main/java/noppes/npcs/controllers/MagicController.java b/src/main/java/noppes/npcs/controllers/MagicController.java index 40febf172..dff89d015 100644 --- a/src/main/java/noppes/npcs/controllers/MagicController.java +++ b/src/main/java/noppes/npcs/controllers/MagicController.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers; import kamkeel.npcs.controllers.SyncController; -import kamkeel.npcs.network.enums.EnumSyncType; +import kamkeel.npcs.network.enums.SyncType; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; @@ -275,7 +275,7 @@ public class MagicController implements IMagicHandler { NBTTagCompound magicCompound = new NBTTagCompound(); mag.writeNBT(magicCompound); - SyncController.syncUpdate(EnumSyncType.MAGIC, -1, magicCompound); + SyncController.syncUpdate(SyncType.MAGIC, -1, magicCompound); saveMagicData(); } @@ -283,7 +283,7 @@ public class MagicController implements IMagicHandler { public void removeMagic(int magicID) { if (magics.containsKey(magicID)) { magics.remove(magicID); - SyncController.syncRemove(EnumSyncType.MAGIC, magicID); + SyncController.syncRemove(SyncType.MAGIC, magicID); saveMagicData(); } } @@ -345,7 +345,7 @@ public class MagicController implements IMagicHandler { NBTTagCompound cycleCompound = new NBTTagCompound(); cycle.writeNBT(cycleCompound); - SyncController.syncUpdate(EnumSyncType.MAGIC_CYCLE, -1, cycleCompound); + SyncController.syncUpdate(SyncType.MAGIC_CYCLE, -1, cycleCompound); saveMagicData(); } @@ -353,7 +353,7 @@ public class MagicController implements IMagicHandler { public void removeCycle(int categoryId) { if (cycles.containsKey(categoryId)) { cycles.remove(categoryId); - SyncController.syncRemove(EnumSyncType.MAGIC_CYCLE, categoryId); + SyncController.syncRemove(SyncType.MAGIC_CYCLE, categoryId); saveMagicData(); } } diff --git a/src/main/java/noppes/npcs/controllers/QuestController.java b/src/main/java/noppes/npcs/controllers/QuestController.java index e9b403ee7..59136b2aa 100644 --- a/src/main/java/noppes/npcs/controllers/QuestController.java +++ b/src/main/java/noppes/npcs/controllers/QuestController.java @@ -1,7 +1,7 @@ package noppes.npcs.controllers; import kamkeel.npcs.controllers.SyncController; -import kamkeel.npcs.network.enums.EnumSyncType; +import kamkeel.npcs.network.enums.SyncType; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; @@ -158,7 +158,7 @@ public class QuestController implements IQuestHandler { for (int dia : cat.quests.keySet()) quests.remove(dia); categories.remove(category); - SyncController.syncRemove(EnumSyncType.QUEST_CATEGORY, category); + SyncController.syncRemove(SyncType.QUEST_CATEGORY, category); } public void saveCategory(QuestCategory category) { @@ -188,7 +188,7 @@ public class QuestController implements IQuestHandler { dir.mkdirs(); } categories.put(category.id, category); - SyncController.syncUpdate(EnumSyncType.QUEST_CATEGORY, -1, SyncController.updateQuestCat(category)); + SyncController.syncUpdate(SyncType.QUEST_CATEGORY, -1, SyncController.updateQuestCat(category)); } private boolean containsCategoryName(String name) { @@ -245,7 +245,7 @@ public class QuestController implements IQuestHandler { if (file2.exists()) file2.delete(); file.renameTo(file2); - SyncController.syncUpdate(EnumSyncType.QUEST, category.id, quest.writeToNBT(new NBTTagCompound())); + SyncController.syncUpdate(SyncType.QUEST, category.id, quest.writeToNBT(new NBTTagCompound())); } catch (Exception e) { e.printStackTrace(); }