Some command refactoring. Switch usages of page args to -p flag.

Dieser Commit ist enthalten in:
wizjany 2019-05-27 18:26:20 -04:00
Ursprung 620992dd57
Commit 9099a17fe5
13 geänderte Dateien mit 211 neuen und 141 gelöschten Zeilen

Datei anzeigen

@ -26,7 +26,9 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.function.FlatRegionFunction; import com.sk89q.worldedit.function.FlatRegionFunction;
import com.sk89q.worldedit.function.FlatRegionMaskingFilter; import com.sk89q.worldedit.function.FlatRegionMaskingFilter;
@ -50,10 +52,10 @@ import com.sk89q.worldedit.world.registry.BiomeRegistry;
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.Switch; import org.enginehub.piston.annotation.param.Switch;
import java.util.HashSet; import java.util.HashSet;
import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -77,17 +79,28 @@ public class BiomeCommands {
desc = "Gets all biomes available." desc = "Gets all biomes available."
) )
@CommandPermissions("worldedit.biome.list") @CommandPermissions("worldedit.biome.list")
public void biomeList(Player player, public void biomeList(Actor actor,
@Arg(desc = "Page number.", def = "1") @ArgFlag(name = 'p', desc = "Page number.", def = "1")
int page) throws WorldEditException { int page) {
BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager() WorldEditAsyncCommandBuilder.createAndSendMessage(actor, () -> {
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry(); BiomeRegistry biomeRegistry = WorldEdit.getInstance().getPlatformManager()
.queryCapability(Capability.GAME_HOOKS).getRegistries().getBiomeRegistry();
PaginationBox paginationBox = PaginationBox.fromStrings("Available Biomes", "/biomelist %page%", PaginationBox paginationBox = PaginationBox.fromStrings("Available Biomes", "/biomelist -p %page%",
BiomeType.REGISTRY.values().stream() BiomeType.REGISTRY.values().stream()
.map(biomeRegistry::getData).filter(Objects::nonNull) .map(biomeType -> {
.map(BiomeData::getName).collect(Collectors.toList())); String id = biomeType.getId();
player.print(paginationBox.create(page)); final BiomeData data = biomeRegistry.getData(biomeType);
if (data != null) {
String name = data.getName();
return id + " (" + name + ")";
} else {
return id;
}
})
.collect(Collectors.toList()));
return paginationBox.create(page);
}, null);
} }
@Command( @Command(

Datei anzeigen

@ -90,7 +90,7 @@ public class BrushCommands {
@CommandPermissions("worldedit.brush.sphere") @CommandPermissions("worldedit.brush.sphere")
public void sphereBrush(Player player, LocalSession session, public void sphereBrush(Player player, LocalSession session,
@Arg(desc = "The pattern of blocks to set") @Arg(desc = "The pattern of blocks to set")
Pattern fill, Pattern pattern,
@Arg(desc = "The radius of the sphere", def = "2") @Arg(desc = "The radius of the sphere", def = "2")
double radius, double radius,
@Switch(name = 'h', desc = "Create hollow spheres instead") @Switch(name = 'h', desc = "Create hollow spheres instead")
@ -98,7 +98,7 @@ public class BrushCommands {
worldEdit.checkMaxBrushRadius(radius); worldEdit.checkMaxBrushRadius(radius);
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()); BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
tool.setFill(fill); tool.setFill(pattern);
tool.setSize(radius); tool.setSize(radius);
if (hollow) { if (hollow) {
@ -118,7 +118,7 @@ public class BrushCommands {
@CommandPermissions("worldedit.brush.cylinder") @CommandPermissions("worldedit.brush.cylinder")
public void cylinderBrush(Player player, LocalSession session, public void cylinderBrush(Player player, LocalSession session,
@Arg(desc = "The pattern of blocks to set") @Arg(desc = "The pattern of blocks to set")
Pattern fill, Pattern pattern,
@Arg(desc = "The radius of the cylinder", def = "2") @Arg(desc = "The radius of the cylinder", def = "2")
double radius, double radius,
@Arg(desc = "The height of the cylinder", def = "1") @Arg(desc = "The height of the cylinder", def = "1")
@ -129,7 +129,7 @@ public class BrushCommands {
worldEdit.checkMaxBrushRadius(height); worldEdit.checkMaxBrushRadius(height);
BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType()); BrushTool tool = session.getBrushTool(player.getItemInHand(HandSide.MAIN_HAND).getType());
tool.setFill(fill); tool.setFill(pattern);
tool.setSize(radius); tool.setSize(radius);
if (hollow) { if (hollow) {

Datei anzeigen

@ -39,6 +39,7 @@ import com.sk89q.worldedit.world.storage.McRegionChunkStore;
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 java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -86,10 +87,10 @@ public class ChunkCommands {
) )
@CommandPermissions("worldedit.listchunks") @CommandPermissions("worldedit.listchunks")
public void listChunks(Player player, LocalSession session, public void listChunks(Player player, LocalSession session,
@Arg(desc = "Page number.", def = "1") int page) throws WorldEditException { @ArgFlag(name = 'p', desc = "Page number.", def = "1") int page) throws WorldEditException {
Set<BlockVector2> chunks = session.getSelection(player.getWorld()).getChunks(); Set<BlockVector2> chunks = session.getSelection(player.getWorld()).getChunks();
PaginationBox paginationBox = PaginationBox.fromStrings("Selected Chunks", "/listchunks %page%", PaginationBox paginationBox = PaginationBox.fromStrings("Selected Chunks", "/listchunks -p %page%",
chunks.stream().map(BlockVector2::toString).collect(Collectors.toList())); chunks.stream().map(BlockVector2::toString).collect(Collectors.toList()));
player.print(paginationBox.create(page)); player.print(paginationBox.create(page));
} }

Datei anzeigen

@ -19,25 +19,35 @@
package com.sk89q.worldedit.command; package com.sk89q.worldedit.command;
import com.google.common.collect.Sets;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
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;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.AsyncCommandBuilder;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.input.DisallowedUsageException; import com.sk89q.worldedit.extension.input.DisallowedUsageException;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.function.mask.Mask; import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.util.formatting.component.PaginationBox;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.item.ItemTypes;
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.Switch; import org.enginehub.piston.annotation.param.Switch;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.Callable;
import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkNotNull;
/** /**
@ -65,7 +75,7 @@ public class GeneralCommands {
@CommandPermissions("worldedit.limit") @CommandPermissions("worldedit.limit")
public void limit(Player player, LocalSession session, public void limit(Player player, LocalSession session,
@Arg(desc = "The limit to set", def = "") @Arg(desc = "The limit to set", def = "")
Integer limit) throws WorldEditException { Integer limit) {
LocalConfiguration config = worldEdit.getConfiguration(); LocalConfiguration config = worldEdit.getConfiguration();
boolean mayDisable = player.hasPermission("worldedit.limit.unrestricted"); boolean mayDisable = player.hasPermission("worldedit.limit.unrestricted");
@ -79,12 +89,8 @@ public class GeneralCommands {
} }
session.setBlockChangeLimit(limit); session.setBlockChangeLimit(limit);
player.print("Block change limit set to " + limit + "."
if (limit != config.defaultChangeLimit) { + (limit == config.defaultChangeLimit ? "" : " (Use //limit to go back to the default.)"));
player.print("Block change limit set to " + limit + ". (Use //limit to go back to the default.)");
} else {
player.print("Block change limit set to " + limit + ".");
}
} }
@Command( @Command(
@ -94,8 +100,7 @@ public class GeneralCommands {
@CommandPermissions("worldedit.timeout") @CommandPermissions("worldedit.timeout")
public void timeout(Player player, LocalSession session, public void timeout(Player player, LocalSession session,
@Arg(desc = "The timeout time to set", def = "") @Arg(desc = "The timeout time to set", def = "")
Integer limit) throws WorldEditException { Integer limit) {
LocalConfiguration config = worldEdit.getConfiguration(); LocalConfiguration config = worldEdit.getConfiguration();
boolean mayDisable = player.hasPermission("worldedit.timeout.unrestricted"); boolean mayDisable = player.hasPermission("worldedit.timeout.unrestricted");
@ -108,12 +113,8 @@ public class GeneralCommands {
} }
session.setTimeout(limit); session.setTimeout(limit);
player.print("Timeout time set to " + limit + " ms."
if (limit != config.calculationTimeout) { + (limit == config.calculationTimeout ? "" : " (Use //timeout to go back to the default.)"));
player.print("Timeout time set to " + limit + " ms. (Use //timeout to go back to the default.)");
} else {
player.print("Timeout time set to " + limit + " ms.");
}
} }
@Command( @Command(
@ -123,7 +124,7 @@ public class GeneralCommands {
@CommandPermissions("worldedit.fast") @CommandPermissions("worldedit.fast")
public void fast(Player player, LocalSession session, public void fast(Player player, LocalSession session,
@Arg(desc = "The new fast mode state", def = "") @Arg(desc = "The new fast mode state", def = "")
Boolean fastMode) throws WorldEditException { Boolean fastMode) {
boolean hasFastMode = session.hasFastMode(); boolean hasFastMode = session.hasFastMode();
if (fastMode != null && fastMode == hasFastMode) { if (fastMode != null && fastMode == hasFastMode) {
player.printError("Fast mode already " + (fastMode ? "enabled" : "disabled") + "."); player.printError("Fast mode already " + (fastMode ? "enabled" : "disabled") + ".");
@ -146,7 +147,7 @@ public class GeneralCommands {
@CommandPermissions("worldedit.reorder") @CommandPermissions("worldedit.reorder")
public void reorderMode(Player player, LocalSession session, public void reorderMode(Player player, LocalSession session,
@Arg(desc = "The reorder mode", def = "") @Arg(desc = "The reorder mode", def = "")
EditSession.ReorderMode reorderMode) throws WorldEditException { EditSession.ReorderMode reorderMode) {
if (reorderMode == null) { if (reorderMode == null) {
player.print("The reorder mode is " + session.getReorderMode().getDisplayName()); player.print("The reorder mode is " + session.getReorderMode().getDisplayName());
} else { } else {
@ -190,9 +191,9 @@ public class GeneralCommands {
@CommandPermissions("worldedit.global-mask") @CommandPermissions("worldedit.global-mask")
public void gmask(Player player, LocalSession session, public void gmask(Player player, LocalSession session,
@Arg(desc = "The mask to set", def = "") @Arg(desc = "The mask to set", def = "")
Mask mask) throws WorldEditException { Mask mask) {
if (mask == null) { if (mask == null) {
session.setMask((Mask) null); session.setMask(null);
player.print("Global mask disabled."); player.print("Global mask disabled.");
} else { } else {
session.setMask(mask); session.setMask(mask);
@ -205,8 +206,7 @@ public class GeneralCommands {
aliases = {"/toggleplace"}, aliases = {"/toggleplace"},
desc = "Switch between your position and pos1 for placement" desc = "Switch between your position and pos1 for placement"
) )
public void togglePlace(Player player, LocalSession session) throws WorldEditException { public void togglePlace(Player player, LocalSession session) {
if (session.togglePlacementPosition()) { if (session.togglePlacementPosition()) {
player.print("Now placing at pos #1."); player.print("Now placing at pos #1.");
} else { } else {
@ -220,41 +220,48 @@ public class GeneralCommands {
desc = "Search for an item" desc = "Search for an item"
) )
public void searchItem(Actor actor, public void searchItem(Actor actor,
@Arg(desc = "Item query") @Arg(desc = "Search query", variable = true)
String query, List<String> query,
@Switch(name = 'b', desc = "Only search for blocks") @Switch(name = 'b', desc = "Only search for blocks")
boolean blocksOnly, boolean blocksOnly,
@Switch(name = 'i', desc = "Only search for items") @Switch(name = 'i', desc = "Only search for items")
boolean itemsOnly) throws WorldEditException { boolean itemsOnly,
ItemType type = ItemTypes.get(query); @ArgFlag(name = 'p', desc = "Page of results to return", def = "1")
int page) {
String search = String.join(" ", query);
if (search.length() <= 2) {
actor.printError("Enter a longer search string (len > 2).");
return;
}
if (blocksOnly && itemsOnly) {
actor.printError("You cannot use both the 'b' and 'i' flags simultaneously.");
return;
}
if (type != null) { WorldEditAsyncCommandBuilder.createAndSendMessage(actor, new ItemSearcher(search, blocksOnly, itemsOnly, page),
actor.print(type.getId() + " (" + type.getName() + ")"); "(Please wait... searching items.)");
} else { }
if (query.length() <= 2) {
actor.printError("Enter a longer search string (len > 2).");
return;
}
if (!blocksOnly && !itemsOnly) { private static class ItemSearcher implements Callable<Component> {
actor.print("Searching for: " + query); private final boolean blocksOnly;
} else if (blocksOnly && itemsOnly) { private final boolean itemsOnly;
actor.printError("You cannot use both the 'b' and 'i' flags simultaneously."); private final String search;
return; private final int page;
} else if (blocksOnly) {
actor.print("Searching for blocks: " + query);
} else {
actor.print("Searching for items: " + query);
}
int found = 0; ItemSearcher(String search, boolean blocksOnly, boolean itemsOnly, int page) {
this.blocksOnly = blocksOnly;
this.itemsOnly = itemsOnly;
this.search = search;
this.page = page;
}
@Override
public Component call() throws Exception {
String command = "/searchitem " + (blocksOnly ? "-b " : "") + (itemsOnly ? "-i " : "") + "-p %page% " + search;
Map<String, String> results = new TreeMap<>();
String idMatch = search.replace(' ', '_');
String nameMatch = search.toLowerCase(Locale.ROOT);
for (ItemType searchType : ItemType.REGISTRY) { for (ItemType searchType : ItemType.REGISTRY) {
if (found >= 15) {
actor.print("Too many results!");
break;
}
if (blocksOnly && !searchType.hasBlockType()) { if (blocksOnly && !searchType.hasBlockType()) {
continue; continue;
} }
@ -262,20 +269,16 @@ public class GeneralCommands {
if (itemsOnly && searchType.hasBlockType()) { if (itemsOnly && searchType.hasBlockType()) {
continue; continue;
} }
final String id = searchType.getId();
for (String alias : Sets.newHashSet(searchType.getId(), searchType.getName())) { String name = searchType.getName();
if (alias.contains(query)) { final boolean hasName = !name.equals(id);
actor.print(searchType.getId() + " (" + searchType.getName() + ")"); name = name.toLowerCase(Locale.ROOT);
++found; if (id.contains(idMatch) || (hasName && name.contains(nameMatch))) {
break; results.put(id, name + (hasName ? " (" + id + ")" : ""));
}
} }
} }
List<String> list = new ArrayList<>(results.values());
if (found == 0) { return PaginationBox.fromStrings("Search results for '" + search + "'", command, list).create(page);
actor.printError("No items found.");
}
} }
} }
} }

Datei anzeigen

@ -26,6 +26,7 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.command.util.AsyncCommandBuilder; import com.sk89q.worldedit.command.util.AsyncCommandBuilder;
import com.sk89q.worldedit.command.util.CommandPermissions; import com.sk89q.worldedit.command.util.CommandPermissions;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.command.util.WorldEditAsyncCommandBuilder;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
@ -39,8 +40,10 @@ import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.transform.Transform; import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.formatting.component.CodeFormat; import com.sk89q.worldedit.util.formatting.component.CodeFormat;
import com.sk89q.worldedit.util.formatting.component.ErrorFormat;
import com.sk89q.worldedit.util.formatting.component.PaginationBox; import com.sk89q.worldedit.util.formatting.component.PaginationBox;
import com.sk89q.worldedit.util.formatting.component.SchematicPaginationBox; import com.sk89q.worldedit.util.formatting.component.SchematicPaginationBox;
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.event.ClickEvent; import com.sk89q.worldedit.util.formatting.text.event.ClickEvent;
import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.util.formatting.text.format.TextColor;
@ -124,7 +127,7 @@ public class SchematicCommands {
.sendMessageAfterDelay("(Please wait... loading schematic.)") .sendMessageAfterDelay("(Please wait... loading schematic.)")
.onSuccess(TextComponent.of(filename, TextColor.GOLD) .onSuccess(TextComponent.of(filename, TextColor.GOLD)
.append(TextComponent.of(" loaded. Paste it with ", TextColor.LIGHT_PURPLE)) .append(TextComponent.of(" loaded. Paste it with ", TextColor.LIGHT_PURPLE))
.append(CodeFormat.wrap("//paste").clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "//paste"))), .append(CodeFormat.wrap("//paste").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "//paste"))),
session::setClipboard) session::setClipboard)
.onFailure("Failed to load schematic", worldEdit.getPlatformManager().getPlatformCommandManager().getExceptionConverter()) .onFailure("Failed to load schematic", worldEdit.getPlatformManager().getPlatformCommandManager().getExceptionConverter())
.buildAndExec(worldEdit.getExecutorService()); .buildAndExec(worldEdit.getExecutorService());
@ -257,59 +260,17 @@ public class SchematicCommands {
@Switch(name = 'd', desc = "Sort by date, oldest first") @Switch(name = 'd', desc = "Sort by date, oldest first")
boolean oldFirst, boolean oldFirst,
@Switch(name = 'n', desc = "Sort by date, newest first") @Switch(name = 'n', desc = "Sort by date, newest first")
boolean newFirst) throws WorldEditException { boolean newFirst) {
if (oldFirst && newFirst) { if (oldFirst && newFirst) {
throw new StopExecutionException(TextComponent.of("Cannot sort by oldest and newest.")); throw new StopExecutionException(TextComponent.of("Cannot sort by oldest and newest."));
} }
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().saveDir); final String saveDir = worldEdit.getConfiguration().saveDir;
List<File> fileList = allFiles(dir);
if (fileList == null || fileList.isEmpty()) {
actor.printError("No schematics found.");
return;
}
File[] files = new File[fileList.size()];
fileList.toArray(files);
final int sortType = oldFirst ? -1 : newFirst ? 1 : 0; final int sortType = oldFirst ? -1 : newFirst ? 1 : 0;
// cleanup file list final String pageCommand = actor.isPlayer()
Arrays.sort(files, (f1, f2) -> { ? "//schem list -p %page%" + (sortType == -1 ? " -d" : sortType == 1 ? " -n" : "") : null;
// http://stackoverflow.com/questions/203030/best-way-to-list-files-in-java-sorted-by-date-modified
int res;
if (sortType == 0) { // use name by default
int p = f1.getParent().compareTo(f2.getParent());
if (p == 0) { // same parent, compare names
res = f1.getName().compareTo(f2.getName());
} else { // different parent, sort by that
res = p;
}
} else {
res = Long.compare(f1.lastModified(), f2.lastModified()); // use date if there is a flag
if (sortType == 1) res = -res; // flip date for newest first instead of oldest first
}
return res;
});
String pageCommand = actor.isPlayer() ? "//schem list -p %page%" + (oldFirst ? " -d" : newFirst ? " -n" : "") : null; WorldEditAsyncCommandBuilder.createAndSendMessage(actor,
PaginationBox paginationBox = new SchematicPaginationBox(worldEdit.getConfiguration().saveDir, files, pageCommand); new SchematicListTask(saveDir, sortType, page, pageCommand), "(Please wait... gathering schematic list.)");
actor.print(paginationBox.create(page));
}
private List<File> allFiles(File root) {
File[] files = root.listFiles();
if (files == null) return null;
List<File> fileList = new ArrayList<>();
for (File f : files) {
if (f.isDirectory()) {
List<File> subFiles = allFiles(f);
if (subFiles == null) continue; // empty subdir
fileList.addAll(subFiles);
} else {
fileList.add(f);
}
}
return fileList;
} }
private static class SchematicLoadTask implements Callable<ClipboardHolder> { private static class SchematicLoadTask implements Callable<ClipboardHolder> {
@ -379,4 +340,68 @@ public class SchematicCommands {
return null; return null;
} }
} }
private static class SchematicListTask implements Callable<Component> {
private final String prefix;
private final int sortType;
private final int page;
private final File rootDir;
private final String pageCommand;
SchematicListTask(String prefix, int sortType, int page, String pageCommand) {
this.prefix = prefix;
this.sortType = sortType;
this.page = page;
this.rootDir = WorldEdit.getInstance().getWorkingDirectoryFile(prefix);
this.pageCommand = pageCommand;
}
@Override
public Component call() throws Exception {
List<File> fileList = allFiles(rootDir);
if (fileList == null || fileList.isEmpty()) {
return ErrorFormat.wrap("No schematics found.");
}
File[] files = new File[fileList.size()];
fileList.toArray(files);
// cleanup file list
Arrays.sort(files, (f1, f2) -> {
// http://stackoverflow.com/questions/203030/best-way-to-list-files-in-java-sorted-by-date-modified
int res;
if (sortType == 0) { // use name by default
int p = f1.getParent().compareTo(f2.getParent());
if (p == 0) { // same parent, compare names
res = f1.getName().compareTo(f2.getName());
} else { // different parent, sort by that
res = p;
}
} else {
res = Long.compare(f1.lastModified(), f2.lastModified()); // use date if there is a flag
if (sortType == 1) res = -res; // flip date for newest first instead of oldest first
}
return res;
});
PaginationBox paginationBox = new SchematicPaginationBox(prefix, files, pageCommand);
return paginationBox.create(page);
}
}
private static List<File> allFiles(File root) {
File[] files = root.listFiles();
if (files == null) return null;
List<File> fileList = new ArrayList<>();
for (File f : files) {
if (f.isDirectory()) {
List<File> subFiles = allFiles(f);
if (subFiles == null) continue; // empty subdir
fileList.addAll(subFiles);
} else {
fileList.add(f);
}
}
return fileList;
}
} }

Datei anzeigen

@ -61,6 +61,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
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.Switch; import org.enginehub.piston.annotation.param.Switch;
import java.text.DecimalFormat; import java.text.DecimalFormat;
@ -517,7 +518,7 @@ public class UtilityCommands {
public void help(Actor actor, public void help(Actor actor,
@Switch(name = 's', desc = "List sub-commands of the given command, if applicable") @Switch(name = 's', desc = "List sub-commands of the given command, if applicable")
boolean listSubCommands, boolean listSubCommands,
@Arg(desc = "The page to retrieve", def = "1") @ArgFlag(name = 'p', desc = "The page to retrieve", def = "1")
int page, int page,
@Arg(desc = "The command to retrieve help for", def = "", variable = true) @Arg(desc = "The command to retrieve help for", def = "", variable = true)
List<String> command) throws WorldEditException { List<String> command) throws WorldEditException {

Datei anzeigen

@ -39,6 +39,7 @@ import com.sk89q.worldedit.util.report.SystemInfoReport;
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.Switch; import org.enginehub.piston.annotation.param.Switch;
import java.io.File; import java.io.File;
@ -159,7 +160,7 @@ public class WorldEditCommands {
public void help(Actor actor, public void help(Actor actor,
@Switch(name = 's', desc = "List sub-commands of the given command, if applicable") @Switch(name = 's', desc = "List sub-commands of the given command, if applicable")
boolean listSubCommands, boolean listSubCommands,
@Arg(desc = "The page to retrieve", def = "1") @ArgFlag(name = 'p', desc = "The page to retrieve", def = "1")
int page, int page,
@Arg(desc = "The command to retrieve help for", def = "", variable = true) @Arg(desc = "The command to retrieve help for", def = "", variable = true)
List<String> command) throws WorldEditException { List<String> command) throws WorldEditException {

Datei anzeigen

@ -22,7 +22,6 @@ package com.sk89q.worldedit.command.util;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import org.enginehub.piston.Command; import org.enginehub.piston.Command;
import org.enginehub.piston.gen.CommandConditionGenerator; import org.enginehub.piston.gen.CommandConditionGenerator;
import org.enginehub.piston.gen.CommandRegistration;
import org.enginehub.piston.util.NonnullByDefault; import org.enginehub.piston.util.NonnullByDefault;
import java.lang.reflect.Method; import java.lang.reflect.Method;

Datei anzeigen

@ -135,7 +135,7 @@ public class PrintCommandHelp {
String used = commandList.isEmpty() ? null : toCommandString(commandList); String used = commandList.isEmpty() ? null : toCommandString(commandList);
CommandListBox box = new CommandListBox( CommandListBox box = new CommandListBox(
(used == null ? "Help" : "Subcommands: " + used), (used == null ? "Help" : "Subcommands: " + used),
"//help -s %page%" + (used == null ? "" : " " + used)); "//help -s -p %page%" + (used == null ? "" : " " + used));
if (!actor.isPlayer()) { if (!actor.isPlayer()) {
box.formatForConsole(); box.formatForConsole();
} }

Datei anzeigen

@ -0,0 +1,27 @@
package com.sk89q.worldedit.command.util;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.formatting.text.Component;
import javax.annotation.Nullable;
import java.util.concurrent.Callable;
/**
* For internal WorldEdit use only.
*/
public final class WorldEditAsyncCommandBuilder {
private WorldEditAsyncCommandBuilder() {
}
public static void createAndSendMessage(Actor actor, Callable<Component> task, @Nullable String desc) {
final AsyncCommandBuilder<Component> builder = AsyncCommandBuilder.wrap(task, actor);
if (desc != null) {
builder.sendMessageAfterDelay(desc);
}
builder
.onSuccess((String) null, actor::print)
.onFailure((String) null, WorldEdit.getInstance().getPlatformManager().getPlatformCommandManager().getExceptionConverter())
.buildAndExec(WorldEdit.getInstance().getExecutorService());
}
}

Datei anzeigen

@ -101,7 +101,6 @@ import com.sk89q.worldedit.util.formatting.text.format.TextColor;
import com.sk89q.worldedit.util.logging.DynamicStreamHandler; import com.sk89q.worldedit.util.logging.DynamicStreamHandler;
import com.sk89q.worldedit.util.logging.LogFormat; import com.sk89q.worldedit.util.logging.LogFormat;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import org.enginehub.piston.ColorConfig;
import org.enginehub.piston.Command; import org.enginehub.piston.Command;
import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandManager;
import org.enginehub.piston.TextConfig; import org.enginehub.piston.TextConfig;
@ -477,6 +476,8 @@ public final class PlatformCommandManager {
} catch (ConditionFailedException e) { } catch (ConditionFailedException e) {
if (e.getCondition() instanceof PermissionCondition) { if (e.getCondition() instanceof PermissionCondition) {
actor.printError("You are not permitted to do that. Are you in the right mode?"); actor.printError("You are not permitted to do that. Are you in the right mode?");
} else {
actor.print(e.getRichMessage());
} }
} catch (UsageException e) { } catch (UsageException e) {
actor.print(TextComponent.builder("") actor.print(TextComponent.builder("")
@ -487,7 +488,6 @@ public final class PlatformCommandManager {
if (!cmd.isEmpty()) { if (!cmd.isEmpty()) {
actor.print(TextComponent.builder("Usage: ") actor.print(TextComponent.builder("Usage: ")
.color(TextColor.RED) .color(TextColor.RED)
.append(TextComponent.of("/", ColorConfig.getMainText()))
.append(HelpGenerator.create(e.getCommandParseResult()).getUsage()) .append(HelpGenerator.create(e.getCommandParseResult()).getUsage())
.build()); .build());
} }

Datei anzeigen

@ -20,15 +20,12 @@
package com.sk89q.worldedit.internal.command; package com.sk89q.worldedit.internal.command;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator; import com.sk89q.worldedit.command.util.CommandPermissionsConditionGenerator;
import com.sk89q.worldedit.internal.command.CommandLoggingHandler;
import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandManager;
import org.enginehub.piston.gen.CommandCallListener; import org.enginehub.piston.gen.CommandCallListener;
import org.enginehub.piston.gen.CommandRegistration; import org.enginehub.piston.gen.CommandRegistration;
import java.util.List; import java.util.List;
import java.util.logging.Logger;
public class CommandRegistrationHandler { public class CommandRegistrationHandler {

Datei anzeigen

@ -33,6 +33,7 @@ public class ItemType implements Keyed {
public static final NamespacedRegistry<ItemType> REGISTRY = new NamespacedRegistry<>("item type"); public static final NamespacedRegistry<ItemType> REGISTRY = new NamespacedRegistry<>("item type");
private String id; private String id;
private String name;
public ItemType(String id) { public ItemType(String id) {
// If it has no namespace, assume minecraft. // If it has no namespace, assume minecraft.
@ -53,12 +54,14 @@ public class ItemType implements Keyed {
* @return The name, or ID * @return The name, or ID
*/ */
public String getName() { public String getName() {
String name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries().getItemRegistry().getName(this);
if (name == null) { if (name == null) {
return getId(); name = WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS).getRegistries()
} else { .getItemRegistry().getName(this);
return name; if (name == null) {
name = "";
}
} }
return name.isEmpty() ? getId() : name;
} }