Skip to content
This repository has been archived by the owner on Mar 11, 2024. It is now read-only.

Commit

Permalink
Changed ServiceManager missing service handling
Browse files Browse the repository at this point in the history
  • Loading branch information
BelgianDev committed Dec 23, 2023
1 parent bad6e80 commit fd637e4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public interface ServiceManager {
* @param serviceClass parent service class.
* @return return the registered service, null if no service we're registered with this class.
*/
@Nullable <T extends Service> T getService(Class<T> serviceClass);
<T extends Service> T getService(Class<T> serviceClass);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package fr.atlasworld.network.api.services.exception;

public class MissingServiceException extends RuntimeException {

public MissingServiceException(String message) {
super(message);
}

public MissingServiceException(String message, Throwable cause) {
super(message, cause);
}

public MissingServiceException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import fr.atlasworld.network.api.module.Module;
import fr.atlasworld.network.api.services.Service;
import fr.atlasworld.network.api.services.ServiceManager;
import fr.atlasworld.network.api.services.exception.MissingServiceException;
import org.jetbrains.annotations.Nullable;

import java.util.Map;
Expand All @@ -29,7 +30,7 @@ public <T extends Service> void registerService(Module module, Class<T> serviceC
@SuppressWarnings("unchecked")
public <T extends Service> @Nullable T getService(Class<T> serviceClass) {
if (!this.registeredServices.containsKey(serviceClass))
return null;
throw new MissingServiceException("No services registered for '" + serviceClass.getName() + "'!");

return (T) this.registeredServices.get(serviceClass);
}
Expand Down

0 comments on commit fd637e4

Please sign in to comment.