diff --git a/src/main/java/com/falsepattern/chunk/api/ChunkDataManager.java b/src/main/java/com/falsepattern/chunk/api/ChunkDataManager.java index ba1fb0b..fce6f7c 100644 --- a/src/main/java/com/falsepattern/chunk/api/ChunkDataManager.java +++ b/src/main/java/com/falsepattern/chunk/api/ChunkDataManager.java @@ -8,9 +8,10 @@ import java.nio.ByteBuffer; /** * Singleton instances that can manage custom in chunks. - * For performance reasons, you should store any data in the chunk itself using a mixin. The type T is the type + *

+ * Implementations should be stateless and thread-safe. + * @implNote For performance reasons, you should store any data in the chunk itself using a mixin. The type T is the type * of the interface that you are mixing into the chunk. - * Note: All the methods should be thread-safe and stateless unless otherwise specified. */ public interface ChunkDataManager { diff --git a/src/main/java/com/falsepattern/chunk/api/ChunkDataRegistry.java b/src/main/java/com/falsepattern/chunk/api/ChunkDataRegistry.java index d193803..af7d1d2 100644 --- a/src/main/java/com/falsepattern/chunk/api/ChunkDataRegistry.java +++ b/src/main/java/com/falsepattern/chunk/api/ChunkDataRegistry.java @@ -21,7 +21,7 @@ public class ChunkDataRegistry { * Disables a ChunkDataManager. Only do this during the preInit phase. * @param id The id of the manager to disable. */ - public static void disableDataManager(String id) { - ChunkDataRegistryImpl.disableDataManager(id); + public static void disableDataManager(String domain, String id) { + ChunkDataRegistryImpl.disableDataManager(domain, id); } } diff --git a/src/main/java/com/falsepattern/chunk/internal/ChunkDataRegistryImpl.java b/src/main/java/com/falsepattern/chunk/internal/ChunkDataRegistryImpl.java index 2aa4559..a923370 100644 --- a/src/main/java/com/falsepattern/chunk/internal/ChunkDataRegistryImpl.java +++ b/src/main/java/com/falsepattern/chunk/internal/ChunkDataRegistryImpl.java @@ -91,8 +91,8 @@ public class ChunkDataRegistryImpl { continue; } int start = buf.position(); - val section = ByteBuffer.wrap(data, start, length); - manager.readFromBuffer(chunk, ebsMask, forceUpdate, section); + val slice = createSlice(buf, start, length); + manager.readFromBuffer(chunk, ebsMask, forceUpdate, slice); buf.position(start + length); } } @@ -106,13 +106,23 @@ public class ChunkDataRegistryImpl { val manager = pair.getValue(); writeString(buf, pair.getKey()); int start = buf.position() + 4; - val section = ByteBuffer.wrap(data, start, manager.maxPacketSize()); - manager.writeToBuffer(chunk, ebsMask, forceUpdate, section); - int length = section.position(); - buf.position(start - 4); + val slice = createSlice(buf, start, manager.maxPacketSize()); + manager.writeToBuffer(chunk, ebsMask, forceUpdate, slice); + int length = slice.position(); buf.putInt(length); buf.position(start + length); } return buf.position(); } + + private static ByteBuffer createSlice(ByteBuffer buffer, int start, int length) { + int oldLimit = buffer.limit(); + int oldPosition = buffer.position(); + buffer.position(start); + buffer.limit(start + length); + ByteBuffer slice = buffer.slice(); + buffer.limit(oldLimit); + buffer.position(oldPosition); + return slice; + } }