From 0fa30a5f62f70b4c5c8f7bf63a3e3a9475c64cca Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 27 Apr 2022 13:04:24 +0100 Subject: [PATCH] Finally removed Display#callDisplayModule --- .../com/willfp/eco/core/display/Display.java | 33 ------------------- .../eco/internal/display/EcoDisplayHandler.kt | 15 +++++++-- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/eco-api/src/main/java/com/willfp/eco/core/display/Display.java b/eco-api/src/main/java/com/willfp/eco/core/display/Display.java index 98c575ab..b767054f 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/display/Display.java +++ b/eco-api/src/main/java/com/willfp/eco/core/display/Display.java @@ -126,39 +126,6 @@ public final class Display { Display.handler = handler; } - /** - * Extremely janky method - also internal, so don't use it. This method is - * NOT part of the API and may be removed at any time! - *

- * This calls a display module with the specified parameters, now - * you might ask why I need a static java method when the DisplayHandler - * implementation could just call it itself? Well, kotlin doesn't really - * like dealing with vararg ambiguity, and so while kotlin can't figure out - * what is and isn't a vararg when I call display with a player, java can. - *

- * Because of this, I need to have this part of the code in java. - * - * Don't call this method as part of your plugins! - *

- * No, seriously - don't. This skips a bunch of checks and you'll almost - * definitely break something. - * - * @param module The display module. - * @param itemStack The ItemStack. - * @param player The player. - * @param args The args. - */ - @ApiStatus.Internal - public static void callDisplayModule(@NotNull final DisplayModule module, - @NotNull final ItemStack itemStack, - @Nullable final Player player, - @NotNull final Object... args) { - module.display(itemStack, args); - if (player != null) { - module.display(itemStack, player, args); - } - } - /** * Set the display handler. *

diff --git a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/display/EcoDisplayHandler.kt b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/display/EcoDisplayHandler.kt index 76bf546a..94dddfa1 100644 --- a/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/display/EcoDisplayHandler.kt +++ b/eco-core/core-backend/src/main/kotlin/com/willfp/eco/internal/display/EcoDisplayHandler.kt @@ -43,7 +43,12 @@ class EcoDisplayHandler(plugin: EcoPlugin) : DisplayHandler { for ((_, modules) in registeredModules) { for (module in modules) { val varargs = pluginVarArgs[module.pluginName] ?: continue - Display.callDisplayModule(module, itemStack, player, *varargs) + + module.invokeWithoutPlayer(itemStack, *varargs) + + if (player != null) { + module.invokeWithPlayer(itemStack, player, *varargs) + } } } @@ -94,4 +99,10 @@ class EcoDisplayHandler(plugin: EcoPlugin) : DisplayHandler { override fun isFinalized(itemStack: ItemStack): Boolean { return itemStack.fast().persistentDataContainer.has(finalizeKey, PersistentDataType.INTEGER) } -} \ No newline at end of file +} + +private fun DisplayModule.invokeWithPlayer(itemStack: ItemStack, player: Player?, vararg varargs: Any) = + this.display(itemStack, player, varargs) + +private fun DisplayModule.invokeWithoutPlayer(itemStack: ItemStack, vararg varargs: Any) = + this.display(itemStack, varargs)