mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
schem list is still broken
clickEvent and hoverEvent don't seem to work, I'm probably doing something wrong
This commit is contained in:
@ -29,7 +29,6 @@ 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.Logging;
|
||||
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.extension.platform.Capability;
|
||||
@ -82,7 +81,6 @@ public class BiomeCommands {
|
||||
public void biomeList(Actor actor,
|
||||
@ArgFlag(name = 'p', desc = "Page number.", def = "1")
|
||||
int page) {
|
||||
WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> {
|
||||
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager()
|
||||
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
|
||||
|
||||
@ -99,8 +97,7 @@ public class BiomeCommands {
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toList()));
|
||||
return paginationBox.create(page);
|
||||
}, null);
|
||||
actor.print(paginationBox.create(page));
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
@ -30,7 +30,6 @@ 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.Logging;
|
||||
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
import com.sk89q.worldedit.internal.anvil.ChunkDeleter;
|
||||
@ -98,9 +97,8 @@ public class ChunkCommands {
|
||||
@ArgFlag(name = 'p', desc = "Page number.", def = "1") int page) throws WorldEditException {
|
||||
final Region region = session.getSelection(world);
|
||||
|
||||
WorldEditAsyncCommandBuilder.createAndSendMessage(actor,
|
||||
() -> new ChunkListPaginationBox(region).create(page),
|
||||
"Listing chunks for " + actor.getName());
|
||||
actor.print("Listing chunks for " + actor.getName());
|
||||
actor.print(new ChunkListPaginationBox(region).create(page));
|
||||
}
|
||||
|
||||
@Command(
|
||||
|
@ -24,6 +24,7 @@ import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
|
||||
import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION;
|
||||
|
||||
import com.boydti.fawe.FaweAPI;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.FaweLimit;
|
||||
@ -135,7 +136,7 @@ public class ClipboardCommands {
|
||||
((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1);
|
||||
FaweLimit limit = actor.getLimit();
|
||||
if (volume >= limit.MAX_CHECKS) {
|
||||
throw FaweException.MAX_CHECKS;
|
||||
throw FaweCache.MAX_CHECKS;
|
||||
}
|
||||
actor.checkConfirmationRegion(() -> {
|
||||
session.setClipboard(null);
|
||||
@ -216,10 +217,10 @@ public class ClipboardCommands {
|
||||
long volume = ((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1);
|
||||
FaweLimit limit = actor.getLimit();
|
||||
if (volume >= limit.MAX_CHECKS) {
|
||||
throw FaweException.MAX_CHECKS;
|
||||
throw FaweCache.MAX_CHECKS;
|
||||
}
|
||||
if (volume >= limit.MAX_CHANGES) {
|
||||
throw FaweException.MAX_CHANGES;
|
||||
throw FaweCache.MAX_CHANGES;
|
||||
}
|
||||
session.setClipboard(null);
|
||||
|
||||
@ -255,10 +256,10 @@ public class ClipboardCommands {
|
||||
long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1));
|
||||
FaweLimit limit = actor.getLimit();
|
||||
if (volume >= limit.MAX_CHECKS) {
|
||||
throw FaweException.MAX_CHECKS;
|
||||
throw FaweCache.MAX_CHECKS;
|
||||
}
|
||||
if (volume >= limit.MAX_CHANGES) {
|
||||
throw FaweException.MAX_CHANGES;
|
||||
throw FaweCache.MAX_CHANGES;
|
||||
}
|
||||
actor.checkConfirmationRegion(() -> {
|
||||
session.setClipboard(null);
|
||||
@ -378,19 +379,19 @@ public class ClipboardCommands {
|
||||
}
|
||||
url = FaweAPI.upload(target, format);
|
||||
}
|
||||
if (url == null) {
|
||||
BBC.GENERATING_LINK_FAILED.send(player);
|
||||
} else {
|
||||
String urlText = url.toString();
|
||||
if (Settings.IMP.WEB.SHORTEN_URLS) {
|
||||
try {
|
||||
urlText = MainUtil.getText("https://empcraft.com/s/?" + URLEncoder.encode(url.toString(), "UTF-8"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (url == null) {
|
||||
BBC.GENERATING_LINK_FAILED.send(player);
|
||||
} else {
|
||||
String urlText = url.toString();
|
||||
if (Settings.IMP.WEB.SHORTEN_URLS) {
|
||||
try {
|
||||
urlText = MainUtil.getText("https://empcraft.com/s/?" + URLEncoder.encode(url.toString(), "UTF-8"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
BBC.DOWNLOAD_LINK.send(player, urlText);
|
||||
}
|
||||
BBC.DOWNLOAD_LINK.send(player, urlText);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -252,7 +252,7 @@ public class GeneralCommands {
|
||||
@ArgFlag(name = 'p', desc = "Page of results to return", def = "1")
|
||||
int page,
|
||||
@Arg(desc = "Search query", variable = true)
|
||||
List<String> query) {
|
||||
List<String> query) throws Exception {
|
||||
String search = String.join(" ", query);
|
||||
if (search.length() <= 2) {
|
||||
actor.printError("Enter a longer search string (len > 2).");
|
||||
@ -263,8 +263,7 @@ public class GeneralCommands {
|
||||
return;
|
||||
}
|
||||
|
||||
WorldEditAsyncCommandBuilder.createAndSendMessage(actor, new ItemSearcher(search, blocksOnly, itemsOnly, page),
|
||||
"(Please wait... searching items.)");
|
||||
actor.print(new ItemSearcher(search, blocksOnly, itemsOnly, page).call());
|
||||
}
|
||||
|
||||
public static class ItemSearcher implements Callable<Component> {
|
||||
|
@ -30,6 +30,7 @@ import static com.sk89q.worldedit.regions.Regions.maximumBlockY;
|
||||
import static com.sk89q.worldedit.regions.Regions.minimumBlockY;
|
||||
|
||||
import com.boydti.fawe.FaweAPI;
|
||||
import com.boydti.fawe.FaweCache;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.object.FaweLimit;
|
||||
import com.boydti.fawe.object.exception.FaweException;
|
||||
@ -410,7 +411,7 @@ public class RegionCommands {
|
||||
long volume = (((long) max.getX() - (long) min.getX() + 1) * ((long) max.getY() - (long) min.getY() + 1) * ((long) max.getZ() - (long) min.getZ() + 1));
|
||||
FaweLimit limit = fp.getLimit();
|
||||
if (volume >= limit.MAX_CHECKS) {
|
||||
throw FaweException.MAX_CHECKS;
|
||||
throw FaweCache.MAX_CHECKS;
|
||||
}
|
||||
fp.checkConfirmationRegion(() -> {
|
||||
try {
|
||||
|
@ -19,25 +19,25 @@
|
||||
|
||||
package com.sk89q.worldedit.command;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.clipboard.MultiClipboardHolder;
|
||||
import com.boydti.fawe.object.clipboard.URIClipboardHolder;
|
||||
import com.boydti.fawe.object.clipboard.remap.ClipboardRemapper;
|
||||
import com.boydti.fawe.object.function.QuadFunction;
|
||||
import com.boydti.fawe.object.schematic.MinecraftStructure;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
import com.sk89q.worldedit.LocalSession;
|
||||
import com.sk89q.worldedit.WorldEdit;
|
||||
import com.sk89q.worldedit.WorldEditException;
|
||||
import com.sk89q.worldedit.command.argument.Arguments;
|
||||
import com.sk89q.worldedit.command.util.AsyncCommandBuilder;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissions;
|
||||
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
|
||||
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.event.extent.ActorSaveClipboardEvent;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
@ -59,6 +59,16 @@ import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
|
||||
import com.sk89q.worldedit.util.formatting.text.format.TextColor;
|
||||
import com.sk89q.worldedit.util.io.Closer;
|
||||
import com.sk89q.worldedit.util.io.file.FilenameException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
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.annotation.param.Switch;
|
||||
import org.enginehub.piston.exception.StopExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
@ -77,17 +87,14 @@ import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.regex.Pattern;
|
||||
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.annotation.param.Switch;
|
||||
import org.enginehub.piston.exception.StopExecutionException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static com.boydti.fawe.util.ReflectionUtils.as;
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
||||
//import com.boydti.fawe.object.schematic.visualizer.SchemVis;
|
||||
|
||||
@ -572,68 +579,109 @@ public class SchematicCommands {
|
||||
descFooter = "Note: Format is not fully verified until loading."
|
||||
)
|
||||
@CommandPermissions("worldedit.schematic.list")
|
||||
public void list(Actor actor,
|
||||
@ArgFlag(name = 'p', desc = "Page to view.", def = "1")
|
||||
public void list(Actor actor, LocalSession session, @Arg(name = "filter", desc = "Filter for schematics", def = "all")
|
||||
String filter, @ArgFlag(name = 'f', desc = "Restricts by format.", def = "")
|
||||
String formatName,
|
||||
@ArgFlag(name = 'p', desc = "Page to view.", def = "-1")
|
||||
int page,
|
||||
@Switch(name = 'd', desc = "Sort by date, oldest first")
|
||||
boolean oldFirst,
|
||||
@Switch(name = 'n', desc = "Sort by date, newest first")
|
||||
boolean newFirst,
|
||||
@ArgFlag(name = 'f', desc = "Restricts by format.")
|
||||
String formatName,
|
||||
@Arg(name = "filter", desc = "Filter for schematics", def = "all")
|
||||
String filter) throws WorldEditException {
|
||||
Arguments arguments
|
||||
) throws WorldEditException {
|
||||
if (oldFirst && newFirst) {
|
||||
throw new StopExecutionException(TextComponent.of("Cannot sort by oldest and newest."));
|
||||
}
|
||||
final String saveDir = worldEdit.getConfiguration().saveDir;
|
||||
final int sortType = oldFirst ? -1 : newFirst ? 1 : 0;
|
||||
String pageCommand = arguments.get();
|
||||
if (pageCommand.contains("-p ")) {
|
||||
pageCommand = pageCommand.replaceAll("-p [0-9]+", "-p %page%");
|
||||
} else{
|
||||
pageCommand = pageCommand + " -p %page%";
|
||||
}
|
||||
LocalConfiguration config = worldEdit.getConfiguration();
|
||||
File dir = worldEdit.getWorkingDirectoryFile(config.saveDir);
|
||||
|
||||
final String pageCommand = actor.isPlayer()
|
||||
? "//schem list -p %page%" + (sortType == -1 ? " -d" : sortType == 1 ? " -n" : "") : null;
|
||||
String schemCmd = "/schematic";
|
||||
String loadSingle = schemCmd + " " + "load";
|
||||
String loadMulti = schemCmd + " " + "loadall";
|
||||
String unload = schemCmd + " " + "unload";
|
||||
String delete = schemCmd + " " + "delete";
|
||||
String list = schemCmd + " " + "list";
|
||||
String showCmd = schemCmd + " " + "show";
|
||||
|
||||
WorldEditAsyncCommandBuilder.createAndSendMessage(actor,
|
||||
new SchematicListTask(saveDir, sortType, page, pageCommand, filter, formatName), "(Please wait... gathering schematic list.)");
|
||||
List<String> args = filter.isEmpty() ? Collections.emptyList() : Arrays.asList(filter.split(" "));
|
||||
|
||||
// UtilityCommands.list(dir, actor, args, page, -1, formatName, Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS, new RunnableVal3<Message, URI, String>() {
|
||||
// @Override
|
||||
// public void run(Message msg, URI uri, String relFilePath) {
|
||||
// boolean isDir = false;
|
||||
// boolean loaded = multi != null && multi.contains(uri);
|
||||
//
|
||||
// String name = relFilePath;
|
||||
// String uriStr = uri.toString();
|
||||
// if (uriStr.startsWith("file:/")) {
|
||||
// File file1 = new File(uri.getPath());
|
||||
// name = file1.getName();
|
||||
// try {
|
||||
// if (!MainUtil.isInSubDirectory(dir, file1)) {
|
||||
// throw new RuntimeException(new CommandException("Invalid path"));
|
||||
// }
|
||||
// } catch (IOException ignore) {}
|
||||
// if (file1.isDirectory()) {
|
||||
// isDir = true;
|
||||
// } else if (name.indexOf('.') != -1) {
|
||||
// name = name.substring(0, name.lastIndexOf('.'));
|
||||
// }
|
||||
// } // url
|
||||
//
|
||||
// msg.text(" - ");
|
||||
//
|
||||
// if (loaded) {
|
||||
// msg.text("[-]").command(unload + " " + relFilePath).tooltip("Unload");
|
||||
// } else {
|
||||
// msg.text("[+]").command(loadMulti + " " + relFilePath).tooltip("Add to clipboard");
|
||||
// }
|
||||
// if (!isDir) msg.text("[X]").suggest("/" + delete + " " + relFilePath).tooltip("Delete");
|
||||
// msg.text(name);
|
||||
// if (isDir) {
|
||||
// msg.command(list + " " + relFilePath).tooltip("List");
|
||||
// } else {
|
||||
// msg.command(loadSingle + " " + relFilePath).tooltip("Load");
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
URIClipboardHolder multi = as(URIClipboardHolder.class, session.getExistingClipboard());
|
||||
|
||||
final boolean hasShow = false;
|
||||
|
||||
//If player forgot -p argument
|
||||
if (page == -1) {
|
||||
page = 1;
|
||||
if (args.size() != 0) {
|
||||
String lastArg = args.get(args.size() - 1);
|
||||
if (MathMan.isInteger(lastArg)) {
|
||||
page = Integer.parseInt(lastArg);
|
||||
}
|
||||
}
|
||||
}
|
||||
boolean playerFolder = Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS;
|
||||
UUID uuid = playerFolder ? actor.getUniqueId() : null;
|
||||
List<File> files = UtilityCommands.getFiles(dir, actor, args, formatName, playerFolder, oldFirst, newFirst);
|
||||
List<Map.Entry<URI, String>> entries = UtilityCommands.filesToEntry(dir, files, uuid);
|
||||
|
||||
Function<URI, Boolean> isLoaded = multi == null ? f -> false : multi::contains;
|
||||
|
||||
List<Component> components = UtilityCommands.entryToComponent(dir, entries, isLoaded, new QuadFunction<String, String, UtilityCommands.URIType, Boolean, Component>() {
|
||||
@Override
|
||||
public Component apply(String name, String path, UtilityCommands.URIType type, Boolean loaded) {
|
||||
TextColor color = TextColor.GRAY;
|
||||
switch (type) {
|
||||
case URL:
|
||||
color = TextColor.DARK_GRAY;
|
||||
break;
|
||||
case FILE:
|
||||
color = TextColor.GREEN;
|
||||
break;
|
||||
case DIRECTORY:
|
||||
color = TextColor.GOLD;
|
||||
break;
|
||||
}
|
||||
|
||||
TextComponent.Builder msg = TextComponent.builder();
|
||||
|
||||
msg.append(TextComponent.of(" - ", color));
|
||||
|
||||
if (loaded) {
|
||||
msg.append(TextComponent.of("[-]", TextColor.RED)
|
||||
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, unload + " " + path))
|
||||
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Unload"))));
|
||||
} else {
|
||||
msg.append(TextComponent.of("[+]", TextColor.GREEN)
|
||||
.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadMulti + " " + path))
|
||||
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Add to clipboard"))));
|
||||
}
|
||||
if (type != UtilityCommands.URIType.DIRECTORY) {
|
||||
msg.append(TextComponent.of("[X]", TextColor.DARK_RED).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, delete + " " + path)));
|
||||
} else if (hasShow) {
|
||||
msg.append(TextComponent.of("[O]", TextColor.DARK_AQUA).clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, showCmd + " " + path)));
|
||||
}
|
||||
TextComponent msgElem = TextComponent.of(name, color);
|
||||
if (type != UtilityCommands.URIType.DIRECTORY) {
|
||||
msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, loadSingle + " " + path))
|
||||
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Load")));
|
||||
} else {
|
||||
msgElem.clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, list + " " + path))
|
||||
.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("List")));
|
||||
}
|
||||
msg.append(msgElem);
|
||||
|
||||
return msg.build();
|
||||
}
|
||||
});
|
||||
PaginationBox paginationBox = PaginationBox.fromStrings("Available schematics", pageCommand, components);
|
||||
actor.print(paginationBox.create(page));
|
||||
}
|
||||
|
||||
private static class SchematicLoadTask implements Callable<ClipboardHolder> {
|
||||
|
@ -19,17 +19,16 @@
|
||||
|
||||
package com.sk89q.worldedit.command;
|
||||
|
||||
import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
|
||||
import static com.sk89q.worldedit.util.formatting.text.TextComponent.newline;
|
||||
|
||||
import com.boydti.fawe.Fawe;
|
||||
import com.boydti.fawe.config.BBC;
|
||||
import com.boydti.fawe.config.Settings;
|
||||
import com.boydti.fawe.object.DelegateConsumer;
|
||||
import com.boydti.fawe.object.RunnableVal3;
|
||||
import com.boydti.fawe.object.function.QuadFunction;
|
||||
import com.boydti.fawe.util.MainUtil;
|
||||
import com.boydti.fawe.util.MathMan;
|
||||
import com.boydti.fawe.util.image.ImageUtil;
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.sk89q.minecraft.util.commands.CommandException;
|
||||
import com.sk89q.worldedit.EditSession;
|
||||
import com.sk89q.worldedit.IncompleteRegionException;
|
||||
import com.sk89q.worldedit.LocalConfiguration;
|
||||
@ -39,12 +38,11 @@ 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.SkipQueue;
|
||||
import com.sk89q.worldedit.command.util.CreatureButcher;
|
||||
import com.sk89q.worldedit.command.util.EntityRemover;
|
||||
import com.sk89q.worldedit.command.util.Logging;
|
||||
import com.sk89q.worldedit.command.util.PrintCommandHelp;
|
||||
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
|
||||
import com.sk89q.worldedit.command.util.SkipQueue;
|
||||
import com.sk89q.worldedit.entity.Entity;
|
||||
import com.sk89q.worldedit.entity.Player;
|
||||
import com.sk89q.worldedit.extension.platform.Actor;
|
||||
@ -65,13 +63,18 @@ import com.sk89q.worldedit.regions.CuboidRegion;
|
||||
import com.sk89q.worldedit.regions.CylinderRegion;
|
||||
import com.sk89q.worldedit.regions.Region;
|
||||
import com.sk89q.worldedit.util.formatting.component.SubtleFormat;
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
||||
import com.sk89q.worldedit.util.formatting.text.TextComponent.Builder;
|
||||
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.block.BlockTypes;
|
||||
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.annotation.param.Switch;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
@ -80,19 +83,18 @@ import java.net.URI;
|
||||
import java.nio.file.Files;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Supplier;
|
||||
import javax.imageio.ImageIO;
|
||||
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.annotation.param.Switch;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import static com.sk89q.worldedit.command.util.Logging.LogMode.PLACEMENT;
|
||||
|
||||
/**
|
||||
* Utility commands.
|
||||
@ -651,7 +653,7 @@ public class UtilityCommands {
|
||||
@CommandPermissions("worldedit.calc")
|
||||
public void calc(Actor actor,
|
||||
@Arg(desc = "Expression to evaluate", variable = true)
|
||||
List<String> input) {
|
||||
List<String> input) throws EvaluationException {
|
||||
Expression expression;
|
||||
try {
|
||||
expression = Expression.compile(String.join(" ", input));
|
||||
@ -660,12 +662,11 @@ public class UtilityCommands {
|
||||
"'%s' could not be parsed as a valid expression", input));
|
||||
return;
|
||||
}
|
||||
WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> {
|
||||
double result = expression.evaluate(
|
||||
new double[]{}, WorldEdit.getInstance().getSessionManager().get(actor).getTimeout());
|
||||
String formatted = Double.isNaN(result) ? "NaN" : formatter.format(result);
|
||||
return SubtleFormat.wrap(input + " = ").append(TextComponent.of(formatted, TextColor.LIGHT_PURPLE));
|
||||
}, null);
|
||||
double result = expression.evaluate(
|
||||
new double[]{}, WorldEdit.getInstance().getSessionManager().get(actor).getTimeout());
|
||||
String formatted = Double.isNaN(result) ? "NaN" : formatter.format(result);
|
||||
TextComponent msg = SubtleFormat.wrap(input + " = ").append(TextComponent.of(formatted, TextColor.LIGHT_PURPLE));
|
||||
actor.print(msg);
|
||||
}
|
||||
|
||||
@Command(
|
||||
@ -695,36 +696,64 @@ public class UtilityCommands {
|
||||
we.getPlatformManager().getPlatformCommandManager().getCommandManager(), actor, "//help");
|
||||
}
|
||||
|
||||
public static void list(File dir, Actor actor, List<String> args, @Range(min = 0) int page, String formatName, boolean playerFolder, String onClickCmd) {
|
||||
list(dir, actor, args, page, -1, formatName, playerFolder, false, false, new RunnableVal3<Builder, URI, String>() {
|
||||
@Override
|
||||
public void run(Builder m, URI uri, String fileName) {
|
||||
m.append(BBC.SCHEMATIC_LIST_ELEM.format(fileName, ""));
|
||||
if (onClickCmd != null) { m.hoverEvent(HoverEvent.showText(TextComponent.of(onClickCmd + " " + fileName)))
|
||||
.clickEvent(ClickEvent.runCommand(onClickCmd + " " + fileName));
|
||||
}
|
||||
}
|
||||
public static List<Map.Entry<URI, String>> filesToEntry(final File root, final List<File> files, final UUID uuid) {
|
||||
return Lists.transform(files, input -> { // Keep this functional, as transform is evaluated lazily
|
||||
URI uri = input.toURI();
|
||||
String path = getPath(root, input, uuid);
|
||||
return new AbstractMap.SimpleEntry<>(uri, path);
|
||||
});
|
||||
}
|
||||
|
||||
public static void list(File dir, Actor actor, List<String> args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, boolean oldFirst, boolean newFirst, RunnableVal3<Builder, URI, String> eachMsg) {
|
||||
List<File> fileList = new ArrayList<>();
|
||||
if (perPage == -1) perPage = actor instanceof Player ? 12 : 20; // More pages for console
|
||||
page = getFiles(dir, actor, args, page, perPage, formatName, playerFolder, fileList::add);
|
||||
public static enum URIType {
|
||||
URL,
|
||||
FILE,
|
||||
DIRECTORY,
|
||||
OTHER
|
||||
}
|
||||
|
||||
public static List<Component> entryToComponent(File root, List<Map.Entry<URI, String>> entries, Function<URI, Boolean> isLoaded, QuadFunction<String, String, URIType, Boolean, Component> adapter) {
|
||||
return Lists.transform(entries, input -> {
|
||||
URI uri = input.getKey();
|
||||
String path = input.getValue();
|
||||
|
||||
boolean url = false;
|
||||
boolean loaded = isLoaded.apply(uri);
|
||||
|
||||
URIType type = URIType.FILE;
|
||||
|
||||
String name = path;
|
||||
String uriStr = uri.toString();
|
||||
if (uriStr.startsWith("file:/")) {
|
||||
File file = new File(uri.getPath());
|
||||
name = file.getName();
|
||||
if (file.isDirectory()) {
|
||||
type = URIType.DIRECTORY;
|
||||
} else {
|
||||
if (name.indexOf('.') != -1) name = name.substring(0, name.lastIndexOf('.'));
|
||||
}
|
||||
try {
|
||||
if (!MainUtil.isInSubDirectory(root, file)) {
|
||||
throw new RuntimeException(new CommandException("Invalid path"));
|
||||
}
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
} else if (uriStr.startsWith("http://") || uriStr.startsWith("https://")) {
|
||||
type = URIType.URL;
|
||||
} else {
|
||||
type = URIType.OTHER;
|
||||
}
|
||||
|
||||
return adapter.apply(name, path, type, loaded);
|
||||
});
|
||||
}
|
||||
|
||||
public static List<File> getFiles(File dir, Actor actor, List<String> args, String formatName, boolean playerFolder, boolean oldFirst, boolean newFirst) {
|
||||
List<File> fileList = new LinkedList<>();
|
||||
getFiles(dir, actor, args, formatName, playerFolder, fileList::add);
|
||||
|
||||
if (fileList.isEmpty()) {
|
||||
BBC.SCHEMATIC_NONE.send(actor);
|
||||
return;
|
||||
}
|
||||
|
||||
int pageCount = (fileList.size() + perPage - 1) / perPage;
|
||||
if (page < 1) {
|
||||
BBC.SCHEMATIC_PAGE.send(actor, ">0");
|
||||
return;
|
||||
}
|
||||
if (page > pageCount) {
|
||||
BBC.SCHEMATIC_PAGE.send(actor, "<" + (pageCount + 1));
|
||||
return;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
final int sortType = oldFirst ? -1 : newFirst ? 1 : 0;
|
||||
@ -750,30 +779,10 @@ public class UtilityCommands {
|
||||
return res;
|
||||
});
|
||||
|
||||
int offset = (page - 1) * perPage;
|
||||
|
||||
int limit = Math.min(offset + perPage, fileList.size());
|
||||
|
||||
// String fullArgs = (String) args.getLocals().get("arguments");
|
||||
// String baseCmd = null;
|
||||
// if (fullArgs != null) {
|
||||
// baseCmd = fullArgs.endsWith(" " + page) ? fullArgs.substring(0, fullArgs.length() - (" " + page).length()) : fullArgs;
|
||||
// }
|
||||
@NotNull Builder m = TextComponent.builder(BBC.SCHEMATIC_LIST.format(page, pageCount));
|
||||
|
||||
UUID uuid = playerFolder ? actor.getUniqueId() : null;
|
||||
for (int i = offset; i < limit; i++) {
|
||||
m.append(newline());
|
||||
File file = fileList.get(i);
|
||||
eachMsg.run(m, file.toURI(), getPath(dir, file, uuid));
|
||||
}
|
||||
// if (baseCmd != null) {
|
||||
// //TODO m.newline().paginate(baseCmd, page, pageCount);
|
||||
// }
|
||||
actor.print(m.build());
|
||||
return fileList;
|
||||
}
|
||||
|
||||
public static int getFiles(File dir, Actor actor, List<String> args, @Range(min = 0) int page, int perPage, String formatName, boolean playerFolder, Consumer<File> forEachFile) {
|
||||
public static void getFiles(File dir, Actor actor, List<String> args, String formatName, boolean playerFolder, Consumer<File> forEachFile) {
|
||||
Consumer<File> rootFunction = forEachFile;
|
||||
//schem list all <path>
|
||||
|
||||
@ -785,10 +794,6 @@ public class UtilityCommands {
|
||||
boolean listMine = false;
|
||||
boolean listGlobal = !Settings.IMP.PATHS.PER_PLAYER_SCHEMATICS;
|
||||
if (len > 0) {
|
||||
int max = len;
|
||||
if (MathMan.isInteger(args.get(len - 1))) {
|
||||
page = Integer.parseInt(args.get(--len));
|
||||
}
|
||||
for (int i = 0; i < len; i++) {
|
||||
String arg = "";
|
||||
switch (arg.toLowerCase()) {
|
||||
@ -872,7 +877,7 @@ public class UtilityCommands {
|
||||
public void accept(File f) {
|
||||
try {
|
||||
if (f.isDirectory()) {
|
||||
UUID uuid = UUID.fromString(f.getName());
|
||||
UUID.fromString(f.getName());
|
||||
return;
|
||||
}
|
||||
} catch (IllegalArgumentException ignored) {}
|
||||
@ -889,7 +894,6 @@ public class UtilityCommands {
|
||||
List<File> result = filter(toFilter, filters);
|
||||
for (File file : result) rootFunction.accept(file);
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
private static List<File> filter(List<File> fileList, List<String> filters) {
|
||||
@ -946,7 +950,7 @@ public class UtilityCommands {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getPath(File root, File file, UUID uuid) {
|
||||
public static String getPath(File root, File file, UUID uuid) {
|
||||
File dir;
|
||||
if (uuid != null) {
|
||||
dir = new File(root, uuid.toString());
|
||||
|
Reference in New Issue
Block a user