44import cpw .mods .fml .relauncher .SideOnly ;
55import io .netty .buffer .ByteBuf ;
66import io .netty .buffer .Unpooled ;
7- import kamkeel .npcdbc .network .DBCPacketHandler ;
8- import kamkeel .npcdbc .network .packets .get .DBCInfoSyncPacket ;
97import kamkeel .npcs .addon .DBCAddon ;
108import kamkeel .npcs .controllers .sync .SyncHandler ;
119import kamkeel .npcs .controllers .sync .SyncRegistry ;
2624import noppes .npcs .client .ClientCacheHandler ;
2725import noppes .npcs .controllers .data .PlayerData ;
2826
29- import java .io .IOException ;
3027import java .util .HashMap ;
3128import java .util .LinkedHashMap ;
3229import java .util .Map ;
@@ -146,7 +143,7 @@ private static void sendPostLoginPackets(EntityPlayerMP player) {
146143 * revision state. Used after the login handshake and by server-side callers
147144 * that need to refresh a player's global cached sync families.
148145 */
149- public static void syncPlayer (EntityPlayerMP player ) {
146+ public static void dispatchSyncForAllTypes (EntityPlayerMP player ) {
150147 PlayerSyncState state = playerSyncState .computeIfAbsent (player .getUniqueID (), PlayerSyncState ::new );
151148
152149 // Registry-driven login iteration: iterate only cached types
@@ -194,7 +191,7 @@ public static void completeLoginRevisionHandshake(EntityPlayerMP player, String
194191 else // The client and server agree on identity, so seed the stored state from the report.
195192 state .applyHandshake (clientRevisions );
196193
197- syncPlayer (player );
194+ dispatchSyncForAllTypes (player );
198195 }
199196
200197
@@ -217,21 +214,42 @@ public static void syncAll(SyncType type) {
217214 // ═══════════════════════════════════════════════════════════════════════
218215 // Server-side dispatchers — registry-driven
219216 // ═══════════════════════════════════════════════════════════════════════
217+ public static void syncUpdate (SyncType type , NBTTagCompound compound ) {
218+ Map <SyncType , Integer > revisions = invalidateCaches (type );
219+ int revision = getRequestedInvalidationRevision (type , revisions );
220+ PacketHandler .Instance .sendToAll (new SyncPacket (type , EnumSyncAction .UPDATE , -1 , null , revision , compound ));
221+ updateAllPlayerRevisions (revisions );
222+ }
220223
221- public static void syncRemove (SyncType syncType , int id ) {
222- Map <SyncType , Integer > revisions = invalidateCaches (syncType );
223- int revision = getRequestedInvalidationRevision (syncType , revisions );
224- PacketHandler .Instance .sendToAll (new SyncPacket (syncType , EnumSyncAction .REMOVE , id , revision , new NBTTagCompound () ));
224+ public static void syncUpdate (SyncType type , String key , NBTTagCompound compound ) {
225+ Map <SyncType , Integer > revisions = invalidateCaches (type );
226+ int revision = getRequestedInvalidationRevision (type , revisions );
227+ PacketHandler .Instance .sendToAll (new SyncPacket (type , EnumSyncAction .UPDATE , - 1 , key , revision , compound ));
225228 updateAllPlayerRevisions (revisions );
226229 }
227230
228231 public static void syncUpdate (SyncType type , int cat , NBTTagCompound compound ) {
229232 Map <SyncType , Integer > revisions = invalidateCaches (type );
230233 int revision = getRequestedInvalidationRevision (type , revisions );
231- PacketHandler .Instance .sendToAll (new SyncPacket (type , EnumSyncAction .UPDATE , cat , revision , compound ));
234+ PacketHandler .Instance .sendToAll (new SyncPacket (type , EnumSyncAction .UPDATE , cat , null , revision , compound ));
232235 updateAllPlayerRevisions (revisions );
233236 }
234237
238+ public static void syncRemove (SyncType syncType , String key ) {
239+ Map <SyncType , Integer > revisions = invalidateCaches (syncType );
240+ int revision = getRequestedInvalidationRevision (syncType , revisions );
241+ PacketHandler .Instance .sendToAll (new SyncPacket (syncType , EnumSyncAction .REMOVE , -1 , key , revision , null ));
242+ updateAllPlayerRevisions (revisions );
243+ }
244+
245+ public static void syncRemove (SyncType syncType , int id ) {
246+ Map <SyncType , Integer > revisions = invalidateCaches (syncType );
247+ int revision = getRequestedInvalidationRevision (syncType , revisions );
248+ PacketHandler .Instance .sendToAll (new SyncPacket (syncType , EnumSyncAction .REMOVE , id , null , revision , null ));
249+ updateAllPlayerRevisions (revisions );
250+ }
251+
252+
235253 // ═══════════════════════════════════════════════════════════════════════
236254 // Client-side handlers — registry-driven handler delegation
237255 // ═══════════════════════════════════════════════════════════════════════
@@ -250,11 +268,12 @@ public static void clientHandleAll(SyncType syncType, int revision, NBTTagCompou
250268 }
251269
252270 @ SideOnly (Side .CLIENT )
253- public static void clientHandleUpdate (SyncType syncType , int category_id , int revision , NBTTagCompound compound ) {
271+ public static void clientHandleUpdate (SyncType syncType , int id , String key , int revision , NBTTagCompound compound ) {
254272 SyncHandler handler = SyncRegistry .getHandler (syncType );
255273 if (handler == null ) return ;
256274 try {
257- handler .clientHandleUpdate (compound , category_id );
275+ handler .clientHandleUpdate (compound , id );
276+ handler .clientHandleUpdate (compound , key );
258277 } catch (Exception e ) {
259278 LogWriter .error ("[SyncController] Failed to handle UPDATE for sync type " + syncType , e );
260279 }
@@ -263,12 +282,12 @@ public static void clientHandleUpdate(SyncType syncType, int category_id, int re
263282 }
264283
265284 @ SideOnly (Side .CLIENT )
266- public static void clientHandleRemove (SyncType syncType , int id , int revision , NBTTagCompound compound ) {
285+ public static void clientHandleRemove (SyncType syncType , int id , String key , int revision ) {
267286 SyncHandler handler = SyncRegistry .getHandler (syncType );
268287 if (handler == null ) return ;
269288 try {
270289 handler .clientHandleRemove (id );
271- handler .clientHandleRemove (compound );
290+ handler .clientHandleRemove (key );
272291 } catch (Exception e ) {
273292 LogWriter .error ("[SyncController] Failed to handle REMOVE for sync type " + syncType , e );
274293 }
0 commit comments