3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-19 09:20:08 +01:00
Dieser Commit ist enthalten in:
MattBDev 2020-03-22 15:46:02 -04:00
Ursprung 89ee1cb21a
Commit 1fd4d7c27e
3 geänderte Dateien mit 206 neuen und 115 gelöschten Zeilen

Datei anzeigen

@ -133,12 +133,12 @@ context.checkArgs(1, 3, "<image> <orientation> <palette>");
var f = context.getSafeOpenFile("drawings", argv[1], "png", ["png", "jpg", "jpeg", "bmp"]); var f = context.getSafeOpenFile("drawings", argv[1], "png", ["png", "jpg", "jpeg", "bmp"]);
var sess = context.remember(); var sess = context.remember();
var upright = argv[2] === "v"; var upright = argv[2] == "v";
var colors = clothColors; var colors = clothColors;
if(argv[3] === "opt") { if(argv[3] == "opt") {
colors = clothColorsOpt; colors = clothColorsOpt;
player.print("Using optimized palette"); player.print("Using optimized palette");
} else if(argv[3] === "optHD") { } else if(argv[3] == "optHD") {
colors = clothColorsOptHD; colors = clothColorsOptHD;
player.print("Using optimized HD palette"); player.print("Using optimized HD palette");
} }

Datei anzeigen

