Added throw exception

This commit is contained in:
lieght
2025-10-05 17:38:01 +02:00
parent 06464945bd
commit b8336ce3d2

View File

@@ -84,22 +84,12 @@ public class ResourceManager {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public static <T extends BaseResource> T get(String name) { public static <T extends BaseResource> T get(String name) {
ResourceMeta<T> asset = (ResourceMeta<T>) assets.get(name); ResourceMeta<T> asset = (ResourceMeta<T>) assets.get(name);
if (asset == null) return null; if (asset == null) {
throw new TypeNotPresentException(name, new RuntimeException(String.format("Type %s not present", name))); // TODO: Create own exception, BAM
}
return asset.getResource(); return asset.getResource();
} }
/**
* Retrieve the resource of a given name, cast to the expected type.
*
* @param name the asset name
* @param <T> the expected resource type
* @return the resource, or null if not found
*/
@SuppressWarnings("unchecked")
public static <T extends BaseResource> T get(Class<T> type, String name) {
return type.cast(assets.get(name).getResource());
}
/** /**
* Retrieve all assets of a specific resource type. * Retrieve all assets of a specific resource type.
* *
@@ -134,26 +124,6 @@ public class ResourceManager {
return null; return null;
} }
/**
* Retrieve an asset by its name.
*
* @param name the asset name
* @return the asset, or null if not found
*/
public static ResourceMeta<? extends BaseResource> getByName(String name) {
return assets.get(name);
}
/**
* Attempt to find an asset by name, returning an {@link Optional}.
*
* @param name the asset name
* @return an Optional containing the asset if found
*/
public static Optional<ResourceMeta<? extends BaseResource>> findByName(String name) {
return Optional.ofNullable(assets.get(name));
}
/** /**
* Add a new asset to the manager. * Add a new asset to the manager.
* *