Merge branch 'IntellectualSites:main' into main

This commit is contained in:
2023-04-21 19:41:30 -05:00
committed by GitHub
20 changed files with 276 additions and 149 deletions

View File

@ -64,9 +64,9 @@ public class DiskOptimizedClipboard extends LinearClipboard {
private final int headerSize;
private RandomAccessFile braf;
private MappedByteBuffer byteBuffer;
private MappedByteBuffer byteBuffer = null;
private FileChannel fileChannel;
private FileChannel fileChannel = null;
private boolean hasBiomes = false;
private boolean canHaveBiomes = true;
private int nbtBytesRemaining;
@ -133,7 +133,7 @@ public class DiskOptimizedClipboard extends LinearClipboard {
e.printStackTrace();
}
this.braf = new RandomAccessFile(file, "rw");
long fileLength = (long) getVolume() * 2L + (long) headerSize;
long fileLength = (long) (getVolume() << 1) + (long) headerSize;
braf.setLength(0);
braf.setLength(fileLength);
this.nbtBytesRemaining = Integer.MAX_VALUE - (int) fileLength;
@ -144,7 +144,11 @@ public class DiskOptimizedClipboard extends LinearClipboard {
byteBuffer.putChar(6, (char) getHeight());
byteBuffer.putChar(8, (char) getLength());
} catch (IOException e) {
close();
throw new RuntimeException(e);
} catch (Throwable t) {
close();
throw t;
}
}
@ -169,11 +173,15 @@ public class DiskOptimizedClipboard extends LinearClipboard {
nbtMap = new HashMap<>();
try {
this.file = file;
checkFileLength(file);
this.braf = new RandomAccessFile(file, "rw");
braf.setLength(file.length());
this.nbtBytesRemaining = Integer.MAX_VALUE - (int) file.length();
init();
long biomeLength = (long) ((getHeight() >> 2) + 1) * ((getLength() >> 2) + 1) * ((getWidth() >> 2) + 1);
int biomeLength = ((getHeight() >> 2) + 1) * ((getLength() >> 2) + 1) * ((getWidth() >> 2) + 1);
canHaveBiomes = (long) headerSize + biomeLength < Integer.MAX_VALUE;
if (headerSize >= VERSION_2_HEADER_SIZE) {
readBiomeStatusFromHeader();
int nbtCount = readNBTSavedCountFromHeader();
@ -181,12 +189,42 @@ public class DiskOptimizedClipboard extends LinearClipboard {
if (Settings.settings().CLIPBOARD.SAVE_CLIPBOARD_NBT_TO_DISK && (nbtCount + entitiesCount > 0)) {
loadNBTFromFileFooter(nbtCount, entitiesCount, biomeLength);
}
} else if (braf.length() - headerSize == ((long) getVolume() << 1) + biomeLength) {
} else if (canHaveBiomes && braf.length() - headerSize == ((long) getVolume() << 1) + biomeLength) {
hasBiomes = true;
}
getAndSetOffsetAndOrigin();
} catch (IOException e) {
close();
throw new RuntimeException(e);
} catch (Throwable t) {
close();
throw t;
}
}
private void checkFileLength(File file) throws IOException {
long expectedFileSize = headerSize + ((long) getVolume() << 1);
if (file.length() > Integer.MAX_VALUE) {
if (expectedFileSize >= Integer.MAX_VALUE) {
throw new IOException(String.format(
"Cannot load clipboard of file size: %d > 2147483647 bytes (2.147 GiB), " + "volume: %d blocks",
file.length(),
getVolume()
));
} else {
throw new IOException(String.format(
"Cannot load clipboard of file size > 2147483647 bytes (2.147 GiB). Possible corrupt file? Mismatch" +
" between volume `%d` and file length `%d`!",
file.length(),
getVolume()
));
}
} else if (expectedFileSize != file.length()) {
throw new IOException(String.format(
"Possible corrupt clipboard file? Mismatch between expected file size `%d` and actual file size `%d`!",
expectedFileSize,
file.length()
));
}
}
@ -486,13 +524,26 @@ public class DiskOptimizedClipboard extends LinearClipboard {
fileChannel.close();
braf.close();
file.setWritable(true);
closeDirectBuffer(byteBuffer);
MappedByteBuffer tmpBuffer = byteBuffer;
byteBuffer = null;
closeDirectBuffer(tmpBuffer);
fileChannel = null;
braf = null;
} else if (fileChannel != null) {
fileChannel.close();
fileChannel = null;
}
} catch (IOException e) {
e.printStackTrace();
if (fileChannel != null) {
try {
fileChannel.close();
fileChannel = null;
} catch (IOException ex) {
LOGGER.error("Could not close file channel on clipboard {}. If this belongs to a player, the server may " +
"need to be restarted for clipboard use to work.", getFile().getName(), ex);
}
}
}
}
@ -648,8 +699,6 @@ public class DiskOptimizedClipboard extends LinearClipboard {
char ordinal = byteBuffer.getChar(diskIndex);
return BlockState.getFromOrdinal(ordinal);
} catch (IndexOutOfBoundsException ignored) {
} catch (Exception e) {
e.printStackTrace();
}
return BlockTypes.AIR.getDefaultState();
}

