diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java index e9a9e231d4..5d5d245d11 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ChunkCommands.java @@ -26,6 +26,7 @@ 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.internal.anvil.ChunkDeleter; import com.sk89q.worldedit.internal.anvil.ChunkDeletionInfo; @@ -34,6 +35,7 @@ import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.util.Location; 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.event.ClickEvent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; @@ -50,8 +52,8 @@ import java.nio.file.Path; import java.time.ZonedDateTime; import java.util.ArrayList; +import java.util.List; import java.util.Set; -import java.util.stream.Collectors; import static com.google.common.base.Preconditions.checkNotNull; import static com.sk89q.worldedit.command.util.Logging.LogMode.REGION; @@ -93,11 +95,11 @@ public void chunkInfo(Player player) { @CommandPermissions("worldedit.listchunks") public void listChunks(Player player, LocalSession session, @ArgFlag(name = 'p', desc = "Page number.", def = "1") int page) throws WorldEditException { - Set chunks = session.getSelection(player.getWorld()).getChunks(); + final Region region = session.getSelection(player.getWorld()); - PaginationBox paginationBox = PaginationBox.fromStrings("Selected Chunks", "/listchunks -p %page%", - chunks.stream().map(BlockVector2::toString).collect(Collectors.toList())); - player.print(paginationBox.create(page)); + WorldEditAsyncCommandBuilder.createAndSendMessage(player, + () -> new ChunkListPaginationBox(region).create(page), + "Listing chunks for " + player.getName()); } @Command( @@ -134,8 +136,8 @@ public void deleteChunks(Player player, LocalSession session, newBatch.backup = true; final Region selection = session.getSelection(player.getWorld()); if (selection instanceof CuboidRegion) { - newBatch.minChunk = BlockVector2.at(selection.getMinimumPoint().getBlockX() >> 4, selection.getMinimumPoint().getBlockZ() >> 4); - newBatch.maxChunk = BlockVector2.at(selection.getMaximumPoint().getBlockX() >> 4, selection.getMaximumPoint().getBlockZ() >> 4); + newBatch.minChunk = selection.getMinimumPoint().shr(4).toBlockVector2(); + newBatch.maxChunk = selection.getMaximumPoint().shr(4).toBlockVector2(); } else { // this has a possibility to OOM for very large selections still Set chunks = selection.getChunks(); @@ -168,4 +170,27 @@ public void deleteChunks(Player player, LocalSession session, .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "/stop")))); } + private static class ChunkListPaginationBox extends PaginationBox { + //private final Region region; + private final List chunks; + + ChunkListPaginationBox(Region region) { + super("Selected Chunks", "/listchunks -p %page%"); + // TODO make efficient/streamable/calculable implementations of this + // for most region types, so we can just store the region and random-access get one page of chunks + // (this is non-trivial for some types of selections...) + //this.region = region.clone(); + this.chunks = new ArrayList<>(region.getChunks()); + } + + @Override + public Component getComponent(int number) { + return TextComponent.of(chunks.get(number).toString()); + } + + @Override + public int getComponentsSize() { + return chunks.size(); + } + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java index 47f3daf9e9..a2b59ffbda 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SchematicCommands.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.command; +import com.google.common.collect.Multimap; +import com.google.common.io.Files; import com.sk89q.worldedit.LocalConfiguration; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; @@ -42,10 +44,10 @@ 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.SchematicPaginationBox; import com.sk89q.worldedit.util.formatting.text.Component; 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.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; @@ -68,7 +70,9 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.Callable; +import java.util.regex.Pattern; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; /** @@ -404,4 +408,44 @@ private static List allFiles(File root) { } return fileList; } + + private static class SchematicPaginationBox extends PaginationBox { + private final String prefix; + private final File[] files; + + SchematicPaginationBox(String rootDir, File[] files, String pageCommand) { + super("Available schematics", pageCommand); + this.prefix = rootDir == null ? "" : rootDir; + this.files = files; + } + + @Override + public Component getComponent(int number) { + checkArgument(number < files.length && number >= 0); + File file = files[number]; + Multimap exts = ClipboardFormats.getFileExtensionMap(); + String format = exts.get(Files.getFileExtension(file.getName())) + .stream().findFirst().map(ClipboardFormat::getName).orElse("Unknown"); + boolean inRoot = file.getParentFile().getName().equals(prefix); + + String path = inRoot ? file.getName() : file.getPath().split(Pattern.quote(prefix + File.separator))[1]; + + return TextComponent.builder() + .content("") + .append(TextComponent.of("[L]") + .color(TextColor.GOLD) + .clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/schem load " + path)) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to load")))) + .append(TextComponent.space()) + .append(TextComponent.of(path) + .color(TextColor.DARK_GREEN) + .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of(format)))) + .build(); + } + + @Override + public int getComponentsSize() { + return files.length; + } + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java index d0dd6ef5aa..88285e4755 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SelectionCommands.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.command; +import com.google.common.base.Strings; import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.LocalSession; import com.sk89q.worldedit.WorldEdit; @@ -56,16 +57,19 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.component.BlockDistributionResult; import com.sk89q.worldedit.util.formatting.component.CommandListBox; +import com.sk89q.worldedit.util.formatting.component.InvalidComponentException; import com.sk89q.worldedit.util.formatting.component.PaginationBox; import com.sk89q.worldedit.util.formatting.component.SubtleFormat; import com.sk89q.worldedit.util.formatting.component.TextComponentProducer; +import com.sk89q.worldedit.util.formatting.text.Component; 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.HoverEvent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockState; +import com.sk89q.worldedit.world.block.BlockType; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.storage.ChunkStore; @@ -570,7 +574,7 @@ public void select(Player player, LocalSession session, } case LIST: default: - CommandListBox box = new CommandListBox("Selection modes", null); + CommandListBox box = new CommandListBox("Selection modes", null, null); box.setHidingHelp(true); TextComponentProducer contents = box.getContents(); contents.append(SubtleFormat.wrap("Select one of the modes below:")).newline(); @@ -608,4 +612,62 @@ public void select(Player player, LocalSession session, session.dispatchCUISelection(player); } + private static class BlockDistributionResult extends PaginationBox { + + private final List> distribution; + private final int totalBlocks; + private final boolean separateStates; + + BlockDistributionResult(List> distribution, boolean separateStates) { + super("Block Distribution", "//distr -p %page%" + (separateStates ? " -d" : "")); + this.distribution = distribution; + // note: doing things like region.getArea is inaccurate for non-cuboids. + this.totalBlocks = distribution.stream().mapToInt(Countable::getAmount).sum(); + this.separateStates = separateStates; + setComponentsPerPage(7); + } + + @Override + public Component getComponent(int number) { + Countable c = distribution.get(number); + TextComponent.Builder line = TextComponent.builder(); + + final int count = c.getAmount(); + + final double perc = count / (double) totalBlocks * 100; + final int maxDigits = (int) (Math.log10(totalBlocks) + 1); + final int curDigits = (int) (Math.log10(count) + 1); + line.append(String.format("%s%.3f%% ", perc < 10 ? " " : "", perc), TextColor.GOLD); + final int space = maxDigits - curDigits; + String pad = Strings.repeat(" ", space == 0 ? 2 : 2 * space + 1); + line.append(String.format("%s%s", count, pad), TextColor.YELLOW); + + final BlockState state = c.getID(); + final BlockType blockType = state.getBlockType(); + TextComponent blockName = TextComponent.of(blockType.getName(), TextColor.LIGHT_PURPLE); + TextComponent toolTip; + if (separateStates && state != blockType.getDefaultState()) { + toolTip = TextComponent.of(state.getAsString(), TextColor.GRAY); + blockName = blockName.append(TextComponent.of("*", TextColor.LIGHT_PURPLE)); + } else { + toolTip = TextComponent.of(blockType.getId(), TextColor.GRAY); + } + blockName = blockName.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, toolTip)); + line.append(blockName); + + return line.build(); + } + + @Override + public int getComponentsSize() { + return distribution.size(); + } + + @Override + public Component create(int page) throws InvalidComponentException { + super.getContents().append(TextComponent.of("Total Block Count: " + totalBlocks, TextColor.GRAY)) + .append(TextComponent.newline()); + return super.create(page); + } + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java index 76e5d441ee..9d3765943c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/UtilityCommands.java @@ -523,7 +523,8 @@ public void help(Actor actor, int page, @Arg(desc = "The command to retrieve help for", def = "", variable = true) List command) throws WorldEditException { - PrintCommandHelp.help(command, page, listSubCommands, we, actor); + PrintCommandHelp.help(command, page, listSubCommands, + we.getPlatformManager().getPlatformCommandManager().getCommandManager(), actor, "//help"); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java index 02ab382a48..25329885ac 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/WorldEditCommands.java @@ -164,6 +164,7 @@ public void help(Actor actor, int page, @Arg(desc = "The command to retrieve help for", def = "", variable = true) List command) throws WorldEditException { - PrintCommandHelp.help(command, page, listSubCommands, we, actor); + PrintCommandHelp.help(command, page, listSubCommands, + we.getPlatformManager().getPlatformCommandManager().getCommandManager(), actor, "/worldedit help"); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PrintCommandHelp.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PrintCommandHelp.java index ad7dad226c..dc3e978652 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PrintCommandHelp.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/PrintCommandHelp.java @@ -67,11 +67,11 @@ private static Command detectCommand(CommandManager manager, String command) { return mapping.orElse(null); } - public static void help(List commandPath, int page, boolean listSubCommands, WorldEdit we, Actor actor) throws InvalidComponentException { - CommandManager manager = we.getPlatformManager().getPlatformCommandManager().getCommandManager(); + public static void help(List commandPath, int page, boolean listSubCommands, + CommandManager manager, Actor actor, String helpRootCommand) throws InvalidComponentException { if (commandPath.isEmpty()) { - printCommands(page, manager.getAllCommands(), actor, ImmutableList.of()); + printCommands(page, manager.getAllCommands(), actor, ImmutableList.of(), helpRootCommand); return; } @@ -93,7 +93,7 @@ public static void help(List commandPath, int page, boolean listSubComma toCommandString(visited), subCommand)); // full help for single command CommandUsageBox box = new CommandUsageBox(visited, visited.stream() - .map(Command::getName).collect(Collectors.joining(" "))); + .map(Command::getName).collect(Collectors.joining(" ")), helpRootCommand); actor.print(box.create()); return; } @@ -105,7 +105,7 @@ public static void help(List commandPath, int page, boolean listSubComma actor.printError(String.format("The sub-command '%s' under '%s' could not be found.", subCommand, toCommandString(visited))); // list subcommands for currentCommand - printCommands(page, getSubCommands(Iterables.getLast(visited)).values().stream(), actor, visited); + printCommands(page, getSubCommands(Iterables.getLast(visited)).values().stream(), actor, visited, helpRootCommand); return; } } @@ -114,10 +114,10 @@ public static void help(List commandPath, int page, boolean listSubComma if (subCommands.isEmpty() || !listSubCommands) { // Create the message - CommandUsageBox box = new CommandUsageBox(visited, toCommandString(visited)); + CommandUsageBox box = new CommandUsageBox(visited, toCommandString(visited), helpRootCommand); actor.print(box.create()); } else { - printCommands(page, subCommands.values().stream(), actor, visited); + printCommands(page, subCommands.values().stream(), actor, visited, helpRootCommand); } } @@ -126,7 +126,7 @@ private static String toCommandString(List visited) { } private static void printCommands(int page, Stream commandStream, Actor actor, - List commandList) throws InvalidComponentException { + List commandList, String helpRootCommand) throws InvalidComponentException { // Get a list of aliases List commands = commandStream .sorted(byCleanName()) @@ -135,7 +135,8 @@ private static void printCommands(int page, Stream commandStream, Actor String used = commandList.isEmpty() ? null : toCommandString(commandList); CommandListBox box = new CommandListBox( (used == null ? "Help" : "Subcommands: " + used), - "//help -s -p %page%" + (used == null ? "" : " " + used)); + helpRootCommand + " -s -p %page%" + (used == null ? "" : " " + used), + helpRootCommand); if (!actor.isPlayer()) { box.formatForConsole(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/BlockDistributionResult.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/BlockDistributionResult.java deleted file mode 100644 index 797557a521..0000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/BlockDistributionResult.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.util.formatting.component; - -import com.google.common.base.Strings; -import com.sk89q.worldedit.util.Countable; -import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockType; - -import java.util.List; - -public class BlockDistributionResult extends PaginationBox { - - private final List> distribution; - private final int totalBlocks; - private final boolean separateStates; - - public BlockDistributionResult(List> distribution, boolean separateStates) { - super("Block Distribution", "//distr -p %page%" + (separateStates ? " -d" : "")); - this.distribution = distribution; - // note: doing things like region.getArea is inaccurate for non-cuboids. - this.totalBlocks = distribution.stream().mapToInt(Countable::getAmount).sum(); - this.separateStates = separateStates; - setComponentsPerPage(7); - } - - @Override - public Component getComponent(int number) { - Countable c = distribution.get(number); - TextComponent.Builder line = TextComponent.builder(); - - final int count = c.getAmount(); - - final double perc = count / (double) totalBlocks * 100; - final int maxDigits = (int) (Math.log10(totalBlocks) + 1); - final int curDigits = (int) (Math.log10(count) + 1); - line.append(String.format("%s%.3f%% ", perc < 10 ? " " : "", perc), TextColor.GOLD); - final int space = maxDigits - curDigits; - String pad = Strings.repeat(" ", space == 0 ? 2 : 2 * space + 1); - line.append(String.format("%s%s", count, pad), TextColor.YELLOW); - - final BlockState state = c.getID(); - final BlockType blockType = state.getBlockType(); - TextComponent blockName = TextComponent.of(blockType.getName(), TextColor.LIGHT_PURPLE); - TextComponent toolTip; - if (separateStates && state != blockType.getDefaultState()) { - toolTip = TextComponent.of(state.getAsString(), TextColor.GRAY); - blockName = blockName.append(TextComponent.of("*", TextColor.LIGHT_PURPLE)); - } else { - toolTip = TextComponent.of(blockType.getId(), TextColor.GRAY); - } - blockName = blockName.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, toolTip)); - line.append(blockName); - - return line.build(); - } - - @Override - public int getComponentsSize() { - return distribution.size(); - } - - @Override - public Component create(int page) throws InvalidComponentException { - super.getContents().append(TextComponent.of("Total Block Count: " + totalBlocks, TextColor.GRAY)) - .append(TextComponent.newline()); - return super.create(page); - } -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java index fd579c6fbe..2efc8b7b3e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandListBox.java @@ -32,14 +32,16 @@ public class CommandListBox extends PaginationBox { private List commands = Lists.newArrayList(); private boolean hideHelp; + private String helpCommand; /** * Create a new box. * * @param title the title */ - public CommandListBox(String title, String pageCommand) { + public CommandListBox(String title, String pageCommand, String helpCommand) { super(title, pageCommand); + this.helpCommand = helpCommand; } @Override @@ -72,7 +74,7 @@ public void setHidingHelp(boolean hideHelp) { this.hideHelp = hideHelp; } - private static class CommandEntry { + private class CommandEntry { private final String alias; private final Component description; private final String insertion; @@ -87,7 +89,7 @@ Component createComponent(boolean hideHelp) { TextComponentProducer line = new TextComponentProducer(); if (!hideHelp) { line.append(SubtleFormat.wrap("? ") - .clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "//help " + insertion)) + .clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, CommandListBox.this.helpCommand + " " + insertion)) .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Additional Help")))); } TextComponent command = TextComponent.of(alias, TextColor.GOLD); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java index e8abe0e386..579bd44a9c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java @@ -45,9 +45,10 @@ public class CommandUsageBox extends TextComponentProducer { * * @param commands the commands to describe * @param commandString the commands that were used, such as "/we" or "/brush sphere" + * @param helpRootCommand the command used to get subcommand help */ - public CommandUsageBox(List commands, String commandString) throws InvalidComponentException { - this(commands, commandString, null); + public CommandUsageBox(List commands, String commandString, String helpRootCommand) throws InvalidComponentException { + this(commands, commandString, helpRootCommand, null); } /** @@ -55,15 +56,18 @@ public CommandUsageBox(List commands, String commandString) throws Inva * * @param commands the commands to describe * @param commandString the commands that were used, such as "/we" or "/brush sphere" + * @param helpRootCommand the command used to get subcommand help * @param parameters list of parameters to use */ - public CommandUsageBox(List commands, String commandString, @Nullable CommandParameters parameters) throws InvalidComponentException { + public CommandUsageBox(List commands, String commandString, String helpRootCommand, + @Nullable CommandParameters parameters) throws InvalidComponentException { checkNotNull(commands); checkNotNull(commandString); - attachCommandUsage(commands, commandString); + checkNotNull(helpRootCommand); + attachCommandUsage(commands, commandString, helpRootCommand); } - private void attachCommandUsage(List commands, String commandString) { + private void attachCommandUsage(List commands, String commandString, String helpRootCommand) { TextComponentProducer boxContent = new TextComponentProducer() .append(HelpGenerator.create(commands).getFullHelp()); if (getSubCommands(Iterables.getLast(commands)).size() > 0) { @@ -73,7 +77,7 @@ private void attachCommandUsage(List commands, String commandString) { .append(TextComponent.builder("List Subcommands") .color(ColorConfig.getMainText()) .decoration(TextDecoration.ITALIC, true) - .clickEvent(ClickEvent.runCommand("//help -s " + commandString)) + .clickEvent(ClickEvent.runCommand(helpRootCommand + " -s " + commandString)) .hoverEvent(HoverEvent.showText(TextComponent.of("List all subcommands of this command"))) .build()) .build()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SchematicPaginationBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SchematicPaginationBox.java deleted file mode 100644 index ae052d1371..0000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SchematicPaginationBox.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.util.formatting.component; - -import com.google.common.collect.Multimap; -import com.google.common.io.Files; -import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormat; -import com.sk89q.worldedit.extent.clipboard.io.ClipboardFormats; -import com.sk89q.worldedit.util.formatting.text.Component; -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.HoverEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; - -import java.io.File; -import java.util.regex.Pattern; - -import static com.google.common.base.Preconditions.checkArgument; - -public class SchematicPaginationBox extends PaginationBox { - private final String prefix; - private final File[] files; - - public SchematicPaginationBox(String rootDir, File[] files, String pageCommand) { - super("Available schematics", pageCommand); - this.prefix = rootDir == null ? "" : rootDir; - this.files = files; - } - - @Override - public Component getComponent(int number) { - checkArgument(number < files.length && number >= 0); - File file = files[number]; - Multimap exts = ClipboardFormats.getFileExtensionMap(); - String format = exts.get(Files.getFileExtension(file.getName())) - .stream().findFirst().map(ClipboardFormat::getName).orElse("Unknown"); - boolean inRoot = file.getParentFile().getName().equals(prefix); - - String path = inRoot ? file.getName() : file.getPath().split(Pattern.quote(prefix + File.separator))[1]; - - return TextComponent.builder() - .content("") - .append(TextComponent.of("[L]") - .color(TextColor.GOLD) - .clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/schem load " + path)) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to load")))) - .append(TextComponent.space()) - .append(TextComponent.of(path) - .color(TextColor.DARK_GREEN) - .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of(format)))) - .build(); - } - - @Override - public int getComponentsSize() { - return files.length; - } -}