From 73de725f8e528b3acb171fcda9c60c9fc10c9e98 Mon Sep 17 00:00:00 2001 From: deirn Date: Sat, 25 Nov 2023 01:01:49 +0700 Subject: [PATCH] add dev warning if provider class is used as target --- .../java/mcp/mobius/waila/registry/Registrar.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/mcp/mobius/waila/registry/Registrar.java b/src/main/java/mcp/mobius/waila/registry/Registrar.java index 36ceca197..7b167aad6 100644 --- a/src/main/java/mcp/mobius/waila/registry/Registrar.java +++ b/src/main/java/mcp/mobius/waila/registry/Registrar.java @@ -183,6 +183,7 @@ public void addIcon(IBlockComponentProvider provider, Class clazz, int pr if (Waila.CLIENT_SIDE) { assertLock(); assertPriority(priority); + warnTargetClass(provider, clazz); blockIcon.add(clazz, provider, priority); } } @@ -192,6 +193,7 @@ public void addComponent(IBlockComponentProvider provider, TooltipPosition p if (Waila.CLIENT_SIDE) { assertLock(); assertPriority(priority); + warnTargetClass(provider, clazz); blockComponent.get(position).add(clazz, provider, priority); } } @@ -201,6 +203,7 @@ public void addComponent(IBlockComponentProvider provider, TooltipPosition p public void addBlockData(IDataProvider provider, Class clazz, int priority) { assertLock(); assertPriority(priority); + warnTargetClass(provider, clazz); blockData.add(clazz, (IDataProvider) provider, priority); } @@ -214,6 +217,7 @@ public void addOverride(IEntityComponentProvider provider, Class clazz, i if (Waila.CLIENT_SIDE) { assertLock(); assertPriority(priority); + warnTargetClass(provider, clazz); entityOverride.add(clazz, provider, priority); } } @@ -223,6 +227,7 @@ public void addIcon(IEntityComponentProvider provider, Class clazz, int p if (Waila.CLIENT_SIDE) { assertLock(); assertPriority(priority); + warnTargetClass(provider, clazz); entityIcon.add(clazz, provider, priority); } } @@ -232,6 +237,7 @@ public void addComponent(IEntityComponentProvider provider, TooltipPosition if (Waila.CLIENT_SIDE) { assertLock(); assertPriority(priority); + warnTargetClass(provider, clazz); entityComponent.get(position).add(clazz, provider, priority); } } @@ -241,6 +247,7 @@ public void addComponent(IEntityComponentProvider provider, TooltipPosition public void addEntityData(IDataProvider provider, Class clazz, int priority) { assertLock(); assertPriority(priority); + warnTargetClass(provider, clazz); entityData.add(clazz, (IDataProvider) provider, priority); } @@ -314,4 +321,10 @@ private void assertPriority(int priority) { "Priority must be equals or more than 0"); } + private void warnTargetClass(Object object, Class clazz) { + if (Waila.DEV && clazz.isInstance(object)) { + LOG.warn("The target class {} is the same as the provider class, this is probably an error", clazz.getSimpleName()); + } + } + }