diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ServerCommandSourceMixin.java b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ServerCommandSourceMixin.java index c4fe902308..8084777481 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ServerCommandSourceMixin.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plan/gathering/listeners/events/mixin/ServerCommandSourceMixin.java @@ -41,7 +41,7 @@ public boolean isPlayer() { @Override public boolean supportsChatEvents() { - return true; + return isPlayer(); } @Shadow @@ -68,7 +68,7 @@ public boolean hasPermission(String permission) { @Override public Optional getUUID() { - return Optional.ofNullable(isConsole() ? null : getEntity().getUuid()); + return getPlayer().map(Entity::getUuid); } @Override @@ -91,4 +91,17 @@ private Optional getPlayer() { } return Optional.empty(); } + + @Override + public int hashCode() { + return Boolean.hashCode(isConsole()) + getUUID().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (!(obj instanceof ServerCommandSourceMixin other)) return false; + + return isConsole() == other.isConsole() + && getUUID().equals(other.getUUID()); + } } diff --git a/Plan/fabric/src/main/java/net/playeranalytics/plugin/scheduling/FabricRunnableFactory.java b/Plan/fabric/src/main/java/net/playeranalytics/plugin/scheduling/FabricRunnableFactory.java index 04f5238ee4..4cbe9d45e1 100644 --- a/Plan/fabric/src/main/java/net/playeranalytics/plugin/scheduling/FabricRunnableFactory.java +++ b/Plan/fabric/src/main/java/net/playeranalytics/plugin/scheduling/FabricRunnableFactory.java @@ -24,7 +24,7 @@ public class FabricRunnableFactory implements RunnableFactory { - private final ScheduledExecutorService executorService; + private ScheduledExecutorService executorService; private final Set tasks; public FabricRunnableFactory() { @@ -34,13 +34,21 @@ public FabricRunnableFactory() { @Override public UnscheduledTask create(Runnable runnable) { - return new UnscheduledFabricTask(executorService, runnable, task -> { + return new UnscheduledFabricTask(getExecutorService(), runnable, task -> { }); } + private ScheduledExecutorService getExecutorService() { + if (executorService.isShutdown() || executorService.isTerminated()) { + // Hacky way of fixing tasks when plugin is disabled, leaks one thread every reload. + executorService = Executors.newSingleThreadScheduledExecutor(); + } + return executorService; + } + @Override public UnscheduledTask create(PluginRunnable runnable) { - return new UnscheduledFabricTask(executorService, runnable, runnable::setCancellable); + return new UnscheduledFabricTask(getExecutorService(), runnable, runnable::setCancellable); } @Override