More fixes

This commit is contained in:
Alexander Söderberg
2020-07-17 16:38:07 +02:00
committed by Alexander Söderberg
parent 5a3eacde0b
commit 020b030667
16 changed files with 65 additions and 47 deletions

View File

@ -227,7 +227,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
// Stuff that needs to be created before the PlotSquared instance
PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer);
TaskManager.setImplementation(new BukkitTaskManager(this, timeConverter));
TaskManager.setPlatformImplementation(new BukkitTaskManager(this, timeConverter));
final PlotSquared plotSquared = new PlotSquared(this, "Bukkit");
@ -510,7 +510,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
this.startMetrics();
if (Settings.Enabled_Components.WORLDS) {
TaskManager.getImplementation().taskRepeat(this::unload, TaskTime.seconds(1L));
TaskManager.getPlatformImplementation().taskRepeat(this::unload, TaskTime.seconds(1L));
try {
singleWorldListener = getInjector().getInstance(SingleWorldListener.class);
} catch (Exception e) {

View File

@ -422,7 +422,7 @@ import java.util.stream.Stream;
Block block = getWorld(location.getWorldName())
.getBlockAt(location.getX(), location.getY(), location.getZ());
try {
return TaskManager.getImplementation().sync(() -> {
return TaskManager.getPlatformImplementation().sync(() -> {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
return sign.getLines();

View File

@ -28,6 +28,7 @@ package com.plotsquared.bukkit.util.task;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.plotsquared.bukkit.BukkitPlatform;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.util.task.PlotSquaredTask;
import com.plotsquared.core.util.task.TaskManager;
import com.plotsquared.core.util.task.TaskTime;
@ -37,6 +38,7 @@ import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
/**
* Bukkit implementation of {@link TaskManager} using
@ -79,6 +81,13 @@ import java.util.concurrent.Future;
}
}
@Override public <T> T sync(@Nonnull final Callable<T> function, final int timeout) throws Exception {
if (PlotSquared.get().isMainThread(Thread.currentThread())) {
return function.call();
}
return this.callMethodSync(function).get(timeout, TimeUnit.MILLISECONDS);
}
@Override public <T> Future<T> callMethodSync(@NotNull final Callable<T> method) {
return Bukkit.getScheduler().callSyncMethod(this.bukkitMain, method);
}