mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-11 20:47:38 +00:00
SyncController OVERHAUL PHASE #1:
- Refactored EnumSyncType into object based SyncType registry, so other mods can register their own types
This commit is contained in:
1 parent
b2c279feeb
commit
48281c8d34
13 files changed
+673
-558
No files matched your search
File diff suppressed because it is too large.
Load diff
@@ -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
|
||||
}
|
||||
@@ -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.
|
||||
*
|
||||
* <p>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.</p>
|
||||
*
|
||||
* <p>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).</p>
|
||||
*
|
||||
* <p>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.</p>
|
||||
*/
|
||||
public final class SyncType {
|
||||
|
||||
// ──────────────────── Registry ────────────────────
|
||||
private static final Map<String, SyncType> 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<SyncType> 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;
|
||||
}
|
||||
}
|
||||
@@ -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<EnumSyncType, Integer> revisionSnapshot = new EnumMap<>(EnumSyncType.class);
|
||||
private final Map<SyncType, Integer> revisionSnapshot = new LinkedHashMap<>();
|
||||
|
||||
public LoginPacket() {
|
||||
}
|
||||
|
||||
public LoginPacket(String serverCacheKey, EnumMap<EnumSyncType, Integer> revisionSnapshot) {
|
||||
public LoginPacket(String serverCacheKey, Map<SyncType, Integer> 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<EnumSyncType, Integer> entry : revisionSnapshot.entrySet()) {
|
||||
for (Map.Entry<SyncType, Integer> 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<EnumSyncType, Integer> serverRevisions = new EnumMap<>(EnumSyncType.class);
|
||||
Map<SyncType, Integer> 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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<EnumSyncType, Integer> revisions = new EnumMap<>(EnumSyncType.class);
|
||||
private final Map<SyncType, Integer> revisions = new LinkedHashMap<>();
|
||||
|
||||
public SyncRevisionInfoPacket() {
|
||||
}
|
||||
|
||||
public SyncRevisionInfoPacket(String serverKey, String previousServerKey, EnumMap<EnumSyncType, Integer> revisions) {
|
||||
public SyncRevisionInfoPacket(String serverKey, String previousServerKey, Map<SyncType, Integer> 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<EnumSyncType, Integer> entry : revisions.entrySet()) {
|
||||
for (Map.Entry<SyncType, Integer> 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<EnumSyncType, Integer> incomingRevisions = new EnumMap<>(EnumSyncType.class);
|
||||
Map<SyncType, Integer> 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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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<String, EnumMap<EnumSyncType, Integer>> clientRevisionCache = new HashMap<>();
|
||||
private static final Map<String, Map<SyncType, Integer>> clientRevisionCache = new HashMap<>();
|
||||
|
||||
public static Party party;
|
||||
|
||||
public static boolean allowProfiles = true;
|
||||
public static boolean allowParties = true;
|
||||
|
||||
public static void setActiveServer(String serverKey, EnumMap<EnumSyncType, Integer> serverRevisions) {
|
||||
public static void setActiveServer(String serverKey, Map<SyncType, Integer> serverRevisions) {
|
||||
String normalizedKey = serverKey == null ? "" : serverKey;
|
||||
String previousKey = activeServerKey == null ? "" : activeServerKey;
|
||||
lastServerKey = previousKey;
|
||||
@@ -54,9 +54,9 @@ public class ClientCacheHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
EnumMap<EnumSyncType, Integer> cached = clientRevisionCache.computeIfAbsent(
|
||||
Map<SyncType, Integer> 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<EnumSyncType, Integer> getCachedRevisionsForServer(String serverKey) {
|
||||
public static Map<SyncType, Integer> getCachedRevisionsForServer(String serverKey) {
|
||||
String key = serverKey == null ? "" : serverKey;
|
||||
if (key.isEmpty()) {
|
||||
return new EnumMap<>(EnumSyncType.class);
|
||||
return new LinkedHashMap<>();
|
||||
}
|
||||
EnumMap<EnumSyncType, Integer> revisions = clientRevisionCache.get(key);
|
||||
Map<SyncType, Integer> 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<EnumSyncType, Integer> revisions = clientRevisionCache.computeIfAbsent(
|
||||
Map<SyncType, Integer> 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();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user