mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 20:56:45 +01:00
Implement progress subscribers
This commit is contained in:
parent
9e85748b2e
commit
f0e9a8c5fe
@ -112,7 +112,7 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
if (chunk == null) {
|
||||
return;
|
||||
}
|
||||
long iterationTime;
|
||||
long[] iterationTime = new long[2];
|
||||
int processedChunks = 0;
|
||||
do {
|
||||
final long start = System.currentTimeMillis();
|
||||
@ -127,8 +127,9 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
|
||||
processedChunks++;
|
||||
final long end = System.currentTimeMillis();
|
||||
// Update iteration time
|
||||
iterationTime = end - start;
|
||||
} while (2 * iterationTime /* last chunk + next chunk */ < this.maxIterationTime && (chunk = availableChunks.poll()) != null);
|
||||
iterationTime[0] = iterationTime[1];
|
||||
iterationTime[1] = end - start;
|
||||
} while (iterationTime[0] + iterationTime[1] < this.maxIterationTime * 2 && (chunk = availableChunks.poll()) != null);
|
||||
if (processedChunks < this.batchSize) {
|
||||
// Adjust batch size based on the amount of processed chunks per tick
|
||||
this.batchSize = processedChunks;
|
||||
|
@ -1,326 +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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.plotsquared.bukkit.queue;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.plotsquared.bukkit.BukkitPlatform;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* Utility that allows for the loading and coordination of chunk actions
|
||||
* <p>
|
||||
* The coordinator takes in collection of chunk coordinates, loads them
|
||||
* and allows the caller to specify a sink for the loaded chunks. The
|
||||
* coordinator will prevent the chunks from being unloaded until the sink
|
||||
* has fully consumed the chunk
|
||||
* <p>
|
||||
* Usage:
|
||||
* <pre>{@code
|
||||
* final ChunkCoordinator chunkCoordinator = ChunkCoordinator.builder()
|
||||
* .inWorld(Objects.requireNonNull(Bukkit.getWorld("world"))).withChunk(BlockVector2.at(0, 0))
|
||||
* .withConsumer(chunk -> System.out.printf("Got chunk %d;%d", chunk.getX(), chunk.getZ()))
|
||||
* .withFinalAction(() -> System.out.println("All chunks have been loaded"))
|
||||
* .withThrowableConsumer(throwable -> System.err.println("Something went wrong... =("))
|
||||
* .withMaxIterationTime(25L)
|
||||
* .build();
|
||||
* chunkCoordinator.subscribeToProgress((coordinator, progress) ->
|
||||
* System.out.printf("Progress: %.1f", progress * 100.0f));
|
||||
* chunkCoordinator.start();
|
||||
* }</pre>
|
||||
*
|
||||
* @author Alexander Söderberg
|
||||
* @see #builder() To create a new coordinator instance
|
||||
*/
|
||||
public final class ChunkCoordinator extends BukkitRunnable {
|
||||
|
||||
private final List<ProgressSubscriber> progressSubscribers = new LinkedList<>();
|
||||
|
||||
private final Queue<BlockVector2> requestedChunks;
|
||||
private final Queue<Chunk> availableChunks;
|
||||
private final long maxIterationTime;
|
||||
private final Plugin plugin;
|
||||
private final Consumer<Chunk> chunkConsumer;
|
||||
private final World world;
|
||||
private final Runnable whenDone;
|
||||
private final Consumer<Throwable> throwableConsumer;
|
||||
private final int totalSize;
|
||||
|
||||
private AtomicInteger expectedSize;
|
||||
private int batchSize;
|
||||
|
||||
private ChunkCoordinator(final long maxIterationTime, final int initialBatchSize,
|
||||
@Nonnull final Consumer<Chunk> chunkConsumer, @Nonnull final World world,
|
||||
@Nonnull final Collection<BlockVector2> requestedChunks, @Nonnull final Runnable whenDone,
|
||||
@Nonnull final Consumer<Throwable> throwableConsumer) {
|
||||
this.requestedChunks = new LinkedBlockingQueue<>(requestedChunks);
|
||||
this.availableChunks = new LinkedBlockingQueue<>();
|
||||
this.totalSize = requestedChunks.size();
|
||||
this.expectedSize = new AtomicInteger(this.totalSize);
|
||||
this.world = world;
|
||||
this.batchSize = initialBatchSize;
|
||||
this.chunkConsumer = chunkConsumer;
|
||||
this.maxIterationTime = maxIterationTime;
|
||||
this.whenDone = whenDone;
|
||||
this.throwableConsumer = throwableConsumer;
|
||||
this.plugin = JavaPlugin.getPlugin(BukkitPlatform.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link ChunkCoordinator} instance
|
||||
*
|
||||
* @return Coordinator builder instance
|
||||
*/
|
||||
@Nonnull public static ChunkCoordinatorBuilder builder() {
|
||||
return new ChunkCoordinatorBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* Start the coordinator instance
|
||||
*/
|
||||
public void start() {
|
||||
// Request initial batch
|
||||
this.requestBatch();
|
||||
// Wait until next tick to give the chunks a chance to be loaded
|
||||
this.runTaskTimer(this.plugin, 1L, 1L);
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
Chunk chunk = this.availableChunks.poll();
|
||||
if (chunk == null) {
|
||||
return;
|
||||
}
|
||||
long iterationTime;
|
||||
int processedChunks = 0;
|
||||
do {
|
||||
final long start = System.currentTimeMillis();
|
||||
try {
|
||||
this.chunkConsumer.accept(chunk);
|
||||
} catch (final Throwable throwable) {
|
||||
this.throwableConsumer.accept(throwable);
|
||||
}
|
||||
this.freeChunk(chunk);
|
||||
processedChunks++;
|
||||
final long end = System.currentTimeMillis();
|
||||
// Update iteration time
|
||||
iterationTime = end - start;
|
||||
} while (2 * iterationTime /* last chunk + next chunk */ < this.maxIterationTime
|
||||
&& (chunk = availableChunks.poll()) != null);
|
||||
if (processedChunks < this.batchSize) {
|
||||
// Adjust batch size based on the amount of processed chunks per tick
|
||||
this.batchSize = processedChunks;
|
||||
}
|
||||
|
||||
final int expected = this.expectedSize.addAndGet(-processedChunks);
|
||||
|
||||
final float progress = ((float) totalSize - (float) expected) / (float) totalSize;
|
||||
for (final ProgressSubscriber subscriber : this.progressSubscribers) {
|
||||
subscriber.notifyProgress(this, progress);
|
||||
}
|
||||
|
||||
if (expected <= 0) {
|
||||
try {
|
||||
this.whenDone.run();
|
||||
} catch (final Throwable throwable) {
|
||||
this.throwableConsumer.accept(throwable);
|
||||
}
|
||||
this.cancel();
|
||||
} else {
|
||||
if (this.availableChunks.size() < processedChunks) {
|
||||
this.requestBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void requestBatch() {
|
||||
BlockVector2 chunk;
|
||||
for (int i = 0; i < this.batchSize && (chunk = this.requestedChunks.poll()) != null; i++) {
|
||||
// This required PaperLib to be bumped to version 1.0.4 to mark the request as urgent
|
||||
PaperLib.getChunkAtAsync(this.world, chunk.getX(), chunk.getZ(), true, true)
|
||||
.whenComplete((chunkObject, throwable) -> {
|
||||
if (throwable != null) {
|
||||
throwable.printStackTrace();
|
||||
// We want one less because this couldn't be processed
|
||||
this.expectedSize.decrementAndGet();
|
||||
} else {
|
||||
this.processChunk(chunkObject);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void processChunk(@Nonnull final Chunk chunk) {
|
||||
if (!chunk.isLoaded()) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||
}
|
||||
chunk.addPluginChunkTicket(this.plugin);
|
||||
this.availableChunks.add(chunk);
|
||||
}
|
||||
|
||||
private void freeChunk(@Nonnull final Chunk chunk) {
|
||||
if (!chunk.isLoaded()) {
|
||||
throw new IllegalArgumentException(
|
||||
String.format("Chunk %d;%d is is not loaded", chunk.getX(), chunk.getZ()));
|
||||
}
|
||||
chunk.removePluginChunkTicket(this.plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of remaining chunks (at the time of the method call)
|
||||
*
|
||||
* @return Snapshot view of remaining chunk count
|
||||
*/
|
||||
public int getRemainingChunks() {
|
||||
return this.expectedSize.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of requested chunks
|
||||
*
|
||||
* @return Requested chunk count
|
||||
*/
|
||||
public int getTotalChunks() {
|
||||
return this.totalSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to coordinator progress updates
|
||||
*
|
||||
* @param subscriber Subscriber
|
||||
*/
|
||||
public void subscribeToProgress(@Nonnull final ChunkCoordinator.ProgressSubscriber subscriber) {
|
||||
this.progressSubscribers.add(subscriber);
|
||||
}
|
||||
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ProgressSubscriber {
|
||||
|
||||
/**
|
||||
* Notify about a progress update in the coordinator
|
||||
*
|
||||
* @param coordinator Coordinator instance that triggered the notification
|
||||
* @param progress Progress in the range [0, 1]
|
||||
*/
|
||||
void notifyProgress(@Nonnull final ChunkCoordinator coordinator, final float progress);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static final class ChunkCoordinatorBuilder {
|
||||
|
||||
private final List<BlockVector2> requestedChunks = new LinkedList<>();
|
||||
private Consumer<Throwable> throwableConsumer = Throwable::printStackTrace;
|
||||
private World world;
|
||||
private Consumer<Chunk> chunkConsumer;
|
||||
private Runnable whenDone = () -> {
|
||||
};
|
||||
private long maxIterationTime = 60; // A little over 1 tick;
|
||||
private int initialBatchSize = 4;
|
||||
|
||||
private ChunkCoordinatorBuilder() {
|
||||
}
|
||||
|
||||
@Nonnull public ChunkCoordinatorBuilder inWorld(@Nonnull final World world) {
|
||||
this.world = Preconditions.checkNotNull(world, "World may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public ChunkCoordinatorBuilder withChunk(@Nonnull final BlockVector2 chunkLocation) {
|
||||
this.requestedChunks
|
||||
.add(Preconditions.checkNotNull(chunkLocation, "Chunk location may not be null"));
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull public ChunkCoordinatorBuilder withChunks(
|
||||
@Nonnull final Collection<BlockVector2> chunkLocations) {
|
||||
chunkLocations.forEach(this::withChunk);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
public ChunkCoordinatorBuilder withConsumer(@Nonnull final Consumer<Chunk> chunkConsumer) {
|
||||
this.chunkConsumer =
|
||||
Preconditions.checkNotNull(chunkConsumer, "Chunk consumer may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull public ChunkCoordinatorBuilder withFinalAction(@Nonnull final Runnable whenDone) {
|
||||
this.whenDone = Preconditions.checkNotNull(whenDone, "Final action may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull public ChunkCoordinatorBuilder withMaxIterationTime(final long maxIterationTime) {
|
||||
Preconditions
|
||||
.checkArgument(maxIterationTime > 0, "Max iteration time must be positive");
|
||||
this.maxIterationTime = maxIterationTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull public ChunkCoordinatorBuilder withInitialBatchSize(final int initialBatchSize) {
|
||||
Preconditions
|
||||
.checkArgument(initialBatchSize > 0, "Initial batch size must be positive");
|
||||
this.initialBatchSize = initialBatchSize;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull public ChunkCoordinatorBuilder withThrowableConsumer(
|
||||
@Nonnull final Consumer<Throwable> throwableConsumer) {
|
||||
this.throwableConsumer =
|
||||
Preconditions.checkNotNull(throwableConsumer, "Throwable consumer may not be null");
|
||||
return this;
|
||||
}
|
||||
|
||||
@Nonnull public ChunkCoordinator build() {
|
||||
Preconditions.checkNotNull(this.world, "No world was supplied");
|
||||
Preconditions.checkNotNull(this.chunkConsumer, "No chunk consumer was supplied");
|
||||
Preconditions.checkNotNull(this.whenDone, "No final action was supplied");
|
||||
Preconditions
|
||||
.checkNotNull(this.throwableConsumer, "No throwable consumer was supplied");
|
||||
return new ChunkCoordinator(this.maxIterationTime, this.initialBatchSize,
|
||||
this.chunkConsumer, this.world, this.requestedChunks, this.whenDone,
|
||||
this.throwableConsumer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -30,6 +30,7 @@ import com.google.inject.Singleton;
|
||||
import com.plotsquared.core.generator.AugmentedUtils;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.location.PlotLoc;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotManager;
|
||||
@ -53,10 +54,9 @@ import org.bukkit.Chunk;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@ -72,24 +72,21 @@ import static com.plotsquared.core.util.entity.EntityCategories.CAP_VEHICLE;
|
||||
@Singleton
|
||||
public class BukkitRegionManager extends RegionManager {
|
||||
|
||||
private static final Logger logger =
|
||||
LoggerFactory.getLogger("P2/" + BukkitRegionManager.class.getSimpleName());
|
||||
private final GlobalBlockQueue blockQueue;
|
||||
|
||||
@Inject
|
||||
public BukkitRegionManager(@Nonnull WorldUtil worldUtil, @Nonnull GlobalBlockQueue blockQueue) {
|
||||
@Inject public BukkitRegionManager(@Nonnull WorldUtil worldUtil, @Nonnull GlobalBlockQueue blockQueue) {
|
||||
super(worldUtil, blockQueue);
|
||||
this.blockQueue = blockQueue;
|
||||
}
|
||||
|
||||
@Override public boolean handleClear(Plot plot, Runnable whenDone, PlotManager manager) {
|
||||
@Override
|
||||
public boolean handleClear(@Nonnull Plot plot, @Nullable Runnable whenDone, @Nonnull PlotManager manager, @Nullable PlotPlayer<?> player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public int[] countEntities(Plot plot) {
|
||||
@Override public int[] countEntities(@Nonnull Plot plot) {
|
||||
int[] existing = (int[]) plot.getMeta("EntityCount");
|
||||
if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime")
|
||||
< 1000)) {
|
||||
if (existing != null && (System.currentTimeMillis() - (long) plot.getMeta("EntityCountTime") < 1000)) {
|
||||
return existing;
|
||||
}
|
||||
PlotArea area = plot.getArea();
|
||||
@ -161,8 +158,10 @@ public class BukkitRegionManager extends RegionManager {
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override public boolean regenerateRegion(final Location pos1, final Location pos2,
|
||||
final boolean ignoreAugment, final Runnable whenDone) {
|
||||
@Override public boolean regenerateRegion(@Nonnull final Location pos1,
|
||||
@Nonnull final Location pos2,
|
||||
final boolean ignoreAugment,
|
||||
@Nullable final Runnable whenDone) {
|
||||
final BukkitWorld world = new BukkitWorld((World) pos1.getWorld());
|
||||
|
||||
final int p1x = pos1.getX();
|
||||
@ -176,8 +175,7 @@ public class BukkitRegionManager extends RegionManager {
|
||||
|
||||
final QueueCoordinator queue = blockQueue.getNewQueue(world);
|
||||
final QueueCoordinator regenQueue = blockQueue.getNewQueue(world);
|
||||
queue.addReadChunks(
|
||||
new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()).getChunks());
|
||||
queue.addReadChunks(new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3()).getChunks());
|
||||
queue.setChunkConsumer(chunk -> {
|
||||
|
||||
int x = chunk.getX();
|
||||
@ -187,8 +185,7 @@ public class BukkitRegionManager extends RegionManager {
|
||||
int xxt = xxb + 15;
|
||||
int zzt = zzb + 15;
|
||||
if (xxb >= p1x && xxt <= p2x && zzb >= p1z && zzt <= p2z) {
|
||||
AugmentedUtils
|
||||
.bypass(ignoreAugment, () -> regenQueue.regenChunk(chunk.getX(), chunk.getZ()));
|
||||
AugmentedUtils.bypass(ignoreAugment, () -> regenQueue.regenChunk(chunk.getX(), chunk.getZ()));
|
||||
return;
|
||||
}
|
||||
boolean checkX1 = false;
|
||||
@ -250,41 +247,37 @@ public class BukkitRegionManager extends RegionManager {
|
||||
if (checkX2 && checkZ2) {
|
||||
map.saveRegion(world, xxt2, xxt, zzt2, zzt); //
|
||||
}
|
||||
CuboidRegion currentPlotClear =
|
||||
RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
map.saveEntitiesOut(Bukkit.getWorld(world.getName()).getChunkAt(x, z),
|
||||
currentPlotClear);
|
||||
AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager
|
||||
.setChunkInPlotArea(null, new RunnableVal<ScopedQueueCoordinator>() {
|
||||
@Override public void run(ScopedQueueCoordinator value) {
|
||||
Location min = value.getMin();
|
||||
int bx = min.getX();
|
||||
int bz = min.getZ();
|
||||
for (int x1 = 0; x1 < 16; x1++) {
|
||||
for (int z1 = 0; z1 < 16; z1++) {
|
||||
PlotLoc plotLoc = new PlotLoc(bx + x1, bz + z1);
|
||||
BaseBlock[] ids = map.allBlocks.get(plotLoc);
|
||||
if (ids != null) {
|
||||
for (int y = 0; y < Math.min(128, ids.length); y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
} else {
|
||||
value.setBlock(x1, y, z1,
|
||||
BlockTypes.AIR.getDefaultState());
|
||||
}
|
||||
CuboidRegion currentPlotClear = RegionUtil.createRegion(pos1.getX(), pos2.getX(), pos1.getZ(), pos2.getZ());
|
||||
map.saveEntitiesOut(Bukkit.getWorld(world.getName()).getChunkAt(x, z), currentPlotClear);
|
||||
AugmentedUtils.bypass(ignoreAugment, () -> ChunkManager.setChunkInPlotArea(null, new RunnableVal<ScopedQueueCoordinator>() {
|
||||
@Override public void run(ScopedQueueCoordinator value) {
|
||||
Location min = value.getMin();
|
||||
int bx = min.getX();
|
||||
int bz = min.getZ();
|
||||
for (int x1 = 0; x1 < 16; x1++) {
|
||||
for (int z1 = 0; z1 < 16; z1++) {
|
||||
PlotLoc plotLoc = new PlotLoc(bx + x1, bz + z1);
|
||||
BaseBlock[] ids = map.allBlocks.get(plotLoc);
|
||||
if (ids != null) {
|
||||
for (int y = 0; y < Math.min(128, ids.length); y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
} else {
|
||||
value.setBlock(x1, y, z1, BlockTypes.AIR.getDefaultState());
|
||||
}
|
||||
for (int y = Math.min(128, ids.length); y < ids.length; y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
}
|
||||
}
|
||||
for (int y = Math.min(128, ids.length); y < ids.length; y++) {
|
||||
BaseBlock id = ids[y];
|
||||
if (id != null) {
|
||||
value.setBlock(x1, y, z1, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, world.getName(), chunk));
|
||||
}
|
||||
}, world.getName(), chunk));
|
||||
//map.restoreBlocks(worldObj, 0, 0);
|
||||
map.restoreEntities(Bukkit.getWorld(world.getName()), 0, 0);
|
||||
});
|
||||
@ -294,7 +287,7 @@ public class BukkitRegionManager extends RegionManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override public void clearAllEntities(Location pos1, Location pos2) {
|
||||
@Override public void clearAllEntities(@Nonnull Location pos1, @Nonnull Location pos2) {
|
||||
String world = pos1.getWorldName();
|
||||
|
||||
final World bukkitWorld = BukkitUtil.getWorld(world);
|
||||
@ -312,8 +305,7 @@ public class BukkitRegionManager extends RegionManager {
|
||||
for (Entity entity : entities) {
|
||||
if (!(entity instanceof Player)) {
|
||||
org.bukkit.Location location = entity.getLocation();
|
||||
if (location.getX() >= bx && location.getX() <= tx && location.getZ() >= bz
|
||||
&& location.getZ() <= tz) {
|
||||
if (location.getX() >= bx && location.getX() <= tx && location.getZ() >= bz && location.getZ() <= tz) {
|
||||
if (entity.hasMetadata("ps-tmp-teleport")) {
|
||||
continue;
|
||||
}
|
||||
@ -323,17 +315,16 @@ public class BukkitRegionManager extends RegionManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void count(int[] count, Entity entity) {
|
||||
final com.sk89q.worldedit.world.entity.EntityType entityType =
|
||||
BukkitAdapter.adapt(entity.getType());
|
||||
private void count(int[] count, @Nonnull Entity entity) {
|
||||
final com.sk89q.worldedit.world.entity.EntityType entityType = BukkitAdapter.adapt(entity.getType());
|
||||
|
||||
if (EntityCategories.PLAYER.contains(entityType)) {
|
||||
return;
|
||||
} else if (EntityCategories.PROJECTILE.contains(entityType) || EntityCategories.OTHER
|
||||
.contains(entityType) || EntityCategories.HANGING.contains(entityType)) {
|
||||
} else if (EntityCategories.PROJECTILE.contains(entityType) || EntityCategories.OTHER.contains(entityType) || EntityCategories.HANGING
|
||||
.contains(entityType)) {
|
||||
count[CAP_MISC]++;
|
||||
} else if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER
|
||||
.contains(entityType) || EntityCategories.TAMEABLE.contains(entityType)) {
|
||||
} else if (EntityCategories.ANIMAL.contains(entityType) || EntityCategories.VILLAGER.contains(entityType) || EntityCategories.TAMEABLE
|
||||
.contains(entityType)) {
|
||||
count[CAP_MOB]++;
|
||||
count[CAP_ANIMAL]++;
|
||||
} else if (EntityCategories.VEHICLE.contains(entityType)) {
|
||||
|
@ -25,7 +25,10 @@
|
||||
*/
|
||||
package com.plotsquared.core.backup;
|
||||
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
@ -64,8 +67,9 @@ public interface BackupProfile {
|
||||
* Restore a backup
|
||||
*
|
||||
* @param backup Backup to restore
|
||||
* @param player The player restoring the backup
|
||||
* @return Future that completes when the backup has finished
|
||||
*/
|
||||
@Nonnull CompletableFuture<Void> restoreBackup(@Nonnull final Backup backup);
|
||||
@Nonnull CompletableFuture<Void> restoreBackup(@Nonnull final Backup backup, @Nullable PlotPlayer<?> player);
|
||||
|
||||
}
|
||||
|
@ -25,7 +25,10 @@
|
||||
*/
|
||||
package com.plotsquared.core.backup;
|
||||
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
@ -53,7 +56,7 @@ public class NullBackupProfile implements BackupProfile {
|
||||
throw new UnsupportedOperationException("Cannot create backup of an unowned plot");
|
||||
}
|
||||
|
||||
@Override @Nonnull public CompletableFuture<Void> restoreBackup(@Nonnull final Backup backup) {
|
||||
@Override @Nonnull public CompletableFuture<Void> restoreBackup(@Nonnull final Backup backup, @Nullable PlotPlayer<?> player) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
|
||||
|
@ -29,6 +29,7 @@ import com.google.inject.Inject;
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.schematic.Schematic;
|
||||
import com.plotsquared.core.util.SchematicHandler;
|
||||
@ -37,6 +38,7 @@ import com.plotsquared.core.util.task.TaskManager;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@ -166,7 +168,7 @@ public class PlayerBackupProfile implements BackupProfile {
|
||||
return future;
|
||||
}
|
||||
|
||||
@Override @Nonnull public CompletableFuture<Void> restoreBackup(@Nonnull final Backup backup) {
|
||||
@Override @Nonnull public CompletableFuture<Void> restoreBackup(@Nonnull final Backup backup, @Nullable PlotPlayer<?> player) {
|
||||
final CompletableFuture<Void> future = new CompletableFuture<>();
|
||||
if (backup.getFile() == null || !Files.exists(backup.getFile())) {
|
||||
future.completeExceptionally(new IllegalArgumentException("The specific backup does not exist"));
|
||||
@ -181,7 +183,7 @@ public class PlayerBackupProfile implements BackupProfile {
|
||||
if (schematic == null) {
|
||||
future.completeExceptionally(new IllegalArgumentException("The backup is non-existent or not in the correct format"));
|
||||
} else {
|
||||
this.schematicHandler.paste(schematic, plot, 0, 1, 0, false, new RunnableVal<Boolean>() {
|
||||
this.schematicHandler.paste(schematic, plot, 0, 1, 0, false, player, new RunnableVal<Boolean>() {
|
||||
@Override public void run(Boolean value) {
|
||||
if (value) {
|
||||
future.complete(null);
|
||||
|
@ -314,7 +314,7 @@ public final class Backup extends Command {
|
||||
);
|
||||
} else {
|
||||
CmdConfirm.addPending(player, "/plot backup load " + number,
|
||||
() -> backupProfile.restoreBackup(backup)
|
||||
() -> backupProfile.restoreBackup(backup, player)
|
||||
.whenComplete((n, error) -> {
|
||||
if (error != null) {
|
||||
player.sendMessage(
|
||||
|
@ -50,7 +50,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@CommandDeclaration(
|
||||
command = "claim",
|
||||
@ -186,7 +185,7 @@ public class Claim extends SubCommand {
|
||||
Template.of("value", "Auto merge on claim")
|
||||
);
|
||||
} else {
|
||||
plot.getPlotModificationManager().autoMerge(mergeEvent.getDir(), mergeEvent.getMax(), player.getUUID(), true);
|
||||
plot.getPlotModificationManager().autoMerge(mergeEvent.getDir(), mergeEvent.getMax(), player.getUUID(), player, true);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -91,7 +91,7 @@ public class Clear extends Command {
|
||||
confirm.run(this, () -> {
|
||||
BackupManager.backup(player, plot, () -> {
|
||||
final long start = System.currentTimeMillis();
|
||||
boolean result = plot.getPlotModificationManager().clear(true, false, () -> {
|
||||
boolean result = plot.getPlotModificationManager().clear(true, false, player, () -> {
|
||||
plot.getPlotModificationManager().unlink();
|
||||
TaskManager.runTask(() -> {
|
||||
plot.removeRunning();
|
||||
|
@ -178,7 +178,7 @@ public class Condense extends SubCommand {
|
||||
i++;
|
||||
final AtomicBoolean result = new AtomicBoolean(false);
|
||||
try {
|
||||
result.set(origin.getPlotModificationManager().move(possible, () -> {
|
||||
result.set(origin.getPlotModificationManager().move(possible, player, () -> {
|
||||
if (result.get()) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("condense.moving"),
|
||||
|
@ -77,7 +77,7 @@ public class Copy extends SubCommand {
|
||||
return false;
|
||||
}
|
||||
|
||||
plot1.getPlotModificationManager().copy(plot2).thenAccept(result -> {
|
||||
plot1.getPlotModificationManager().copy(plot2, player).thenAccept(result -> {
|
||||
if (result) {
|
||||
player.sendMessage(TranslatableCaption.of("move.copy_success"));
|
||||
} else {
|
||||
|
@ -98,7 +98,7 @@ public class Delete extends SubCommand {
|
||||
return;
|
||||
}
|
||||
final long start = System.currentTimeMillis();
|
||||
boolean result = plot.getPlotModificationManager().deletePlot(() -> {
|
||||
boolean result = plot.getPlotModificationManager().deletePlot(player, () -> {
|
||||
plot.removeRunning();
|
||||
if (this.econHandler.isEnabled(plotArea)) {
|
||||
Expression<Double> valueExr = plotArea.getPrices().get("sell");
|
||||
|
@ -26,10 +26,10 @@
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.StaticCaption;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.MetaDataAccess;
|
||||
import com.plotsquared.core.player.PlayerMetaDataKeys;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
@ -137,17 +137,16 @@ public class Load extends SubCommand {
|
||||
return;
|
||||
}
|
||||
PlotArea area = plot.getArea();
|
||||
this.schematicHandler
|
||||
.paste(taskSchematic, plot, 0, area.getMinBuildHeight(), 0, false, new RunnableVal<Boolean>() {
|
||||
@Override public void run(Boolean value) {
|
||||
plot.removeRunning();
|
||||
if (value) {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_success"));
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_failed"));
|
||||
}
|
||||
this.schematicHandler.paste(taskSchematic, plot, 0, area.getMinBuildHeight(), 0, false, player, new RunnableVal<Boolean>() {
|
||||
@Override public void run(Boolean value) {
|
||||
plot.removeRunning();
|
||||
if (value) {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_success"));
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_failed"));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ public class Merge extends SubCommand {
|
||||
);
|
||||
return true;
|
||||
}
|
||||
if (plot.getPlotModificationManager().autoMerge(Direction.ALL, maxSize, uuid, terrain)) {
|
||||
if (plot.getPlotModificationManager().autoMerge(Direction.ALL, maxSize, uuid, player, terrain)) {
|
||||
if (this.econHandler.isEnabled(plotArea) && price > 0d) {
|
||||
this.econHandler.withdrawMoney(player, price);
|
||||
player.sendMessage(
|
||||
@ -224,7 +224,7 @@ public class Merge extends SubCommand {
|
||||
);
|
||||
return true;
|
||||
}
|
||||
if (plot.getPlotModificationManager().autoMerge(direction, maxSize - size, uuid, terrain)) {
|
||||
if (plot.getPlotModificationManager().autoMerge(direction, maxSize - size, uuid, player, terrain)) {
|
||||
if (this.econHandler.isEnabled(plotArea) && price > 0d) {
|
||||
this.econHandler.withdrawMoney(player, price);
|
||||
player.sendMessage(
|
||||
@ -259,7 +259,7 @@ public class Merge extends SubCommand {
|
||||
final Direction dir = direction;
|
||||
Runnable run = () -> {
|
||||
accepter.sendMessage(TranslatableCaption.of("merge.merge_accepted"));
|
||||
plot.getPlotModificationManager().autoMerge(dir, maxSize - size, owner, terrain);
|
||||
plot.getPlotModificationManager().autoMerge(dir, maxSize - size, owner, player, terrain);
|
||||
PlotPlayer<?> plotPlayer = PlotSquared.platform().getPlayerManager().getPlayerIfExists(player.getUUID());
|
||||
if (plotPlayer == null) {
|
||||
accepter.sendMessage(TranslatableCaption.of("merge.merge_not_valid"));
|
||||
|
@ -106,7 +106,7 @@ public class Move extends SubCommand {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
return plot1.getPlotModificationManager().move(plot2, () -> {
|
||||
return plot1.getPlotModificationManager().move(plot2, player, () -> {
|
||||
}, false).thenApply(result -> {
|
||||
if (result) {
|
||||
player.sendMessage(TranslatableCaption.of("move.move_success"));
|
||||
|
@ -214,7 +214,7 @@ public class Purge extends SubCommand {
|
||||
try {
|
||||
ids.add(plot.temp);
|
||||
if (finalClear) {
|
||||
plot.getPlotModificationManager().clear(false, true, () -> {
|
||||
plot.getPlotModificationManager().clear(false, true, player, () -> {
|
||||
if (Settings.DEBUG) {
|
||||
logger.info("Plot {} cleared by purge", plot.getId());
|
||||
}
|
||||
|
@ -27,10 +27,10 @@ package com.plotsquared.core.command;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.permissions.Permission;
|
||||
import com.plotsquared.core.player.ConsolePlayer;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
@ -149,16 +149,16 @@ public class SchematicCmd extends SubCommand {
|
||||
);
|
||||
return;
|
||||
}
|
||||
this.schematicHandler.paste(schematic, plot, 0, 1, 0, false, new RunnableVal<Boolean>() {
|
||||
@Override public void run(Boolean value) {
|
||||
SchematicCmd.this.running = false;
|
||||
if (value) {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_success"));
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_failed"));
|
||||
}
|
||||
this.schematicHandler.paste(schematic, plot, 0, 1, 0, false, player, new RunnableVal<Boolean>() {
|
||||
@Override public void run(Boolean value) {
|
||||
SchematicCmd.this.running = false;
|
||||
if (value) {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_success"));
|
||||
} else {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_failed"));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
break;
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ public class Set extends SubCommand {
|
||||
plot.addRunning();
|
||||
QueueCoordinator queue = plotArea.getQueue();
|
||||
for (final Plot current : plot.getConnectedPlots()) {
|
||||
current.getPlotModificationManager().setComponent(component, pattern, queue);
|
||||
current.getPlotModificationManager().setComponent(component, pattern, player, queue);
|
||||
}
|
||||
queue.setCompleteTask(plot::removeRunning);
|
||||
queue.enqueue();
|
||||
|
@ -84,7 +84,7 @@ public class Swap extends SubCommand {
|
||||
return CompletableFuture.completedFuture(false);
|
||||
}
|
||||
|
||||
return plot1.getPlotModificationManager().move(plot2, () -> {
|
||||
return plot1.getPlotModificationManager().move(plot2, player, () -> {
|
||||
}, true).thenApply(result -> {
|
||||
if (result) {
|
||||
player.sendMessage(TranslatableCaption.of("swap.swap_success"));
|
||||
|
@ -194,7 +194,7 @@ public class ComponentPresetManager {
|
||||
plot.addRunning();
|
||||
QueueCoordinator queue = plot.getArea().getQueue();
|
||||
for (Plot current : plot.getConnectedPlots()) {
|
||||
current.getPlotModificationManager().setComponent(componentPreset.getComponent().name(), pattern, queue);
|
||||
current.getPlotModificationManager().setComponent(componentPreset.getComponent().name(), pattern, player, queue);
|
||||
}
|
||||
queue.setCompleteTask(plot::removeRunning);
|
||||
queue.enqueue();
|
||||
|
@ -531,8 +531,18 @@ public class Settings extends Config {
|
||||
@Comment("Settings relating to PlotSquared's GlobalBlockQueue")
|
||||
public static final class QUEUE {
|
||||
@Comment({"Average time per tick spent completing chunk tasks in ms.",
|
||||
"Waits (chunk task time / target_time) ticks before completely the next task."})
|
||||
public static int TARGET_TIME = 65;
|
||||
"Queue will adjust the batch size to match this."})
|
||||
public static int MAX_ITERATION_TIME = 30;
|
||||
@Comment({"Initial number of chunks to process by the queue. This can be increased or",
|
||||
"decreased by the queue based on the actual iteration time compared to above."})
|
||||
public static int INITIAL_BATCH_SIZE = 5;
|
||||
@Comment("Notify progress of the queue to the player or console.")
|
||||
public static boolean NOTIFY_PROGRESS = true;
|
||||
@Comment("Interval in ms to notify player or console of progress.")
|
||||
public static int NOTIFY_INTERVAL = 1000;
|
||||
@Comment({"Time to wait in ms before beginning to notify player or console of progress.",
|
||||
"Prevent needless notification of progress for short queues."})
|
||||
public static int NOTIFY_WAIT = 5000;
|
||||
}
|
||||
|
||||
@Comment("Settings related to tab completion")
|
||||
|
@ -25,9 +25,12 @@
|
||||
*/
|
||||
package com.plotsquared.core.generator;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.inject.factory.ProgressSubscriberFactory;
|
||||
import com.plotsquared.core.location.Direction;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.BlockBucket;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotAreaTerrainType;
|
||||
@ -53,44 +56,48 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
|
||||
private final ClassicPlotWorld classicPlotWorld;
|
||||
private final RegionManager regionManager;
|
||||
@Inject private ProgressSubscriberFactory subscriberFactory;
|
||||
|
||||
public ClassicPlotManager(@Nonnull final ClassicPlotWorld classicPlotWorld, @Nonnull final RegionManager regionManager) {
|
||||
@Inject public ClassicPlotManager(@Nonnull final ClassicPlotWorld classicPlotWorld, @Nonnull final RegionManager regionManager) {
|
||||
super(classicPlotWorld, regionManager);
|
||||
this.classicPlotWorld = classicPlotWorld;
|
||||
this.regionManager = regionManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setComponent(@Nonnull PlotId plotId, @Nonnull String component, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
@Override public boolean setComponent(@Nonnull PlotId plotId,
|
||||
@Nonnull String component,
|
||||
@Nonnull Pattern blocks,
|
||||
@Nullable PlotPlayer<?> actor,
|
||||
@Nullable QueueCoordinator queue) {
|
||||
final Optional<ClassicPlotManagerComponent> componentOptional = ClassicPlotManagerComponent.fromString(component);
|
||||
if (componentOptional.isPresent()) {
|
||||
switch (componentOptional.get()) {
|
||||
case FLOOR:
|
||||
return setFloor(plotId, blocks, queue);
|
||||
return setFloor(plotId, blocks, actor, queue);
|
||||
case WALL:
|
||||
return setWallFilling(plotId, blocks, queue);
|
||||
return setWallFilling(plotId, blocks, actor, queue);
|
||||
case AIR:
|
||||
return setAir(plotId, blocks, queue);
|
||||
return setAir(plotId, blocks, actor, queue);
|
||||
case MAIN:
|
||||
return setMain(plotId, blocks, queue);
|
||||
return setMain(plotId, blocks, actor, queue);
|
||||
case MIDDLE:
|
||||
return setMiddle(plotId, blocks, queue);
|
||||
case OUTLINE:
|
||||
return setOutline(plotId, blocks, queue);
|
||||
return setOutline(plotId, blocks, actor, queue);
|
||||
case BORDER:
|
||||
return setWall(plotId, blocks, queue);
|
||||
return setWall(plotId, blocks, actor, queue);
|
||||
case ALL:
|
||||
return setAll(plotId, blocks, queue);
|
||||
return setAll(plotId, blocks, actor, queue);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean unClaimPlot(@Nonnull Plot plot, @Nullable Runnable whenDone, @Nullable QueueCoordinator queue) {
|
||||
setWallFilling(plot.getId(), classicPlotWorld.WALL_FILLING.toPattern(), queue);
|
||||
setWallFilling(plot.getId(), classicPlotWorld.WALL_FILLING.toPattern(), null, queue);
|
||||
if (classicPlotWorld.PLACE_TOP_BLOCK && (!classicPlotWorld.WALL_BLOCK.isAir() || !classicPlotWorld.WALL_BLOCK
|
||||
.equals(classicPlotWorld.CLAIMED_WALL_BLOCK))) {
|
||||
setWall(plot.getId(), classicPlotWorld.WALL_BLOCK.toPattern(), queue);
|
||||
setWall(plot.getId(), classicPlotWorld.WALL_BLOCK.toPattern(), null, queue);
|
||||
}
|
||||
TaskManager.runTask(whenDone);
|
||||
return true;
|
||||
@ -105,11 +112,11 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return success or not
|
||||
*/
|
||||
public boolean setFloor(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
public boolean setFloor(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable PlotPlayer<?> actor, @Nullable QueueCoordinator queue) {
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
if (plot != null && plot.isBasePlot()) {
|
||||
return this.regionManager
|
||||
.setCuboids(classicPlotWorld, plot.getRegions(), blocks, classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.PLOT_HEIGHT, queue);
|
||||
.setCuboids(classicPlotWorld, plot.getRegions(), blocks, classicPlotWorld.PLOT_HEIGHT, classicPlotWorld.PLOT_HEIGHT, actor, queue);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -123,10 +130,10 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return success or not
|
||||
*/
|
||||
public boolean setAll(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
public boolean setAll(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable PlotPlayer<?> actor, @Nullable QueueCoordinator queue) {
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
if (plot != null && plot.isBasePlot()) {
|
||||
return this.regionManager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1, getWorldHeight(), queue);
|
||||
return this.regionManager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1, getWorldHeight(), actor, queue);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -140,11 +147,11 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return success or not
|
||||
*/
|
||||
public boolean setAir(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
public boolean setAir(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable PlotPlayer<?> actor, @Nullable QueueCoordinator queue) {
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
if (plot != null && plot.isBasePlot()) {
|
||||
return this.regionManager
|
||||
.setCuboids(classicPlotWorld, plot.getRegions(), blocks, classicPlotWorld.PLOT_HEIGHT + 1, getWorldHeight(), queue);
|
||||
.setCuboids(classicPlotWorld, plot.getRegions(), blocks, classicPlotWorld.PLOT_HEIGHT + 1, getWorldHeight(), actor, queue);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -158,10 +165,10 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return success or not
|
||||
*/
|
||||
public boolean setMain(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
public boolean setMain(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable PlotPlayer<?> actor, @Nullable QueueCoordinator queue) {
|
||||
Plot plot = classicPlotWorld.getPlotAbs(plotId);
|
||||
if (plot == null || plot.isBasePlot()) {
|
||||
return this.regionManager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1, classicPlotWorld.PLOT_HEIGHT - 1, queue);
|
||||
return this.regionManager.setCuboids(classicPlotWorld, plot.getRegions(), blocks, 1, classicPlotWorld.PLOT_HEIGHT - 1, actor, queue);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -203,7 +210,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return success or not
|
||||
*/
|
||||
public boolean setOutline(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
public boolean setOutline(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable PlotPlayer<?> actor, @Nullable QueueCoordinator queue) {
|
||||
if (classicPlotWorld.ROAD_WIDTH == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -224,6 +231,9 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
if (queue == null) {
|
||||
queue = classicPlotWorld.getQueue();
|
||||
enqueue = true;
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
}
|
||||
}
|
||||
|
||||
int maxY = classicPlotWorld.getPlotManager().getWorldHeight();
|
||||
@ -279,7 +289,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return success or not
|
||||
*/
|
||||
public boolean setWallFilling(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
public boolean setWallFilling(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable PlotPlayer<?> actor, @Nullable QueueCoordinator queue) {
|
||||
if (classicPlotWorld.ROAD_WIDTH == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -300,6 +310,9 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
if (queue == null) {
|
||||
queue = classicPlotWorld.getQueue();
|
||||
enqueue = true;
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
}
|
||||
}
|
||||
|
||||
if (!plot.isMerged(Direction.NORTH)) {
|
||||
@ -346,7 +359,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return success or not
|
||||
*/
|
||||
public boolean setWall(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
public boolean setWall(@Nonnull PlotId plotId, @Nonnull Pattern blocks, @Nullable PlotPlayer<?> actor, @Nullable QueueCoordinator queue) {
|
||||
if (classicPlotWorld.ROAD_WIDTH == 0) {
|
||||
return false;
|
||||
}
|
||||
@ -367,6 +380,9 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
if (queue == null) {
|
||||
enqueue = true;
|
||||
queue = classicPlotWorld.getQueue();
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
}
|
||||
}
|
||||
|
||||
int y = classicPlotWorld.WALL_HEIGHT + 1;
|
||||
@ -578,13 +594,13 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
|
||||
if (classicPlotWorld.PLACE_TOP_BLOCK && (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK))) {
|
||||
for (PlotId plotId : plotIds) {
|
||||
setWall(plotId, claim.toPattern(), queue);
|
||||
setWall(plotId, claim.toPattern(), null, queue);
|
||||
}
|
||||
}
|
||||
if (Settings.General.MERGE_REPLACE_WALL) {
|
||||
final BlockBucket wallBlock = classicPlotWorld.WALL_FILLING;
|
||||
for (PlotId id : plotIds) {
|
||||
setWallFilling(id, wallBlock.toPattern(), queue);
|
||||
setWallFilling(id, wallBlock.toPattern(), null, queue);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
@ -594,7 +610,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
|
||||
if (classicPlotWorld.PLACE_TOP_BLOCK && (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK))) {
|
||||
for (PlotId id : plotIds) {
|
||||
setWall(id, claim.toPattern(), queue);
|
||||
setWall(id, claim.toPattern(), null, queue);
|
||||
}
|
||||
}
|
||||
return true; // return false if unlink has been denied
|
||||
@ -611,7 +627,7 @@ public class ClassicPlotManager extends SquarePlotManager {
|
||||
@Override public boolean claimPlot(@Nonnull Plot plot, @Nullable QueueCoordinator queue) {
|
||||
final BlockBucket claim = classicPlotWorld.CLAIMED_WALL_BLOCK;
|
||||
if (classicPlotWorld.PLACE_TOP_BLOCK && (!claim.isAir() || !claim.equals(classicPlotWorld.WALL_BLOCK))) {
|
||||
return setWall(plot.getId(), claim.toPattern(), queue);
|
||||
return setWall(plot.getId(), claim.toPattern(), null, queue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.command.Template;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotAreaTerrainType;
|
||||
import com.plotsquared.core.plot.PlotAreaType;
|
||||
@ -200,17 +201,13 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
return !enqueue || queue.enqueue();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Clearing the plot needs to only consider removing the blocks - This implementation has
|
||||
* used the setCuboidAsync function, as it is fast, and uses NMS code - It also makes use of the
|
||||
* fact that deleting chunks is a lot faster than block updates This code is very messy, but you
|
||||
* don't need to do something quite as complex unless you happen to have 512x512 sized plots.
|
||||
* </p>
|
||||
*/
|
||||
@Override public boolean clearPlot(@Nonnull final Plot plot, @Nullable final Runnable whenDone, @Nullable QueueCoordinator queue) {
|
||||
@Override public boolean clearPlot(@Nonnull final Plot plot,
|
||||
@Nullable final Runnable whenDone,
|
||||
@Nullable PlotPlayer<?> actor,
|
||||
@Nullable QueueCoordinator queue) {
|
||||
if (this.regionManager.notifyClear(this)) {
|
||||
//If this returns false, the clear didn't work
|
||||
if (this.regionManager.handleClear(plot, whenDone, this)) {
|
||||
if (this.regionManager.handleClear(plot, whenDone, this, actor)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ package com.plotsquared.core.generator;
|
||||
|
||||
import com.plotsquared.core.location.Direction;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
@ -59,7 +60,10 @@ public abstract class SquarePlotManager extends GridPlotManager {
|
||||
this.regionManager = regionManager;
|
||||
}
|
||||
|
||||
@Override public boolean clearPlot(final @NotNull Plot plot, final @Nullable Runnable whenDone, @Nullable QueueCoordinator queue) {
|
||||
@Override public boolean clearPlot(final @NotNull Plot plot,
|
||||
final @Nullable Runnable whenDone,
|
||||
@Nullable PlotPlayer<?> actor,
|
||||
@Nullable QueueCoordinator queue) {
|
||||
final Set<CuboidRegion> regions = plot.getRegions();
|
||||
Runnable run = new Runnable() {
|
||||
@Override public void run() {
|
||||
|
@ -26,6 +26,7 @@
|
||||
package com.plotsquared.core.inject.factory;
|
||||
|
||||
import com.google.inject.assistedinject.Assisted;
|
||||
import com.plotsquared.core.configuration.caption.Caption;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
|
||||
import com.plotsquared.core.util.task.TaskManager;
|
||||
@ -35,8 +36,12 @@ import javax.annotation.Nullable;
|
||||
|
||||
public interface ProgressSubscriberFactory {
|
||||
|
||||
@Nonnull ProgressSubscriber create(@Nullable @Assisted("subscriber") PlotPlayer actor,
|
||||
@Nonnull ProgressSubscriber create(@Nonnull @Assisted("subscriber") PlotPlayer<?> actor);
|
||||
|
||||
@Nonnull ProgressSubscriber create(@Nonnull @Assisted("subscriber") PlotPlayer<?> actor,
|
||||
@Nonnull TaskManager taskManager,
|
||||
@Assisted("progressInterval") final long interval,
|
||||
@Nonnull TaskManager taskManager);
|
||||
@Assisted("progressInterval") final long wait,
|
||||
@Nullable @Assisted("caption") Caption caption);
|
||||
|
||||
}
|
||||
|
@ -576,7 +576,7 @@ public abstract class PlotPlayer<P> implements CommandCaller, OfflinePlotPlayer,
|
||||
}
|
||||
if (Settings.Enabled_Components.BAN_DELETER && isBanned()) {
|
||||
for (Plot owned : getPlots()) {
|
||||
owned.getPlotModificationManager().deletePlot(null);
|
||||
owned.getPlotModificationManager().deletePlot(null, null);
|
||||
if (Settings.DEBUG) {
|
||||
logger.info("Plot {} was deleted + cleared due to {} getting banned", owned.getId(), getName());
|
||||
}
|
||||
|
@ -1623,7 +1623,7 @@ public class Plot {
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
schematicHandler.paste(sch, this, 0, 1, 0, Settings.Schematics.PASTE_ON_TOP, new RunnableVal<Boolean>() {
|
||||
schematicHandler.paste(sch, this, 0, 1, 0, Settings.Schematics.PASTE_ON_TOP, player, new RunnableVal<Boolean>() {
|
||||
@Override public void run(Boolean value) {
|
||||
if (value) {
|
||||
player.sendMessage(TranslatableCaption.of("schematics.schematic_paste_success"));
|
||||
|
@ -28,6 +28,7 @@ package com.plotsquared.core.plot;
|
||||
import com.plotsquared.core.command.Template;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.FileBytes;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
@ -61,7 +62,10 @@ public abstract class PlotManager {
|
||||
// the same applies here
|
||||
public abstract Location getPlotTopLocAbs(@Nonnull PlotId plotId);
|
||||
|
||||
public abstract boolean clearPlot(@Nonnull Plot plot, @Nullable Runnable whenDone, @Nullable QueueCoordinator queue);
|
||||
public abstract boolean clearPlot(@Nonnull Plot plot,
|
||||
@Nullable Runnable whenDone,
|
||||
@Nullable PlotPlayer<?> actor,
|
||||
@Nullable QueueCoordinator queue);
|
||||
|
||||
public abstract boolean claimPlot(@Nonnull Plot plot, @Nullable QueueCoordinator queue);
|
||||
|
||||
@ -98,6 +102,7 @@ public abstract class PlotManager {
|
||||
* @param plotId id of plot to set component to
|
||||
* @param component FLOOR, WALL, AIR, MAIN, MIDDLE, OUTLINE, BORDER, ALL (floor, air and main).
|
||||
* @param blocks Pattern to set component to
|
||||
* @param actor The player executing the task
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return success or not
|
||||
@ -105,6 +110,7 @@ public abstract class PlotManager {
|
||||
public abstract boolean setComponent(@Nonnull PlotId plotId,
|
||||
@Nonnull String component,
|
||||
@Nonnull Pattern blocks,
|
||||
@Nullable PlotPlayer<?> actor,
|
||||
@Nullable QueueCoordinator queue);
|
||||
|
||||
/**
|
||||
|
@ -25,8 +25,10 @@
|
||||
*/
|
||||
package com.plotsquared.core.plot;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.ConfigurationUtil;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.Caption;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.database.DBFunc;
|
||||
@ -35,6 +37,7 @@ import com.plotsquared.core.events.PlotMergeEvent;
|
||||
import com.plotsquared.core.events.PlotUnlinkEvent;
|
||||
import com.plotsquared.core.events.Result;
|
||||
import com.plotsquared.core.generator.SquarePlotWorld;
|
||||
import com.plotsquared.core.inject.factory.ProgressSubscriberFactory;
|
||||
import com.plotsquared.core.location.Direction;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
@ -75,8 +78,9 @@ public final class PlotModificationManager {
|
||||
private static final Logger logger = LoggerFactory.getLogger("P2/" + PlotModificationManager.class.getSimpleName());
|
||||
|
||||
private final Plot plot;
|
||||
@Inject private ProgressSubscriberFactory subscriberFactory;
|
||||
|
||||
PlotModificationManager(@Nonnull final Plot plot) {
|
||||
@Inject PlotModificationManager(@Nonnull final Plot plot) {
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
@ -85,9 +89,10 @@ public final class PlotModificationManager {
|
||||
* Copy a plot to a location, both physically and the settings
|
||||
*
|
||||
* @param destination destination plot
|
||||
* @param actor the actor associated with the copy
|
||||
* @return Future that completes with {@code true} if the copy was successful, else {@code false}
|
||||
*/
|
||||
public CompletableFuture<Boolean> copy(@Nonnull final Plot destination) {
|
||||
public CompletableFuture<Boolean> copy(@Nonnull final Plot destination, @Nullable PlotPlayer<?> actor) {
|
||||
final CompletableFuture<Boolean> future = new CompletableFuture<>();
|
||||
final PlotId offset = PlotId.of(destination.getId().getX() - this.plot.getId().getX(), destination.getId().getY() - this.plot.getId().getY());
|
||||
final Location db = destination.getBottomAbs();
|
||||
@ -169,7 +174,7 @@ public final class PlotModificationManager {
|
||||
Location pos1 = corners[0];
|
||||
Location pos2 = corners[1];
|
||||
Location newPos = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
|
||||
PlotSquared.platform().getRegionManager().copyRegion(pos1, pos2, newPos, this);
|
||||
PlotSquared.platform().getRegionManager().copyRegion(pos1, pos2, newPos, actor, this);
|
||||
}
|
||||
};
|
||||
run.run();
|
||||
@ -180,22 +185,26 @@ public final class PlotModificationManager {
|
||||
* Clear the plot
|
||||
*
|
||||
* @param whenDone A runnable to execute when clearing finishes, or null
|
||||
* @see #clear(boolean, boolean, Runnable)
|
||||
* @see #deletePlot(Runnable) to clear and delete a plot
|
||||
* @see #clear(boolean, boolean, PlotPlayer, Runnable)
|
||||
* @see #deletePlot(PlotPlayer, Runnable) to clear and delete a plot
|
||||
*/
|
||||
public void clear(@Nullable final Runnable whenDone) {
|
||||
this.clear(false, false, whenDone);
|
||||
this.clear(false, false, null, whenDone);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear the plot
|
||||
*
|
||||
* @param checkRunning Whether or not already executing tasks should be checked
|
||||
* @param isDelete Whether or not the plot is being deleted
|
||||
* @param whenDone A runnable to execute when clearing finishes, or null
|
||||
* @see #deletePlot(Runnable) to clear and delete a plot
|
||||
* @param isDelete Whether or not the plot is being deleted
|
||||
* @param actor The actor clearing the plot
|
||||
* @param whenDone A runnable to execute when clearing finishes, or null
|
||||
* @see #deletePlot(PlotPlayer, Runnable) to clear and delete a plot
|
||||
*/
|
||||
public boolean clear(final boolean checkRunning, final boolean isDelete, @Nullable final Runnable whenDone) {
|
||||
public boolean clear(final boolean checkRunning,
|
||||
final boolean isDelete,
|
||||
@Nullable final PlotPlayer<?> actor,
|
||||
@Nullable final Runnable whenDone) {
|
||||
if (checkRunning && this.plot.getRunning() != 0) {
|
||||
return false;
|
||||
}
|
||||
@ -229,6 +238,9 @@ public final class PlotModificationManager {
|
||||
manager.claimPlot(current, queue);
|
||||
}
|
||||
}
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
}
|
||||
if (queue.size() > 0) {
|
||||
queue.enqueue();
|
||||
}
|
||||
@ -245,7 +257,7 @@ public final class PlotModificationManager {
|
||||
}
|
||||
return;
|
||||
}
|
||||
manager.clearPlot(current, this, null);
|
||||
manager.clearPlot(current, this, actor, null);
|
||||
}
|
||||
};
|
||||
run.run();
|
||||
@ -352,11 +364,8 @@ public final class PlotModificationManager {
|
||||
if (this.plot.getArea().allowSigns()) {
|
||||
Location location = manager.getSignLoc(this.plot);
|
||||
String id = this.plot.getId().toString();
|
||||
Caption[] lines =
|
||||
new Caption[] {TranslatableCaption.of("signs.owner_sign_line_1"),
|
||||
TranslatableCaption.of("signs.owner_sign_line_2"),
|
||||
TranslatableCaption.of("signs.owner_sign_line_3"),
|
||||
TranslatableCaption.of("signs.owner_sign_line_4")};
|
||||
Caption[] lines = new Caption[] {TranslatableCaption.of("signs.owner_sign_line_1"), TranslatableCaption.of("signs.owner_sign_line_2"),
|
||||
TranslatableCaption.of("signs.owner_sign_line_3"), TranslatableCaption.of("signs.owner_sign_line_4")};
|
||||
PlotSquared.platform().getWorldUtil().setSign(location, lines, Template.of("id", id), Template.of("owner", name));
|
||||
}
|
||||
}
|
||||
@ -387,8 +396,8 @@ public final class PlotModificationManager {
|
||||
return;
|
||||
}
|
||||
Location location = manager.getSignLoc(this.plot);
|
||||
QueueCoordinator queue = PlotSquared.platform().getGlobalBlockQueue()
|
||||
.getNewQueue(PlotSquared.platform().getWorldUtil().getWeWorld(this.plot.getWorldName()));
|
||||
QueueCoordinator queue =
|
||||
PlotSquared.platform().getGlobalBlockQueue().getNewQueue(PlotSquared.platform().getWorldUtil().getWeWorld(this.plot.getWorldName()));
|
||||
queue.setBlock(location.getX(), location.getY(), location.getZ(), BlockTypes.AIR.getDefaultState());
|
||||
queue.enqueue();
|
||||
}
|
||||
@ -450,17 +459,15 @@ public final class PlotModificationManager {
|
||||
if (notify && plotworld.isAutoMerge()) {
|
||||
final PlotPlayer<?> player = PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid);
|
||||
|
||||
PlotMergeEvent
|
||||
event = PlotSquared.get().getEventDispatcher().callMerge(this.plot, Direction.ALL, Integer.MAX_VALUE, player);
|
||||
PlotMergeEvent event = PlotSquared.get().getEventDispatcher().callMerge(this.plot, Direction.ALL, Integer.MAX_VALUE, player);
|
||||
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
if (player != null) {
|
||||
player.sendMessage(TranslatableCaption.of("events.event_denied"),
|
||||
Template.of("value", "Auto merge on claim"));
|
||||
player.sendMessage(TranslatableCaption.of("events.event_denied"), Template.of("value", "Auto merge on claim"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
plot.getPlotModificationManager().autoMerge(event.getDir(), event.getMax(), uuid, true);
|
||||
plot.getPlotModificationManager().autoMerge(event.getDir(), event.getMax(), uuid, player, true);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
@ -495,10 +502,15 @@ public final class PlotModificationManager {
|
||||
* @param dir the direction to merge
|
||||
* @param max the max number of merges to do
|
||||
* @param uuid the UUID it is allowed to merge with
|
||||
* @param actor The actor executing the task
|
||||
* @param removeRoads whether to remove roads
|
||||
* @return {@code true} if a merge takes place, else {@code false}
|
||||
*/
|
||||
public boolean autoMerge(@Nonnull final Direction dir, int max, @Nonnull final UUID uuid, final boolean removeRoads) {
|
||||
public boolean autoMerge(@Nonnull final Direction dir,
|
||||
int max,
|
||||
@Nonnull final UUID uuid,
|
||||
@Nullable PlotPlayer<?> actor,
|
||||
final boolean removeRoads) {
|
||||
//Ignore merging if there is no owner for the plot
|
||||
if (!this.plot.hasOwner()) {
|
||||
return false;
|
||||
@ -584,6 +596,9 @@ public final class PlotModificationManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
}
|
||||
if (queue.size() > 0) {
|
||||
queue.enqueue();
|
||||
}
|
||||
@ -595,11 +610,13 @@ public final class PlotModificationManager {
|
||||
* Moves a plot physically, as well as the corresponding settings.
|
||||
*
|
||||
* @param destination Plot moved to
|
||||
* @param actor The actor executing the task
|
||||
* @param whenDone task when done
|
||||
* @param allowSwap whether to swap plots
|
||||
* @return {@code true} if the move was successful, else {@code false}
|
||||
*/
|
||||
@Nonnull public CompletableFuture<Boolean> move(@Nonnull final Plot destination,
|
||||
@Nullable final PlotPlayer<?> actor,
|
||||
@Nonnull final Runnable whenDone,
|
||||
final boolean allowSwap) {
|
||||
final PlotId offset = PlotId.of(destination.getId().getX() - this.plot.getId().getX(), destination.getId().getY() - this.plot.getId().getY());
|
||||
@ -669,7 +686,7 @@ public final class PlotModificationManager {
|
||||
Location pos1 = corners[0];
|
||||
Location pos2 = corners[1];
|
||||
Location pos3 = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
|
||||
PlotSquared.platform().getRegionManager().swap(pos1, pos2, pos3, this);
|
||||
PlotSquared.platform().getRegionManager().swap(pos1, pos2, pos3, actor, this);
|
||||
}
|
||||
}
|
||||
}.run();
|
||||
@ -678,7 +695,8 @@ public final class PlotModificationManager {
|
||||
@Override public void run() {
|
||||
if (regions.isEmpty()) {
|
||||
Plot plot = destination.getRelative(0, 0);
|
||||
Plot originPlot = originArea.getPlotAbs(PlotId.of(plot.getId().getX() - offset.getX(), plot.getId().getY() - offset.getY()));
|
||||
Plot originPlot =
|
||||
originArea.getPlotAbs(PlotId.of(plot.getId().getX() - offset.getX(), plot.getId().getY() - offset.getY()));
|
||||
final Runnable clearDone = () -> {
|
||||
QueueCoordinator queue = PlotModificationManager.this.plot.getArea().getQueue();
|
||||
for (final Plot current : plot.getConnectedPlots()) {
|
||||
@ -691,7 +709,7 @@ public final class PlotModificationManager {
|
||||
TaskManager.runTask(whenDone);
|
||||
};
|
||||
if (originPlot != null) {
|
||||
originPlot.getPlotModificationManager().clear(false, true, clearDone);
|
||||
originPlot.getPlotModificationManager().clear(false, true, actor, clearDone);
|
||||
} else {
|
||||
clearDone.run();
|
||||
}
|
||||
@ -703,7 +721,7 @@ public final class PlotModificationManager {
|
||||
final Location pos1 = corners[0];
|
||||
final Location pos2 = corners[1];
|
||||
Location newPos = pos1.add(offsetX, 0, offsetZ).withWorld(destination.getWorldName());
|
||||
PlotSquared.platform().getRegionManager().copyRegion(pos1, pos2, newPos, task);
|
||||
PlotSquared.platform().getRegionManager().copyRegion(pos1, pos2, newPos, actor, task);
|
||||
}
|
||||
}.run();
|
||||
}
|
||||
@ -726,11 +744,14 @@ public final class PlotModificationManager {
|
||||
* - The destination must correspond to a valid plot of equal dimensions
|
||||
*
|
||||
* @param destination The other plot to swap with
|
||||
* @param actor The actor executing the task
|
||||
* @param whenDone A task to run when finished, or null
|
||||
* @return Future that completes with {@code true} if the swap was successful, else {@code false}
|
||||
*/
|
||||
@Nonnull public CompletableFuture<Boolean> swap(@Nonnull final Plot destination, @Nonnull final Runnable whenDone) {
|
||||
return this.move(destination, whenDone, true);
|
||||
@Nonnull public CompletableFuture<Boolean> swap(@Nonnull final Plot destination,
|
||||
@Nullable PlotPlayer<?> actor,
|
||||
@Nonnull final Runnable whenDone) {
|
||||
return this.move(destination, actor, whenDone, true);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -738,11 +759,14 @@ public final class PlotModificationManager {
|
||||
* - The location must be empty
|
||||
*
|
||||
* @param destination Where to move the plot
|
||||
* @param actor The actor executing the task
|
||||
* @param whenDone A task to run when done, or null
|
||||
* @return Future that completes with {@code true} if the move was successful, else {@code false}
|
||||
*/
|
||||
@Nonnull public CompletableFuture<Boolean> move(@Nonnull final Plot destination, @Nonnull final Runnable whenDone) {
|
||||
return this.move(destination, whenDone, false);
|
||||
@Nonnull public CompletableFuture<Boolean> move(@Nonnull final Plot destination,
|
||||
@Nullable PlotPlayer<?> actor,
|
||||
@Nonnull final Runnable whenDone) {
|
||||
return this.move(destination, actor, whenDone, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -752,31 +776,34 @@ public final class PlotModificationManager {
|
||||
*
|
||||
* @param component Component to set
|
||||
* @param blocks Pattern to use the generation
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @param actor The actor executing the task
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return {@code true} if the component was set successfully, else {@code false}
|
||||
*/
|
||||
public boolean setComponent(@Nonnull final String component, @Nonnull final Pattern blocks, @Nullable final QueueCoordinator queue) {
|
||||
public boolean setComponent(@Nonnull final String component,
|
||||
@Nonnull final Pattern blocks,
|
||||
@Nullable PlotPlayer<?> actor,
|
||||
@Nullable final QueueCoordinator queue) {
|
||||
final PlotComponentSetEvent event = PlotSquared.get().getEventDispatcher().callComponentSet(this.plot, component, blocks);
|
||||
return this.plot.getManager().setComponent(this.plot.getId(), event.getComponent(), event.getPattern(), queue);
|
||||
return this.plot.getManager().setComponent(this.plot.getId(), event.getComponent(), event.getPattern(), actor, queue);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a plot (use null for the runnable if you don't need to be notified on completion)
|
||||
*
|
||||
* @see PlotSquared#removePlot(Plot, boolean)
|
||||
* @see PlotModificationManager#clear(boolean, boolean, Runnable) to simply clear a plot
|
||||
*
|
||||
* @param actor The actor executing the task
|
||||
* @param whenDone task to run when plot has been deleted. Nullable
|
||||
*
|
||||
* @return {@code true} if the deletion was successful, {@code false} if not
|
||||
* @see PlotSquared#removePlot(Plot, boolean)
|
||||
* @see PlotModificationManager#clear(boolean, boolean, PlotPlayer, Runnable) to simply clear a plot
|
||||
*/
|
||||
public boolean deletePlot(final Runnable whenDone) {
|
||||
public boolean deletePlot(@Nullable PlotPlayer<?> actor, final Runnable whenDone) {
|
||||
if (!this.plot.hasOwner()) {
|
||||
return false;
|
||||
}
|
||||
final Set<Plot> plots = this.plot.getConnectedPlots();
|
||||
this.clear(false, true, () -> {
|
||||
this.clear(false, true, actor, () -> {
|
||||
for (Plot current : plots) {
|
||||
current.unclaim();
|
||||
}
|
||||
@ -790,18 +817,18 @@ public final class PlotModificationManager {
|
||||
* (components are generator specific)
|
||||
*
|
||||
* @param component component to set
|
||||
* @param blocks string of block(s) to set component to
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
*
|
||||
* @param blocks string of block(s) to set component to
|
||||
* @param actor The player executing the task
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return {@code true} if the update was successful, {@code false} if not
|
||||
*/
|
||||
@Deprecated public boolean setComponent(String component, String blocks, QueueCoordinator queue) {
|
||||
@Deprecated public boolean setComponent(String component, String blocks, @Nullable PlotPlayer<?> actor, @Nullable QueueCoordinator queue) {
|
||||
final BlockBucket parsed = ConfigurationUtil.BLOCK_BUCKET.parseString(blocks);
|
||||
if (parsed != null && parsed.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
return this.setComponent(component, parsed.toPattern(), queue);
|
||||
return this.setComponent(component, parsed.toPattern(), actor, queue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -426,7 +426,7 @@ public class ExpireManager {
|
||||
Templates.of("plot", plot.toString()));
|
||||
}
|
||||
}
|
||||
plot.getPlotModificationManager().deletePlot(whenDone);
|
||||
plot.getPlotModificationManager().deletePlot(null, whenDone);
|
||||
}
|
||||
|
||||
public long getAge(UUID uuid) {
|
||||
|
@ -27,6 +27,7 @@ package com.plotsquared.core.plot.world;
|
||||
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotId;
|
||||
@ -64,7 +65,7 @@ public class SinglePlotManager extends PlotManager {
|
||||
return Location.at(plotId.toCommaSeparatedString(), 30000000, 0, 30000000);
|
||||
}
|
||||
|
||||
@Override public boolean clearPlot(@NotNull Plot plot, final Runnable whenDone, @Nullable QueueCoordinator queue) {
|
||||
@Override public boolean clearPlot(@NotNull Plot plot, final Runnable whenDone, @Nullable PlotPlayer<?> actor, @Nullable QueueCoordinator queue) {
|
||||
PlotSquared.platform().getSetupUtils().unload(plot.getWorldName(), false);
|
||||
final File worldFolder = new File(PlotSquared.platform().getWorldContainer(), plot.getWorldName());
|
||||
TaskManager.getPlatformImplementation().taskAsync(() -> {
|
||||
@ -96,8 +97,11 @@ public class SinglePlotManager extends PlotManager {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setComponent(@NotNull PlotId plotId, @NotNull String component, @NotNull Pattern blocks, @Nullable QueueCoordinator queue) {
|
||||
@Override public boolean setComponent(@NotNull PlotId plotId,
|
||||
@NotNull String component,
|
||||
@NotNull Pattern blocks,
|
||||
@Nullable PlotPlayer<?> actor,
|
||||
@Nullable QueueCoordinator queue) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -27,6 +27,7 @@ package com.plotsquared.core.queue;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.inject.factory.ChunkCoordinatorFactory;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
|
||||
@ -54,8 +55,8 @@ public class ChunkCoordinatorBuilder {
|
||||
private Consumer<BlockVector2> chunkConsumer;
|
||||
private Runnable whenDone = () -> {
|
||||
};
|
||||
private long maxIterationTime = 60; // A little over 1 tick;
|
||||
private int initialBatchSize = 4;
|
||||
private long maxIterationTime = Settings.QUEUE.MAX_ITERATION_TIME; // A little over 1 tick;
|
||||
private int initialBatchSize = Settings.QUEUE.INITIAL_BATCH_SIZE;
|
||||
private boolean unloadAfter = true;
|
||||
|
||||
@Inject public ChunkCoordinatorBuilder(@Nonnull ChunkCoordinatorFactory chunkCoordinatorFactory) {
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package com.plotsquared.core.queue;
|
||||
|
||||
import com.plotsquared.core.queue.subscriber.ProgressSubscriber;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.function.pattern.Pattern;
|
||||
@ -203,6 +204,12 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void addProgressSubscriber(@Nonnull ProgressSubscriber progressSubscriber) {
|
||||
if (parent != null) {
|
||||
parent.addProgressSubscriber(progressSubscriber);
|
||||
}
|
||||
}
|
||||
|
||||
@Override @Nonnull public List<BlockVector2> getReadChunks() {
|
||||
if (parent != null) {
|
||||
return parent.getReadChunks();
|
||||
@ -246,6 +253,5 @@ public class DelegateQueueCoordinator extends QueueCoordinator {
|
||||
if (parent != null) {
|
||||
parent.setRegenRegion(regenRegion);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -26,8 +26,12 @@
|
||||
|
||||
package com.plotsquared.core.queue.subscriber;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.util.concurrent.AtomicDouble;
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.Caption;
|
||||
import com.plotsquared.core.configuration.caption.TranslatableCaption;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.queue.ChunkCoordinator;
|
||||
import com.plotsquared.core.util.task.PlotSquaredTask;
|
||||
@ -48,33 +52,43 @@ public class DefaultProgressSubscriber implements ProgressSubscriber {
|
||||
|
||||
@Nonnull private final AtomicDouble progress = new AtomicDouble(0);
|
||||
@Nonnull private final AtomicBoolean started = new AtomicBoolean(false);
|
||||
@Nonnull private final TaskManager taskManager;
|
||||
@Nonnull private final TaskTime interval;
|
||||
@Nonnull private final TaskTime wait;
|
||||
@Nonnull private final PlotPlayer<?> actor;
|
||||
@Nonnull private final Caption caption;
|
||||
@Inject @Nonnull private TaskManager taskManager;
|
||||
private PlotSquaredTask task;
|
||||
|
||||
public DefaultProgressSubscriber(@Nullable final PlotPlayer<?> actor,
|
||||
@Nonnull final TaskTime interval,
|
||||
@Nonnull TaskManager taskManager,
|
||||
@Nullable Caption caption) {
|
||||
if (actor == null) {
|
||||
throw new NullPointerException(
|
||||
"Actor cannot be null when using DefaultProgressSubscriber! Make sure if attempting to use custom Subscribers it is correctly parsed to the queue!");
|
||||
}
|
||||
if (caption == null) {
|
||||
throw new NullPointerException(
|
||||
"Caption cannot be null when using DefaultProgressSubscriber! Make sure if attempting to use custom Subscribers it is correctly parsed to the queue!");
|
||||
}
|
||||
this.interval = interval;
|
||||
this.taskManager = taskManager;
|
||||
@Inject public DefaultProgressSubscriber(@Nonnull final PlotPlayer<?> actor) {
|
||||
Preconditions.checkNotNull(actor,
|
||||
"Actor cannot be null when using DefaultProgressSubscriber! Make sure if attempting to use custom Subscribers it is correctly parsed to the queue!");
|
||||
this.actor = actor;
|
||||
this.caption = caption;
|
||||
this.interval = TaskTime.ms(Settings.QUEUE.NOTIFY_INTERVAL);
|
||||
this.wait = TaskTime.ms(Settings.QUEUE.NOTIFY_WAIT);
|
||||
this.caption = TranslatableCaption.of("working.progress");
|
||||
}
|
||||
|
||||
public DefaultProgressSubscriber(@Nonnull final PlotPlayer<?> actor,
|
||||
@Nonnull final TaskManager taskManager,
|
||||
final long interval,
|
||||
final long wait,
|
||||
@Nullable final Caption caption) {
|
||||
Preconditions.checkNotNull(actor,
|
||||
"Actor cannot be null when using DefaultProgressSubscriber! Make sure if attempting to use custom Subscribers it is correctly parsed to the queue!");
|
||||
this.actor = actor;
|
||||
this.interval = TaskTime.ms(interval);
|
||||
this.wait = TaskTime.ms(wait);
|
||||
this.taskManager = taskManager;
|
||||
if (caption == null) {
|
||||
this.caption = TranslatableCaption.of("working.progress");
|
||||
} else {
|
||||
this.caption = caption;
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void notifyProgress(@Nonnull ChunkCoordinator coordinator, float progress) {
|
||||
this.progress.set((double) Math.round(progress * 100) / 100);
|
||||
if (coordinator.isCancelled() || progress == 1) {
|
||||
this.progress.set(progress);
|
||||
if (coordinator.isCancelled() || progress >= 1) {
|
||||
if (task != null) {
|
||||
task.cancel();
|
||||
}
|
||||
@ -83,8 +97,8 @@ public class DefaultProgressSubscriber implements ProgressSubscriber {
|
||||
if (!started.get()) {
|
||||
return;
|
||||
}
|
||||
actor.sendMessage(caption, Template.of("%s", this.progress.toString()));
|
||||
}, interval), interval);
|
||||
actor.sendMessage(caption, Template.of("progress", String.valueOf((double) Math.round(this.progress.doubleValue() * 100) / 100)));
|
||||
}, interval), wait);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,11 @@ package com.plotsquared.core.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.StaticCaption;
|
||||
import com.plotsquared.core.inject.factory.ProgressSubscriberFactory;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.PlotManager;
|
||||
@ -59,6 +63,8 @@ public abstract class RegionManager {
|
||||
public static RegionManager manager = null;
|
||||
private final WorldUtil worldUtil;
|
||||
private final GlobalBlockQueue blockQueue;
|
||||
@Inject private ProgressSubscriberFactory subscriberFactory;
|
||||
@Inject private TaskManager taskManager;
|
||||
|
||||
@Inject public RegionManager(@Nonnull WorldUtil worldUtil, @Nonnull GlobalBlockQueue blockQueue) {
|
||||
this.worldUtil = worldUtil;
|
||||
@ -106,20 +112,25 @@ public abstract class RegionManager {
|
||||
* @param blocks pattern
|
||||
* @param minY y to set from
|
||||
* @param maxY y to set to
|
||||
* @param actor the actor associated with the cuboid set
|
||||
* @param queue Nullable {@link QueueCoordinator}. If null, creates own queue and enqueues,
|
||||
* otherwise writes to the queue but does not enqueue.
|
||||
* @return true if not enqueued, otherwise whether the created queue enqueued.
|
||||
*/
|
||||
public boolean setCuboids(final PlotArea area,
|
||||
final Set<CuboidRegion> regions,
|
||||
final Pattern blocks,
|
||||
public boolean setCuboids(@Nonnull final PlotArea area,
|
||||
@Nonnull final Set<CuboidRegion> regions,
|
||||
@Nonnull final Pattern blocks,
|
||||
int minY,
|
||||
int maxY,
|
||||
@Nullable PlotPlayer<?> actor,
|
||||
@Nullable QueueCoordinator queue) {
|
||||
boolean enqueue = false;
|
||||
if (queue == null) {
|
||||
queue = area.getQueue();
|
||||
enqueue = true;
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
}
|
||||
}
|
||||
for (CuboidRegion region : regions) {
|
||||
Location pos1 = Location.at(area.getWorldName(), region.getMinimumPoint().getX(), minY, region.getMinimumPoint().getZ());
|
||||
@ -145,9 +156,13 @@ public abstract class RegionManager {
|
||||
* @param plot plot
|
||||
* @param whenDone task to run when complete
|
||||
* @param manager plot manager
|
||||
* @param actor the player running the clear
|
||||
* @return true if the clear worked. False if someone went wrong so P2 can then handle the clear
|
||||
*/
|
||||
public abstract boolean handleClear(Plot plot, final Runnable whenDone, PlotManager manager);
|
||||
public abstract boolean handleClear(@Nonnull Plot plot,
|
||||
@Nullable final Runnable whenDone,
|
||||
@Nonnull PlotManager manager,
|
||||
@Nullable PlotPlayer<?> actor);
|
||||
|
||||
/**
|
||||
* Copy a region to a new location (in the same world)
|
||||
@ -155,10 +170,15 @@ public abstract class RegionManager {
|
||||
* @param pos1 position 1
|
||||
* @param pos2 position 2
|
||||
* @param newPos position to move pos1 to
|
||||
* @param actor the actor associated with the region copy
|
||||
* @param whenDone task to run when complete
|
||||
* @return success or not
|
||||
*/
|
||||
public boolean copyRegion(final Location pos1, final Location pos2, final Location newPos, final Runnable whenDone) {
|
||||
public boolean copyRegion(@Nonnull final Location pos1,
|
||||
@Nonnull final Location pos2,
|
||||
@Nonnull final Location newPos,
|
||||
@Nullable final PlotPlayer<?> actor,
|
||||
@Nonnull final Runnable whenDone) {
|
||||
final int relX = newPos.getX() - pos1.getX();
|
||||
final int relZ = newPos.getZ() - pos1.getZ();
|
||||
final com.sk89q.worldedit.world.World oldWorld = worldUtil.getWeWorld(pos1.getWorldName());
|
||||
@ -167,9 +187,17 @@ public abstract class RegionManager {
|
||||
final BasicQueueCoordinator copyTo = (BasicQueueCoordinator) blockQueue.getNewQueue(newWorld);
|
||||
copyFromTo(pos1, pos2, relX, relZ, oldWorld, copyFrom, copyTo, false);
|
||||
copyFrom.setCompleteTask(copyTo::enqueue);
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
copyFrom.addProgressSubscriber(subscriberFactory.create(actor, taskManager, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
StaticCaption.of("<prefix><gray>Current copy progress: </gray><gold><progress></gold><gray>%</gray>")));
|
||||
}
|
||||
copyFrom
|
||||
.addReadChunks(new CuboidRegion(BlockVector3.at(pos1.getX(), 0, pos1.getZ()), BlockVector3.at(pos2.getX(), 0, pos2.getZ())).getChunks());
|
||||
copyTo.setCompleteTask(whenDone);
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
copyTo.addProgressSubscriber(subscriberFactory.create(actor, taskManager, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
StaticCaption.of("<prefix><gray>Current paste progress: </gray><gold><progress></gold><gray>%</gray>")));
|
||||
}
|
||||
return copyFrom.enqueue();
|
||||
}
|
||||
|
||||
@ -188,7 +216,16 @@ public abstract class RegionManager {
|
||||
|
||||
public abstract void clearAllEntities(Location pos1, Location pos2);
|
||||
|
||||
public void swap(Location pos1, Location pos2, Location swapPos, final Runnable whenDone) {
|
||||
/**
|
||||
* Swap two regions withn the same world
|
||||
*
|
||||
* @param pos1 position 1
|
||||
* @param pos2 position 2
|
||||
* @param swapPos position to swap with
|
||||
* @param actor the actor associated with the region copy
|
||||
* @param whenDone task to run when complete
|
||||
*/
|
||||
public void swap(Location pos1, Location pos2, Location swapPos, @Nullable final PlotPlayer<?> actor, final Runnable whenDone) {
|
||||
int relX = swapPos.getX() - pos1.getX();
|
||||
int relZ = swapPos.getZ() - pos1.getZ();
|
||||
|
||||
@ -208,9 +245,26 @@ public abstract class RegionManager {
|
||||
copyFromTo(pos1, pos2, relX, relZ, world1, fromQueue1, toQueue2, true);
|
||||
copyFromTo(pos1, pos2, relX, relZ, world1, fromQueue2, toQueue1, true);
|
||||
fromQueue1.setCompleteTask(fromQueue2::enqueue);
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
fromQueue1.addProgressSubscriber(subscriberFactory.create(actor, taskManager, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
StaticCaption.of("<prefix><gray>Current region 1 copy progress: </gray><gold><progress></gold><gray>%</gray>")));
|
||||
}
|
||||
fromQueue2.setCompleteTask(toQueue1::enqueue);
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
fromQueue2.addProgressSubscriber(subscriberFactory.create(actor, taskManager, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
StaticCaption.of("<prefix><gray>Current region 2 copy progress: </gray><gold><progress></gold><gray>%</gray>")));
|
||||
}
|
||||
toQueue1.setCompleteTask(toQueue2::enqueue);
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
toQueue1.addProgressSubscriber(subscriberFactory.create(actor, taskManager, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
StaticCaption.of("<prefix><gray>Current region 1 paste progress: </gray><gold><progress></gold><gray>%</gray>")));
|
||||
}
|
||||
toQueue2.setCompleteTask(whenDone);
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
toQueue2.addProgressSubscriber(subscriberFactory.create(actor, taskManager, Settings.QUEUE.NOTIFY_INTERVAL, Settings.QUEUE.NOTIFY_WAIT,
|
||||
StaticCaption.of("<prefix><gray>Current region 2 paste progress: </gray><gold><progress></gold><gray>%</gray>")));
|
||||
}
|
||||
fromQueue1.enqueue();
|
||||
}
|
||||
|
||||
private void copyFromTo(Location pos1,
|
||||
|
@ -25,10 +25,13 @@
|
||||
*/
|
||||
package com.plotsquared.core.util;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.generator.ClassicPlotWorld;
|
||||
import com.plotsquared.core.inject.factory.ProgressSubscriberFactory;
|
||||
import com.plotsquared.core.location.Location;
|
||||
import com.plotsquared.core.player.PlotPlayer;
|
||||
import com.plotsquared.core.plot.Plot;
|
||||
import com.plotsquared.core.plot.PlotArea;
|
||||
import com.plotsquared.core.plot.schematic.Schematic;
|
||||
@ -109,8 +112,9 @@ public abstract class SchematicHandler {
|
||||
public static SchematicHandler manager;
|
||||
private final WorldUtil worldUtil;
|
||||
private boolean exportAll = false;
|
||||
@Inject private ProgressSubscriberFactory subscriberFactory;
|
||||
|
||||
public SchematicHandler(@Nonnull final WorldUtil worldUtil) {
|
||||
@Inject public SchematicHandler(@Nonnull final WorldUtil worldUtil) {
|
||||
this.worldUtil = worldUtil;
|
||||
}
|
||||
|
||||
@ -257,6 +261,7 @@ public abstract class SchematicHandler {
|
||||
* @param yOffset offset y to paste it from plot origin
|
||||
* @param zOffset offset z to paste it from plot origin
|
||||
* @param autoHeight if to automatically choose height to paste from
|
||||
* @param actor the actor pasting the schematic
|
||||
* @param whenDone task to run when schematic is pasted
|
||||
*/
|
||||
public void paste(final Schematic schematic,
|
||||
@ -265,6 +270,7 @@ public abstract class SchematicHandler {
|
||||
final int yOffset,
|
||||
final int zOffset,
|
||||
final boolean autoHeight,
|
||||
final PlotPlayer<?> actor,
|
||||
final RunnableVal<Boolean> whenDone) {
|
||||
|
||||
TaskManager.runTask(() -> {
|
||||
@ -344,6 +350,9 @@ public abstract class SchematicHandler {
|
||||
if (whenDone != null) {
|
||||
whenDone.value = true;
|
||||
}
|
||||
if (actor != null && Settings.QUEUE.NOTIFY_PROGRESS) {
|
||||
queue.addProgressSubscriber(subscriberFactory.create(actor));
|
||||
}
|
||||
queue.setCompleteTask(whenDone);
|
||||
queue.enqueue();
|
||||
} catch (Exception e) {
|
||||
|
@ -41,13 +41,13 @@ import java.util.concurrent.Callable;
|
||||
|
||||
public final class AutoClaimFinishTask implements Callable<Boolean> {
|
||||
|
||||
private final PlotPlayer player;
|
||||
private final PlotPlayer<?> player;
|
||||
private final Plot plot;
|
||||
private final PlotArea area;
|
||||
private final String schematic;
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
public AutoClaimFinishTask(final PlotPlayer player, final Plot plot, final PlotArea area,
|
||||
public AutoClaimFinishTask(final PlotPlayer<?> player, final Plot plot, final PlotArea area,
|
||||
final String schematic, final EventDispatcher eventDispatcher) {
|
||||
this.player = player;
|
||||
this.plot = plot;
|
||||
@ -72,7 +72,7 @@ public final class AutoClaimFinishTask implements Callable<Boolean> {
|
||||
player.sendMessage(TranslatableCaption.of("events.event_denied"),
|
||||
Templates.of("value", "Auto Merge"));
|
||||
} else {
|
||||
plot.getPlotModificationManager().autoMerge(event.getDir(), event.getMax(), player.getUUID(), true);
|
||||
plot.getPlotModificationManager().autoMerge(event.getDir(), event.getMax(), player.getUUID(), player, true);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -410,6 +410,7 @@
|
||||
"working.plot_not_claimed": "<prefix><gray>Plot not claimed.</gray>",
|
||||
"working.plot_is_claimed": "<prefix><gray>This plot is already claimed.</gray>",
|
||||
"working.claimed": "<prefix><dark_aqua>You successfully claimed the plot.</dark_aqua>",
|
||||
"working.progress": "<prefix><gray>Current progress: </gray><gold><progress></gold><gray>%</gray>",
|
||||
|
||||
"list.comment_list_header_paged": "<gray>(Page </gray><gold><cur></gold><gray>/</gray><gold><max></gold><gray>) </gray><gold>List of <amount> comments</gold>",
|
||||
"list.comment_list_comment": "<dark_gray>[</dark_gray><gray>#<number></gray><dark_gray>[</dark_gray><gray><world>;<plot_id></gray><dark_gray>][</dark_gray><gold><commenter></gold><dark_gray>]</dark_gray><comment>\n",
|
||||
|
Loading…
Reference in New Issue
Block a user