diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java
index a08aa72a1..e1edfaba2 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java
@@ -43,11 +43,13 @@ import com.plotsquared.bukkit.listener.WorldEvents;
import com.plotsquared.bukkit.placeholder.PlaceholderFormatter;
import com.plotsquared.bukkit.placeholder.Placeholders;
import com.plotsquared.bukkit.player.BukkitPlayerManager;
-import com.plotsquared.bukkit.util.BukkitTaskManager;
+import com.plotsquared.bukkit.util.task.BukkitTaskManager;
import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.bukkit.util.BukkitWorld;
import com.plotsquared.bukkit.util.SetGenCB;
import com.plotsquared.bukkit.util.UpdateUtility;
+import com.plotsquared.bukkit.util.task.PaperTimeConverter;
+import com.plotsquared.bukkit.util.task.SpigotTimeConverter;
import com.plotsquared.bukkit.uuid.BungeePermsUUIDService;
import com.plotsquared.bukkit.uuid.EssentialsUUIDService;
import com.plotsquared.bukkit.uuid.LuckPermsUUIDService;
@@ -102,6 +104,7 @@ import com.plotsquared.core.util.ReflectionUtils;
import com.plotsquared.core.util.SetupUtils;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.task.TaskManager;
+import com.plotsquared.core.util.task.TaskTime;
import com.plotsquared.core.uuid.CacheUUIDService;
import com.plotsquared.core.uuid.UUIDPipeline;
import com.plotsquared.core.uuid.offline.OfflineModeUUIDService;
@@ -212,9 +215,16 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
@Override public void onEnable() {
this.pluginName = getDescription().getName();
+ final TaskTime.TimeConverter timeConverter;
+ if (PaperLib.isPaper()) {
+ timeConverter = new PaperTimeConverter();
+ } else {
+ timeConverter = new SpigotTimeConverter();
+ }
+
// Stuff that needs to be created before the PlotSquared instance
PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer);
- TaskManager.setImplementation(new BukkitTaskManager(this));
+ TaskManager.setPlatformImplementation(new BukkitTaskManager(this, timeConverter));
final PlotSquared plotSquared = new PlotSquared(this, "Bukkit");
@@ -364,7 +374,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
this.setGenerator(world);
}
}
- }, 1);
+ }, TaskTime.ticks(1L));
}
// Services are accessed in order
@@ -494,7 +504,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
this.startMetrics();
if (Settings.Enabled_Components.WORLDS) {
- TaskManager.getImplementation().taskRepeat(this::unload, 20);
+ TaskManager.getPlatformImplementation().taskRepeat(this::unload, TaskTime.seconds(1L));
try {
singleWorldListener = getInjector().getInstance(SingleWorldListener.class);
} catch (Exception e) {
@@ -954,7 +964,7 @@ import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
} catch (Throwable e) {
e.printStackTrace();
}
- }), 20);
+ }), TaskTime.seconds(1L));
}
@Override @Nullable
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java
index 9c817c8af..c9231110b 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/inject/BukkitModule.java
@@ -26,6 +26,8 @@
package com.plotsquared.bukkit.inject;
import com.google.inject.AbstractModule;
+import com.google.inject.Provides;
+import com.google.inject.Singleton;
import com.google.inject.assistedinject.FactoryModuleBuilder;
import com.google.inject.util.Providers;
import com.plotsquared.bukkit.BukkitPlatform;
@@ -39,6 +41,8 @@ import com.plotsquared.bukkit.util.BukkitPermHandler;
import com.plotsquared.bukkit.util.BukkitRegionManager;
import com.plotsquared.bukkit.util.BukkitSetupUtils;
import com.plotsquared.bukkit.util.BukkitUtil;
+import com.plotsquared.bukkit.util.task.PaperTimeConverter;
+import com.plotsquared.bukkit.util.task.SpigotTimeConverter;
import com.plotsquared.core.PlotPlatform;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.generator.HybridGen;
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java
index a4b0e3430..bf756fcf0 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/ChunkListener.java
@@ -33,7 +33,9 @@ import com.plotsquared.core.plot.world.PlotAreaManager;
import com.plotsquared.core.util.ReflectionUtils.RefClass;
import com.plotsquared.core.util.ReflectionUtils.RefField;
import com.plotsquared.core.util.ReflectionUtils.RefMethod;
+import com.plotsquared.core.util.task.PlotSquaredTask;
import com.plotsquared.core.util.task.TaskManager;
+import com.plotsquared.core.util.task.TaskTime;
import io.papermc.lib.PaperLib;
import org.bukkit.Bukkit;
import org.bukkit.Chunk;
@@ -58,6 +60,7 @@ import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import java.lang.reflect.Method;
import java.util.HashSet;
+import java.util.Objects;
import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
@@ -131,7 +134,7 @@ public class ChunkListener implements Listener {
} catch (Throwable e) {
e.printStackTrace();
}
- }, 1);
+ }, TaskTime.ticks(1L));
}
public boolean unloadChunk(String world, Chunk chunk, boolean safe) {
@@ -253,17 +256,15 @@ public class ChunkListener implements Listener {
private void cleanChunk(final Chunk chunk) {
TaskManager.index.incrementAndGet();
final Integer currentIndex = TaskManager.index.get();
- Integer task = TaskManager.runTaskRepeat(() -> {
+ PlotSquaredTask task = TaskManager.runTaskRepeat(() -> {
if (!chunk.isLoaded()) {
- Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
- TaskManager.tasks.remove(currentIndex);
+ Objects.requireNonNull(TaskManager.removeTask(currentIndex)).cancel();
chunk.unload(true);
return;
}
BlockState[] tiles = chunk.getTileEntities();
if (tiles.length == 0) {
- Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
- TaskManager.tasks.remove(currentIndex);
+ Objects.requireNonNull(TaskManager.removeTask(currentIndex)).cancel();
chunk.unload(true);
return;
}
@@ -271,16 +272,15 @@ public class ChunkListener implements Listener {
int i = 0;
while (System.currentTimeMillis() - start < 250) {
if (i >= tiles.length - Settings.Chunk_Processor.MAX_TILES) {
- Bukkit.getScheduler().cancelTask(TaskManager.tasks.get(currentIndex));
- TaskManager.tasks.remove(currentIndex);
+ Objects.requireNonNull(TaskManager.removeTask(currentIndex)).cancel();
chunk.unload(true);
return;
}
tiles[i].getBlock().setType(Material.AIR, false);
i++;
}
- }, 5);
- TaskManager.tasks.put(currentIndex, task);
+ }, TaskTime.ticks(5L));
+ TaskManager.addTask(task, currentIndex);
}
public boolean processChunk(Chunk chunk, boolean unload) {
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
index 71d5b9b7c..a3bc9eb5c 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java
@@ -111,6 +111,7 @@ import com.plotsquared.core.util.RegExUtil;
import com.plotsquared.core.util.WorldUtil;
import com.plotsquared.core.util.entity.EntityCategories;
import com.plotsquared.core.util.task.TaskManager;
+import com.plotsquared.core.util.task.TaskTime;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.world.block.BlockType;
@@ -281,7 +282,7 @@ import java.util.regex.Pattern;
((BukkitPlayer) player).player.sendBlockChange(bloc, data);
}
}
- }, 3);
+ }, TaskTime.ticks(3L));
}
public static boolean checkEntity(Entity entity, Plot plot) {
@@ -701,7 +702,7 @@ import java.util.regex.Pattern;
player.saveData();
}
this.eventDispatcher.doJoinTask(pp);
- }, 20);
+ }, TaskTime.seconds(1L));
if (pp.hasPermission(Captions.PERMISSION_ADMIN_UPDATE_NOTIFICATION.getTranslated())
&& Settings.Enabled_Components.UPDATE_NOTIFICATIONS && PremiumVerification.isPremium()
@@ -841,7 +842,7 @@ import java.util.regex.Pattern;
Player player = event.getPlayer();
BukkitPlayer pp = BukkitUtil.getPlayer(player);
// Cancel teleport
- if (TaskManager.TELEPORT_QUEUE.remove(pp.getName())) {
+ if (TaskManager.removeFromTeleportQueue(pp.getName())) {
MainUtil.sendMessage(pp, Captions.TELEPORT_FAILED);
}
// Set last location
@@ -903,7 +904,7 @@ import java.util.regex.Pattern;
Player player = event.getPlayer();
BukkitPlayer pp = BukkitUtil.getPlayer(player);
// Cancel teleport
- if (TaskManager.TELEPORT_QUEUE.remove(pp.getName())) {
+ if (TaskManager.removeFromTeleportQueue(pp.getName())) {
MainUtil.sendMessage(pp, Captions.TELEPORT_FAILED);
}
// Set last location
@@ -2416,7 +2417,7 @@ import java.util.regex.Pattern;
}
@EventHandler(priority = EventPriority.MONITOR) public void onLeave(PlayerQuitEvent event) {
- TaskManager.TELEPORT_QUEUE.remove(event.getPlayer().getName());
+ TaskManager.removeFromTeleportQueue(event.getPlayer().getName());
BukkitPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
pp.unregister();
this.logout(pp.getUUID());
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java
index 55dc45512..f9b0eb563 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitRegionManager.java
@@ -44,6 +44,7 @@ import com.plotsquared.core.util.RegionUtil;
import com.plotsquared.core.util.entity.EntityCategories;
import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
+import com.plotsquared.core.util.task.TaskTime;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.math.BlockVector2;
@@ -399,9 +400,9 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
});
}
if (!chunks.isEmpty()) {
- TaskManager.runTaskLater(this, 1);
+ TaskManager.runTaskLater(this, TaskTime.ticks(1L));
} else {
- TaskManager.runTaskLater(whenDone, 1);
+ TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L));
}
}
});
@@ -456,7 +457,7 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(() -> {
for (ContentMap map : maps) {
map.restoreEntities(world1, 0, 0);
- TaskManager.runTaskLater(whenDone, 1);
+ TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L));
}
});
}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java
deleted file mode 100644
index c5928c261..000000000
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitTaskManager.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * _____ _ _ _____ _
- * | __ \| | | | / ____| | |
- * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
- * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
- * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
- * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
- * | |
- * |_|
- * PlotSquared plot management system for Minecraft
- * Copyright (C) 2020 IntellectualSites
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-package com.plotsquared.bukkit.util;
-
-import com.google.inject.Inject;
-import com.google.inject.Singleton;
-import com.plotsquared.bukkit.BukkitPlatform;
-import com.plotsquared.core.util.task.TaskManager;
-import org.bukkit.Bukkit;
-
-@Singleton public class BukkitTaskManager extends TaskManager {
-
- private final BukkitPlatform bukkitMain;
-
- @Inject public BukkitTaskManager(BukkitPlatform bukkitMain) {
- this.bukkitMain = bukkitMain;
- }
-
- @Override public int taskRepeat(Runnable runnable, int interval) {
- return this.bukkitMain.getServer().getScheduler()
- .scheduleSyncRepeatingTask(this.bukkitMain, runnable, interval, interval);
- }
-
- @SuppressWarnings("deprecation") @Override
- public int taskRepeatAsync(Runnable runnable, int interval) {
- return this.bukkitMain.getServer().getScheduler()
- .scheduleAsyncRepeatingTask(this.bukkitMain, runnable, interval, interval);
- }
-
- @Override public void taskAsync(Runnable runnable) {
- if (this.bukkitMain.isEnabled()) {
- this.bukkitMain.getServer().getScheduler()
- .runTaskAsynchronously(this.bukkitMain, runnable);
- } else {
- runnable.run();
- }
- }
-
- @Override public void task(Runnable runnable) {
- this.bukkitMain.getServer().getScheduler().runTask(this.bukkitMain, runnable).getTaskId();
- }
-
- @Override public void taskLater(Runnable runnable, int delay) {
- this.bukkitMain.getServer().getScheduler().runTaskLater(this.bukkitMain, runnable, delay)
- .getTaskId();
- }
-
- @Override public void taskLaterAsync(Runnable runnable, int delay) {
- this.bukkitMain.getServer().getScheduler()
- .runTaskLaterAsynchronously(this.bukkitMain, runnable, delay);
- }
-
- @Override public void cancelTask(int task) {
- if (task != -1) {
- Bukkit.getScheduler().cancelTask(task);
- }
- }
-}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java
index c6e3111ca..b17633605 100644
--- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java
@@ -42,7 +42,6 @@ import com.plotsquared.core.util.PlayerManager;
import com.plotsquared.core.util.RegionManager;
import com.plotsquared.core.util.StringComparison;
import com.plotsquared.core.util.WorldUtil;
-import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitWorld;
@@ -409,14 +408,18 @@ import java.util.stream.Stream;
@Override @Nullable public String[] getSignSynchronous(@Nonnull final Location location) {
Block block = getWorld(location.getWorldName())
.getBlockAt(location.getX(), location.getY(), location.getZ());
- return TaskManager.getImplementation().sync(new RunnableVal() {
- @Override public void run(String[] value) {
+ try {
+ return TaskManager.getPlatformImplementation().sync(() -> {
if (block.getState() instanceof Sign) {
Sign sign = (Sign) block.getState();
- this.value = sign.getLines();
+ return sign.getLines();
}
- }
- });
+ return new String[0];
+ });
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
+ return new String[0];
}
@Override public Location getSpawn(@Nonnull final String world) {
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/BukkitPlotSquaredTask.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/BukkitPlotSquaredTask.java
new file mode 100644
index 000000000..d6b2cc7bf
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/BukkitPlotSquaredTask.java
@@ -0,0 +1,46 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * PlotSquared plot management system for Minecraft
+ * Copyright (C) 2020 IntellectualSites
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.plotsquared.bukkit.util.task;
+
+import com.plotsquared.core.util.task.PlotSquaredTask;
+import lombok.RequiredArgsConstructor;
+import org.bukkit.scheduler.BukkitRunnable;
+
+import javax.annotation.Nonnull;
+
+/**
+ * Bukkit implementation of {@link PlotSquaredTask}
+ */
+@RequiredArgsConstructor
+public final class BukkitPlotSquaredTask extends BukkitRunnable implements PlotSquaredTask {
+
+ @Nonnull private final Runnable runnable;
+
+ @Override public void runTask() {
+ this.runnable.run();
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/BukkitTaskManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/BukkitTaskManager.java
new file mode 100644
index 000000000..643c4d8f3
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/BukkitTaskManager.java
@@ -0,0 +1,111 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * PlotSquared plot management system for Minecraft
+ * Copyright (C) 2020 IntellectualSites
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+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;
+import org.bukkit.Bukkit;
+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
+ * by {@link org.bukkit.scheduler.BukkitScheduler} and {@link BukkitPlotSquaredTask}
+ */
+@Singleton public class BukkitTaskManager extends TaskManager {
+
+ private final BukkitPlatform bukkitMain;
+ private final TaskTime.TimeConverter timeConverter;
+
+ @Inject public BukkitTaskManager(@Nonnull final BukkitPlatform bukkitMain,
+ @Nonnull final TaskTime.TimeConverter timeConverter) {
+ this.bukkitMain = bukkitMain;
+ this.timeConverter = timeConverter;
+ }
+
+ @Override
+ public PlotSquaredTask taskRepeat(@Nonnull final Runnable runnable,
+ @Nonnull final TaskTime taskTime) {
+ final long ticks = this.timeConverter.toTicks(taskTime);
+ final BukkitPlotSquaredTask bukkitPlotSquaredTask = new BukkitPlotSquaredTask(runnable);
+ bukkitPlotSquaredTask.runTaskTimer(this.bukkitMain, ticks, ticks);
+ return bukkitPlotSquaredTask;
+ }
+
+ @Override
+ public PlotSquaredTask taskRepeatAsync(@Nonnull final Runnable runnable,
+ @Nonnull final TaskTime taskTime) {
+ final long ticks = this.timeConverter.toTicks(taskTime);
+ final BukkitPlotSquaredTask bukkitPlotSquaredTask = new BukkitPlotSquaredTask(runnable);
+ bukkitPlotSquaredTask.runTaskTimerAsynchronously(this.bukkitMain, ticks, ticks);
+ return bukkitPlotSquaredTask;
+ }
+
+ @Override public void taskAsync(@Nonnull final Runnable runnable) {
+ if (this.bukkitMain.isEnabled()) {
+ new BukkitPlotSquaredTask(runnable).runTaskAsynchronously(this.bukkitMain);
+ } else {
+ runnable.run();
+ }
+ }
+
+ @Override public T sync(@Nonnull final Callable 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 Future callMethodSync(@NotNull final Callable method) {
+ return Bukkit.getScheduler().callSyncMethod(this.bukkitMain, method);
+ }
+
+ @Override public void task(@Nonnull final Runnable runnable) {
+ new BukkitPlotSquaredTask(runnable).runTaskAsynchronously(this.bukkitMain);
+ }
+
+ @Override public void taskLater(@Nonnull final Runnable runnable,
+ @Nonnull final TaskTime taskTime) {
+ final long delay = this.timeConverter.toTicks(taskTime);
+ new BukkitPlotSquaredTask(runnable).runTaskLater(this.bukkitMain, delay);
+ }
+
+ @Override public void taskLaterAsync(@Nonnull final Runnable runnable,
+ @Nonnull final TaskTime taskTime) {
+ final long delay = this.timeConverter.toTicks(taskTime);
+ new BukkitPlotSquaredTask(runnable).runTaskLaterAsynchronously(this.bukkitMain, delay);
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/PaperTimeConverter.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/PaperTimeConverter.java
new file mode 100644
index 000000000..53fd535c2
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/PaperTimeConverter.java
@@ -0,0 +1,47 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * PlotSquared plot management system for Minecraft
+ * Copyright (C) 2020 IntellectualSites
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.plotsquared.bukkit.util.task;
+
+import com.plotsquared.core.util.task.TaskTime;
+import org.bukkit.Bukkit;
+
+import javax.annotation.Nonnegative;
+
+/**
+ * Time converter that uses the server MSPT count to convert between
+ * different time units
+ */
+public final class PaperTimeConverter implements TaskTime.TimeConverter {
+
+ @Override public long msToTicks(@Nonnegative final long ms) {
+ return Math.max(1L, (long) (ms / Bukkit.getAverageTickTime()));
+ }
+
+ @Override public long ticksToMs(@Nonnegative final long ticks) {
+ return Math.max(1L, (long) (ticks * Bukkit.getAverageTickTime()));
+ }
+
+}
diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/SpigotTimeConverter.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/SpigotTimeConverter.java
new file mode 100644
index 000000000..1605e7b77
--- /dev/null
+++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/task/SpigotTimeConverter.java
@@ -0,0 +1,47 @@
+/*
+ * _____ _ _ _____ _
+ * | __ \| | | | / ____| | |
+ * | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
+ * | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
+ * | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
+ * |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
+ * | |
+ * |_|
+ * PlotSquared plot management system for Minecraft
+ * Copyright (C) 2020 IntellectualSites
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package com.plotsquared.bukkit.util.task;
+
+import com.plotsquared.core.util.task.TaskTime;
+
+import javax.annotation.Nonnegative;
+
+/**
+ * Naive time converter that assumes that all ticks are 50 milliseconds
+ */
+public final class SpigotTimeConverter implements TaskTime.TimeConverter {
+
+ private static final long MS_PER_TICKS = 50L;
+
+ @Override public long msToTicks(@Nonnegative final long ms) {
+ return Math.max(1L, ms / MS_PER_TICKS);
+ }
+
+ @Override public long ticksToMs(@Nonnegative final long ticks) {
+ return Math.max(1L, ticks * MS_PER_TICKS);
+ }
+
+}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Auto.java b/Core/src/main/java/com/plotsquared/core/command/Auto.java
index e1c32e28b..398beccf8 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Auto.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Auto.java
@@ -150,13 +150,17 @@ public class Auto extends SubCommand {
* @param start
* @param schematic
*/
- public static void autoClaimSafe(final PlotPlayer player, final PlotArea area, PlotId start,
+ public static void autoClaimSafe(final PlotPlayer> player, final PlotArea area, PlotId start,
final String schematic) {
player.setMeta(Auto.class.getName(), true);
autoClaimFromDatabase(player, area, start, new RunnableVal() {
@Override public void run(final Plot plot) {
- TaskManager.getImplementation().sync(new AutoClaimFinishTask(player, plot, area, schematic,
- PlotSquared.get().getEventDispatcher()));
+ try {
+ TaskManager.getPlatformImplementation().sync(new AutoClaimFinishTask(player, plot, area, schematic,
+ PlotSquared.get().getEventDispatcher()));
+ } catch (final Exception e) {
+ e.printStackTrace();
+ }
}
});
}
diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java
index e49afd85c..c4b19d018 100644
--- a/Core/src/main/java/com/plotsquared/core/command/Claim.java
+++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java
@@ -43,30 +43,26 @@ import com.plotsquared.core.util.EconHandler;
import com.plotsquared.core.util.EventDispatcher;
import com.plotsquared.core.util.Expression;
import com.plotsquared.core.util.Permissions;
-import com.plotsquared.core.util.task.RunnableVal;
import com.plotsquared.core.util.task.TaskManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
-@CommandDeclaration(command = "claim",
- aliases = "c",
- description = "Claim the current plot you're standing on",
- category = CommandCategory.CLAIMING,
- requiredType = RequiredType.PLAYER,
- permission = "plots.claim",
- usage = "/plot claim")
+@CommandDeclaration(command = "claim", aliases = "c", description = "Claim the current plot you're standing on", category = CommandCategory.CLAIMING, requiredType = RequiredType.PLAYER, permission = "plots.claim", usage = "/plot claim")
public class Claim extends SubCommand {
- private static final Logger logger = LoggerFactory.getLogger("P2/" + Claim.class.getSimpleName());
+ private static final Logger logger =
+ LoggerFactory.getLogger("P2/" + Claim.class.getSimpleName());
private final EventDispatcher eventDispatcher;
private final EconHandler econHandler;
@Inject public Claim(@Nonnull final EventDispatcher eventDispatcher,
- @Nullable final EconHandler econHandler) {
+ @Nullable final EconHandler econHandler) {
this.eventDispatcher = eventDispatcher;
this.econHandler = econHandler;
}
@@ -146,24 +142,29 @@ public class Claim extends SubCommand {
}
plot.setOwnerAbs(player.getUUID());
final String finalSchematic = schematic;
- DBFunc.createPlotSafe(plot, () -> TaskManager.getImplementation().sync(new RunnableVal