Telesphoreo 2024-02-04 13:19:30 -06:00
commit b3346fe67b
12 changed files with 62 additions and 17 deletions

View File

@ -148,6 +148,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked."); throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked.");
} }
this.createCopy = createCopy; this.createCopy = createCopy;
// Increment regardless of whether copy will be created or not to return null from getCopy()
return ++this.copyKey; return ++this.copyKey;
} }

View File

@ -153,6 +153,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked."); throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked.");
} }
this.createCopy = createCopy; this.createCopy = createCopy;
// Increment regardless of whether copy will be created or not to return null from getCopy()
return ++this.copyKey; return ++this.copyKey;
} }

View File

@ -156,6 +156,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked."); throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked.");
} }
this.createCopy = createCopy; this.createCopy = createCopy;
// Increment regardless of whether copy will be created or not to return null from getCopy()
return ++this.copyKey; return ++this.copyKey;
} }

View File

@ -156,6 +156,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked."); throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked.");
} }
this.createCopy = createCopy; this.createCopy = createCopy;
// Increment regardless of whether copy will be created or not to return null from getCopy()
return ++this.copyKey; return ++this.copyKey;
} }

View File

@ -135,6 +135,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked."); throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked.");
} }
this.createCopy = createCopy; this.createCopy = createCopy;
// Increment regardless of whether copy will be created or not to return null from getCopy()
return ++this.copyKey; return ++this.copyKey;
} }

View File

@ -135,6 +135,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked."); throw new IllegalStateException("Attempting to set if chunk GET should create copy, but it is not call-locked.");
} }
this.createCopy = createCopy; this.createCopy = createCopy;
// Increment regardless of whether copy will be created or not to return null from getCopy()
return ++this.copyKey; return ++this.copyKey;
} }

View File

@ -245,6 +245,11 @@ public class TestOfflinePermissible implements OfflinePlayer, Permissible {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
@Override
public @Nullable Location getRespawnLocation() {
return null;
}
@Override @Override
public void incrementStatistic(@Nonnull Statistic statistic) throws IllegalArgumentException { public void incrementStatistic(@Nonnull Statistic statistic) throws IllegalArgumentException {
@ -365,4 +370,9 @@ public class TestOfflinePermissible implements OfflinePlayer, Permissible {
return null; return null;
} }
@Override
public @Nullable Location getLocation() {
return null;
}
} }

View File

