Some code cleanup and API changes

This commit is contained in:
2023-06-02 23:59:14 +02:00
parent 846191ec95
commit 78bec96ae8
35 changed files with 183 additions and 198 deletions

View File

@@ -0,0 +1,27 @@
package com.hypherionmc.craterlib.util;
import com.hypherionmc.craterlib.CraterConstants;
import java.util.ServiceLoader;
/**
* @author HypherionSA
* Utility class to handle SPI loading
*/
public class ServiceUtil {
/**
* Try to load a service
* @param clazz The service class type to load
* @return The loaded class
*/
public static <T> T load(Class<T> clazz) {
final T loadedService = ServiceLoader.load(clazz)
.findFirst()
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
CraterConstants.LOG.debug("Loaded {} for service {}", loadedService, clazz);
return loadedService;
}
}