diff --git a/src/main/java/com/falsepattern/chunk/api/ChunkDataManager.java b/src/main/java/com/falsepattern/chunk/api/ChunkDataManager.java index fce6f7c..1fc3681 100644 --- a/src/main/java/com/falsepattern/chunk/api/ChunkDataManager.java +++ b/src/main/java/com/falsepattern/chunk/api/ChunkDataManager.java @@ -25,20 +25,6 @@ public interface ChunkDataManager { */ String id(); - /** - * Used for sorting the managers. Managers with a lower order index are processed first. - * If unsure, return 0, and let the implementation decide. - */ - default int orderIndex() { - return 0; - } - - /** - * Initializes your data in a chunk. This is called at the end of the chunk constructor. One less mixin per manager! - * @param chunk The chunk to initialize. - */ - void init(T chunk); - /** * @implNote This is used to determine the size of the packet compression/decompression buffer. * @return The maximum amount of bytes your data can take up in a packet. diff --git a/src/main/java/com/falsepattern/chunk/api/ChunkDataRegistry.java b/src/main/java/com/falsepattern/chunk/api/ChunkDataRegistry.java index af7d1d2..987c317 100644 --- a/src/main/java/com/falsepattern/chunk/api/ChunkDataRegistry.java +++ b/src/main/java/com/falsepattern/chunk/api/ChunkDataRegistry.java @@ -1,7 +1,6 @@ package com.falsepattern.chunk.api; import com.falsepattern.chunk.internal.ChunkDataRegistryImpl; -import com.falsepattern.chunk.api.exception.ManagerRegistrationException; /** * This class is used to register ChunkDataManagers. @@ -11,17 +10,19 @@ public class ChunkDataRegistry { /** * Registers a ChunkDataManager. Only do this during the preInit phase. * @param manager The manager to register. - * @throws ManagerRegistrationException If the manager is already registered. + * @throws IllegalStateException If the registration stage is over. + * @throws IllegalArgumentException If the manager has a duplicate id. */ - public static void registerDataManager(ChunkDataManager manager) throws ManagerRegistrationException { + public static void registerDataManager(ChunkDataManager manager) throws IllegalStateException, IllegalArgumentException { ChunkDataRegistryImpl.registerDataManager(manager); } /** * Disables a ChunkDataManager. Only do this during the preInit phase. * @param id The id of the manager to disable. + * @throws IllegalStateException If the disable stage is over. */ - public static void disableDataManager(String domain, String id) { + public static void disableDataManager(String domain, String id) throws IllegalStateException { ChunkDataRegistryImpl.disableDataManager(domain, id); } } diff --git a/src/main/java/com/falsepattern/chunk/api/exception/ManagerRegistrationException.java b/src/main/java/com/falsepattern/chunk/api/exception/ManagerRegistrationException.java deleted file mode 100644 index a493fef..0000000 --- a/src/main/java/com/falsepattern/chunk/api/exception/ManagerRegistrationException.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.falsepattern.chunk.api.exception; - -import com.falsepattern.chunk.api.ChunkDataManager; - -/** - * This exception is thrown when a {@link ChunkDataManager} could not be registered. - *

- * Possible reasons include: - *

- */ -public class ManagerRegistrationException extends RuntimeException { - public ManagerRegistrationException() { - super(); - } - - public ManagerRegistrationException(String message) { - super(message); - } - - public ManagerRegistrationException(String message, Throwable cause) { - super(message, cause); - } - - public ManagerRegistrationException(Throwable cause) { - super(cause); - } - - protected ManagerRegistrationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { - super(message, cause, enableSuppression, writableStackTrace); - } -} diff --git a/src/main/java/com/falsepattern/chunk/internal/ChunkDataRegistryImpl.java b/src/main/java/com/falsepattern/chunk/internal/ChunkDataRegistryImpl.java index a923370..5840269 100644 --- a/src/main/java/com/falsepattern/chunk/internal/ChunkDataRegistryImpl.java +++ b/src/main/java/com/falsepattern/chunk/internal/ChunkDataRegistryImpl.java @@ -1,7 +1,6 @@ package com.falsepattern.chunk.internal; import com.falsepattern.chunk.api.ChunkDataManager; -import com.falsepattern.chunk.api.exception.ManagerRegistrationException; import lombok.val; import lombok.var; @@ -20,14 +19,14 @@ public class ChunkDataRegistryImpl { private static final Map managers = new HashMap<>(); private static final Set disabledManagers = new HashSet<>(); private static int maxPacketSize = 0; - public static void registerDataManager(ChunkDataManager manager) throws ManagerRegistrationException { + public static void registerDataManager(ChunkDataManager manager) throws IllegalStateException, IllegalArgumentException { if (!ChunkAPI.isRegistrationStage()) { - throw new ManagerRegistrationException("ChunkDataManager registration is not allowed at this time! " + + throw new IllegalStateException("ChunkDataManager registration is not allowed at this time! " + "Please register your ChunkDataManager in the preInit phase of your mod."); } var id = manager.domain() + ":" + manager.id(); if (managers.containsKey(id)) { - throw new ManagerRegistrationException("ChunkDataManager " + manager + " has a duplicate id!"); + throw new IllegalArgumentException("ChunkDataManager " + manager + " has a duplicate id!"); } // If the manager was disabled, do not add it to the list of managers. @@ -42,11 +41,10 @@ public class ChunkDataRegistryImpl { public static void disableDataManager(String domain, String id) { if (!ChunkAPI.isDisableStage()) { - throw new ManagerRegistrationException("ChunkDataManager disabling is not allowed at this time! " + - "Please disable any ChunkDataManagers in the preInit/init phases."); + throw new IllegalStateException("ChunkDataManager disabling is not allowed at this time! " + + "Please disable any ChunkDataManagers in the preInit/init phases."); } - val fusedId = domain + ":" + id; - id = id.intern(); + id = domain + ":" + id; Common.LOG.warn("Disabling ChunkDataManager " + id + ". See the stacktrace for the source of this event.", new Throwable()); //Remove the manager from the list of managers, if it exists val removed = managers.remove(id);