mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-25 22:56:45 +01:00
Address comments
This commit is contained in:
parent
020b030667
commit
43d058d3db
@ -64,10 +64,8 @@ import com.plotsquared.core.util.RegionManager;
|
|||||||
import com.plotsquared.core.util.SchematicHandler;
|
import com.plotsquared.core.util.SchematicHandler;
|
||||||
import com.plotsquared.core.util.SetupUtils;
|
import com.plotsquared.core.util.SetupUtils;
|
||||||
import com.plotsquared.core.util.WorldUtil;
|
import com.plotsquared.core.util.WorldUtil;
|
||||||
import com.plotsquared.core.util.task.TaskTime;
|
|
||||||
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
||||||
import com.sk89q.worldedit.extension.platform.Actor;
|
import com.sk89q.worldedit.extension.platform.Actor;
|
||||||
import io.papermc.lib.PaperLib;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
|
@ -60,6 +60,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
import static com.plotsquared.core.util.ReflectionUtils.getRefClass;
|
||||||
|
|
||||||
@ -257,15 +258,13 @@ public class ChunkListener implements Listener {
|
|||||||
final Integer currentIndex = TaskManager.index.get();
|
final Integer currentIndex = TaskManager.index.get();
|
||||||
PlotSquaredTask task = TaskManager.runTaskRepeat(() -> {
|
PlotSquaredTask task = TaskManager.runTaskRepeat(() -> {
|
||||||
if (!chunk.isLoaded()) {
|
if (!chunk.isLoaded()) {
|
||||||
TaskManager.tasks.get(currentIndex).cancel();
|
Objects.requireNonNull(TaskManager.removeTask(currentIndex)).cancel();
|
||||||
TaskManager.tasks.remove(currentIndex);
|
|
||||||
chunk.unload(true);
|
chunk.unload(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BlockState[] tiles = chunk.getTileEntities();
|
BlockState[] tiles = chunk.getTileEntities();
|
||||||
if (tiles.length == 0) {
|
if (tiles.length == 0) {
|
||||||
TaskManager.tasks.get(currentIndex).cancel();
|
Objects.requireNonNull(TaskManager.removeTask(currentIndex)).cancel();
|
||||||
TaskManager.tasks.remove(currentIndex);
|
|
||||||
chunk.unload(true);
|
chunk.unload(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -273,8 +272,7 @@ public class ChunkListener implements Listener {
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
while (System.currentTimeMillis() - start < 250) {
|
while (System.currentTimeMillis() - start < 250) {
|
||||||
if (i >= tiles.length - Settings.Chunk_Processor.MAX_TILES) {
|
if (i >= tiles.length - Settings.Chunk_Processor.MAX_TILES) {
|
||||||
TaskManager.tasks.get(currentIndex).cancel();
|
Objects.requireNonNull(TaskManager.removeTask(currentIndex)).cancel();
|
||||||
TaskManager.tasks.remove(currentIndex);
|
|
||||||
chunk.unload(true);
|
chunk.unload(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -282,7 +280,7 @@ public class ChunkListener implements Listener {
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}, TaskTime.ticks(5L));
|
}, TaskTime.ticks(5L));
|
||||||
TaskManager.tasks.put(currentIndex, task);
|
TaskManager.addTask(task, currentIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean processChunk(Chunk chunk, boolean unload) {
|
public boolean processChunk(Chunk chunk, boolean unload) {
|
||||||
|
@ -842,7 +842,7 @@ import java.util.regex.Pattern;
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
// Cancel teleport
|
// Cancel teleport
|
||||||
if (TaskManager.TELEPORT_QUEUE.remove(pp.getName())) {
|
if (TaskManager.removeFromTeleportQueue(pp.getName())) {
|
||||||
MainUtil.sendMessage(pp, Captions.TELEPORT_FAILED);
|
MainUtil.sendMessage(pp, Captions.TELEPORT_FAILED);
|
||||||
}
|
}
|
||||||
// Set last location
|
// Set last location
|
||||||
@ -904,7 +904,7 @@ import java.util.regex.Pattern;
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
BukkitPlayer pp = BukkitUtil.getPlayer(player);
|
||||||
// Cancel teleport
|
// Cancel teleport
|
||||||
if (TaskManager.TELEPORT_QUEUE.remove(pp.getName())) {
|
if (TaskManager.removeFromTeleportQueue(pp.getName())) {
|
||||||
MainUtil.sendMessage(pp, Captions.TELEPORT_FAILED);
|
MainUtil.sendMessage(pp, Captions.TELEPORT_FAILED);
|
||||||
}
|
}
|
||||||
// Set last location
|
// Set last location
|
||||||
@ -2417,7 +2417,7 @@ import java.util.regex.Pattern;
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.MONITOR) public void onLeave(PlayerQuitEvent event) {
|
@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());
|
BukkitPlayer pp = BukkitUtil.getPlayer(event.getPlayer());
|
||||||
pp.unregister();
|
pp.unregister();
|
||||||
this.logout(pp.getUUID());
|
this.logout(pp.getUUID());
|
||||||
|
@ -121,7 +121,7 @@ public class Trim extends SubCommand {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).thenAccept(ignore ->
|
}).thenAccept(ignore ->
|
||||||
TaskManager.getPlatformImplementation().taskLater(result, TaskTime.ticks(1)));
|
TaskManager.getPlatformImplementation().taskLater(result, TaskTime.ticks(1L)));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -196,7 +196,7 @@ public class Trim extends SubCommand {
|
|||||||
queue.regenChunk(value.getX(), value.getZ());
|
queue.regenChunk(value.getX(), value.getZ());
|
||||||
}
|
}
|
||||||
}).thenAccept(ignore -> TaskManager.getPlatformImplementation()
|
}).thenAccept(ignore -> TaskManager.getPlatformImplementation()
|
||||||
.taskLater(this, TaskTime.ticks(1)));
|
.taskLater(this, TaskTime.ticks(1L)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
|
@ -2996,9 +2996,9 @@ public class Plot {
|
|||||||
MainUtil
|
MainUtil
|
||||||
.sendMessage(player, Captions.TELEPORT_IN_SECONDS, Settings.Teleport.DELAY + "");
|
.sendMessage(player, Captions.TELEPORT_IN_SECONDS, Settings.Teleport.DELAY + "");
|
||||||
final String name = player.getName();
|
final String name = player.getName();
|
||||||
TaskManager.TELEPORT_QUEUE.add(name);
|
TaskManager.addToTeleportQueue(name);
|
||||||
TaskManager.runTaskLater(() -> {
|
TaskManager.runTaskLater(() -> {
|
||||||
if (!TaskManager.TELEPORT_QUEUE.remove(name)) {
|
if (!TaskManager.removeFromTeleportQueue(name)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (player.isOnline()) {
|
if (player.isOnline()) {
|
||||||
|
@ -377,7 +377,7 @@ public class ExpireManager {
|
|||||||
ExpireManager.this.running = 2;
|
ExpireManager.this.running = 2;
|
||||||
runTask(expiredTask);
|
runTask(expiredTask);
|
||||||
}
|
}
|
||||||
}, TaskTime.ticks(86400000));
|
}, TaskTime.ticks(86400000L));
|
||||||
} else {
|
} else {
|
||||||
TaskManager.runTaskLaterAsync(task, TaskTime.seconds(10L));
|
TaskManager.runTaskLaterAsync(task, TaskTime.seconds(10L));
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ public abstract class RegionManager {
|
|||||||
.thenRun(() -> task.run(value));
|
.thenRun(() -> task.run(value));
|
||||||
}
|
}
|
||||||
}).thenAccept(ignore ->
|
}).thenAccept(ignore ->
|
||||||
TaskManager.getPlatformImplementation().taskLater(whenDone, TaskTime.ticks(1)));
|
TaskManager.getPlatformImplementation().taskLater(whenDone, TaskTime.ticks(1L)));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,8 @@ import java.util.Collection;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
@ -51,12 +53,52 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||||||
*/
|
*/
|
||||||
public abstract class TaskManager {
|
public abstract class TaskManager {
|
||||||
|
|
||||||
public static final HashSet<String> TELEPORT_QUEUE = new HashSet<>();
|
private static final Set<String> teleportQueue = new HashSet<>();
|
||||||
public static final HashMap<Integer, PlotSquaredTask> tasks = new HashMap<>();
|
private static final Map<Integer, PlotSquaredTask> tasks = new HashMap<>();
|
||||||
|
|
||||||
public static AtomicInteger index = new AtomicInteger(0);
|
public static AtomicInteger index = new AtomicInteger(0);
|
||||||
|
|
||||||
@Getter @Setter private static TaskManager platformImplementation;
|
@Getter @Setter private static TaskManager platformImplementation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a string to the teleport queue
|
||||||
|
*
|
||||||
|
* @param string String to add
|
||||||
|
*/
|
||||||
|
public static void addToTeleportQueue(@Nonnull final String string) {
|
||||||
|
teleportQueue.add(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a string from the teleport queue
|
||||||
|
*
|
||||||
|
* @param string String to remove
|
||||||
|
* return {@code true} if the value was stored in the map, or {@code false}
|
||||||
|
*/
|
||||||
|
public static boolean removeFromTeleportQueue(@Nonnull final String string) {
|
||||||
|
return teleportQueue.remove(string);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a task to the task map
|
||||||
|
*
|
||||||
|
* @param task Task
|
||||||
|
* @param id Task ID
|
||||||
|
*/
|
||||||
|
public static void addTask(@Nonnull final PlotSquaredTask task, final int id) {
|
||||||
|
tasks.put(id, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a task from the task map and return the stored value
|
||||||
|
*
|
||||||
|
* @param id Task ID
|
||||||
|
* @return Task if stored, or {@code null}
|
||||||
|
*/
|
||||||
|
@Nullable public static PlotSquaredTask removeTask(final int id) {
|
||||||
|
return tasks.get(id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Run a repeating synchronous task. If using a platform scheduler,
|
* Run a repeating synchronous task. If using a platform scheduler,
|
||||||
* this is guaranteed to run on the server thread
|
* this is guaranteed to run on the server thread
|
||||||
|
Loading…
Reference in New Issue
Block a user