@ -139,8 +139,8 @@ public class LocalSession implements TextureHolder {
private transient int maxBlocksChanged = -1; private transient int maxBlocksChanged = -1;
private transient int maxTimeoutTime; private transient int maxTimeoutTime;
private transient boolean useInventory; private transient boolean useInventory;
private transient Snapshot snapshot; private transient com.sk89q.worldedit.world.snapshot.Snapshot snapshot;
private transient boolean hasCUISupport = false; private transient com.sk89q.worldedit.world.snapshot.experimental.Snapshot snapshotExperimental; private transient boolean hasCUISupport = false;
private transient int cuiVersion = -1; private transient int cuiVersion = -1;
private transient boolean fastMode = false; private transient boolean fastMode = false;
private transient Mask mask; private transient Mask mask;
@ -959,17 +959,36 @@ public class LocalSession implements TextureHolder {
* @return the legacy snapshot * @return the legacy snapshot
*/ */
@Nullable @Nullable
public Snapshot getSnapshot() { public com.sk89q.worldedit.world.snapshot.Snapshot getSnapshot() {
return snapshot; return snapshot;
} }
/**
* Select a legacy snapshot.
*
* @param snapshot a legacy snapshot
*/
public void setSnapshot(@Nullable com.sk89q.worldedit.world.snapshot.Snapshot snapshot) {
this.snapshot = snapshot;
}
/**
* Get the snapshot that has been selected.
*
* @return the snapshot
*/
public @Nullable
com.sk89q.worldedit.world.snapshot.experimental.Snapshot getSnapshotExperimental() {
return snapshotExperimental;
}
/** /**
* Select a snapshot. * Select a snapshot.
* *
* @param snapshot a snapshot * @param snapshotExperimental a snapshot
*/ */
public void setSnapshot(@Nullable Snapshot snapshot) { public void setSnapshotExperimental(@Nullable com.sk89q.worldedit.world.snapshot.experimental.Snapshot snapshotExperimental) {
this.snapshot = snapshot; this.snapshotExperimental = snapshotExperimental;
} }
/** /**

Datei anzeigen

@ -21,7 +21,6 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.LocalSession;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
@ -32,22 +31,30 @@ import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.formatting.component.PaginationBox; import com.sk89q.worldedit.util.formatting.component.PaginationBox;
import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException; import com.sk89q.worldedit.world.snapshot.experimental.Snapshot;
import com.sk89q.worldedit.world.snapshot.Snapshot; import com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabase;
import com.sk89q.worldedit.world.storage.MissingWorldException;
import java.io.File;
import java.io.IOException;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.ArgFlag; import org.enginehub.piston.annotation.param.ArgFlag;
import org.enginehub.piston.exception.StopExecutionException;
import java.io.IOException;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
/** /**
* Snapshot commands. * Snapshot commands.
@ -58,49 +65,77 @@ public class SnapshotCommands {
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z"); private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
private final WorldEdit we; private final WorldEdit we;
private final LegacySnapshotCommands legacy;
public SnapshotCommands(WorldEdit we) { public SnapshotCommands(WorldEdit we) {
this.we = we; this.we = we;
this.legacy = new LegacySnapshotCommands(we);
} }
static void checkSnapshotsConfigured(LocalConfiguration localConfiguration) {
if (!localConfiguration.snapshotsConfigured) {
throw new StopExecutionException(TranslatableComponent.of(
"worldedit.restore.not-configured"
));
}
}
static URI resolveSnapshotName(LocalConfiguration config, String name) {
if (!name.contains("://")) {
if (config.snapshotDatabase instanceof FileSystemSnapshotDatabase) {
String newName = name;
while (newName.startsWith("/")) {
newName = newName.substring(1);
}
return FileSystemSnapshotDatabase.createUri(newName);
}
}
return URI.create(name);
}
@Command( @Command(
name = "list", name = "list",
desc = "List snapshots" desc = "List snapshots"
) )
@CommandPermissions("worldedit.snapshots.list") @CommandPermissions("worldedit.snapshots.list")
public void list(Actor actor, World world, void list(Actor actor, World world,
@ArgFlag(name = 'p', desc = "Page of results to return", def = "1") @ArgFlag(name = 'p', desc = "Page of results to return", def = "1")
int page) throws WorldEditException { int page) throws WorldEditException, IOException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo == null) { if (config.snapshotRepo != null) {
actor.printError(TranslatableComponent.of("worldedit.restore.not-configured")); legacy.list(actor, world, page);
return; return;
} }
try { List<Snapshot> snapshots;
List<Snapshot> snapshots = config.snapshotRepo.getSnapshots(true, world.getName()); try (Stream<Snapshot> snapshotStream =
config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshots = snapshotStream
.collect(toList());
}
if (!snapshots.isEmpty()) { if (!snapshots.isEmpty()) {
actor.print(new SnapshotListBox(world.getName(), snapshots).create(page)); actor.print(new SnapshotListBox(world.getName(), snapshots).create(page));
} else { } else {
actor.printError(TranslatableComponent.of("worldedit.restore.none-found-console")); actor.printError(TranslatableComponent.of(
"worldedit.restore.none-for-specific-world",
TextComponent.of(world.getName())
));
// Okay, let's toss some debugging information! if (config.snapshotDatabase instanceof FileSystemSnapshotDatabase) {
File dir = config.snapshotRepo.getDirectory(); FileSystemSnapshotDatabase db = (FileSystemSnapshotDatabase) config.snapshotDatabase;
Path root = db.getRoot();
try { if (Files.isDirectory(root)) {
WorldEdit.logger.info("WorldEdit found no snapshots: looked in: " WorldEdit.logger.info("No snapshots were found for world '"
+ dir.getCanonicalPath()); + world.getName() + "'; looked in " + root.toRealPath());
} catch (IOException e) { } else {
WorldEdit.logger.info("WorldEdit found no snapshots: looked in " WorldEdit.logger.info("No snapshots were found for world '"
+ "(NON-RESOLVABLE PATH - does it exist?): " + world.getName() + "'; " + root.toRealPath() + " is not a directory");
+ dir.getPath());
} }
} }
} catch (MissingWorldException ex) {
actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world"));
} }
} }
@ -109,36 +144,47 @@ public class SnapshotCommands {
desc = "Choose a snapshot to use" desc = "Choose a snapshot to use"
) )
@CommandPermissions("worldedit.snapshots.restore") @CommandPermissions("worldedit.snapshots.restore")
public void use(Actor actor, World world, LocalSession session, void use(Actor actor, World world, LocalSession session,
@Arg(desc = "Snapshot to use") @Arg(desc = "Snapshot to use")
String name) throws WorldEditException { String name) throws IOException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo == null) { if (config.snapshotRepo != null) {
actor.printError(TranslatableComponent.of("worldedit.restore.not-configured")); legacy.use(actor, world, session, name);
return; return;
} }
// Want the latest snapshot? // Want the latest snapshot?
if (name.equalsIgnoreCase("latest")) { if (name.equalsIgnoreCase("latest")) {
try { Snapshot snapshot;
Snapshot snapshot = config.snapshotRepo.getDefaultSnapshot(world.getName()); try (Stream<Snapshot> snapshotStream =
config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshot = snapshotStream
.findFirst().orElse(null);
}
if (snapshot != null) { if (snapshot != null) {
if (session.getSnapshotExperimental() != null) {
session.getSnapshotExperimental().close();
}
session.setSnapshot(null); session.setSnapshot(null);
actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use.newest")); actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use.newest"));
} else { } else {
actor.printError(TranslatableComponent.of("worldedit.restore.none-found"));
}
} catch (MissingWorldException ex) {
actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world")); actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world"));
} }
} else { } else {
try { URI uri = resolveSnapshotName(config, name);
session.setSnapshot(config.snapshotRepo.getSnapshot(name)); Optional<Snapshot> snapshot = config.snapshotDatabase.getSnapshot(uri);
actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use", TextComponent.of(name))); if (snapshot.isPresent()) {
} catch (InvalidSnapshotException e) { if (session.getSnapshotExperimental() != null) {
session.getSnapshotExperimental().close();
}
session.setSnapshotExperimental(snapshot.get());
actor.printInfo(TranslatableComponent.of(
"worldedit.snapshot.use", TextComponent.of(name)
));
} else {
actor.printError(TranslatableComponent.of("worldedit.restore.not-available")); actor.printError(TranslatableComponent.of("worldedit.restore.not-available"));
} }
} }
@ -149,13 +195,14 @@ public class SnapshotCommands {
desc = "Choose the snapshot based on the list id" desc = "Choose the snapshot based on the list id"
) )
@CommandPermissions("worldedit.snapshots.restore") @CommandPermissions("worldedit.snapshots.restore")
public void sel(Actor actor, World world, LocalSession session, void sel(Actor actor, World world, LocalSession session,
@Arg(desc = "The list ID to select") @Arg(desc = "The list ID to select")
int index) throws WorldEditException { int index) throws IOException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo == null) { if (config.snapshotRepo != null) {
actor.printError(TranslatableComponent.of("worldedit.restore.not-configured")); legacy.sel(actor, world, session, index);
return; return;
} }
@ -164,10 +211,17 @@ public class SnapshotCommands {
return; return;
} }
try { List<Snapshot> snapshots;
List<Snapshot> snapshots = config.snapshotRepo.getSnapshots(true, world.getName()); try (Stream<Snapshot> snapshotStream =
config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshots = snapshotStream
.collect(toList());
}
if (snapshots.size() < index) { if (snapshots.size() < index) {
actor.printError(TranslatableComponent.of("worldedit.snapshot.index-oob", TextComponent.of(snapshots.size()))); actor.printError(TranslatableComponent.of(
"worldedit.snapshot.index-oob",
TextComponent.of(snapshots.size())
));
return; return;
} }
Snapshot snapshot = snapshots.get(index - 1); Snapshot snapshot = snapshots.get(index - 1);
@ -175,11 +229,14 @@ public class SnapshotCommands {
actor.printError(TranslatableComponent.of("worldedit.restore.not-available")); actor.printError(TranslatableComponent.of("worldedit.restore.not-available"));
return; return;
} }
session.setSnapshot(snapshot); if (session.getSnapshotExperimental() != null) {
actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use", TextComponent.of(snapshot.getName()))); session.getSnapshotExperimental().close();
} catch (MissingWorldException e) {
actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world"));
} }
session.setSnapshotExperimental(snapshot);
actor.printInfo(TranslatableComponent.of(
"worldedit.snapshot.use",
TextComponent.of(snapshot.getInfo().getDisplayName())
));
} }
@Command( @Command(
@ -187,19 +244,23 @@ public class SnapshotCommands {
desc = "Choose the nearest snapshot before a date" desc = "Choose the nearest snapshot before a date"
) )
@CommandPermissions("worldedit.snapshots.restore") @CommandPermissions("worldedit.snapshots.restore")
public void before(Actor actor, World world, LocalSession session, void before(Actor actor, World world, LocalSession session,
@Arg(desc = "The soonest date that may be used") @Arg(desc = "The soonest date that may be used")
ZonedDateTime date) throws WorldEditException { ZonedDateTime date) throws IOException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo == null) { if (config.snapshotRepo != null) {
actor.printError(TranslatableComponent.of("worldedit.restore.not-configured")); legacy.before(actor, world, session, date);
return; return;
} }
try { Snapshot snapshot;
Snapshot snapshot = config.snapshotRepo.getSnapshotBefore(date, world.getName()); try (Stream<Snapshot> snapshotStream =
config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshot = snapshotStream
.findFirst().orElse(null);
}
if (snapshot == null) { if (snapshot == null) {
actor.printError(TranslatableComponent.of( actor.printError(TranslatableComponent.of(
@ -207,11 +268,14 @@ public class SnapshotCommands {
TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date))) TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date)))
); );
} else { } else {
session.setSnapshot(snapshot); if (session.getSnapshotExperimental() != null) {
actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use", TextComponent.of(snapshot.getName()))); session.getSnapshotExperimental().close();
} }
} catch (MissingWorldException ex) { session.setSnapshotExperimental(snapshot);
actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world")); actor.printInfo(TranslatableComponent.of(
"worldedit.snapshot.use",
TextComponent.of(snapshot.getInfo().getDisplayName())
));
} }
} }
@ -220,30 +284,37 @@ public class SnapshotCommands {
desc = "Choose the nearest snapshot after a date" desc = "Choose the nearest snapshot after a date"
) )
@CommandPermissions("worldedit.snapshots.restore") @CommandPermissions("worldedit.snapshots.restore")
public void after(Actor actor, World world, LocalSession session, void after(Actor actor, World world, LocalSession session,
@Arg(desc = "The soonest date that may be used") @Arg(desc = "The soonest date that may be used")
ZonedDateTime date) throws WorldEditException { ZonedDateTime date) throws IOException {
LocalConfiguration config = we.getConfiguration(); LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo == null) { if (config.snapshotRepo != null) {
actor.printError(TranslatableComponent.of("worldedit.restore.not-configured")); legacy.after(actor, world, session, date);
return; return;
} }
try { Snapshot snapshot;
Snapshot snapshot = config.snapshotRepo.getSnapshotAfter(date, world.getName()); try (Stream<Snapshot> snapshotStream =
config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshot = snapshotStream
.findFirst().orElse(null);
}
if (snapshot == null) { if (snapshot == null) {
actor.printError(TranslatableComponent.of( actor.printError(TranslatableComponent.of(
"worldedit.snapshot.none-after", "worldedit.snapshot.none-after",
TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date))) TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date)))
); );
} else { } else {
session.setSnapshot(snapshot); if (session.getSnapshotExperimental() != null) {
actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use", TextComponent.of(snapshot.getName()))); session.getSnapshotExperimental().close();
} }
} catch (MissingWorldException ex) { session.setSnapshotExperimental(snapshot);
actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world")); actor.printInfo(TranslatableComponent.of(
"worldedit.snapshot.use",
TextComponent.of(snapshot.getInfo().getDisplayName())
));
} }
} }
@ -258,10 +329,11 @@ public class SnapshotCommands {
@Override @Override
public Component getComponent(int number) { public Component getComponent(int number) {
final Snapshot snapshot = snapshots.get(number); final Snapshot snapshot = snapshots.get(number);
String displayName = snapshot.getInfo().getDisplayName();
return TextComponent.of(number + 1 + ". ", TextColor.GOLD) return TextComponent.of(number + 1 + ". ", TextColor.GOLD)
.append(TextComponent.of(snapshot.getName(), TextColor.LIGHT_PURPLE) .append(TextComponent.builder(displayName, TextColor.LIGHT_PURPLE)
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to use"))) .hoverEvent(HoverEvent.showText(TextComponent.of("Click to use")))
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/snap use " + snapshot.getName()))); .clickEvent(ClickEvent.runCommand("/snap use " + displayName)));
} }
@Override @Override