From 16b1ed227ee84216bb07f7260ff4da3aa55c2de8 Mon Sep 17 00:00:00 2001 From: broccolai Date: Tue, 31 Oct 2023 12:34:29 +0000 Subject: [PATCH] hacky fix for plugins using paper loader --- .../paper/PaperInterfaceListeners.java | 22 ++++++++++++++----- .../interfaces/paper/view/ChestView.java | 7 +++++- .../interfaces/paper/view/CombinedView.java | 7 +++++- .../paper/view/PlayerInventoryView.java | 8 ++++++- 4 files changed, 35 insertions(+), 9 deletions(-) diff --git a/paper/src/main/java/org/incendo/interfaces/paper/PaperInterfaceListeners.java b/paper/src/main/java/org/incendo/interfaces/paper/PaperInterfaceListeners.java index e949c928..4300b777 100644 --- a/paper/src/main/java/org/incendo/interfaces/paper/PaperInterfaceListeners.java +++ b/paper/src/main/java/org/incendo/interfaces/paper/PaperInterfaceListeners.java @@ -76,7 +76,17 @@ public class PaperInterfaceListeners implements Listener { "PLAYER", "UNKNOWN", "PLUGIN" ); - private final @NonNull Plugin plugin; + private static Plugin targetPlugin; + + /** + * Reference to plugin using Interfaces + * + * @return plugin reference + */ + public static Plugin plugin() { + return targetPlugin; + } + private final @NonNull Map<@NonNull SelfUpdatingInterfaceView, @NonNull Integer> updatingRunnables; private final @Nullable Cache spamPrevention; @@ -87,7 +97,7 @@ public class PaperInterfaceListeners implements Listener { * @param plugin the plugin instance to register against */ public PaperInterfaceListeners(final @NonNull Plugin plugin) { - this.plugin = plugin; + targetPlugin = plugin; this.updatingRunnables = new ConcurrentHashMap<>(); this.spamPrevention = null; } @@ -99,7 +109,7 @@ public PaperInterfaceListeners(final @NonNull Plugin plugin) { * @param clickThrottle the minimum amount of ticks between every accepted click */ public PaperInterfaceListeners(final @NonNull Plugin plugin, final long clickThrottle) { - this.plugin = plugin; + targetPlugin = plugin; this.updatingRunnables = new ConcurrentHashMap<>(); this.spamPrevention = CacheBuilder.newBuilder().expireAfterWrite( 50L * clickThrottle, @@ -123,7 +133,7 @@ public static void install(final @NonNull Plugin plugin) { */ @EventHandler public void onDisable(final @NonNull PluginDisableEvent event) { - if (event.getPlugin() != this.plugin) { + if (event.getPlugin() != targetPlugin) { return; } @@ -184,10 +194,10 @@ public void run() { if (view instanceof SelfUpdatingInterfaceView) { SelfUpdatingInterfaceView selfUpdating = (SelfUpdatingInterfaceView) view; - runnable.runTaskTimerAsynchronously(this.plugin, updatingInterface.updateDelay(), updatingInterface.updateDelay()); + runnable.runTaskTimerAsynchronously(targetPlugin, updatingInterface.updateDelay(), updatingInterface.updateDelay()); this.updatingRunnables.put(selfUpdating, runnable.getTaskId()); } else { - runnable.runTaskLaterAsynchronously(this.plugin, updatingInterface.updateDelay()); + runnable.runTaskLaterAsynchronously(targetPlugin, updatingInterface.updateDelay()); } } } diff --git a/paper/src/main/java/org/incendo/interfaces/paper/view/ChestView.java b/paper/src/main/java/org/incendo/interfaces/paper/view/ChestView.java index 19ad43ac..e9f3e7f1 100644 --- a/paper/src/main/java/org/incendo/interfaces/paper/view/ChestView.java +++ b/paper/src/main/java/org/incendo/interfaces/paper/view/ChestView.java @@ -18,6 +18,7 @@ import org.incendo.interfaces.core.util.Vector2; import org.incendo.interfaces.core.view.InterfaceView; import org.incendo.interfaces.core.view.SelfUpdatingInterfaceView; +import org.incendo.interfaces.paper.PaperInterfaceListeners; import org.incendo.interfaces.paper.PlayerViewer; import org.incendo.interfaces.paper.element.ItemStackElement; import org.incendo.interfaces.paper.pane.ChestPane; @@ -33,6 +34,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; /** @@ -104,7 +106,10 @@ public ChestView( this.pane = new ChestPane(this.backing.rows()); } - this.plugin = JavaPlugin.getProvidingPlugin(this.getClass()); + this.plugin = Objects.requireNonNullElseGet( + PaperInterfaceListeners.plugin(), + () -> JavaPlugin.getProvidingPlugin(this.getClass()) + ); if (Bukkit.isPrimaryThread()) { this.inventory = this.createInventory(); diff --git a/paper/src/main/java/org/incendo/interfaces/paper/view/CombinedView.java b/paper/src/main/java/org/incendo/interfaces/paper/view/CombinedView.java index c58a5b7d..953bebdf 100644 --- a/paper/src/main/java/org/incendo/interfaces/paper/view/CombinedView.java +++ b/paper/src/main/java/org/incendo/interfaces/paper/view/CombinedView.java @@ -19,6 +19,7 @@ import org.incendo.interfaces.core.util.Vector2; import org.incendo.interfaces.core.view.InterfaceView; import org.incendo.interfaces.core.view.SelfUpdatingInterfaceView; +import org.incendo.interfaces.paper.PaperInterfaceListeners; import org.incendo.interfaces.paper.PlayerViewer; import org.incendo.interfaces.paper.element.ItemStackElement; import org.incendo.interfaces.paper.pane.ChestPane; @@ -35,6 +36,7 @@ import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; /** @@ -106,7 +108,10 @@ public CombinedView( this.pane = new CombinedPane(this.backing.totalRows()); } - this.plugin = JavaPlugin.getProvidingPlugin(this.getClass()); + this.plugin = Objects.requireNonNullElseGet( + PaperInterfaceListeners.plugin(), + () -> JavaPlugin.getProvidingPlugin(this.getClass()) + ); if (Bukkit.isPrimaryThread()) { this.inventory = this.createInventory(); diff --git a/paper/src/main/java/org/incendo/interfaces/paper/view/PlayerInventoryView.java b/paper/src/main/java/org/incendo/interfaces/paper/view/PlayerInventoryView.java index fcd7b24b..026dd31a 100644 --- a/paper/src/main/java/org/incendo/interfaces/paper/view/PlayerInventoryView.java +++ b/paper/src/main/java/org/incendo/interfaces/paper/view/PlayerInventoryView.java @@ -16,6 +16,7 @@ import org.incendo.interfaces.core.transform.InterruptUpdateException; import org.incendo.interfaces.core.view.InterfaceView; import org.incendo.interfaces.core.view.SelfUpdatingInterfaceView; +import org.incendo.interfaces.paper.PaperInterfaceListeners; import org.incendo.interfaces.paper.PlayerViewer; import org.incendo.interfaces.paper.element.ItemStackElement; import org.incendo.interfaces.paper.pane.PlayerPane; @@ -28,6 +29,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.WeakHashMap; public final class PlayerInventoryView implements @@ -67,7 +69,11 @@ public PlayerInventoryView( oldView.close(); } - this.plugin = JavaPlugin.getProvidingPlugin(this.getClass()); + this.plugin = Objects.requireNonNullElseGet( + PaperInterfaceListeners.plugin(), + () -> JavaPlugin.getProvidingPlugin(this.getClass()) + ); + this.viewer = viewer; this.backing = backing; this.arguments = argument;