Fix fabric command issues:
- 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
This commit is contained in:
parent
ed17ebd402
commit
1bffefe931
|
@ -41,7 +41,7 @@ public abstract class ServerCommandSourceMixin implements CMDSender {
|
|||
|
||||
@Override
|
||||
public boolean supportsChatEvents() {
|
||||
return true;
|
||||
return isPlayer();
|
||||
}
|
||||
|
||||
@Shadow
|
||||
|
@ -68,7 +68,7 @@ public abstract class ServerCommandSourceMixin implements CMDSender {
|
|||
|
||||
@Override
|
||||
public Optional<UUID> getUUID() {
|
||||
return Optional.ofNullable(isConsole() ? null : getEntity().getUuid());
|
||||
return getPlayer().map(Entity::getUuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -91,4 +91,17 @@ public abstract class ServerCommandSourceMixin implements CMDSender {
|
|||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.concurrent.ScheduledExecutorService;
|
|||
|
||||
public class FabricRunnableFactory implements RunnableFactory {
|
||||
|
||||
private final ScheduledExecutorService executorService;
|
||||
private ScheduledExecutorService executorService;
|
||||
private final Set<FabricTask> tasks;
|
||||
|
||||
public FabricRunnableFactory() {
|
||||
|
@ -34,13 +34,21 @@ public class FabricRunnableFactory implements RunnableFactory {
|
|||
|
||||
@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
|
||||
|
|
Loading…
Reference in New Issue