Skip to content

Commit

Permalink
hacky fix for plugins using paper loader
Browse files Browse the repository at this point in the history
  • Loading branch information
broccolai committed Oct 31, 2023
1 parent 9ab5417 commit 16b1ed2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<UUID, Long> spamPrevention;
Expand All @@ -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;
}
Expand All @@ -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,
Expand All @@ -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;
}

Expand Down Expand Up @@ -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());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,6 +34,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,6 +36,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 16b1ed2

Please sign in to comment.