From 8971d7064cb05f8f202e26d212bd2d793def400b Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 13 Oct 2022 18:21:02 +0100 Subject: [PATCH] feat: Reduce any spam caused by exceptions thrown when writing history (#1976) - Closes #1960 --- .../core/history/changeset/AbstractChangeSet.java | 6 +++++- .../history/changeset/FaweStreamChangeSet.java | 10 +++++----- .../core/internal/exception/FaweException.java | 1 + .../FaweSmallEditUnsupportedException.java | 15 +++++++++++++++ 4 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 worldedit-core/src/main/java/com/fastasyncworldedit/core/internal/exception/FaweSmallEditUnsupportedException.java diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/AbstractChangeSet.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/AbstractChangeSet.java index 5c5e1f682..e52ef0cba 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/AbstractChangeSet.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/AbstractChangeSet.java @@ -47,6 +47,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor { private static final Logger LOGGER = LogManagerCompat.getLogger(); private final World world; + private final AtomicInteger lastException = new AtomicInteger(); protected AtomicInteger waitingCombined = new AtomicInteger(0); protected AtomicInteger waitingAsync = new AtomicInteger(0); @@ -369,7 +370,10 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor { if (completeNow) { throw t; } else { - t.printStackTrace(); + int hash = t.getMessage().hashCode(); + if (lastException.getAndSet(hash) != hash) { + t.printStackTrace(); + } } } finally { if (AbstractChangeSet.this.waitingCombined.decrementAndGet() <= 0) { diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/FaweStreamChangeSet.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/FaweStreamChangeSet.java index 77869a7ce..75fa4d8f3 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/FaweStreamChangeSet.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/history/changeset/FaweStreamChangeSet.java @@ -6,6 +6,7 @@ import com.fastasyncworldedit.core.history.change.MutableBlockChange; import com.fastasyncworldedit.core.history.change.MutableEntityChange; import com.fastasyncworldedit.core.history.change.MutableFullBlockChange; import com.fastasyncworldedit.core.history.change.MutableTileChange; +import com.fastasyncworldedit.core.internal.exception.FaweSmallEditUnsupportedException; import com.fastasyncworldedit.core.internal.io.FaweInputStream; import com.fastasyncworldedit.core.internal.io.FaweOutputStream; import com.fastasyncworldedit.core.util.MainUtil; @@ -146,8 +147,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet { @Override public void write(OutputStream out, int x, int y, int z) throws IOException { if (y < 0 || y > 255) { - throw new UnsupportedOperationException("y cannot be outside range 0-255 for " + - "small-edits=true"); + throw new FaweSmallEditUnsupportedException(); } int rx = -lx + (lx = x); int ry = -ly + (ly = y); @@ -332,7 +332,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet { //x posDel.write(stream, x - originX, y, z - originZ); idDel.writeChange(stream, combinedFrom, combinedTo); - } catch (Throwable e) { + } catch (IOException e) { e.printStackTrace(); } } @@ -358,7 +358,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet { os.write((byte) (y + 128)); os.writeVarInt(from.getInternalId()); os.writeVarInt(to.getInternalId()); - } catch (Throwable e) { + } catch (IOException e) { e.printStackTrace(); } } @@ -699,7 +699,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet { final Iterator biomeChange = getBiomeIterator(dir); - return new Iterator() { + return new Iterator<>() { final Iterator[] iterators = new Iterator[]{tileCreate, tileRemove, entityCreate, entityRemove, blockChange, biomeChange}; int i = 0; Iterator current = iterators[0]; diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/internal/exception/FaweException.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/internal/exception/FaweException.java index 83504f6b8..ff1d7913d 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/internal/exception/FaweException.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/internal/exception/FaweException.java @@ -91,6 +91,7 @@ public class FaweException extends RuntimeException { PLAYER_ONLY, ACTOR_REQUIRED, CLIPBOARD, + HISTORY, OTHER } diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/internal/exception/FaweSmallEditUnsupportedException.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/internal/exception/FaweSmallEditUnsupportedException.java new file mode 100644 index 000000000..1d7509149 --- /dev/null +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/internal/exception/FaweSmallEditUnsupportedException.java @@ -0,0 +1,15 @@ +package com.fastasyncworldedit.core.internal.exception; + +import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.formatting.text.TextComponent; + +public class FaweSmallEditUnsupportedException extends FaweException { + + private static final Component message = TextComponent.of( + "y cannot be outside range 0-255 for small-edits=true. History will NOT work on edits outside this range."); + + public FaweSmallEditUnsupportedException() { + super(message, Type.HISTORY); + } + +}