diff --git a/projects/common-api/src/main/java/dan200/computercraft/api/detail/BasicItemDetailProvider.java b/projects/common-api/src/main/java/dan200/computercraft/api/detail/BasicItemDetailProvider.java index bf706f0db..c709b79f6 100644 --- a/projects/common-api/src/main/java/dan200/computercraft/api/detail/BasicItemDetailProvider.java +++ b/projects/common-api/src/main/java/dan200/computercraft/api/detail/BasicItemDetailProvider.java @@ -13,7 +13,7 @@ import java.util.Map; import java.util.Objects; /** - * An item detail provider for {@link ItemStack}'s whose {@link Item} has a specific type. + * An item detail provider for {@link ItemStack}s whose {@link Item} has a specific type. * * @param The type the stack's item must have. */ @@ -22,7 +22,7 @@ public abstract class BasicItemDetailProvider implements DetailProvider implements DetailProvider implements DetailProvider data, ItemStack stack, T item - ); + public abstract void provideDetails(Map data, ItemStack stack, T item); @Override - public void provideDetails(Map data, ItemStack stack) { + public final void provideDetails(Map data, ItemStack stack) { var item = stack.getItem(); if (!itemType.isInstance(item)) return; - // If `namespace` is specified, insert into a new data map instead of the existing one. - Map child = namespace == null ? data : new HashMap<>(); - - provideDetails(child, stack, itemType.cast(item)); - - if (namespace != null) { + if (namespace == null) { + provideDetails(data, stack, itemType.cast(item)); + } else { + Map child = new HashMap<>(); + provideDetails(child, stack, itemType.cast(item)); data.put(namespace, child); } } diff --git a/projects/common-api/src/main/java/dan200/computercraft/api/detail/DetailRegistry.java b/projects/common-api/src/main/java/dan200/computercraft/api/detail/DetailRegistry.java index 7c355e8b0..4f21ff81f 100644 --- a/projects/common-api/src/main/java/dan200/computercraft/api/detail/DetailRegistry.java +++ b/projects/common-api/src/main/java/dan200/computercraft/api/detail/DetailRegistry.java @@ -26,7 +26,7 @@ public interface DetailRegistry { * @param provider The detail provider to register. * @see DetailProvider */ - void addProvider(DetailProvider provider); + void addProvider(DetailProvider provider); /** * Compute basic details about an object. This is cheaper than computing all details operation, and so is suitable diff --git a/projects/common/src/main/java/dan200/computercraft/impl/detail/DetailRegistryImpl.java b/projects/common/src/main/java/dan200/computercraft/impl/detail/DetailRegistryImpl.java index 3f16b6893..31d42bba2 100644 --- a/projects/common/src/main/java/dan200/computercraft/impl/detail/DetailRegistryImpl.java +++ b/projects/common/src/main/java/dan200/computercraft/impl/detail/DetailRegistryImpl.java @@ -15,7 +15,7 @@ import java.util.*; * @param The type of object that this registry provides details for. */ public class DetailRegistryImpl implements DetailRegistry { - private final Collection> providers = new ArrayList<>(); + private final Collection> providers = new ArrayList<>(); private final DetailProvider basic; public DetailRegistryImpl(DetailProvider basic) { @@ -24,7 +24,7 @@ public class DetailRegistryImpl implements DetailRegistry { } @Override - public synchronized void addProvider(DetailProvider provider) { + public synchronized void addProvider(DetailProvider provider) { Objects.requireNonNull(provider, "provider cannot be null"); if (!providers.contains(provider)) providers.add(provider); }