feat: Reduce any spam caused by exceptions thrown when writing history (#1976)

- Closes #1960
Dieser Commit ist enthalten in:
Jordan 2022-10-13 18:21:02 +01:00 committet von GitHub
Ursprung ccb31c0ecc
Commit 8971d7064c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
4 geänderte Dateien mit 26 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -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) {

Datei anzeigen

@ -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<MutableBiomeChange> biomeChange = getBiomeIterator(dir);
return new Iterator<Change>() {
return new Iterator<>() {
final Iterator<Change>[] iterators = new Iterator[]{tileCreate, tileRemove, entityCreate, entityRemove, blockChange, biomeChange};
int i = 0;
Iterator<Change> current = iterators[0];

Datei anzeigen

@ -91,6 +91,7 @@ public class FaweException extends RuntimeException {
PLAYER_ONLY,
ACTOR_REQUIRED,
CLIPBOARD,
HISTORY,
OTHER
}

Datei anzeigen

@ -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);
}
}