Skip to content

Commit

Permalink
Fix fabric command issues:
Browse files Browse the repository at this point in the history
- Made only players support chat events
- Added hashcode and equals needed for storing in cache (Confirmation uses CMDSender as key)
- Hacky fix for running tasks when plugin is disabled

Affects issues:
- Fixed #2183
  • Loading branch information
AuroraLS3 committed Jan 9, 2022
1 parent ed17ebd commit 1bffefe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public boolean isPlayer() {

@Override
public boolean supportsChatEvents() {
return true;
return isPlayer();
}

@Shadow
Expand All @@ -68,7 +68,7 @@ public boolean hasPermission(String permission) {

@Override
public Optional<UUID> getUUID() {
return Optional.ofNullable(isConsole() ? null : getEntity().getUuid());
return getPlayer().map(Entity::getUuid);
}

@Override
Expand All @@ -91,4 +91,17 @@ private Optional<ServerPlayerEntity> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public class FabricRunnableFactory implements RunnableFactory {

private final ScheduledExecutorService executorService;
private ScheduledExecutorService executorService;
private final Set<FabricTask> tasks;

public FabricRunnableFactory() {
Expand All @@ -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
Expand Down

0 comments on commit 1bffefe

Please sign in to comment.