cleanup API

This commit is contained in:
FalsePattern committed 2023-03-29 21:59:56 +02:00
1 parent e2a718efec
commit b91c4e7342
4 files changed
+11 -61

No files matched your search

@@ -25,20 +25,6 @@ public interface ChunkDataManager<T> {
*/
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.
@@ -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);
}
}
@@ -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.
* <p>
* Possible reasons include:
* <ul>
* <li>The manager is already registered</li>
* <li>The manager's name collides with a different manager</li>
* <li>The manager was registered too late (should be done in init)</li>
* </ul>
*/
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);
}
}
@@ -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<String, ChunkDataManager> managers = new HashMap<>();
private static final Set<String> 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);