Merge branch 'v6' into v7

This commit is contained in:
Alexander Brandes
2022-05-18 22:13:29 +02:00
18 changed files with 213 additions and 70 deletions

View File

@ -25,7 +25,11 @@
*/
package com.plotsquared.bukkit.generator;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.generator.AugmentedUtils;
import com.plotsquared.core.queue.QueueCoordinator;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.util.SideEffectSet;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.generator.BlockPopulator;
@ -52,7 +56,14 @@ public class BukkitAugmentedGenerator extends BlockPopulator {
@Override
public void populate(@NonNull World world, @NonNull Random random, @NonNull Chunk source) {
AugmentedUtils.generate(source, world.getName(), source.getX(), source.getZ(), null);
QueueCoordinator queue = PlotSquared.platform().globalBlockQueue().getNewQueue(BukkitAdapter.adapt(world));
// The chunk is already loaded and we do not want to load the chunk in "fully" by using any PaperLib methods.
queue.setForceSync(true);
queue.setSideEffectSet(SideEffectSet.none());
queue.setBiomesEnabled(false);
queue.setChunkObject(source);
AugmentedUtils.generateChunk(world.getName(), source.getX(), source.getZ(), queue);
queue.enqueue();
}
}

View File

@ -168,6 +168,7 @@ public class EntityEventListener implements Listener {
case "RAID":
case "SHEARED":
case "SILVERFISH_BLOCK":
case "ENDER_PEARL":
case "TRAP":
case "VILLAGE_DEFENSE":
case "VILLAGE_INVASION":

View File

@ -198,6 +198,7 @@ public class PaperListener implements Listener {
case "RAID":
case "SHEARED":
case "SILVERFISH_BLOCK":
case "ENDER_PEARL":
case "TRAP":
case "VILLAGE_DEFENSE":
case "VILLAGE_INVASION":

View File

@ -76,10 +76,11 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
private final int totalSize;
private final AtomicInteger expectedSize;
private final AtomicInteger loadingChunks = new AtomicInteger();
private final boolean forceSync;
private int batchSize;
private PlotSquaredTask task;
private boolean shouldCancel;
private volatile boolean shouldCancel;
private boolean finished;
@Inject
@ -92,7 +93,8 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
@Assisted final @NonNull Runnable whenDone,
@Assisted final @NonNull Consumer<Throwable> throwableConsumer,
@Assisted final boolean unloadAfter,
@Assisted final @NonNull Collection<ProgressSubscriber> progressSubscribers
@Assisted final @NonNull Collection<ProgressSubscriber> progressSubscribers,
@Assisted final boolean forceSync
) {
this.requestedChunks = new LinkedBlockingQueue<>(requestedChunks);
this.availableChunks = new LinkedBlockingQueue<>();
@ -107,14 +109,27 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
this.plugin = JavaPlugin.getPlugin(BukkitPlatform.class);
this.bukkitWorld = Bukkit.getWorld(world.getName());
this.progressSubscribers.addAll(progressSubscribers);
this.forceSync = forceSync;
}
@Override
public void start() {
// Request initial batch
this.requestBatch();
// Wait until next tick to give the chunks a chance to be loaded
TaskManager.runTaskLater(() -> task = TaskManager.runTaskRepeat(this, TaskTime.ticks(1)), TaskTime.ticks(1));
if (!forceSync) {
// Request initial batch
this.requestBatch();
// Wait until next tick to give the chunks a chance to be loaded
TaskManager.runTaskLater(() -> task = TaskManager.runTaskRepeat(this, TaskTime.ticks(1)), TaskTime.ticks(1));
} else {
try {
while (!shouldCancel && !requestedChunks.isEmpty()) {
chunkConsumer.accept(requestedChunks.poll());
}
} catch (Throwable t) {
throwableConsumer.accept(t);
} finally {
finish();
}
}
}
@Override
@ -131,7 +146,9 @@ public final class BukkitChunkCoordinator extends ChunkCoordinator {
for (final ProgressSubscriber subscriber : this.progressSubscribers) {
subscriber.notifyEnd();
}
task.cancel();
if (task != null) {
task.cancel();
}
finished = true;
}
}

View File