@ -612,12 +612,38 @@ public enum FaweCache implements Trimable {
/* /*
Thread stuff Thread stuff
*/ */
/**
* Create a new blocking executor with default name and FaweCache logger
*
* @return new blocking executor
*/
public ThreadPoolExecutor newBlockingExecutor() { public ThreadPoolExecutor newBlockingExecutor() {
return newBlockingExecutor("FAWE Blocking Executor - %d");
}
/**
* Create a new blocking executor with specified name and FaweCache logger
*
* @return new blocking executor
* @since TODO
*/
public ThreadPoolExecutor newBlockingExecutor(String name) {
return newBlockingExecutor(name, LOGGER);
}
/**
* Create a new blocking executor with specified name and logger
*
* @return new blocking executor
* @since TODO
*/
public ThreadPoolExecutor newBlockingExecutor(String name, Logger logger) {
int nThreads = Settings.settings().QUEUE.PARALLEL_THREADS; int nThreads = Settings.settings().QUEUE.PARALLEL_THREADS;
ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(nThreads, true); ArrayBlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(nThreads, true);
return new ThreadPoolExecutor(nThreads, nThreads, return new ThreadPoolExecutor(nThreads, nThreads,
0L, TimeUnit.MILLISECONDS, queue, 0L, TimeUnit.MILLISECONDS, queue,
new ThreadFactoryBuilder().setNameFormat("FAWE Blocking Executor - %d").build(), new ThreadFactoryBuilder().setNameFormat(name).build(),
new ThreadPoolExecutor.CallerRunsPolicy() new ThreadPoolExecutor.CallerRunsPolicy()
) { ) {
@ -652,10 +678,10 @@ public enum FaweCache implements Trimable {
int hash = throwable.getMessage() != null ? throwable.getMessage().hashCode() : 0; int hash = throwable.getMessage() != null ? throwable.getMessage().hashCode() : 0;
if (hash != lastException) { if (hash != lastException) {
lastException = hash; lastException = hash;
LOGGER.catching(throwable); logger.catching(throwable);
count = 0; count = 0;
} else if (count < Settings.settings().QUEUE.PARALLEL_THREADS) { } else if (count < Settings.settings().QUEUE.PARALLEL_THREADS) {
LOGGER.warn(throwable.getMessage()); logger.warn(throwable.getMessage());
count++; count++;
} }
} }
@ -665,10 +691,10 @@ public enum FaweCache implements Trimable {
private void handleFaweException(FaweException e) { private void handleFaweException(FaweException e) {
FaweException.Type type = e.getType(); FaweException.Type type = e.getType();
if (e.getType() == FaweException.Type.OTHER) { if (e.getType() == FaweException.Type.OTHER) {
LOGGER.catching(e); logger.catching(e);
} else if (!faweExceptionReasonsUsed[type.ordinal()]) { } else if (!faweExceptionReasonsUsed[type.ordinal()]) {
faweExceptionReasonsUsed[type.ordinal()] = true; faweExceptionReasonsUsed[type.ordinal()] = true;
LOGGER.warn("FaweException: " + e.getMessage()); logger.warn("FaweException: " + e.getMessage());
} }
} }
}; };

View File

@ -67,11 +67,11 @@ public class ErodeBrush implements Brush {
final int by = target.getBlockY(); final int by = target.getBlockY();
final int bz = target.getBlockZ(); final int bz = target.getBlockZ();
for (int x = -brushSize, relx = 0; x <= brushSize; x++, relx++) { for (int x = -brushSize, relx = 0; x <= brushSize && relx < buffer1.getWidth(); x++, relx++) {
int x0 = x + bx; int x0 = x + bx;
for (int y = -brushSize, rely = 0; y <= brushSize; y++, rely++) { for (int y = -brushSize, rely = 0; y <= brushSize && rely < buffer1.getHeight(); y++, rely++) {
int y0 = y + by; int y0 = y + by;
for (int z = -brushSize, relz = 0; z <= brushSize; z++, relz++) { for (int z = -brushSize, relz = 0; z <= brushSize && relz < buffer1.getLength(); z++, relz++) {
int z0 = z + bz; int z0 = z + bz;
BlockState state = es.getBlock(x0, y0, z0); BlockState state = es.getBlock(x0, y0, z0);
buffer1.setBlock(relx, rely, relz, state); buffer1.setBlock(relx, rely, relz, state);
@ -115,11 +115,11 @@ public class ErodeBrush implements Brush {
Clipboard current, Clipboard target Clipboard current, Clipboard target
) { ) {
int[] frequency = null; int[] frequency = null;
for (int x = -brushSize, relx = 0; x <= brushSize; x++, relx++) { for (int x = -brushSize, relx = 0; x <= brushSize && relx < target.getWidth(); x++, relx++) {
int x2 = x * x; int x2 = x * x;
for (int z = -brushSize, relz = 0; z <= brushSize; z++, relz++) { for (int z = -brushSize, relz = 0; z <= brushSize && relz < target.getLength(); z++, relz++) {
int x2y2 = x2 + z * z; int x2y2 = x2 + z * z;
for (int y = -brushSize, rely = 0; y <= brushSize; y++, rely++) { for (int y = -brushSize, rely = 0; y <= brushSize && rely < target.getHeight(); y++, rely++) {
int cube = x2y2 + y * y; int cube = x2y2 + y * y;
target.setBlock(relx, rely, relz, current.getBlock(relx, rely, relz)); target.setBlock(relx, rely, relz, current.getBlock(relx, rely, relz));
if (cube >= brushSizeSquared) { if (cube >= brushSizeSquared) {
@ -166,11 +166,11 @@ public class ErodeBrush implements Brush {
Clipboard current, Clipboard target Clipboard current, Clipboard target
) { ) {
int[] frequency = null; int[] frequency = null;
for (int x = -brushSize, relx = 0; x <= brushSize; x++, relx++) { for (int x = -brushSize, relx = 0; x <= brushSize && relx < target.getWidth(); x++, relx++) {
int x2 = x * x; int x2 = x * x;
for (int z = -brushSize, relz = 0; z <= brushSize; z++, relz++) { for (int z = -brushSize, relz = 0; z <= brushSize && relz < target.getLength(); z++, relz++) {
int x2y2 = x2 + z * z; int x2y2 = x2 + z * z;
for (int y = -brushSize, rely = 0; y <= brushSize; y++, rely++) { for (int y = -brushSize, rely = 0; y <= brushSize && rely < target.getHeight(); y++, rely++) {
int cube = x2y2 + y * y; int cube = x2y2 + y * y;
target.setBlock(relx, rely, relz, current.getBlock(relx, rely, relz)); target.setBlock(relx, rely, relz, current.getBlock(relx, rely, relz));
if (cube >= brushSizeSquared) { if (cube >= brushSizeSquared) {

View File

@ -68,7 +68,8 @@ public abstract class QueueHandler implements Trimable, Runnable {
* Main "work-horse" queue for FAWE. Handles chunk submission (and chunk submission alone). Blocking in order to forcibly * Main "work-horse" queue for FAWE. Handles chunk submission (and chunk submission alone). Blocking in order to forcibly
* prevent overworking/over-submission of chunk process tasks. * prevent overworking/over-submission of chunk process tasks.
*/ */
private final ThreadPoolExecutor blockingExecutor = FaweCache.INSTANCE.newBlockingExecutor(); private final ThreadPoolExecutor blockingExecutor = FaweCache.INSTANCE.newBlockingExecutor(
"FAWE QueueHandler Blocking Executor - %d");
/** /**
* Queue for tasks to be completed on the main thread. These take priority of tasks submitted to syncWhenFree queue * Queue for tasks to be completed on the main thread. These take priority of tasks submitted to syncWhenFree queue
*/ */

View File

@ -158,6 +158,7 @@ public class SingleThreadQueueExtent extends ExtentBatchProcessorHolder implemen
this.setProcessor(EmptyBatchProcessor.getInstance()); this.setProcessor(EmptyBatchProcessor.getInstance());
this.setPostProcessor(EmptyBatchProcessor.getInstance()); this.setPostProcessor(EmptyBatchProcessor.getInstance());
this.world = null; this.world = null;
this.faweExceptionReasonsUsed = new boolean[FaweException.Type.values().length];
} }
/** /**

View File

@ -12,6 +12,7 @@ import com.fastasyncworldedit.core.queue.IChunkSet;
import com.fastasyncworldedit.core.queue.IQueueChunk; import com.fastasyncworldedit.core.queue.IQueueChunk;
import com.fastasyncworldedit.core.queue.IQueueExtent; import com.fastasyncworldedit.core.queue.IQueueExtent;
import com.fastasyncworldedit.core.queue.Pool; import com.fastasyncworldedit.core.queue.Pool;
import com.fastasyncworldedit.core.util.MemUtil;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
@ -959,7 +960,7 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk<T> {
public final IChunkGet getOrCreateGet() { public final IChunkGet getOrCreateGet() {
if (chunkExisting == null) { if (chunkExisting == null) {
chunkExisting = newWrappedGet(); chunkExisting = newWrappedGet();
chunkExisting.trim(false); chunkExisting.trim(MemUtil.isMemoryLimited());
} }
return chunkExisting; return chunkExisting;
} }
@ -1031,10 +1032,10 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk<T> {
try { try {
get.lockCall(); get.lockCall();
boolean postProcess = !(getExtent().getPostProcessor() instanceof EmptyBatchProcessor); boolean postProcess = !(getExtent().getPostProcessor() instanceof EmptyBatchProcessor);
final int copyKey = get.setCreateCopy(postProcess);
final IChunkSet iChunkSet = getExtent().processSet(this, get, set); final IChunkSet iChunkSet = getExtent().processSet(this, get, set);
Runnable finalizer; Runnable finalizer;
if (postProcess) { if (postProcess) {
int copyKey = get.setCreateCopy(true);
finalizer = () -> { finalizer = () -> {
getExtent().postProcess(this, get.getCopy(copyKey), iChunkSet); getExtent().postProcess(this, get.getCopy(copyKey), iChunkSet);
finalize.run(); finalize.run();