This commit is contained in:
FalsePattern committed 2023-03-29 00:26:15 +02:00
1 parent 17183b3824
commit e2a718efec
3 files changed
+21 -10

No files matched your search

@@ -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
* <p>
* 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<T> {
@@ -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);
}
}
@@ -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;
}
}