View File

@ -169,9 +169,14 @@ public class ToolUtilCommands {
public void traceMask(
Player player, LocalSession session,
@Arg(desc = "The trace mask to set", def = "")
Mask maskOpt
Mask maskOpt
) throws WorldEditException {
session.getBrushTool(player, false).setTraceMask(maskOpt);
BrushTool brushTool = session.getBrushTool(player, false);
if (brushTool == null) {
player.print(Caption.of("worldedit.brush.none.equipped"));
return;
}
brushTool.setTraceMask(maskOpt);
if (maskOpt == null) {
player.print(Caption.of("worldedit.tool.tracemask.disabled"));
} else {

View File

@ -207,7 +207,7 @@ public class DefaultBlockParser extends InputParser<BaseBlock> {
}).collect(Collectors.toSet());
if (!blocked.isEmpty()) {
throw new DisallowedUsageException(Caption.of(
"fawe.error.limit.disallowed-block",
"fawe.error.limit.disallowed-property",
TextComponent.of(input)
));
}

View File

@ -671,31 +671,26 @@ public final class PlatformCommandManager {
Actor actor = event.getActor();
String args = event.getArguments();
TaskManager.taskManager().taskNow(() -> {
if (!Fawe.isMainThread()) {
Thread.currentThread().setName("FAWE Thread for player: " + actor.getName());
int space0 = args.indexOf(' ');
String arg0 = space0 == -1 ? args : args.substring(0, space0);
Optional<Command> optional = commandManager.getCommand(arg0);
if (optional.isEmpty()) {
return;
}
Command cmd = optional.get();
PermissionCondition queued = cmd.getCondition().as(PermissionCondition.class).orElse(null);
if (queued != null && !queued.isQueued()) {
TaskManager.taskManager().taskNow(() -> handleCommandOnCurrentThread(event), Fawe.isMainThread());
return;
} else {
actor.decline();
}
actor.runAction(() -> {
SessionKey key = actor.getSessionKey();
if (key.isActive()) {
PlatformCommandManager.this.handleCommandOnCurrentThread(event);
}
int space0 = args.indexOf(' ');
String arg0 = space0 == -1 ? args : args.substring(0, space0);
Optional<Command> optional = commandManager.getCommand(arg0);
if (!optional.isPresent()) {
return;
}
Command cmd = optional.get();
PermissionCondition queued = cmd.getCondition().as(PermissionCondition.class).orElse(null);
if (queued != null && !queued.isQueued()) {
handleCommandOnCurrentThread(event);
return;
} else {
actor.decline();
}
actor.runAction(() -> {
SessionKey key = actor.getSessionKey();
if (key.isActive()) {
PlatformCommandManager.this.handleCommandOnCurrentThread(event);
}
}, false, true);
}, Fawe.isMainThread());
}, false, true);
}
public void handleCommandOnCurrentThread(CommandEvent event) {

View File

@ -555,10 +555,11 @@ public class BlockTransformExtent extends ResettableExtent {
int transformedId = transformState(state, transform);
BlockState transformed = BlockState.getFromInternalId(transformedId);
if (block.hasNbtData()) {
boolean baseBlock = block instanceof BaseBlock;
if (baseBlock && block.hasNbtData()) {
return (B) transformBaseBlockNBT(transformed, block.getNbtData(), transform);
}
return (B) (block instanceof BaseBlock ? transformed.toBaseBlock() : transformed);
return (B) (baseBlock? transformed.toBaseBlock() : transformed);
//FAWE end
}

View File

@ -283,6 +283,7 @@
"worldedit.brush.butcher.equip": "Butcher brush equipped ({0}).",
"worldedit.brush.operation.equip": "Set brush to {0}.",
"worldedit.brush.none.equip": "Brush unbound from your current item.",
"worldedit.brush.none.equipped": "You have no brush bound to your current item. Try /brush sphere for a basic brush.",
"worldedit.setbiome.changed": "Biomes were changed in {0} columns. You may have to rejoin your game (or close and reopen your world) to see a change.",
"worldedit.setbiome.not-locatable": "Command sender must be present in the world to use the -p flag.",
"worldedit.drawsel.disabled": "Server CUI disabled.",