mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-11 09:54:42 +02:00
Merge branch 'v6' into feature/v6/pipeline-queue
# Conflicts: # Core/src/main/java/com/plotsquared/core/command/Trim.java # Core/src/main/java/com/plotsquared/core/queue/BasicLocalBlockQueue.java # Core/src/main/java/com/plotsquared/core/queue/GlobalBlockQueue.java
This commit is contained in:
@ -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;
|
||||
@ -402,9 +403,9 @@ public class BukkitRegionManager extends RegionManager {
|
||||
});
|
||||
}
|
||||
if (!chunks.isEmpty()) {
|
||||
TaskManager.runTaskLater(this, 1);
|
||||
TaskManager.runTaskLater(this, TaskTime.ticks(1L));
|
||||
} else {
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L));
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -458,7 +459,7 @@ public class BukkitRegionManager extends RegionManager {
|
||||
PlotSquared.platform().getGlobalBlockQueue().addEmptyTask(() -> {
|
||||
for (ContentMap map : maps) {
|
||||
map.restoreEntities(world1, 0, 0);
|
||||
TaskManager.runTaskLater(whenDone, 1);
|
||||
TaskManager.runTaskLater(whenDone, TaskTime.ticks(1L));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
@ -54,7 +53,6 @@ import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockType;
|
||||
import com.sk89q.worldedit.world.block.BlockTypes;
|
||||
import io.papermc.lib.PaperLib;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.Material;
|
||||
@ -96,11 +94,11 @@ import org.bukkit.entity.Snowman;
|
||||
import org.bukkit.entity.Tameable;
|
||||
import org.bukkit.entity.Vehicle;
|
||||
import org.bukkit.entity.WaterMob;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@ -423,14 +421,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<String[]>() {
|
||||
@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) {
|
||||
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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> 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);
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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()));
|
||||
}
|
||||
|
||||
}
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user