@ -63,10 +63,27 @@ import java.util.function.Consumer;
public class BukkitQueueCoordinator extends BasicQueueCoordinator {
private final SideEffectSet noSideEffectSet;
private final SideEffectSet lightingSideEffectSet;
private final SideEffectSet edgeSideEffectSet;
private final SideEffectSet edgeLightingSideEffectSet;
private static final SideEffectSet NO_SIDE_EFFECT_SET;
private static final SideEffectSet EDGE_SIDE_EFFECT_SET;
private static final SideEffectSet LIGHTING_SIDE_EFFECT_SET;
private static final SideEffectSet EDGE_LIGHTING_SIDE_EFFECT_SET;
static {
NO_SIDE_EFFECT_SET = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(
SideEffect.NEIGHBORS,
SideEffect.State.OFF
);
EDGE_SIDE_EFFECT_SET = SideEffectSet.none().with(SideEffect.UPDATE, SideEffect.State.ON).with(
SideEffect.NEIGHBORS,
SideEffect.State.ON
);
LIGHTING_SIDE_EFFECT_SET = SideEffectSet.none().with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
EDGE_LIGHTING_SIDE_EFFECT_SET = SideEffectSet.none().with(SideEffect.UPDATE, SideEffect.State.ON).with(
SideEffect.NEIGHBORS,
SideEffect.State.ON
);
}
private org.bukkit.World bukkitWorld;
@Inject
private ChunkCoordinatorBuilderFactory chunkCoordinatorBuilderFactory;
@ -77,19 +94,6 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
@Inject
public BukkitQueueCoordinator(@NonNull World world) {
super(world);
noSideEffectSet = SideEffectSet.none().with(SideEffect.LIGHTING, SideEffect.State.OFF).with(
SideEffect.NEIGHBORS,
SideEffect.State.OFF
);
lightingSideEffectSet = SideEffectSet.none().with(SideEffect.NEIGHBORS, SideEffect.State.OFF);
edgeSideEffectSet = noSideEffectSet.with(SideEffect.UPDATE, SideEffect.State.ON).with(
SideEffect.NEIGHBORS,
SideEffect.State.ON
);
edgeLightingSideEffectSet = noSideEffectSet.with(SideEffect.UPDATE, SideEffect.State.ON).with(
SideEffect.NEIGHBORS,
SideEffect.State.ON
);
}
@Override
@ -202,7 +206,7 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
localChunk.getTiles().forEach((blockVector3, tag) -> {
try {
BaseBlock block = getWorld().getBlock(blockVector3).toBaseBlock(tag);
getWorld().setBlock(blockVector3, block, noSideEffectSet);
getWorld().setBlock(blockVector3, block, getSideEffectSet(SideEffectState.NONE));
} catch (WorldEditException ignored) {
StateWrapper sw = new StateWrapper(tag);
sw.restoreTag(getWorld().getName(), blockVector3.getX(), blockVector3.getY(), blockVector3.getZ());
@ -259,9 +263,9 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
}
SideEffectSet sideEffectSet;
if (lighting) {
sideEffectSet = edge ? edgeLightingSideEffectSet : lightingSideEffectSet;
sideEffectSet = getSideEffectSet(edge ? SideEffectState.EDGE_LIGHTING : SideEffectState.LIGHTING);
} else {
sideEffectSet = edge ? edgeSideEffectSet : noSideEffectSet;
sideEffectSet = getSideEffectSet(edge ? SideEffectState.EDGE : SideEffectState.NONE);
}
getWorld().setBlock(loc, block, sideEffectSet);
} catch (WorldEditException ignored) {
@ -382,4 +386,23 @@ public class BukkitQueueCoordinator extends BasicQueueCoordinator {
return false;
}
private SideEffectSet getSideEffectSet(SideEffectState state) {
if (getSideEffectSet() != null) {
return getSideEffectSet();
}
return switch (state) {
case NONE -> NO_SIDE_EFFECT_SET;
case EDGE -> EDGE_SIDE_EFFECT_SET;
case LIGHTING -> LIGHTING_SIDE_EFFECT_SET;
case EDGE_LIGHTING -> EDGE_LIGHTING_SIDE_EFFECT_SET;
};
}
private enum SideEffectState {
NONE,
EDGE,
LIGHTING,
EDGE_LIGHTING
}
}

View File

@ -76,7 +76,7 @@ public class BukkitSetupUtils extends SetupUtils {
@Override
public void updateGenerators(final boolean force) {
if (!SetupUtils.generators.isEmpty() && !force) {
if (loaded && !SetupUtils.generators.isEmpty() && !force) {
return;
}
String testWorld = "CheckingPlotSquaredGenerator";
@ -100,6 +100,7 @@ public class BukkitSetupUtils extends SetupUtils {
e.printStackTrace();
}
}
loaded = true;
}
@Override