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 sess = context.remember();
var upright = argv[2] === "v";
var upright = argv[2] == "v";
var colors = clothColors;
if(argv[3] === "opt") {
if(argv[3] == "opt") {
colors = clothColorsOpt;
player.print("Using optimized palette");
} else if(argv[3] === "optHD") {
} else if(argv[3] == "optHD") {
colors = clothColorsOptHD;
player.print("Using optimized HD palette");
}
@ -165,4 +165,4 @@ if (!f.exists()) {
}
}
}
}
}

Datei anzeigen

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

Datei anzeigen

@ -21,7 +21,6 @@
package com.sk89q.worldedit.command;
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import com.sk89q.worldedit.LocalConfiguration;
import com.sk89q.worldedit.LocalSession;
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.text.Component;
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.HoverEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException;
import com.sk89q.worldedit.world.snapshot.Snapshot;
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 com.sk89q.worldedit.world.snapshot.experimental.Snapshot;
import com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabase;
import org.enginehub.piston.annotation.Command;
import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg;
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.
@ -58,49 +65,77 @@ public class SnapshotCommands {
private static final DateTimeFormatter dateFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
private final WorldEdit we;
private final LegacySnapshotCommands legacy;
public SnapshotCommands(WorldEdit 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(
name = "list",
desc = "List snapshots"
)
@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")
int page) throws WorldEditException {
int page) throws WorldEditException, IOException {
LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo == null) {
actor.printError(TranslatableComponent.of("worldedit.restore.not-configured"));
if (config.snapshotRepo != null) {
legacy.list(actor, world, page);
return;
}
try {
List<Snapshot> snapshots = config.snapshotRepo.getSnapshots(true, world.getName());
List<Snapshot> snapshots;
try (Stream<Snapshot> snapshotStream =
config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshots = snapshotStream
.collect(toList());
}
if (!snapshots.isEmpty()) {
actor.print(new SnapshotListBox(world.getName(), snapshots).create(page));
} else {
actor.printError(TranslatableComponent.of("worldedit.restore.none-found-console"));
if (!snapshots.isEmpty()) {
actor.print(new SnapshotListBox(world.getName(), snapshots).create(page));
} else {
actor.printError(TranslatableComponent.of(
"worldedit.restore.none-for-specific-world",
TextComponent.of(world.getName())
));
// Okay, let's toss some debugging information!
File dir = config.snapshotRepo.getDirectory();
try {
WorldEdit.logger.info("WorldEdit found no snapshots: looked in: "
+ dir.getCanonicalPath());
} catch (IOException e) {
WorldEdit.logger.info("WorldEdit found no snapshots: looked in "
+ "(NON-RESOLVABLE PATH - does it exist?): "
+ dir.getPath());
if (config.snapshotDatabase instanceof FileSystemSnapshotDatabase) {
FileSystemSnapshotDatabase db = (FileSystemSnapshotDatabase) config.snapshotDatabase;
Path root = db.getRoot();
if (Files.isDirectory(root)) {
WorldEdit.logger.info("No snapshots were found for world '"
+ world.getName() + "'; looked in " + root.toRealPath());
} else {
WorldEdit.logger.info("No snapshots were found for world '"
+ world.getName() + "'; " + root.toRealPath() + " is not a directory");
}
}
} 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"
)
@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")
String name) throws WorldEditException {
String name) throws IOException {
LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo == null) {
actor.printError(TranslatableComponent.of("worldedit.restore.not-configured"));
if (config.snapshotRepo != null) {
legacy.use(actor, world, session, name);
return;
}
// Want the latest snapshot?
if (name.equalsIgnoreCase("latest")) {
try {
Snapshot snapshot = config.snapshotRepo.getDefaultSnapshot(world.getName());
Snapshot snapshot;
try (Stream<Snapshot> snapshotStream =
config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshot = snapshotStream
.findFirst().orElse(null);
}
if (snapshot != null) {
session.setSnapshot(null);
actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use.newest"));
} else {
actor.printError(TranslatableComponent.of("worldedit.restore.none-found"));
if (snapshot != null) {
if (session.getSnapshotExperimental() != null) {
session.getSnapshotExperimental().close();
}
} catch (MissingWorldException ex) {
session.setSnapshot(null);
actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use.newest"));
} else {
actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world"));
}
} else {
try {
session.setSnapshot(config.snapshotRepo.getSnapshot(name));
actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use", TextComponent.of(name)));
} catch (InvalidSnapshotException e) {
URI uri = resolveSnapshotName(config, name);
Optional<Snapshot> snapshot = config.snapshotDatabase.getSnapshot(uri);
if (snapshot.isPresent()) {
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"));
}
}
@ -149,13 +195,14 @@ public class SnapshotCommands {
desc = "Choose the snapshot based on the list id"
)
@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")
int index) throws WorldEditException {
int index) throws IOException {
LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo == null) {
actor.printError(TranslatableComponent.of("worldedit.restore.not-configured"));
if (config.snapshotRepo != null) {
legacy.sel(actor, world, session, index);
return;
}
@ -164,22 +211,32 @@ public class SnapshotCommands {
return;
}
try {
List<Snapshot> snapshots = config.snapshotRepo.getSnapshots(true, world.getName());
if (snapshots.size() < index) {
actor.printError(TranslatableComponent.of("worldedit.snapshot.index-oob", TextComponent.of(snapshots.size())));
return;
}
Snapshot snapshot = snapshots.get(index - 1);
if (snapshot == null) {
actor.printError(TranslatableComponent.of("worldedit.restore.not-available"));
return;
}
session.setSnapshot(snapshot);
actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use", TextComponent.of(snapshot.getName())));
} catch (MissingWorldException e) {
actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world"));
List<Snapshot> snapshots;
try (Stream<Snapshot> snapshotStream =
config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshots = snapshotStream
.collect(toList());
}
if (snapshots.size() < index) {
actor.printError(TranslatableComponent.of(
"worldedit.snapshot.index-oob",
TextComponent.of(snapshots.size())
));
return;
}
Snapshot snapshot = snapshots.get(index - 1);
if (snapshot == null) {
actor.printError(TranslatableComponent.of("worldedit.restore.not-available"));
return;
}
if (session.getSnapshotExperimental() != null) {
session.getSnapshotExperimental().close();
}
session.setSnapshotExperimental(snapshot);
actor.printInfo(TranslatableComponent.of(
"worldedit.snapshot.use",
TextComponent.of(snapshot.getInfo().getDisplayName())
));
}
@Command(
@ -187,31 +244,38 @@ public class SnapshotCommands {
desc = "Choose the nearest snapshot before a date"
)
@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")
ZonedDateTime date) throws WorldEditException {
ZonedDateTime date) throws IOException {
LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo == null) {
actor.printError(TranslatableComponent.of("worldedit.restore.not-configured"));
if (config.snapshotRepo != null) {
legacy.before(actor, world, session, date);
return;
}
try {
Snapshot snapshot = config.snapshotRepo.getSnapshotBefore(date, world.getName());
Snapshot snapshot;
try (Stream<Snapshot> snapshotStream =
config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshot = snapshotStream
.findFirst().orElse(null);
}
if (snapshot == null) {
actor.printError(TranslatableComponent.of(
"worldedit.snapshot.none-before",
TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date)))
);
} else {
session.setSnapshot(snapshot);
actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use", TextComponent.of(snapshot.getName())));
if (snapshot == null) {
actor.printError(TranslatableComponent.of(
"worldedit.snapshot.none-before",
TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date)))
);
} else {
if (session.getSnapshotExperimental() != null) {
session.getSnapshotExperimental().close();
}
} catch (MissingWorldException ex) {
actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world"));
session.setSnapshotExperimental(snapshot);
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"
)
@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")
ZonedDateTime date) throws WorldEditException {
ZonedDateTime date) throws IOException {
LocalConfiguration config = we.getConfiguration();
checkSnapshotsConfigured(config);
if (config.snapshotRepo == null) {
actor.printError(TranslatableComponent.of("worldedit.restore.not-configured"));
if (config.snapshotRepo != null) {
legacy.after(actor, world, session, date);
return;
}
try {
Snapshot snapshot = config.snapshotRepo.getSnapshotAfter(date, world.getName());
if (snapshot == null) {
actor.printError(TranslatableComponent.of(
"worldedit.snapshot.none-after",
TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date)))
);
} else {
session.setSnapshot(snapshot);
actor.printInfo(TranslatableComponent.of("worldedit.snapshot.use", TextComponent.of(snapshot.getName())));
Snapshot snapshot;
try (Stream<Snapshot> snapshotStream =
config.snapshotDatabase.getSnapshotsNewestFirst(world.getName())) {
snapshot = snapshotStream
.findFirst().orElse(null);
}
if (snapshot == null) {
actor.printError(TranslatableComponent.of(
"worldedit.snapshot.none-after",
TextComponent.of(dateFormat.withZone(session.getTimeZone()).format(date)))
);
} else {
if (session.getSnapshotExperimental() != null) {
session.getSnapshotExperimental().close();
}
} catch (MissingWorldException ex) {
actor.printError(TranslatableComponent.of("worldedit.restore.none-for-world"));
session.setSnapshotExperimental(snapshot);
actor.printInfo(TranslatableComponent.of(
"worldedit.snapshot.use",
TextComponent.of(snapshot.getInfo().getDisplayName())
));
}
}
@ -258,10 +329,11 @@ public class SnapshotCommands {
@Override
public Component getComponent(int number) {
final Snapshot snapshot = snapshots.get(number);
String displayName = snapshot.getInfo().getDisplayName();
return TextComponent.of(number + 1 + ". ", TextColor.GOLD)
.append(TextComponent.of(snapshot.getName(), TextColor.LIGHT_PURPLE)
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to use")))
.clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/snap use " + snapshot.getName())));
.append(TextComponent.builder(displayName, TextColor.LIGHT_PURPLE)
.hoverEvent(HoverEvent.showText(TextComponent.of("Click to use")))
.clickEvent(ClickEvent.runCommand("/snap use " + displayName)));
}
@Override