Add tracing feature to EditSessions (Upstream 1301) (#1112)

Co-authored-by: Octavia Togami <octavia.togami@gmail.com>
Co-authored-by: dordsor21 <dordsor21@gmail.com>
Co-authored-by: NotMyFault <mc.cache@web.de>
Dieser Commit ist enthalten in:
Matt 2021-09-19 16:02:41 -04:00 committet von GitHub
Ursprung f405994346
Commit 4f68fb0e26
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
52 geänderte Dateien mit 1248 neuen und 279 gelöschten Zeilen

Datei anzeigen

@ -12,8 +12,8 @@ import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.util.nbt.BinaryTag;
import com.sk89q.worldedit.util.nbt.CompoundBinaryTag;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;

Datei anzeigen

@ -2,7 +2,6 @@ package com.fastasyncworldedit.bukkit.regions.plotsquared;
import com.fastasyncworldedit.core.FaweAPI;
import com.fastasyncworldedit.core.extent.processor.lighting.RelightMode;
import com.fastasyncworldedit.core.util.EditSessionBuilder;
import com.fastasyncworldedit.core.util.TaskManager;
import com.plotsquared.core.configuration.Settings;
import com.plotsquared.core.generator.HybridPlotManager;
@ -57,9 +56,8 @@ public class FaweDelegateRegionManager {
TaskManager.IMP.async(() -> {
synchronized (FaweDelegateRegionManager.class) {
World world = BukkitAdapter.adapt(getWorld(area.getWorldName()));
EditSession session =
new EditSessionBuilder(world).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull()
.autoQueue(false).build();
EditSession session = WorldEdit.getInstance().newEditSessionBuilder().world(world).checkMemory(false).
fastMode(true).limitUnlimited().changeSetNull().build();
for (CuboidRegion region : regions) {
region.setPos1(region.getPos1().withY(minY));
region.setPos2(region.getPos2().withY(maxY));
@ -96,12 +94,11 @@ public class FaweDelegateRegionManager {
synchronized (FaweDelegateRegionManager.class) {
final HybridPlotWorld hybridPlotWorld = ((HybridPlotManager) manager).getHybridPlotWorld();
World world = BukkitAdapter.adapt(getWorld(hybridPlotWorld.getWorldName()));
EditSession editSession = new EditSessionBuilder(world)
EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().world(world)
.checkMemory(false)
.fastmode(true)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.autoQueue(false)
.build();
if (!hybridPlotWorld.PLOT_SCHEMATIC || !Settings.Schematics.PASTE_ON_TOP) {
@ -145,12 +142,11 @@ public class FaweDelegateRegionManager {
if (hybridPlotWorld.PLOT_SCHEMATIC) {
// We cannot reuse the editsession
EditSession scheditsession = !Settings.Schematics.PASTE_ON_TOP ? editSession :
new EditSessionBuilder(world)
WorldEdit.getInstance().newEditSessionBuilder().world(world)
.checkMemory(false)
.fastmode(true)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.autoQueue(false)
.build();
File schematicFile = new File(hybridPlotWorld.getRoot(), "plot.schem");
if (!schematicFile.exists()) {
@ -197,20 +193,17 @@ public class FaweDelegateRegionManager {
//todo because of the following code this should proably be in the Bukkit module
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorldName()));
World pos3World = BukkitAdapter.adapt(getWorld(swapPos.getWorldName()));
WorldEdit.getInstance().getEditSessionFactory().getEditSession(pos1World, -1);
EditSession sessionA = new EditSessionBuilder(pos1World)
EditSession sessionA = WorldEdit.getInstance().newEditSessionBuilder().world(pos1World)
.checkMemory(false)
.fastmode(true)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.autoQueue(false)
.build();
EditSession sessionB = new EditSessionBuilder(pos3World)
EditSession sessionB = WorldEdit.getInstance().newEditSessionBuilder().world(pos3World)
.checkMemory(false)
.fastmode(true)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.autoQueue(false)
.build();
CuboidRegion regionA = new CuboidRegion(pos1.getBlockVector3(), pos2.getBlockVector3());
CuboidRegion regionB = new CuboidRegion(
@ -256,12 +249,14 @@ public class FaweDelegateRegionManager {
region.expand(BlockVector3.at(-extendBiome, 0, -extendBiome));
TaskManager.IMP.async(() -> {
synchronized (FaweDelegateRegionManager.class) {
EditSession editSession = new EditSessionBuilder(BukkitAdapter.adapt(getWorld(world)))
EditSession editSession = WorldEdit
.getInstance()
.newEditSessionBuilder()
.world(BukkitAdapter.adapt(getWorld(world)))
.checkMemory(false)
.fastmode(true)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.autoQueue(false)
.build();
FlatRegionFunction replace = new BiomeReplace(editSession, biome);
FlatRegionVisitor visitor = new FlatRegionVisitor(region, replace, editSession);
@ -286,19 +281,17 @@ public class FaweDelegateRegionManager {
synchronized (FaweDelegateRegionManager.class) {
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorldName()));
World pos3World = BukkitAdapter.adapt(getWorld(pos3.getWorldName()));
EditSession from = new EditSessionBuilder(pos1World)
EditSession from = WorldEdit.getInstance().newEditSessionBuilder().world(pos1World)
.checkMemory(false)
.fastmode(true)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.autoQueue(false)
.build();
EditSession to = new EditSessionBuilder(pos3World)
EditSession to = WorldEdit.getInstance().newEditSessionBuilder().world(pos3World)
.checkMemory(false)
.fastmode(true)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.autoQueue(false)
.build();
CuboidRegion region = new CuboidRegion(
BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()),
@ -333,12 +326,11 @@ public class FaweDelegateRegionManager {
TaskManager.IMP.async(() -> {
synchronized (FaweDelegateRegionManager.class) {
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorldName()));
try (EditSession editSession = new EditSessionBuilder(pos1World)
try (EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().world(pos1World)
.checkMemory(false)
.fastmode(true)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.autoQueue(false)
.build()) {
CuboidRegion region = new CuboidRegion(
BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()),

Datei anzeigen

@ -7,7 +7,6 @@ import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicReader;
import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicWriter;
import com.fastasyncworldedit.core.jnbt.CompressedCompoundTag;
import com.fastasyncworldedit.core.jnbt.CompressedSchematicTag;
import com.fastasyncworldedit.core.util.EditSessionBuilder;
import com.fastasyncworldedit.core.util.IOUtil;
import com.plotsquared.core.PlotSquared;
import com.plotsquared.core.generator.ClassicPlotWorld;
@ -23,6 +22,7 @@ import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.BuiltInClipboardFormat;
import com.sk89q.worldedit.extent.clipboard.io.MCEditSchematicReader;
@ -108,8 +108,15 @@ public class FaweDelegateSchematicHandler {
final BlockVector3 to = BlockVector3
.at(region.getMinimumPoint().getX() + xOffset, y_offset_actual, region.getMinimumPoint().getZ() + zOffset);
try (EditSession editSession = new EditSessionBuilder(FaweAPI.getWorld(plot.getWorldName())).checkMemory(false)
.fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build()) {
try (EditSession editSession = WorldEdit
.getInstance()
.newEditSessionBuilder()
.world(FaweAPI.getWorld(plot.getWorldName()))
.checkMemory(false)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.build()) {
final Clipboard clipboard = schematic.getClipboard();
clipboard.paste(editSession, to, true, false, true);
if (whenDone != null) {

Datei anzeigen

@ -1,6 +1,5 @@
package com.fastasyncworldedit.bukkit.regions.plotsquared;
import com.fastasyncworldedit.core.util.EditSessionBuilder;
import com.fastasyncworldedit.core.util.TaskManager;
import com.plotsquared.core.command.Command;
import com.plotsquared.core.command.CommandCategory;
@ -92,9 +91,17 @@ public class PlotSetBiome extends Command {
plot.addRunning();
TaskManager.IMP.async(() -> {
EditSession session =
new EditSessionBuilder(BukkitAdapter.adapt(Bukkit.getWorld(plot.getArea().getWorldName())))
.autoQueue(false).checkMemory(false).allowedRegionsEverywhere()
.player(BukkitAdapter.adapt(Bukkit.getPlayer(player.getUUID()))).limitUnlimited().build();
WorldEdit
.getInstance()
.newEditSessionBuilder()
.world(BukkitAdapter.adapt(Bukkit.getWorld(plot
.getArea()
.getWorldName())))
.checkMemory(false)
.allowedRegionsEverywhere()
.actor(BukkitAdapter.adapt(Bukkit.getPlayer(player.getUUID())))
.limitUnlimited()
.build();
long seed = ThreadLocalRandom.current().nextLong();
for (CuboidRegion region : regions) {
session.regenerate(region, biome, seed);

Datei anzeigen

@ -1,7 +1,6 @@
package com.fastasyncworldedit.bukkit.regions.plotsquaredv4;
import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.util.EditSessionBuilder;
import com.fastasyncworldedit.core.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.object.Location;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
@ -65,21 +64,17 @@ public class FaweChunkManager extends ChunkManager {
//todo because of the following code this should proably be in the Bukkit module
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorld()));
World pos3World = BukkitAdapter.adapt(getWorld(pos3.getWorld()));
WorldEdit.getInstance().getEditSessionFactory().getEditSession(
pos1World, -1);
EditSession sessionA = new EditSessionBuilder(pos1World)
EditSession sessionA = WorldEdit.getInstance().newEditSessionBuilder().world(pos1World)
.checkMemory(false)
.fastmode(true)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.autoQueue(false)
.build();
EditSession sessionB = new EditSessionBuilder(pos3World)
EditSession sessionB = WorldEdit.getInstance().newEditSessionBuilder().world(pos3World)
.checkMemory(false)
.fastmode(true)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.autoQueue(false)
.build();
CuboidRegion regionA = new CuboidRegion(
BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()),
@ -113,19 +108,17 @@ public class FaweChunkManager extends ChunkManager {
synchronized (FaweChunkManager.class) {
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorld()));
World pos3World = BukkitAdapter.adapt(getWorld(pos3.getWorld()));
EditSession from = new EditSessionBuilder(pos1World)
EditSession from = WorldEdit.getInstance().newEditSessionBuilder().world(pos1World)
.checkMemory(false)
.fastmode(true)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.autoQueue(false)
.build();
EditSession to = new EditSessionBuilder(pos3World)
EditSession to = WorldEdit.getInstance().newEditSessionBuilder().world(pos3World)
.checkMemory(false)
.fastmode(true)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.autoQueue(false)
.build();
CuboidRegion region = new CuboidRegion(
BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()),
@ -154,8 +147,15 @@ public class FaweChunkManager extends ChunkManager {
TaskManager.IMP.async(() -> {
synchronized (FaweChunkManager.class) {
World pos1World = BukkitAdapter.adapt(getWorld(pos1.getWorld()));
try (EditSession editSession = new EditSessionBuilder(pos1World).checkMemory(false)
.fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build()) {
try (EditSession editSession = WorldEdit
.getInstance()
.newEditSessionBuilder()
.world(pos1World)
.checkMemory(false)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.build()) {
CuboidRegion region = new CuboidRegion(
BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()),
BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ())

Datei anzeigen

@ -6,7 +6,6 @@ import com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard;
import com.fastasyncworldedit.core.extent.clipboard.io.FastSchematicWriter;
import com.fastasyncworldedit.core.jnbt.CompressedCompoundTag;
import com.fastasyncworldedit.core.jnbt.CompressedSchematicTag;
import com.fastasyncworldedit.core.util.EditSessionBuilder;
import com.fastasyncworldedit.core.util.IOUtil;
import com.fastasyncworldedit.core.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.PlotSquared;
@ -19,6 +18,7 @@ import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -64,12 +64,11 @@ public class FaweSchematicHandler extends SchematicHandler {
BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()),
BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ())
);
final EditSession editSession = new EditSessionBuilder(adaptedWorld)
final EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder().world(adaptedWorld)
.checkMemory(false)
.fastmode(true)
.fastMode(true)
.limitUnlimited()
.changeSetNull()
.autoQueue(false)
.build();
ReadOnlyClipboard clipboard = ReadOnlyClipboard.of(editSession, region, false, true);

Datei anzeigen

@ -1,6 +1,5 @@
package com.fastasyncworldedit.bukkit.regions.plotsquaredv4;
import com.fastasyncworldedit.core.util.EditSessionBuilder;
import com.fastasyncworldedit.core.util.TaskManager;
import com.github.intellectualsites.plotsquared.commands.Command;
import com.github.intellectualsites.plotsquared.commands.CommandDeclaration;
@ -84,11 +83,11 @@ public class PlotSetBiome extends Command {
}
plot.addRunning();
TaskManager.IMP.async(() -> {
EditSession session = new EditSessionBuilder(BukkitAdapter.adapt(Bukkit.getWorld(plot.getArea().worldname)))
.autoQueue(false)
EditSession session = WorldEdit.getInstance().newEditSessionBuilder().world(BukkitAdapter.adapt(Bukkit.getWorld(
plot.getArea().worldname)))
.checkMemory(false)
.allowedRegionsEverywhere()
.player(BukkitAdapter.adapt(Bukkit.getPlayer(player.getUUID())))
.actor(BukkitAdapter.adapt(Bukkit.getPlayer(player.getUUID())))
.limitUnlimited()
.build();
long seed = ThreadLocalRandom.current().nextLong();

Datei anzeigen

@ -1,10 +1,10 @@
package com.fastasyncworldedit.bukkit.util;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap;
import it.unimi.dsi.fastutil.longs.LongArraySet;
import it.unimi.dsi.fastutil.longs.LongIterator;
import it.unimi.dsi.fastutil.longs.LongSet;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
/**
* Class to prevent the above/below being removed from shaded/relocated dependencies via minimization

Datei anzeigen

@ -465,8 +465,11 @@ public class WorldEditPlugin extends JavaPlugin {
LocalSession session = WorldEdit.getInstance().getSessionManager().get(wePlayer);
BlockBag blockBag = session.getBlockBag(wePlayer);
EditSession editSession = WorldEdit.getInstance().getEditSessionFactory()
.getEditSession(wePlayer.getWorld(), session.getBlockChangeLimit(), blockBag, wePlayer);
EditSession editSession = WorldEdit.getInstance().newEditSessionBuilder()
.locatableActor(wePlayer)
.maxBlocks(session.getBlockChangeLimit())
.blockBag(blockBag)
.build();
editSession.enableStandardMode();
return editSession;

Datei anzeigen

@ -194,6 +194,8 @@ public class Fawe {
case OTHER:
logger.catching(e);
throw e;
case PLAYER_ONLY:
case ACTOR_REQUIRED:
case LOW_MEMORY:
if (!faweExceptionReasonsUsed[type.ordinal()]) {
logger.warn("FaweException: " + e.getMessage());

Datei anzeigen

@ -64,9 +64,9 @@ public class FaweAPI {
* Offers a lot of options for building an EditSession.
*
* @return A new EditSessionBuilder
* @see EditSessionBuilder
* @deprecated See {@link WorldEdit#newEditSessionBuilder()}
*/
@Deprecated
@Deprecated(forRemoval = true)
public static EditSessionBuilder getEditSessionBuilder(World world) {
return new EditSessionBuilder(world);
}

Datei anzeigen

@ -172,6 +172,16 @@ public enum FaweCache implements Trimable {
"fawe.cancel.worldedit.cancel.reason.max.iterations"),
Type.MAX_ITERATIONS
);
public static final FaweException PLAYER_ONLY = new FaweException(
Caption.of(
"fawe.cancel.worldedit.cancel.reason.player-only"),
Type.PLAYER_ONLY
);
public static final FaweException ACTOR_REQUIRED = new FaweException(
Caption.of(
"fawe.cancel.worldedit.cancel.reason.actor-required"),
Type.ACTOR_REQUIRED
);
/*
thread cache

Datei anzeigen

@ -60,7 +60,7 @@ public class AnvilCommands {
// boolean copy = false;
// if (FaweAPI.getWorld(folder) != null) {
// if (!force) {
// player.print(TranslatableComponent.of("fawe.worldedit.anvil.world.is.loaded"))
// player.print(Caption.of("fawe.worldedit.anvil.world.is.loaded"))
// return null;
// }
// copy = true;
@ -88,7 +88,7 @@ public class AnvilCommands {
// @Deprecated
// public static <G, T extends MCAFilter<G>> T runWithSelection(Player player, EditSession editSession, Region selection, T filter) {
// if (!(selection instanceof CuboidRegion)) {
// player.print(TranslatableComponent.of("fawe.error.no.region"))
// player.print(Caption.of("fawe.error.no.region"))
// return null;
// }
// CuboidRegion cuboid = (CuboidRegion) selection;
@ -111,7 +111,7 @@ public class AnvilCommands {
// } else {
// AnvilHistory history = new AnvilHistory(world.getName(), fp.getUUID());
// run.accept(history);
// session.remember(fp.getPlayer(), world, history, fp.getLimit());
// session.remember(fp.getActor(), world, history, fp.getLimit());
// }
// }
@ -141,7 +141,7 @@ public class AnvilCommands {
// final FaweBlockMatcher matchTo = FaweBlockMatcher.setBlocks(worldEdit.getBlocks(player, to, true));
// ReplaceSimpleFilter filter = new ReplaceSimpleFilter(matchFrom, matchTo);
// ReplaceSimpleFilter result = runWithWorld(player, folder, filter, true);
// if (result != null) player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// if (result != null) player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
}
@Command(
@ -158,7 +158,7 @@ public class AnvilCommands {
// RemapFilter filter = new RemapFilter(from, to);
// RemapFilter result = runWithWorld(player, folder, filter, true);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -181,7 +181,7 @@ public class AnvilCommands {
// DeleteUninhabitedFilter filter = new DeleteUninhabitedFilter(fileDurationMillis, inhabitedTicks, fileDurationMillis); TODO NOT IMPLEMENTED
// DeleteUninhabitedFilter result = runWithWorld(player, folder, filter, true);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -210,7 +210,7 @@ public class AnvilCommands {
// }
// DeleteUnclaimedFilter result = runWithWorld(player, folder, filter, true);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -238,7 +238,7 @@ public class AnvilCommands {
// }
// DeleteUnclaimedFilter result = runWithSelection(player, editSession, selection, filter);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -255,7 +255,7 @@ public class AnvilCommands {
// DeleteOldFilter filter = new DeleteOldFilter(duration);
// DeleteOldFilter result = runWithWorld(player, folder, filter, true);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -278,7 +278,7 @@ public class AnvilCommands {
// MCAQueue queue = new MCAQueue(defaultQueue);
// PlotTrimFilter result = queue.filterWorld(filter);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -295,7 +295,7 @@ public class AnvilCommands {
// DeleteBiomeFilterSimple filter = new DeleteBiomeFilterSimple(biome); TODO NOT IMPLEMENTED
// DeleteBiomeFilterSimple result = runWithWorld(player, folder, filter, true, unsafe);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -312,7 +312,7 @@ public class AnvilCommands {
// TrimAirFilter filter = new TrimAirFilter(); TODO NOT IMPLEMENTED
// TrimAirFilter result = runWithWorld(player, folder, filter, true, unsafe);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -325,7 +325,7 @@ public class AnvilCommands {
// DebugFixP2Roads filter = new DebugFixP2Roads(); TODO NOT IMPLEMENTED
// DebugFixP2Roads result = runWithWorld(player, folder, filter, true, true);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -363,7 +363,7 @@ public class AnvilCommands {
// filter = new ReplacePatternFilter(matchFrom, to);
// }
// MCAFilterCounter result = runWithWorld(player, folder, filter, true);
// if (result != null) player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// if (result != null) player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
}
//
@ -389,7 +389,7 @@ public class AnvilCommands {
// filter = counter;
// }
// MCAFilterCounter result = runWithWorld(player, folder, filter, true);
// if (result != null) player.print(TranslatableComponent.of("fawe.worldedit.selection.selection.count", (result.getTotal())));
// if (result != null) player.print(Caption.of("fawe.worldedit.selection.selection.count", (result.getTotal())));
}
@Command(
@ -441,7 +441,7 @@ public class AnvilCommands {
// };
// MCAFilterCounter result = runWithSelection(player, editSession, selection, filter);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -467,7 +467,7 @@ public class AnvilCommands {
// filter = counter;
// }
// MCAFilterCounter result = runWithSelection(player, editSession, selection, filter);
// if (result != null) player.print(TranslatableComponent.of("fawe.worldedit.selection.selection.count", (result.getTotal())));
// if (result != null) player.print(Caption.of("fawe.worldedit.selection.selection.count", (result.getTotal())));
}
//
@ -576,7 +576,7 @@ public class AnvilCommands {
// ReplaceSimpleFilter filter = new ReplaceSimpleFilter(matchFrom, matchTo);
// MCAFilterCounter result = runWithSelection(player, editSession, selection, filter);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -616,7 +616,7 @@ public class AnvilCommands {
// }
// MCAFilterCounter result = runWithSelection(player, editSession, selection, filter);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -631,7 +631,7 @@ public class AnvilCommands {
// MCAFilterCounter filter = new SetPatternFilter(to); TODO NOT IMPLEMENTED
// MCAFilterCounter result = runWithSelection(player, editSession, selection, filter);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -650,7 +650,7 @@ public class AnvilCommands {
// RemoveLayerFilter filter = new RemoveLayerFilter(minY, maxY, id);
// MCAFilterCounter result = runWithSelection(player, editSession, selection, filter);
// if (result != null) {
// player.print(TranslatableComponent.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// player.print(Caption.of("fawe.worldedit.visitor.visitor.block", (result.getTotal())));
// }
}
@ -663,7 +663,7 @@ public class AnvilCommands {
public void copy(Player player, LocalSession session, EditSession editSession, @Selection Region selection) throws
WorldEditException {
// if (!(selection instanceof CuboidRegion)) { TODO NOT IMPLEMENTED
// player.print(TranslatableComponent.of("fawe.error.no.region"))
// player.print(Caption.of("fawe.error.no.region"))
// return;
// }
// CuboidRegion cuboid = (CuboidRegion) selection;
@ -674,7 +674,7 @@ public class AnvilCommands {
// MCAClipboard clipboard = new MCAClipboard(queue, cuboid, origin);
// FawePlayer fp = FawePlayer.wrap(player);
// fp.setMeta(FawePlayer.METADATA_KEYS.ANVIL_CLIPBOARD, clipboard);
// player.print(TranslatableComponent.of("fawe.worldedit.copy.command.copy", selection.getArea()));
// player.print(Caption.of("fawe.worldedit.copy.command.copy", selection.getArea()));
}
@Command(
@ -714,7 +714,7 @@ public class AnvilCommands {
// pasteQueue.pasteRegion(copyQueue, copyRegion, offset, iAnvilHistory);
// } catch (IOException e) { throw new RuntimeException(e); }
// });
// player.print(TranslatableComponent.of("fawe.worldedit.paste.command.paste", player.getPosition().toBlockVector()));
// player.print(Caption.of("fawe.worldedit.paste.command.paste", player.getPosition().toBlockVector()));
}
}

Datei anzeigen

@ -1,11 +1,14 @@
package com.fastasyncworldedit.core.command.tool.brush;
import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.command.tool.ResettableTool;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.internal.exception.FaweException;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
@ -35,19 +38,20 @@ public class CatenaryBrush implements Brush, ResettableTool {
@Override
public void build(EditSession editSession, BlockVector3 pos2, final Pattern pattern, double size) throws
MaxChangedBlocksException {
Player player = editSession.getPlayer();
if (player == null) {
return; //todo throw error
Actor actor = editSession.getActor();
if (!(actor instanceof Player)) {
throw FaweCache.PLAYER_ONLY;
}
Player player = (Player) actor;
if (pos1 == null || pos2.equals(pos1)) {
pos1 = pos2;
player.print(Caption.of("fawe.worldedit.brush.brush.line.primary", pos2));
actor.print(Caption.of("fawe.worldedit.brush.brush.line.primary", pos2));
return;
}
if (this.vertex == null) {
vertex = getVertex(pos1.toVector3(), pos2.toVector3(), slack);
if (this.direction) {
player.print(Caption.of("fawe.worldedit.brush.brush.catenary.direction", 2));
actor.print(Caption.of("fawe.worldedit.brush.brush.catenary.direction", 2));
return;
}
} else if (this.direction) {

Datei anzeigen

@ -1,9 +1,11 @@
package com.fastasyncworldedit.core.command.tool.brush;
import com.fastasyncworldedit.core.FaweCache;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.math.Vector3;
@ -21,10 +23,11 @@ public class CircleBrush implements Brush {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws
MaxChangedBlocksException {
Player player = editSession.getPlayer();
if (player == null) {
return;
Actor actor = editSession.getActor();
if (!(actor instanceof Player)) {
throw FaweCache.PLAYER_ONLY;
}
Player player = (Player) actor;
Vector3 normal = position.toVector3().subtract(player.getLocation());
editSession.makeCircle(position, pattern, size, size, size, filled, normal);
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.fastasyncworldedit.core.command.tool.brush;
import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.util.StringMan;
import com.fastasyncworldedit.core.wrappers.AsyncPlayer;
import com.fastasyncworldedit.core.wrappers.LocationMaskedPlayerWrapper;
@ -9,6 +10,7 @@ import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
@ -40,7 +42,11 @@ public class CommandBrush implements Brush {
.replace("{world}", editSession.getWorld().getName())
.replace("{size}", Integer.toString(radius));
Player player = editSession.getPlayer();
Actor actor = editSession.getActor();
if (!(actor instanceof Player)) {
throw FaweCache.PLAYER_ONLY;
}
Player player = (Player) actor;
//Use max world height to allow full coverage of the world height
Location face = player.getBlockTraceFace(editSession.getWorld().getMaxY(), true);
if (face == null) {

Datei anzeigen

@ -1,5 +1,6 @@
package com.fastasyncworldedit.core.command.tool.brush;
import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.command.tool.ResettableTool;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.extent.clipboard.ResizableClipboardBuilder;
@ -10,6 +11,7 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.mask.Masks;
@ -51,10 +53,11 @@ public class CopyPastaBrush implements Brush, ResettableTool {
@Override
public void build(EditSession editSession, BlockVector3 position, Pattern pattern, double size) throws
MaxChangedBlocksException {
Player player = editSession.getPlayer();
if (player == null) {
return;
Actor actor = editSession.getActor();
if (!(actor instanceof Player)) {
throw FaweCache.PLAYER_ONLY;
}
Player player = (Player) actor;
ClipboardHolder clipboard = session.getExistingClipboard();
if (clipboard == null) {
Mask mask = editSession.getMask();

Datei anzeigen

@ -1,10 +1,10 @@
package com.fastasyncworldedit.core.command.tool.brush;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.internal.exception.FaweException;
import com.fastasyncworldedit.core.math.heightmap.HeightMap;
import com.fastasyncworldedit.core.math.heightmap.RotatableHeightMap;
import com.fastasyncworldedit.core.math.heightmap.ScalableHeightMap;
import com.fastasyncworldedit.core.internal.exception.FaweException;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.command.tool.brush.Brush;

Datei anzeigen

@ -1,5 +1,6 @@
package com.fastasyncworldedit.core.command.tool.brush;
import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.function.mask.ImageBrushMask;
import com.fastasyncworldedit.core.function.mask.SurfaceMask;
import com.fastasyncworldedit.core.util.TextureUtil;
@ -8,6 +9,8 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.Operations;
@ -85,7 +88,12 @@ public class ImageBrush implements Brush {
double scale = Math.max(width, height) / sizeDouble;
Location loc = editSession.getPlayer().getLocation();
Actor actor = editSession.getActor();
if (!(actor instanceof Player)) {
throw FaweCache.PLAYER_ONLY;
}
Player player = (Player) actor;
Location loc = player.getLocation();
float yaw = loc.getYaw();
float pitch = loc.getPitch();
AffineTransform transform = new AffineTransform().rotateY((-yaw) % 360).rotateX((pitch - 90) % 360).inverse();

Datei anzeigen

@ -26,11 +26,11 @@ public class LineBrush implements Brush, ResettableTool {
MaxChangedBlocksException {
if (pos1 == null) {
pos1 = position;
editSession.getPlayer().print(Caption.of("fawe.worldedit.brush.brush.line.primary", position));
editSession.getActor().print(Caption.of("fawe.worldedit.brush.brush.line.primary", position));
return;
}
editSession.drawLine(pattern, pos1, position, size, !shell, flat);
editSession.getPlayer().print(Caption.of("fawe.worldedit.brush.brush.line.secondary"));
editSession.getActor().print(Caption.of("fawe.worldedit.brush.brush.line.secondary"));
if (!select) {
pos1 = null;
} else {

Datei anzeigen

@ -1,5 +1,6 @@
package com.fastasyncworldedit.core.command.tool.brush;
import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.math.LocalBlockVectorSet;
import com.fastasyncworldedit.core.util.StringMan;
import com.fastasyncworldedit.core.wrappers.LocationMaskedPlayerWrapper;
@ -7,6 +8,7 @@ import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.CommandEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.PlatformCommandManager;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
@ -47,7 +49,11 @@ public class ScatterCommand extends ScatterBrush {
.replace("{world}", editSession.getWorld().getName())
.replace("{size}", Integer.toString(radius));
Player player = editSession.getPlayer();
Actor actor = editSession.getActor();
if (!(actor instanceof Player)) {
throw FaweCache.PLAYER_ONLY;
}
Player player = (Player) actor;
player.setSelection(selector);
List<String> cmds = StringMan.split(replaced, ';');
for (String cmd : cmds) {

Datei anzeigen

@ -1,9 +1,12 @@
package com.fastasyncworldedit.core.command.tool.brush;
import com.fastasyncworldedit.core.math.heightmap.HeightMap;
import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.function.mask.StencilBrushMask;
import com.fastasyncworldedit.core.math.heightmap.HeightMap;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.mask.SolidBlockMask;
import com.sk89q.worldedit.function.operation.Operations;
@ -47,7 +50,12 @@ public class StencilBrush extends HeightBrush {
int cutoff = onlyWhite ? maxY - minY : 0;
final SolidBlockMask solid = new SolidBlockMask(editSession);
Location loc = editSession.getPlayer().getLocation();
Actor actor = editSession.getActor();
if (!(actor instanceof Player)) {
throw FaweCache.PLAYER_ONLY;
}
Player player = (Player) actor;
Location loc = player.getLocation();
float yaw = loc.getYaw();
float pitch = loc.getPitch();
AffineTransform transform = new AffineTransform().rotateY((-yaw) % 360).rotateX(pitch - 90).inverse();

Datei anzeigen

@ -49,7 +49,9 @@ public class SurfaceSpline implements Brush {
return;
}
path.add(BlockVector3.at(pos.getBlockX(), max, pos.getBlockZ()));
editSession.getPlayer().print(Caption.of("fawe.worldedit.brush.spline.primary.2"));
if (editSession.getActor() != null) {
editSession.getActor().print(Caption.of("fawe.worldedit.brush.spline.primary.2"));
}
return;
}
final List<Node> nodes = new ArrayList<>(path.size());
@ -105,7 +107,9 @@ public class SurfaceSpline implements Brush {
editSession.setBlocks(newSet, pattern);
path.clear();
}
editSession.getPlayer().print(Caption.of("fawe.worldedit.brush.spline.secondary"));
if (editSession.getActor() != null) {
editSession.getActor().print(Caption.of("fawe.worldedit.brush.spline.secondary"));
}
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.fastasyncworldedit.core.command.tool.sweep;
import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.command.tool.ResettableTool;
import com.fastasyncworldedit.core.configuration.Caption;
import com.sk89q.worldedit.EditSession;
@ -8,6 +9,7 @@ import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.command.tool.brush.Brush;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.pattern.Pattern;
import com.sk89q.worldedit.math.BlockVector3;
@ -44,19 +46,18 @@ public class SweepBrush implements Brush, ResettableTool {
boolean newPos = !position.equals(this.position);
this.position = position;
Player player = editSession.getPlayer();
if (player == null) {
//TODO Insert Error Message here or modify EditSession to not require a player.
return;
Actor actor = editSession.getActor();
if (!(actor instanceof Player)) {
throw FaweCache.ACTOR_REQUIRED;
}
if (newPos) {
player.print(Caption.of("fawe.worldedit.brush.spline.primary.2"));
actor.print(Caption.of("fawe.worldedit.brush.spline.primary.2"));
positions.add(position);
return;
}
if (positions.size() < 2) {
player.print(Caption.of("fawe.worldedit.brush.brush.spline.secondary.error"));
actor.print(Caption.of("fawe.worldedit.brush.brush.spline.secondary.error"));
return;
}
@ -70,7 +71,7 @@ public class SweepBrush implements Brush, ResettableTool {
}).collect(Collectors.toList());
interpol.setNodes(nodes);
LocalSession session = player.getSession();
LocalSession session = actor.getSession();
ClipboardHolder holder = session.getExistingClipboard();
if (holder == null) {
throw new RuntimeException(new EmptyClipboardException());
@ -108,7 +109,7 @@ public class SweepBrush implements Brush, ResettableTool {
break;
}
}
player.print(Caption.of("fawe.worldedit.brush.spline.secondary"));
actor.print(Caption.of("fawe.worldedit.brush.spline.secondary"));
reset();
}

Datei anzeigen

@ -1,5 +1,6 @@
package com.fastasyncworldedit.core.extension.factory.parser.transform;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.extension.factory.parser.RichParser;
import com.fastasyncworldedit.core.extent.ResettableExtent;
import com.fastasyncworldedit.core.extent.transform.OffsetTransform;
@ -9,9 +10,8 @@ import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extension.input.ParserContext;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import org.jetbrains.annotations.NotNull;
import javax.annotation.Nonnull;
import java.util.stream.Stream;
public class OffsetTransformParser extends RichParser<ResettableExtent> {
@ -36,9 +36,9 @@ public class OffsetTransformParser extends RichParser<ResettableExtent> {
}
@Override
protected ResettableExtent parseFromInput(@NotNull String[] arguments, ParserContext context) throws InputParseException {
protected ResettableExtent parseFromInput(@Nonnull String[] arguments, ParserContext context) throws InputParseException {
if (arguments.length != 3 && arguments.length != 4) {
throw new InputParseException(TranslatableComponent.of(
throw new InputParseException(Caption.of(
"fawe.error.command.syntax",
TextComponent.of("#offset[x][y][z]")
));

Datei anzeigen

@ -129,7 +129,7 @@
// URI uri = file.toURI();
// ClipboardFormat format = ClipboardFormats.findByFile(file);
// format.hold(player, uri, new FileInputStream(file));
// player.print(TranslatableComponent.of("fawe.worldedit.schematic.schematic.loaded", filename));
// player.print(Caption.of("fawe.worldedit.schematic.schematic.loaded", filename));
// session.setVirtualWorld(null);
// return;
// }
@ -157,7 +157,7 @@
// session.setClipboard(null);
// }
// select.put(clicked, false);
// player.print(TranslatableComponent.of("fawe.worldedit.clipboard.clipboard.cleared"))
// player.print(Caption.of("fawe.worldedit.clipboard.clipboard.cleared"))
// }
// } else {
// // Add it
@ -165,7 +165,7 @@
// MultiClipboardHolder multi = new MultiClipboardHolder(URI.create(""), new LazyClipboardHolder(uri, source, format, null));
// session.addClipboard(multi);
// select.put(clicked, true);
// player.print(TranslatableComponent.of("fawe.worldedit.schematic.schematic.loaded", file.getName()));
// player.print(Caption.of("fawe.worldedit.schematic.schematic.loaded", file.getName()));
// }
// }
// // Resend relevant chunks
@ -501,7 +501,7 @@
// }
//
// @Override
// public FawePlayer getPlayer() {
// public FawePlayer getActor() {
// return player;
// }
//
@ -567,7 +567,7 @@
// clear();
// chunks.clear();
// files.clear();
// player.getPlayer().setPosition(origin, origin.getPitch(), origin.getYaw());
// player.getActor().setPosition(origin, origin.getPitch(), origin.getYaw());
// if (update) {
// IQueueExtent packetQueue = SetQueue.IMP.getNewQueue(player.getWorld(), true, false);
//

Datei anzeigen

@ -1,7 +1,7 @@
package com.fastasyncworldedit.core.function.mask;
import com.fastasyncworldedit.core.math.heightmap.HeightMap;
import com.fastasyncworldedit.core.math.MutableVector3;
import com.fastasyncworldedit.core.math.heightmap.HeightMap;
import com.fastasyncworldedit.core.util.MathMan;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.extent.Extent;

Datei anzeigen

@ -8,13 +8,14 @@ import com.fastasyncworldedit.core.queue.IBatchProcessor;
import com.fastasyncworldedit.core.queue.IChunk;
import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet;
import com.fastasyncworldedit.core.util.EditSessionBuilder;
import com.fastasyncworldedit.core.util.MainUtil;
import com.fastasyncworldedit.core.util.TaskManager;
import com.fastasyncworldedit.core.world.block.BlockID;
import com.google.common.util.concurrent.Futures;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.EditSessionBuilder;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.inventory.BlockBag;
@ -253,9 +254,8 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
}
public EditSession toEditSession(Player player, Region[] regions) {
EditSessionBuilder builder =
new EditSessionBuilder(getWorld()).player(player).autoQueue(false).fastmode(false)
.checkMemory(false).limitUnlimited();
EditSessionBuilder builder = WorldEdit.getInstance().newEditSessionBuilder().world(getWorld()).actor(player).
fastMode(false).checkMemory(false).changeSet(this).limitUnlimited();
if (regions != null) {
builder.allowedRegions(regions);
} else {

Datei anzeigen

@ -88,6 +88,8 @@ public class FaweException extends RuntimeException {
MAX_ITERATIONS,
BLOCK_BAG,
CHUNK,
PLAYER_ONLY,
ACTOR_REQUIRED,
OTHER
}

Datei anzeigen

@ -3,12 +3,12 @@ package com.fastasyncworldedit.core.regions.selector;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.extent.PassthroughExtent;
import com.fastasyncworldedit.core.regions.FuzzyRegion;
import com.fastasyncworldedit.core.util.EditSessionBuilder;
import com.fastasyncworldedit.core.util.ExtentTraverser;
import com.fastasyncworldedit.core.util.MaskTraverser;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.IncompleteRegionException;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.mask.Mask;
@ -31,11 +31,10 @@ public class FuzzyRegionSelector extends PassthroughExtent implements RegionSele
private final ArrayList<BlockVector3> positions;
public FuzzyRegionSelector(Player player, @Nullable World world, Mask mask) {
super(new EditSessionBuilder(world)
.player(player)
super(WorldEdit.getInstance().newEditSessionBuilder().world(world)
.actor(player)
.changeSetNull()
.checkMemory(false)
.autoQueue(false)
.build());
this.player = player;
this.region = new FuzzyRegion(world, getExtent(), mask);
@ -51,11 +50,10 @@ public class FuzzyRegionSelector extends PassthroughExtent implements RegionSele
@Override
public void setWorld(@Nullable World world) {
EditSession extent = new EditSessionBuilder(world)
.player(player)
EditSession extent = WorldEdit.getInstance().newEditSessionBuilder().world(world)
.actor(player)
.changeSetNull()
.checkMemory(false)
.autoQueue(true)
.build();
new ExtentTraverser(this).setNext(extent);
this.region.setWorld(world);

Datei anzeigen

@ -43,14 +43,15 @@ import com.sk89q.worldedit.util.eventbus.EventBus;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.world.World;
import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Locale;
import java.util.UUID;
import static com.google.common.base.Preconditions.checkNotNull;
@Deprecated(forRemoval = true)
public class EditSessionBuilder {
private static final Logger LOGGER = LogManagerCompat.getLogger();
@ -73,6 +74,12 @@ public class EditSessionBuilder {
private RelightMode relightMode;
private Relighter relighter;
private Boolean wnaMode;
private AbstractChangeSet changeTask;
private Extent bypassHistory;
private Extent bypassAll;
private Extent extent;
private boolean compiled;
private boolean wrapped;
/**
* An EditSession builder<br>
@ -89,7 +96,7 @@ public class EditSessionBuilder {
*
* @param world A world must be provided for all EditSession(s)
*/
public EditSessionBuilder(@Nonnull World world) {
public EditSessionBuilder(World world) {
checkNotNull(world);
this.world = world;
}
@ -271,13 +278,6 @@ public class EditSessionBuilder {
return extent;
}
private AbstractChangeSet changeTask;
private Extent bypassHistory;
private Extent bypassAll;
private Extent extent;
private boolean compiled;
private boolean wrapped;
public EditSessionBuilder compile() {
if (compiled) {
return this;
@ -326,9 +326,9 @@ public class EditSessionBuilder {
if (extent == null) {
IQueueExtent<IQueueChunk> queue = null;
World unwrapped = WorldWrapper.unwrap(world);
boolean placeChunks = this.fastmode || this.limit.FAST_PLACEMENT;
boolean placeChunks = (this.fastmode || this.limit.FAST_PLACEMENT) && (wnaMode == null || !wnaMode);
if (placeChunks && (wnaMode == null || !wnaMode)) {
if (placeChunks) {
wnaMode = false;
if (unwrapped instanceof IQueueExtent) {
extent = queue = (IQueueExtent) unwrapped;
@ -413,18 +413,18 @@ public class EditSessionBuilder {
}
} else {
allowedRegions = new Region[]{RegionWrapper.GLOBAL()};
// this.extent = new HeightBoundExtent(this.extent, this.limit, 0, world.getMaxY());
}
// There's no need to do lighting (and it'll also just be a pain to implement) if we're not placing chunks
if (placeChunks && ((relightMode != null && relightMode != RelightMode.NONE) || (relightMode == null && Settings.IMP.LIGHTING.MODE > 0))) {
if (placeChunks) {
if (((relightMode != null && relightMode != RelightMode.NONE) || (relightMode == null && Settings.IMP.LIGHTING.MODE > 0))) {
relighter = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.WORLD_EDITING)
.getRelighterFactory().createRelighter(relightMode, world, queue);
extent.addProcessor(new RelightProcessor(relighter));
} else {
relighter = NullRelighter.INSTANCE;
}
extent.addProcessor(new HeightmapProcessor(world.getMinY(), world.getMaxY()));
relighter = NullRelighter.INSTANCE;
}
if (limit != null && !limit.isUnlimited() && regionExtent != null) {
this.extent = new LimitExtent(regionExtent, limit);
} else if (limit != null && !limit.isUnlimited()) {
@ -496,4 +496,5 @@ public class EditSessionBuilder {
return allowedRegions;
}
}

Datei anzeigen

@ -2,11 +2,11 @@ package com.fastasyncworldedit.core.wrappers;
import com.fastasyncworldedit.core.Fawe;
import com.fastasyncworldedit.core.math.MutableBlockVector3;
import com.fastasyncworldedit.core.util.EditSessionBuilder;
import com.fastasyncworldedit.core.util.TaskManager;
import com.fastasyncworldedit.core.util.task.RunnableVal;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.PlayerProxy;
import com.sk89q.worldedit.extent.Extent;
@ -151,8 +151,8 @@ public class AsyncPlayer extends PlayerProxy {
if (alwaysGlass || !isAllowedToFly()) {
RuntimeException caught = null;
try {
EditSession edit =
new EditSessionBuilder(WorldWrapper.unwrap(getWorld())).player(unwrap(getBasePlayer())).build();
EditSession edit = WorldEdit.getInstance().newEditSessionBuilder().world(WorldWrapper.unwrap(getWorld())).actor(
unwrap(getBasePlayer())).build();
edit.setBlock(BlockVector3.at(x, y - 1, z), BlockTypes.GLASS);
edit.flushQueue();
LocalSession session = Fawe.get().getWorldEdit().getSessionManager().get(this);

Datei anzeigen

@ -53,7 +53,6 @@ import com.fastasyncworldedit.core.math.random.SimplexNoise;
import com.fastasyncworldedit.core.object.FaweLimit;
import com.fastasyncworldedit.core.queue.implementation.preloader.Preloader;
import com.fastasyncworldedit.core.regions.RegionWrapper;
import com.fastasyncworldedit.core.util.EditSessionBuilder;
import com.fastasyncworldedit.core.util.ExtentTraverser;
import com.fastasyncworldedit.core.util.MaskTraverser;
import com.fastasyncworldedit.core.util.MathMan;
@ -63,10 +62,12 @@ import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.ChangeSetExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.MaskingExtent;
import com.sk89q.worldedit.extent.TracingExtent;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.extent.inventory.BlockBagExtent;
@ -135,7 +136,9 @@ import com.sk89q.worldedit.util.Direction;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.TreeGenerator;
import com.sk89q.worldedit.util.collection.BlockMap;
import com.sk89q.worldedit.util.eventbus.EventBus;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -155,12 +158,14 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
@ -224,10 +229,11 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
@SuppressWarnings("ProtectedField")
protected final World world;
private final @Nullable
Actor actor;
//FAWE start
private final FaweLimit originalLimit;
private final FaweLimit limit;
private final Player player;
private AbstractChangeSet changeSet;
private boolean history;
@ -243,33 +249,31 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
private final int maxY;
//FAWE end
private final List<WatchdogTickingExtent> watchdogExtents = new ArrayList<>(2);
@Nullable
private final List<TracingExtent> tracingExtents;
//FAWE start
private final Relighter relighter;
private final boolean wnaMode;
@Nullable
private final Region[] allowedRegions;
@Deprecated
@Deprecated(forRemoval = true)
public EditSession(
@Nonnull EventBus bus, World world, @Nullable Player player,
@Nonnull EventBus bus, World world, @Nullable Player actor,
@Nullable FaweLimit limit, @Nullable AbstractChangeSet changeSet,
@Nullable RegionWrapper[] allowedRegions, @Nullable Boolean autoQueue,
@Nullable Boolean fastmode, @Nullable Boolean checkMemory, @Nullable Boolean combineStages,
@Nullable BlockBag blockBag, @Nullable EditSessionEvent event
) {
this(new EditSessionBuilder(world)
.player(player)
this(new EditSessionBuilder(bus).world(world).actor(actor)
.limit(limit)
.changeSet(changeSet)
.allowedRegions(allowedRegions)
.autoQueue(autoQueue)
.fastmode(fastmode)
.fastMode(fastmode)
.checkMemory(checkMemory)
.combineStages(combineStages)
.blockBag(blockBag)
.eventBus(bus)
.event(event));
}
//FAWE end
@ -284,6 +288,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* @param event the event to call with the extent
*/
//FAWE start - EditSessionEvent
@Deprecated(forRemoval = true)
public EditSession(
@Nonnull EventBus eventBus,
World world,
@ -294,14 +299,14 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
this(eventBus, world, null, null, null, null, true, null, null, null, blockBag, event);
}
public EditSession(EditSessionBuilder builder) {
EditSession(EditSessionBuilder builder) {
super(builder.compile().getExtent());
this.world = builder.getWorld();
this.bypassHistory = builder.getBypassHistory();
this.bypassAll = builder.getBypassAll();
this.originalLimit = builder.getLimit();
this.limit = builder.getLimit().copy();
this.player = builder.getPlayer();
this.actor = builder.getActor();
this.changeSet = builder.getChangeTask();
this.minY = world.getMinY();
this.maxY = world.getMaxY();
@ -309,6 +314,34 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
this.history = changeSet != null;
this.relighter = builder.getRelighter();
this.wnaMode = builder.isWNAMode();
if (builder.isTracing()) {
this.tracingExtents = new ArrayList<>();
checkNotNull(actor, "A player is required while tracing");
} else {
this.tracingExtents = null;
}
this.allowedRegions = builder.getAllowedRegions() != null ? builder.getAllowedRegions().clone() : null;
}
@Deprecated(forRemoval = true)
public EditSession(com.fastasyncworldedit.core.util.EditSessionBuilder builder) {
super(builder.compile().getExtent());
this.world = builder.getWorld();
this.bypassHistory = builder.getBypassHistory();
this.bypassAll = builder.getBypassAll();
this.originalLimit = builder.getLimit();
this.limit = builder.getLimit().copy();
this.actor = builder.getPlayer();
this.changeSet = builder.getChangeTask();
this.minY = world.getMinY();
this.maxY = world.getMaxY();
this.blockBag = builder.getBlockBag();
this.history = changeSet != null;
this.relighter = builder.getRelighter();
this.wnaMode = builder.isWNAMode();
this.tracingExtents = null;
this.allowedRegions = builder.getAllowedRegions() != null ? builder.getAllowedRegions().clone() : null;
}
@ -378,22 +411,48 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
new ExtentTraverser(this).setNext(extent);
}
//FAWE Start
/**
* Get the Player or null.
* Get the Actor or null.
*
* @return the player
* @return the actor
*/
@Nullable
public Player getPlayer() {
return player;
public Actor getActor() {
return actor;
}
//FAWE End
private Extent traceIfNeeded(Extent input) {
Extent output = input;
if (tracingExtents != null) {
TracingExtent newExtent = new TracingExtent(input);
output = newExtent;
tracingExtents.add(newExtent);
}
return output;
}
// pkg private for TracedEditSession only, may later become public API
boolean commitRequired() {
//FAWE start
return false;
}
//FAWE end
/**
* Get the current list of active tracing extents.
*/
private List<TracingExtent> getActiveTracingExtents() {
if (tracingExtents == null) {
return List.of();
}
return tracingExtents.stream()
.filter(TracingExtent::isActive)
.collect(Collectors.toList());
}
/**
* Turns on specific features for a normal WorldEdit session, such as
* {@link #setBatchingChunks(boolean)
@ -801,7 +860,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
}
}
player.print(Caption.of("fawe.error.worldedit.some.fails.blockbag", str.toString()));
actor.print(Caption.of("fawe.error.worldedit.some.fails.blockbag", str.toString()));
}
}
return Collections.emptyMap();
@ -964,6 +1023,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* @param stage the level
* @return whether the block changed
* @throws WorldEditException thrown on a set error
* @deprecated Deprecated as may perform differently in FAWE.
*/
@Deprecated
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, Stage stage) throws
@ -995,6 +1055,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* @param position the position to set the block at
* @param block the block
* @return whether the block changed
* @deprecated Deprecated as may perform differently in FAWE.
*/
@Deprecated
public <B extends BlockStateHolder<B>> boolean rawSetBlock(BlockVector3 position, B block) {
@ -1209,7 +1270,47 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
*/
@Override
public void close() {
flushSession();
flushQueue();
dumpTracingInformation();
}
private void dumpTracingInformation() {
if (this.tracingExtents == null) {
return;
}
List<TracingExtent> tracingExtents = getActiveTracingExtents();
assert actor != null;
if (tracingExtents.isEmpty()) {
actor.printError(TextComponent.of("worldedit.trace.no-tracing-extents"));
return;
}
// find the common stacks
Set<List<TracingExtent>> stacks = new LinkedHashSet<>();
Map<List<TracingExtent>, BlockVector3> stackToPosition = new HashMap<>();
Set<BlockVector3> touchedLocations = Collections.newSetFromMap(BlockMap.create());
for (TracingExtent tracingExtent : tracingExtents) {
touchedLocations.addAll(tracingExtent.getTouchedLocations());
}
for (BlockVector3 loc : touchedLocations) {
List<TracingExtent> stack = tracingExtents.stream()
.filter(it -> it.getTouchedLocations().contains(loc))
.collect(Collectors.toList());
boolean anyFailed = stack.stream()
.anyMatch(it -> it.getFailedActions().containsKey(loc));
if (anyFailed && stacks.add(stack)) {
stackToPosition.put(stack, loc);
}
}
stackToPosition.forEach((stack, position) -> {
// stack can never be empty, something has to have touched the position
TracingExtent failure = stack.get(0);
actor.printDebug(Caption.of(
"worldedit.trace.action-failed",
failure.getFailedActions().get(position).toString(),
position.toString(),
failure.getExtent().getClass().getName()
));
});
}
/**
@ -1234,11 +1335,11 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
FaweLimit used = getLimitUsed();
if (used.MAX_FAILS > 0) {
if (used.MAX_CHANGES > 0 || used.MAX_ENTITIES > 0) {
player.print(Caption.of("fawe.error.worldedit.some.fails", used.MAX_FAILS));
actor.print(Caption.of("fawe.error.worldedit.some.fails", used.MAX_FAILS));
} else if (new ExtentTraverser<>(getExtent()).findAndGet(FaweRegionExtent.class) != null) {
player.print(Caption.of("fawe.cancel.worldedit.cancel.reason.outside.region"));
actor.print(Caption.of("fawe.cancel.worldedit.cancel.reason.outside.region"));
} else {
player.print(Caption.of("fawe.cancel.worldedit.cancel.reason.outside.level"));
actor.print(Caption.of("fawe.cancel.worldedit.cancel.reason.outside.level"));
}
}
if (wnaMode) {
@ -1262,14 +1363,14 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
}
}
} catch (Throwable e) {
player.print(Caption.of("fawe.error.lighting"));
actor.print(Caption.of("fawe.error.lighting"));
e.printStackTrace();
}
// Cancel any preloader associated with the actor if present
if (getPlayer() != null) {
if (getActor() instanceof Player) {
Preloader preloader = Fawe.imp().getPreloader(false);
if (preloader != null) {
preloader.cancel(getPlayer());
preloader.cancel(getActor());
}
}
// Enqueue it
@ -1738,7 +1839,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* Stack a cuboid region.
*
* @param region the region to stack
* @param dir the direction to stack
* @param offset how far to move the contents each stack. Is directional.
* @param count the number of times to stack
* @param copyEntities true to copy entities
* @param copyBiomes true to copy biomes
@ -1747,18 +1848,18 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* @throws MaxChangedBlocksException thrown if too many blocks are changed
*/
public int stackCuboidRegion(
Region region, BlockVector3 dir, int count,
Region region, BlockVector3 offset, int count,
boolean copyEntities, boolean copyBiomes, Mask mask
) throws MaxChangedBlocksException {
checkNotNull(region);
checkNotNull(dir);
checkNotNull(offset);
checkArgument(count >= 1, "count >= 1 required");
BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
BlockVector3 to = region.getMinimumPoint();
ForwardExtentCopy copy = new ForwardExtentCopy(this, region, this, to);
copy.setRepetitions(count);
copy.setTransform(new AffineTransform().translate(dir.multiply(size)));
copy.setTransform(new AffineTransform().translate(offset.multiply(size)));
copy.setCopyingEntities(copyEntities);
copy.setCopyingBiomes(copyBiomes);
final Region allowedRegion;
@ -1781,8 +1882,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* Move the blocks in a region a certain direction.
*
* @param region the region to move
* @param dir the direction
* @param distance the distance to move
* @param offset the offset. Is directional.
* @param multiplier the number to multiply the offset by
* @param copyAir true to copy air blocks
* @param moveEntities true to move entities
* @param copyBiomes true to copy biomes
@ -1792,8 +1893,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
*/
public int moveRegion(
Region region,
BlockVector3 dir,
int distance,
BlockVector3 offset,
int multiplier,
boolean copyAir,
boolean moveEntities,
boolean copyBiomes,
@ -1804,7 +1905,7 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
if (!copyAir) {
mask = new ExistingBlockMask(this);
}
return moveRegion(region, dir, distance, moveEntities, copyBiomes, mask, replacement);
return moveRegion(region, offset, multiplier, moveEntities, copyBiomes, mask, replacement);
//FAWE end
}
@ -1812,8 +1913,8 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* Move the blocks in a region a certain direction.
*
* @param region the region to move
* @param dir the direction
* @param distance the distance to move
* @param offset the offset. Is directional.
* @param multiplier the number to multiply the offset by
* @param moveEntities true to move entities
* @param copyBiomes true to copy biomes (source biome is unchanged)
* @param mask source mask for the operation (only matching blocks are moved)
@ -1823,18 +1924,18 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
* @throws IllegalArgumentException thrown if the region is not a flat region, but copyBiomes is true
*/
public int moveRegion(
Region region, BlockVector3 dir, int distance,
Region region, BlockVector3 offset, int multiplier,
boolean moveEntities, boolean copyBiomes, Mask mask, Pattern replacement
) throws MaxChangedBlocksException {
checkNotNull(region);
checkNotNull(dir);
checkArgument(distance >= 1, "distance >= 1 required");
checkNotNull(offset);
checkArgument(multiplier >= 1, "distance >= 1 required");
checkArgument(!copyBiomes || region instanceof FlatRegion, "can't copy biomes from non-flat region");
//FAWE start - add up distance
BlockVector3 to = region.getMinimumPoint().add(dir.multiply(distance));
BlockVector3 to = region.getMinimumPoint().add(offset.multiply(multiplier));
final BlockVector3 displace = dir.multiply(distance);
final BlockVector3 displace = offset.multiply(multiplier);
final BlockVector3 size = region.getMaximumPoint().subtract(region.getMinimumPoint()).add(1, 1, 1);
BlockVector3 disAbs = displace.abs();
@ -2941,7 +3042,20 @@ public class EditSession extends PassthroughExtent implements AutoCloseable {
) throws ExpressionException, MaxChangedBlocksException {
final Expression expression = Expression.compile(expressionString, "x", "y", "z");
expression.optimize();
return deformRegion(region, zero, unit, expression, timeout);
}
/**
* Internal version of {@link EditSession#deformRegion(Region, Vector3, Vector3, String, int)}.
*
* <p>
* The Expression class is subject to change. Expressions should be provided via the string overload.
* </p>
*/
public int deformRegion(
final Region region, final Vector3 zero, final Vector3 unit, final Expression expression,
final int timeout
) throws ExpressionException, MaxChangedBlocksException {
final Variable x = expression.getSlots().getVariable("x")
.orElseThrow(IllegalStateException::new);
final Variable y = expression.getSlots().getVariable("y")

Datei anzeigen

@ -0,0 +1,682 @@
/*
* WorldEdit, a Minecraft world manipulation toolkit
* Copyright (C) sk89q <http://www.sk89q.com>
* Copyright (C) WorldEdit team and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.sk89q.worldedit;
import com.fastasyncworldedit.core.Fawe;
import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.extent.FaweRegionExtent;
import com.fastasyncworldedit.core.extent.HistoryExtent;
import com.fastasyncworldedit.core.extent.LimitExtent;
import com.fastasyncworldedit.core.extent.MultiRegionExtent;
import com.fastasyncworldedit.core.extent.NullExtent;
import com.fastasyncworldedit.core.extent.SingleRegionExtent;
import com.fastasyncworldedit.core.extent.SlowExtent;
import com.fastasyncworldedit.core.extent.StripNBTExtent;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightmapProcessor;
import com.fastasyncworldedit.core.extent.processor.lighting.NullRelighter;
import com.fastasyncworldedit.core.extent.processor.lighting.RelightMode;
import com.fastasyncworldedit.core.extent.processor.lighting.RelightProcessor;
import com.fastasyncworldedit.core.extent.processor.lighting.Relighter;
import com.fastasyncworldedit.core.history.DiskStorageHistory;
import com.fastasyncworldedit.core.history.MemoryOptimizedHistory;
import com.fastasyncworldedit.core.history.RollbackOptimizedHistory;
import com.fastasyncworldedit.core.history.changeset.AbstractChangeSet;
import com.fastasyncworldedit.core.history.changeset.BlockBagChangeSet;
import com.fastasyncworldedit.core.history.changeset.NullChangeSet;
import com.fastasyncworldedit.core.object.FaweLimit;
import com.fastasyncworldedit.core.queue.IQueueChunk;
import com.fastasyncworldedit.core.queue.IQueueExtent;
import com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent;
import com.fastasyncworldedit.core.regions.RegionWrapper;
import com.fastasyncworldedit.core.util.MemUtil;
import com.fastasyncworldedit.core.util.Permission;
import com.fastasyncworldedit.core.wrappers.WorldWrapper;
import com.google.common.base.Preconditions;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Locatable;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.Identifiable;
import com.sk89q.worldedit.util.eventbus.EventBus;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.world.World;
import org.apache.logging.log4j.Logger;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.Locale;
import java.util.UUID;
/**
* A builder-style factory for {@link EditSession EditSessions}.
*/
public final class EditSessionBuilder {
private static final Logger LOGGER = LogManagerCompat.getLogger();
private final EventBus eventBus;
private FaweLimit limit;
private AbstractChangeSet changeSet;
private Region[] allowedRegions;
private Boolean fastMode;
private Boolean checkMemory;
private Boolean combineStages;
private EditSessionEvent event;
private String command;
private RelightMode relightMode;
private Relighter relighter;
private Boolean wnaMode;
private AbstractChangeSet changeTask;
private Extent bypassHistory;
private Extent bypassAll;
private Extent extent;
private boolean compiled;
private boolean wrapped;
private @Nullable
World world;
private int maxBlocks = -1;
@Nullable
private Actor actor;
@Nullable
private BlockBag blockBag;
private boolean tracing;
EditSessionBuilder(EventBus eventBus) {
this.eventBus = eventBus;
}
/**
* Set the world for the {@link EditSession}.
*
* @param world the world
* @return this builder
*/
public EditSessionBuilder world(@Nullable World world) {
this.world = world;
return setDirty();
}
/**
* Get the world to be edited if present or null
*/
@Nullable
public World getWorld() {
return world;
}
/**
* Get the maximum number of block changes allowed
*/
public int getMaxBlocks() {
return maxBlocks;
}
/**
* Set the maximum blocks to change for the {@link EditSession}.
*
* @param maxBlocks the maximum blocks to change
* @return this builder
*/
public EditSessionBuilder maxBlocks(int maxBlocks) {
this.maxBlocks = maxBlocks;
return setDirty();
}
/**
* Get the actor associated with the edit if present or null
*/
@Nullable
public Actor getActor() {
return actor;
}
/**
* Set the actor who owns the {@link EditSession}.
*
* @param actor the actor
* @return this builder
*/
public EditSessionBuilder actor(@Nullable Actor actor) {
this.actor = actor;
return setDirty();
}
/**
*
* Get the {@link BlockBag} associated with the edit if present or null
*/
@Nullable
public BlockBag getBlockBag() {
return blockBag;
}
/**
* Set the block bag for the {@link EditSession}.
*
* @param blockBag the block bag
* @return this builder
*/
public EditSessionBuilder blockBag(@Nullable BlockBag blockBag) {
this.blockBag = blockBag;
return setDirty();
}
/**
* Check if tracing is enabled.
*
* <em>Internal use only.</em>
*/
public boolean isTracing() {
return tracing;
}
/**
* Set tracing enabled/disabled.
*
* <em>Internal use only.</em>
*/
public EditSessionBuilder tracing(boolean tracing) {
this.tracing = tracing;
return setDirty();
}
/**
* Set the actor to one with a location/extent associated. Sets both the actor and the world.
*/
public <A extends Actor & Locatable> EditSessionBuilder locatableActor(A locatable) {
Extent extent = locatable.getExtent();
Preconditions.checkArgument(extent instanceof World, "%s is not located in a World", locatable);
return world(((World) extent)).actor(locatable);
}
/**
* Build the {@link EditSession} using properties described in this builder.
*
* @return the new EditSession
*/
public EditSession build() {
// TracedEditSession does nothing at the moment.
//if (WorldEdit.getInstance().getConfiguration().traceUnflushedSessions) {
// return new TracedEditSession(this);
//}
return new EditSession(this);
}
/**
* Set builder as changed and requiring (re-)compilation
*/
private EditSessionBuilder setDirty() {
compiled = false;
return this;
}
/**
* Set the {@link EditSessionEvent} instance to be used for firing at different stages of preparation
*/
public EditSessionBuilder event(@Nullable EditSessionEvent event) {
this.event = event;
return setDirty();
}
/**
* Set the limit(s) for the edit to use
*/
public EditSessionBuilder limit(@Nullable FaweLimit limit) {
this.limit = limit;
return setDirty();
}
/**
* Set the edit to be able to edit everywhere, and for any number of blocks
*/
public EditSessionBuilder limitUnlimited() {
return limit(FaweLimit.MAX.copy());
}
/**
* Unlimited in regions/block changes, but uses the given {@link Actor}'s inventory mode.
*/
public EditSessionBuilder limitUnprocessed(@Nonnull Actor player) {
limitUnlimited();
FaweLimit tmp = player.getLimit();
limit.INVENTORY_MODE = tmp.INVENTORY_MODE;
return setDirty();
}
/**
* Set the changeset to be used for history
*/
public EditSessionBuilder changeSet(@Nullable AbstractChangeSet changeSet) {
this.changeSet = changeSet;
return setDirty();
}
/**
* Do not process any history
*/
public EditSessionBuilder changeSetNull() {
return changeSet(new NullChangeSet(world));
}
/**
* Set the command used that created this edit. Used in {@link RollbackOptimizedHistory}
*/
public EditSessionBuilder command(String command) {
this.command = command;
return this;
}
/**
* Create a new changeset to be used for the edit's history.
*
* @param disk If disk should be used for history storage
* @param uuid UUID to be used for the history or null if unneeded.
*/
public EditSessionBuilder changeSet(boolean disk, @Nullable UUID uuid) {
if (disk) {
if (Settings.IMP.HISTORY.USE_DATABASE) {
this.changeSet = new RollbackOptimizedHistory(world, uuid);
} else {
this.changeSet = new DiskStorageHistory(world, uuid);
}
} else {
this.changeSet = new MemoryOptimizedHistory(world);
}
return setDirty();
}
/**
* Set the regions the edit is allowed to operate in. Set to null for the regions to be calculated based on the actor if
* present
*/
public EditSessionBuilder allowedRegions(@Nullable Region[] allowedRegions) {
this.allowedRegions = allowedRegions;
return setDirty();
}
/**
* Set the regions the edit is allowed to operate in. Set to null for the regions to be calculated based on the actor if
* present
*/
@Deprecated
public EditSessionBuilder allowedRegions(@Nullable RegionWrapper[] allowedRegions) {
this.allowedRegions = allowedRegions;
return setDirty();
}
/**
* Set the region the edit is allowed to operate in. Set to null for the regions to be calculated based on the actor if
* present
*/
public EditSessionBuilder allowedRegions(@Nullable RegionWrapper allowedRegion) {
this.allowedRegions = allowedRegion == null ? null : allowedRegion.toArray();
return setDirty();
}
/**
* Set the edit to be allowed to edit everywhere
*/
public EditSessionBuilder allowedRegionsEverywhere() {
return allowedRegions(new Region[]{RegionWrapper.GLOBAL()});
}
/**
* Does nothing as of 1.13 new queueing system
*/
@Deprecated(forRemoval = true)
public EditSessionBuilder autoQueue(@Nullable Boolean autoQueue) {
return setDirty();
}
/**
* Set fast mode. Use null to set to actor's fast mode setting. Also set to true by default if history for console disabled
*/
public EditSessionBuilder fastMode(@Nullable Boolean fastMode) {
this.fastMode = fastMode;
return setDirty();
}
/**
* Set the {@link RelightMode}
*/
public EditSessionBuilder relightMode(@Nullable RelightMode relightMode) {
this.relightMode = relightMode;
return setDirty();
}
/**
* Override if memory usage should be checked during editsession compilation. By default, checks memory if fastmode is not
* enabled and actor is not null.
*/
public EditSessionBuilder checkMemory(@Nullable Boolean checkMemory) {
this.checkMemory = checkMemory;
return setDirty();
}
/**
* Record history with dispatching:,
* - Much faster as it avoids duplicate block checks,
* - Slightly worse compression since dispatch order is different.
*/
public EditSessionBuilder combineStages(@Nullable Boolean combineStages) {
this.combineStages = combineStages;
return setDirty();
}
/**
* Compile the builder to the settings given. Prepares history, limits, lighting, etc.
*/
public EditSessionBuilder compile() {
if (compiled) {
return this;
}
compiled = true;
wrapped = false;
if (event == null) {
event = new EditSessionEvent(world, actor, -1, null);
}
if (actor == null && event.getActor() != null) {
actor = event.getActor();
}
if (limit == null) {
if (actor == null) {
limit = FaweLimit.MAX;
} else {
limit = actor.getLimit();
}
}
if (fastMode == null) {
if (actor == null) {
fastMode = !Settings.IMP.HISTORY.ENABLE_FOR_CONSOLE;
} else {
fastMode = actor.getSession().hasFastMode();
}
}
if (checkMemory == null) {
checkMemory = actor != null && !this.fastMode;
}
if (checkMemory) {
if (MemUtil.isMemoryLimitedSlow()) {
if (Permission.hasPermission(actor, "worldedit.fast")) {
actor.print(Caption.of("fawe.info.worldedit.oom.admin"));
}
throw FaweCache.LOW_MEMORY;
}
}
// this.originalLimit = limit;
this.blockBag = limit.INVENTORY_MODE != 0 ? blockBag : null;
this.limit = limit.copy();
if (extent == null) {
IQueueExtent<IQueueChunk> queue = null;
World unwrapped = WorldWrapper.unwrap(world);
boolean placeChunks = (this.fastMode || this.limit.FAST_PLACEMENT) && (wnaMode == null || !wnaMode);
if (placeChunks) {
wnaMode = false;
if (unwrapped instanceof IQueueExtent) {
extent = queue = (IQueueExtent) unwrapped;
} else if (Settings.IMP.QUEUE.PARALLEL_THREADS > 1 && !Fawe.isMainThread()) {
ParallelQueueExtent parallel = new ParallelQueueExtent(Fawe.get().getQueueHandler(), world, fastMode);
queue = parallel.getExtent();
extent = parallel;
} else {
extent = queue = Fawe.get().getQueueHandler().getQueue(world);
}
} else {
wnaMode = true;
extent = world;
}
if (combineStages == null) {
combineStages =
// If it's enabled in the settings
Settings.IMP.HISTORY.COMBINE_STAGES
// If fast placement is disabled, it's slower to perform a copy on each chunk
&& this.limit.FAST_PLACEMENT
// If the edit uses items from the inventory we can't use a delayed task
&& this.blockBag == null;
}
extent = this.bypassAll = wrapExtent(extent, eventBus, event, EditSession.Stage.BEFORE_CHANGE);
this.bypassHistory = this.extent = wrapExtent(bypassAll, eventBus, event, EditSession.Stage.BEFORE_REORDER);
if (!this.fastMode || changeSet != null) {
if (changeSet == null) {
if (Settings.IMP.HISTORY.USE_DISK) {
UUID uuid = actor == null ? Identifiable.CONSOLE : actor.getUniqueId();
if (Settings.IMP.HISTORY.USE_DATABASE) {
changeSet = new RollbackOptimizedHistory(world, uuid);
} else {
changeSet = new DiskStorageHistory(world, uuid);
}
} else {
if (combineStages && Settings.IMP.HISTORY.COMPRESSION_LEVEL == 0) {
//TODO add CPUOptimizedChangeSet
}
changeSet = new MemoryOptimizedHistory(world);
}
}
if (this.limit.SPEED_REDUCTION > 0) {
this.extent = this.bypassHistory = new SlowExtent(this.bypassHistory, this.limit.SPEED_REDUCTION);
}
if (command != null && changeSet instanceof RollbackOptimizedHistory) {
((RollbackOptimizedHistory) changeSet).setCommand(this.command);
}
if (!(changeSet instanceof NullChangeSet)) {
if (this.blockBag != null) {
//TODO implement block bag as IBatchProcessor
changeSet = new BlockBagChangeSet(changeSet, blockBag, limit.INVENTORY_MODE == 1);
}
if (combineStages) {
changeTask = changeSet;
this.extent = extent.enableHistory(changeSet);
} else {
this.extent = new HistoryExtent(extent, changeSet);
}
}
}
if (allowedRegions == null) {
if (actor != null && !actor.hasPermission("fawe.bypass") && !actor.hasPermission("fawe.bypass.regions")) {
if (actor instanceof Player) {
Player player = (Player) actor;
allowedRegions = player.getCurrentRegions();
}
}
}
FaweRegionExtent regionExtent = null;
if (allowedRegions != null) {
if (allowedRegions.length == 0) {
regionExtent = new NullExtent(this.extent, FaweCache.NO_REGION);
} else {
if (allowedRegions.length == 1) {
regionExtent = new SingleRegionExtent(this.extent, this.limit, allowedRegions[0]);
} else {
regionExtent = new MultiRegionExtent(this.extent, this.limit, allowedRegions);
}
}
} else {
allowedRegions = new Region[]{RegionWrapper.GLOBAL()};
}
// There's no need to do lighting (and it'll also just be a pain to implement) if we're not placing chunks
if (placeChunks) {
if (((relightMode != null && relightMode != RelightMode.NONE) || (relightMode == null && Settings.IMP.LIGHTING.MODE > 0))) {
relighter = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.WORLD_EDITING)
.getRelighterFactory().createRelighter(relightMode, world, queue);
extent.addProcessor(new RelightProcessor(relighter));
}
extent.addProcessor(new HeightmapProcessor(world.getMinY(), world.getMaxY()));
} else {
relighter = NullRelighter.INSTANCE;
}
if (limit != null && !limit.isUnlimited() && regionExtent != null) {
this.extent = new LimitExtent(regionExtent, limit);
} else if (limit != null && !limit.isUnlimited()) {
this.extent = new LimitExtent(this.extent, limit);
} else if (regionExtent != null) {
this.extent = regionExtent;
}
if (this.limit != null && this.limit.STRIP_NBT != null && !this.limit.STRIP_NBT.isEmpty()) {
//TODO add batch processor for strip nbt
this.extent = new StripNBTExtent(this.extent, this.limit.STRIP_NBT);
}
this.extent = wrapExtent(this.extent, eventBus, event, EditSession.Stage.BEFORE_HISTORY);
}
return this;
}
/**
* Get the relight engine to be used
*/
public Relighter getRelighter() {
return relighter;
}
/**
* If the edit will force using WNA
*/
public boolean isWNAMode() {
return wnaMode;
}
/**
* get the allowed regions associated with the edit's restricttions
*/
@Nullable
public Region[] getAllowedRegions() {
return allowedRegions;
}
/**
* Force WNA to be used instead of FAWE's queue system. Will use more memory, be slower, and more likely to cause issues.
*/
public EditSessionBuilder forceWNA() {
this.wnaMode = true;
return setDirty();
}
/**
* If an {@link EditSessionEvent} has been fired yet
*/
public boolean isWrapped() {
return wrapped;
}
/**
* Get the base extent that blocks are set to, bypassing any restrictions, limits and history. All extents up to and including
* {@link com.sk89q.worldedit.EditSession.Stage#BEFORE_REORDER}
*/
public Extent getBypassHistory() {
return bypassHistory;
}
/**
* Get the base extent that blocks are set to, bypassing any restrictions, limits and history. All extents up to and including
* {@link com.sk89q.worldedit.EditSession.Stage#BEFORE_CHANGE}
*/
public Extent getBypassAll() {
return bypassAll;
}
/**
* Get the edit's limits
*/
@Nonnull
public FaweLimit getLimit() {
return limit;
}
/**
* Get the change set that will be used for history
*/
public AbstractChangeSet getChangeTask() {
return changeTask;
}
/**
* Get the ultimate resultant extent
*/
public Extent getExtent() {
return extent != null ? extent : world;
}
/**
* Fire an {@link EditSessionEvent}. Fired after each stage of preparation, allows other plugins to add/alter extents.
*/
private Extent wrapExtent(
final Extent extent,
final EventBus eventBus,
EditSessionEvent event,
final EditSession.Stage stage
) {
event = event.clone(stage);
event.setExtent(extent);
eventBus.post(event);
if (event.isCancelled()) {
return new NullExtent(extent, FaweCache.MANUAL);
}
final Extent toReturn = event.getExtent();
if (toReturn instanceof com.sk89q.worldedit.extent.NullExtent) {
return new NullExtent(toReturn, FaweCache.MANUAL);
}
if (toReturn != extent) {
String className = toReturn.getClass().getName().toLowerCase(Locale.ROOT);
for (String allowed : Settings.IMP.EXTENT.ALLOWED_PLUGINS) {
if (className.contains(allowed.toLowerCase(Locale.ROOT))) {
this.wrapped = true;
return toReturn;
}
}
if (Settings.IMP.EXTENT.DEBUG) {
if (event.getActor() != null) {
event.getActor().printDebug(TextComponent.of("Potentially unsafe extent blocked: " + toReturn
.getClass()
.getName()));
event.getActor().printDebug(TextComponent.of(
" - For area restrictions and block logging, it is recommended to use the FaweAPI"));
event.getActor().printDebug(TextComponent.of(" - To allow " + toReturn
.getClass()
.getName() + ", add it to the FAWE `allowed-plugins` list in config.yml"));
event.getActor().printDebug(TextComponent.of(
" - If you are unsure which plugin tries to use the extent, you can find some additional information below:"));
event.getActor().printDebug(TextComponent.of(" - " + toReturn.getClass().getClassLoader()));
} else {
LOGGER.debug("Potentially unsafe extent blocked: " + toReturn.getClass().getName());
LOGGER.debug(" - For area restrictions and block logging, it is recommended to use the FaweAPI");
LOGGER.debug(" - To allow " + toReturn
.getClass()
.getName() + ", add it to the FAWE `allowed-plugins` list in config.yml");
LOGGER.debug(
" - If you are unsure which plugin tries to use the extent, you can find some additional information below:");
LOGGER.debug(" - " + toReturn.getClass().getClassLoader());
}
}
}
return extent;
}
}

Datei anzeigen

@ -22,11 +22,8 @@ package com.sk89q.worldedit;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.util.eventbus.EventBus;
import com.sk89q.worldedit.world.World;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* Creates new {@link EditSession}s. To get an instance of this factory,
* use {@link WorldEdit#getEditSessionFactory()}.
@ -34,7 +31,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
* <p>It is no longer possible to replace the instance of this in WorldEdit
* with a custom one. Use {@link EditSessionEvent} to override
* the creation of {@link EditSession}s.</p>
*
* @deprecated Using the ever-extending factory methods is deprecated. Replace with {@link EditSessionBuilder},
* which in most cases will be as simple as calling {@code builder.world(world).build()}.
*/
@Deprecated
public class EditSessionFactory {
/**
@ -138,16 +139,10 @@ public class EditSessionFactory {
*/
static final class EditSessionFactoryImpl extends EditSessionFactory {
private final EventBus eventBus;
/**
* Create a new factory.
*
* @param eventBus the event bus
*/
EditSessionFactoryImpl(EventBus eventBus) {
checkNotNull(eventBus);
this.eventBus = eventBus;
EditSessionFactoryImpl() {
}
@Override
@ -167,16 +162,12 @@ public class EditSessionFactory {
@Override
public EditSession getEditSession(World world, int maxBlocks, BlockBag blockBag, Actor actor) {
if (WorldEdit.getInstance().getConfiguration().traceUnflushedSessions) {
return new TracedEditSession(
eventBus,
world,
maxBlocks,
blockBag,
new EditSessionEvent(world, actor, maxBlocks, null)
);
}
return new EditSession(eventBus, world, maxBlocks, blockBag, new EditSessionEvent(world, actor, maxBlocks, null));
return WorldEdit.getInstance().newEditSessionBuilder()
.world(world)
.maxBlocks(maxBlocks)
.blockBag(blockBag)
.actor(actor)
.build();
}
}

Datei anzeigen

@ -29,7 +29,6 @@ import com.fastasyncworldedit.core.internal.io.FaweInputStream;
import com.fastasyncworldedit.core.internal.io.FaweOutputStream;
import com.fastasyncworldedit.core.object.FaweLimit;
import com.fastasyncworldedit.core.util.BrushCache;
import com.fastasyncworldedit.core.util.EditSessionBuilder;
import com.fastasyncworldedit.core.util.MainUtil;
import com.fastasyncworldedit.core.util.StringMan;
import com.fastasyncworldedit.core.util.TextureHolder;
@ -168,6 +167,7 @@ public class LocalSession implements TextureHolder {
private transient World worldOverride;
private transient boolean tickingWatchdog = false;
private transient boolean hasBeenToldVersion;
private transient boolean tracingActions;
// Saved properties
private String lastScript;
@ -421,8 +421,8 @@ public class LocalSession implements TextureHolder {
}
//FAWE start
Player player = editSession.getPlayer();
int limit = player == null ? Integer.MAX_VALUE : player.getLimit().MAX_HISTORY;
Actor actor = editSession.getActor();
int limit = actor == null ? Integer.MAX_VALUE : actor.getLimit().MAX_HISTORY;
remember(editSession, true, limit);
}
@ -519,9 +519,9 @@ public class LocalSession implements TextureHolder {
return;
}
Player player = editSession.getPlayer();
if (player != null) {
loadSessionHistoryFromDisk(player.getUniqueId(), editSession.getWorld());
Actor actor = editSession.getActor();
if (actor != null) {
loadSessionHistoryFromDisk(actor.getUniqueId(), editSession.getWorld());
}
// Destroy any sessions after this undo point
if (append) {
@ -583,15 +583,17 @@ public class LocalSession implements TextureHolder {
loadSessionHistoryFromDisk(actor.getUniqueId(), world);
if (getHistoryNegativeIndex() < history.size()) {
ChangeSet changeSet = getChangeSet(history.get(getHistoryIndex()));
EditSessionBuilder builder = new EditSessionBuilder(world)
EditSessionBuilder builder = WorldEdit.getInstance().newEditSessionBuilder().world(world)
.checkMemory(false)
.changeSetNull()
.fastmode(false)
.limitUnprocessed((Player) actor)
.player((Player) actor)
.blockBag(getBlockBag((Player) actor));
.fastMode(false)
.limitUnprocessed(actor)
.actor(actor);
if (actor instanceof Player) {
builder = builder.blockBag(getBlockBag((Player) actor));
}
if (!actor.getLimit().RESTRICT_HISTORY_TO_REGIONS) {
builder.allowedRegionsEverywhere();
builder = builder.allowedRegionsEverywhere();
}
try (EditSession newEditSession = builder.build()) {
newEditSession.setBlocks(changeSet, ChangeSetExecutor.Type.UNDO);
@ -629,15 +631,17 @@ public class LocalSession implements TextureHolder {
setDirty();
historyNegativeIndex--;
ChangeSet changeSet = getChangeSet(history.get(getHistoryIndex()));
EditSessionBuilder builder = new EditSessionBuilder(world)
EditSessionBuilder builder = WorldEdit.getInstance().newEditSessionBuilder().world(world)
.checkMemory(false)
.changeSetNull()
.fastmode(false)
.limitUnprocessed((Player) actor)
.player((Player) actor)
.blockBag(getBlockBag((Player) actor));
.fastMode(false)
.limitUnprocessed(actor)
.actor(actor);
if (actor instanceof Player) {
builder = builder.blockBag(getBlockBag((Player) actor));
}
if (!actor.getLimit().RESTRICT_HISTORY_TO_REGIONS) {
builder.allowedRegionsEverywhere();
builder = builder.allowedRegionsEverywhere();
}
try (EditSession newEditSession = builder.build()) {
newEditSession.setBlocks(changeSet, ChangeSetExecutor.Type.REDO);
@ -670,6 +674,14 @@ public class LocalSession implements TextureHolder {
this.tickingWatchdog = tickingWatchdog;
}
public boolean isTracingActions() {
return tracingActions;
}
public void setTracingActions(boolean tracingActions) {
this.tracingActions = tracingActions;
}
/**
* Get the default region selector.
*
@ -1594,14 +1606,14 @@ public class LocalSession implements TextureHolder {
// Create an edit session
//FAWE start - we don't use the edit session builder yet
EditSession editSession;
EditSessionBuilder builder = new EditSessionBuilder(world);
EditSessionBuilder builder = WorldEdit.getInstance().newEditSessionBuilder().world(world);
if (actor.isPlayer() && actor instanceof Player) {
BlockBag blockBag = getBlockBag((Player) actor);
builder.player((Player) actor);
builder.actor(actor);
builder.blockBag(blockBag);
}
builder.command(command);
builder.fastmode(!this.sideEffectSet.doesApplyAny());
builder.fastMode(!this.sideEffectSet.doesApplyAny());
editSession = builder.build();

Datei anzeigen

@ -19,18 +19,36 @@
package com.sk89q.worldedit;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.util.eventbus.EventBus;
import com.sk89q.worldedit.world.World;
import javax.annotation.Nullable;
/**
* Internal use only.
* Internal use only. Unused for now, but present in case upstream make it API.
*/
class TracedEditSession extends EditSession {
TracedEditSession(EventBus eventBus, World world, int maxBlocks, BlockBag blockBag, EditSessionEvent event) {
super(eventBus, world, maxBlocks, blockBag, event);
//FAWE start - does not work with FAWE's ways of doing things...
@Deprecated
//FAWE end
TracedEditSession(
EventBus eventBus, @Nullable World world, int maxBlocks, @Nullable BlockBag blockBag,
@Nullable Actor actor,
boolean tracing
) {
super(new EditSessionBuilder(eventBus)
.world(world)
.maxBlocks(maxBlocks)
.blockBag(blockBag)
.actor(actor)
.tracing(tracing));
}
TracedEditSession(EditSessionBuilder builder) {
super(builder);
}
private final Throwable stacktrace = new Throwable("Creation trace.");

Datei anzeigen

@ -41,6 +41,7 @@ import com.sk89q.worldedit.extension.factory.MaskFactory;
import com.sk89q.worldedit.extension.factory.PatternFactory;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extension.platform.Locatable;
import com.sk89q.worldedit.extension.platform.Platform;
import com.sk89q.worldedit.extension.platform.PlatformManager;
import com.sk89q.worldedit.extent.inventory.BlockBag;
@ -68,6 +69,7 @@ import com.sk89q.worldedit.util.io.file.InvalidFilenameException;
import com.sk89q.worldedit.util.task.SimpleSupervisor;
import com.sk89q.worldedit.util.task.Supervisor;
import com.sk89q.worldedit.util.translation.TranslationManager;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BundledBlockData;
@ -120,7 +122,8 @@ public final class WorldEdit {
private final EventBus eventBus = new EventBus();
private final PlatformManager platformManager = new PlatformManager(this);
private final EditSessionFactory editSessionFactory = new EditSessionFactory.EditSessionFactoryImpl(eventBus);
@Deprecated
private final EditSessionFactory editSessionFactory = new EditSessionFactory.EditSessionFactoryImpl();
private final SessionManager sessions = new SessionManager(this);
private final ListeningExecutorService executorService = MoreExecutors.listeningDecorator(EvenMoreExecutors.newBoundedCachedThreadPool(
0,
@ -838,12 +841,41 @@ public final class WorldEdit {
/**
* Get a factory for {@link EditSession}s.
*
* @deprecated Use {@link #newEditSessionBuilder()} instead. See {@link EditSessionFactory} for details.
*/
@Deprecated
public EditSessionFactory getEditSessionFactory() {
return editSessionFactory;
}
/**
* Create a builder for {@link EditSession}s.
*/
public EditSessionBuilder newEditSessionBuilder() {
return new EditSessionBuilder(eventBus);
}
/**
* Shorthand for {@code newEditSessionBuilder().world(world).build()}.
*
* @param world the world
* @return the new {@link EditSession}
*/
public EditSession newEditSession(@Nullable World world) {
return newEditSessionBuilder().world(world).build();
}
/**
* Shorthand for {@code newEditSessionBuilder().locatableActor(locatableActor).build()}.
*
* @param locatableActor the actor
* @return the new {@link EditSession}
*/
public <A extends Actor & Locatable> EditSession newEditSession(A locatableActor) {
return newEditSessionBuilder().locatableActor(locatableActor).build();
}
/**
* Get the version.
*

Datei anzeigen

@ -110,7 +110,7 @@ public class ChunkCommands {
WorldEditAsyncCommandBuilder.createAndSendMessage(
actor,
() -> new ChunkListPaginationBox(region).create(page),
TranslatableComponent.of(
Caption.of(
"worldedit.listchunks.listfor",
TextComponent.of(actor.getName())
)

Datei anzeigen

@ -24,7 +24,6 @@ import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.event.extent.PasteEvent;
import com.fastasyncworldedit.core.extent.clipboard.DiskOptimizedClipboard;
import com.fastasyncworldedit.core.extent.clipboard.MultiClipboardHolder;
import com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard;
import com.fastasyncworldedit.core.extent.clipboard.URIClipboardHolder;

Datei anzeigen

@ -29,6 +29,7 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.HookMode;
import com.sk89q.worldedit.command.util.PrintCommandHelp;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.platform.ConfigurationLoadEvent;
@ -182,6 +183,32 @@ public class WorldEditCommands {
}
//FAWE end
@Command(
name = "trace",
desc = "Toggles trace hook"
)
void trace(
Actor actor, LocalSession session,
@Arg(desc = "The mode to set the trace hook to", def = "")
HookMode hookMode
) {
boolean previousMode = session.isTracingActions();
boolean newMode;
if (hookMode != null) {
newMode = hookMode == HookMode.ACTIVE;
if (newMode == previousMode) {
actor.printError(Caption.of(previousMode
? "worldedit.trace.active.already"
: "worldedit.trace.inactive.already"));
return;
}
} else {
newMode = !previousMode;
}
session.setTracingActions(newMode);
actor.printInfo(Caption.of(newMode ? "worldedit.trace.active" : "worldedit.trace.inactive"));
}
@Command(
name = "cui",
desc = "Complete CUI handshake (internal usage)"

Datei anzeigen

@ -69,8 +69,8 @@ public class EditSessionEvent extends Event implements Cancellable {
private final Actor actor;
private final int maxBlocks;
private final Stage stage;
private Extent extent;
private final List<TracingExtent> tracingExtents = new ArrayList<>();
private Extent extent;
private boolean tracing;
//FAWE start
private boolean cancelled;

Datei anzeigen

@ -404,7 +404,7 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
BlockVector3 spot = BlockVector3.at(x, y - 1, z);
final World world = getWorld();
if (!world.getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) {
try (EditSession session = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, 1, this)) {
try (EditSession session = WorldEdit.getInstance().newEditSession(this)) {
session.setBlock(spot, BlockTypes.GLASS.getDefaultState());
} catch (MaxChangedBlocksException ignored) {
}

Datei anzeigen

@ -25,7 +25,6 @@ import com.fastasyncworldedit.core.entity.MapMetadatable;
import com.fastasyncworldedit.core.object.FaweLimit;
import com.fastasyncworldedit.core.util.task.InterruptableCondition;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.internal.cui.CUIEvent;
import com.sk89q.worldedit.session.SessionOwner;
import com.sk89q.worldedit.session.request.Request;
@ -250,8 +249,8 @@ public interface Actor extends Identifiable, SessionOwner, Subject, MapMetadatab
for (Request request : Request.getAll()) {
EditSession editSession = request.getEditSession();
if (editSession != null) {
Player player = editSession.getPlayer();
if (equals(player)) {
Actor actor = editSession.getActor();
if (equals(actor)) {
editSession.cancel();
cancelled++;
}

Datei anzeigen

@ -798,7 +798,7 @@ public final class PlatformCommandManager {
// Require null CommandEvent#getSession as it means the editsession is being handled somewhere else.
if (editSessionOpt.isPresent() && event.getSession() == null) {
EditSession editSession = editSessionOpt.get();
editSession.flushQueue();
editSession.close();
session.remember(editSession);
long time = System.currentTimeMillis() - start;

Datei anzeigen

@ -26,9 +26,10 @@ import com.fastasyncworldedit.core.extent.clipboard.MemoryOptimizedClipboard;
import com.fastasyncworldedit.core.extent.clipboard.ReadOnlyClipboard;
import com.fastasyncworldedit.core.function.visitor.Order;
import com.fastasyncworldedit.core.queue.Filter;
import com.fastasyncworldedit.core.util.EditSessionBuilder;
import com.fastasyncworldedit.core.util.MaskTraverser;
import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.EditSessionBuilder;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat;
@ -75,8 +76,12 @@ public interface Clipboard extends Extent, Iterable<BlockVector3>, Closeable, Fl
region.getWorld(),
"World cannot be null (use the other constructor for the region)"
);
EditSession session = new EditSessionBuilder(region.getWorld()).allowedRegionsEverywhere()
.autoQueue(false).build();
EditSession session = WorldEdit
.getInstance()
.newEditSessionBuilder()
.world(region.getWorld())
.allowedRegionsEverywhere()
.build();
return ReadOnlyClipboard.of(session, region);
}
@ -252,12 +257,17 @@ public interface Clipboard extends Extent, Iterable<BlockVector3>, Closeable, Fl
if (world instanceof EditSession) {
editSession = (EditSession) world;
} else {
EditSessionBuilder builder = new EditSessionBuilder(world).autoQueue(true)
.checkMemory(false).allowedRegionsEverywhere().limitUnlimited();
EditSessionBuilder builder = WorldEdit
.getInstance()
.newEditSessionBuilder()
.world(world)
.checkMemory(false)
.allowedRegionsEverywhere()
.limitUnlimited();
if (allowUndo) {
editSession = builder.build();
} else {
editSession = builder.changeSetNull().fastmode(true).build();
editSession = builder.changeSetNull().fastMode(true).build();
}
}
Extent extent = this;
@ -297,8 +307,14 @@ public interface Clipboard extends Extent, Iterable<BlockVector3>, Closeable, Fl
@Nullable Transform transform
) {
if (extent instanceof World) {
EditSessionBuilder builder = new EditSessionBuilder((World) extent).autoQueue(true)
.checkMemory(false).allowedRegionsEverywhere().limitUnlimited().changeSetNull();
EditSessionBuilder builder = WorldEdit
.getInstance()
.newEditSessionBuilder()
.world((World) extent)
.checkMemory(false)
.allowedRegionsEverywhere()
.limitUnlimited()
.changeSetNull();
extent = builder.build();
}
@ -334,8 +350,14 @@ public interface Clipboard extends Extent, Iterable<BlockVector3>, Closeable, Fl
default void paste(Extent extent, BlockVector3 to, boolean pasteAir, boolean pasteEntities, boolean pasteBiomes) {
if (extent instanceof World) {
EditSessionBuilder builder = new EditSessionBuilder((World) extent).autoQueue(true)
.checkMemory(false).allowedRegionsEverywhere().limitUnlimited().changeSetNull();
EditSessionBuilder builder = WorldEdit
.getInstance()
.newEditSessionBuilder()
.world((World) extent)
.checkMemory(false)
.allowedRegionsEverywhere()
.limitUnlimited()
.changeSetNull();
extent = builder.build();
}

Datei anzeigen

@ -68,10 +68,11 @@ public class CraftScriptContext extends CraftScriptEnvironment {
* @return an edit session
*/
public EditSession remember() {
EditSession editSession = controller.getEditSessionFactory()
.getEditSession(player.getWorld(),
session.getBlockChangeLimit(), session.getBlockBag(player), player
);
EditSession editSession = controller.newEditSessionBuilder()
.locatableActor(player)
.maxBlocks(session.getBlockChangeLimit())
.blockBag(session.getBlockBag(player))
.build();
Request.request().setEditSession(editSession);
editSession.enableStandardMode();
editSessions.add(editSession);

Datei anzeigen

@ -161,6 +161,8 @@
"fawe.cancel.worldedit.cancel.reason.outside.level": "Outside world",
"fawe.cancel.worldedit.cancel.reason.outside.region": "Outside allowed region (bypass with /wea, or disable `region-restrictions` in config.yml)",
"fawe.cancel.worldedit.cancel.reason.no.region": "No allowed region (bypass with /wea, or disable `region-restrictions` in config.yml)",
"fawe.cancel.worldedit.cancel.reason.player-only": "This operation requires a player, and cannot be executed from console, or without an actor.",
"fawe.cancel.worldedit.cancel.reason.actor-required": "This operation requires an actor.",
"fawe.cancel.worldedit.failed.load.chunk": "Skipped loading chunk: {0};{1}. Try increasing chunk-wait.",
"fawe.navigation.no.block": "No block in sight! (or too far)",
@ -529,6 +531,13 @@
"worldedit.version.version": "FAWE version:\n - Date {0}\n - Commit {1}\n - Build {2}\n - Platform {3}",
"worldedit.version.bukkit.unsupported-adapter": "This FAWE version does not fully support your version of Bukkit. Block entities (e.g. chests) will be empty, block properties (e.g. rotation) will be missing, and other things may not work.\nUpdate FAWE and your server software to restore this functionality:\n{0}",
"worldedit.trace.no-tracing-extents": "Trace: No extent was used.",
"worldedit.trace.action-failed": "Trace: Action(s) {0} at {1} discarded by extent {2}",
"worldedit.trace.active.already": "Trace mode already active.",
"worldedit.trace.inactive.already": "Trace mode already inactive.",
"worldedit.trace.active": "Trace mode now active.",
"worldedit.trace.inactive": "Trace mode now inactive.",
"worldedit.command.time-elapsed": "{0}s elapsed (history: {1} changed; {2} blocks/sec).",
"worldedit.command.permissions": "You are not permitted to do that. Are you in the right mode?",
"worldedit.command.player-only": "This command must be used with a player.",