mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
Update to Piston 0.5.2 + Doctools/Deprecation improvements (#523)
* Update to Piston 0.5.2 * [Doctools] Fix output, be verbose about deprecations * Improve deprecation system, doctools output
This commit is contained in:
committed by
Matthew Miller
parent
d8d25fbff1
commit
03c0cce53e
@ -88,7 +88,7 @@ public class ToolCommands {
|
||||
).build();
|
||||
}
|
||||
commandManager.register(CommandUtil.deprecate(
|
||||
command, "Using global tool names is deprecated " +
|
||||
command, "Global tool names cause conflicts " +
|
||||
"and will be removed in WorldEdit 8", ToolCommands::asNonGlobal
|
||||
));
|
||||
}
|
||||
|
@ -106,7 +106,8 @@ import com.sk89q.worldedit.util.logging.LogFormat;
|
||||
import com.sk89q.worldedit.world.World;
|
||||
import org.enginehub.piston.Command;
|
||||
import org.enginehub.piston.CommandManager;
|
||||
import org.enginehub.piston.TextConfig;
|
||||
import org.enginehub.piston.config.ConfigHolder;
|
||||
import org.enginehub.piston.config.TextConfig;
|
||||
import org.enginehub.piston.converter.ArgumentConverters;
|
||||
import org.enginehub.piston.exception.CommandException;
|
||||
import org.enginehub.piston.exception.CommandExecutionException;
|
||||
@ -152,10 +153,6 @@ public final class PlatformCommandManager {
|
||||
private static final java.util.logging.Logger COMMAND_LOG =
|
||||
java.util.logging.Logger.getLogger("com.sk89q.worldedit.CommandLog");
|
||||
|
||||
static {
|
||||
TextConfig.setCommandPrefix("/");
|
||||
}
|
||||
|
||||
private final WorldEdit worldEdit;
|
||||
private final PlatformManager platformManager;
|
||||
private final CommandManagerServiceImpl commandManagerService;
|
||||
|
@ -42,6 +42,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
@ -49,11 +50,16 @@ import static java.util.stream.Collectors.toList;
|
||||
|
||||
public class CommandUtil {
|
||||
|
||||
private static Component makeDeprecatedFooter(Component newCommand) {
|
||||
return TextComponent.builder("This command is deprecated. Use ", TextColor.GOLD)
|
||||
.decoration(TextDecoration.ITALIC, true)
|
||||
private static final Component DEPRECATION_MARKER = TextComponent.of("This command is deprecated.");
|
||||
|
||||
private static Component makeDeprecatedFooter(String reason, Component newCommand) {
|
||||
return TextComponent.builder()
|
||||
.append(DEPRECATION_MARKER)
|
||||
.append(" " + reason + ".")
|
||||
.append(TextComponent.newline())
|
||||
.append(TextComponent.of("Use ", TextColor.GOLD, TextDecoration.ITALIC))
|
||||
.append(newCommand)
|
||||
.append(" instead.")
|
||||
.append(TextComponent.of(" instead.", TextColor.GOLD, TextDecoration.ITALIC))
|
||||
.build();
|
||||
}
|
||||
|
||||
@ -66,6 +72,7 @@ public class CommandUtil {
|
||||
public static Command deprecate(Command command, String reason,
|
||||
NewCommandGenerator newCommandGenerator) {
|
||||
Component deprecatedWarning = makeDeprecatedFooter(
|
||||
reason,
|
||||
newCommandSuggestion(newCommandGenerator,
|
||||
NoInputCommandParameters.builder().build(),
|
||||
command)
|
||||
@ -80,6 +87,54 @@ public class CommandUtil {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static Optional<Component> footerWithoutDeprecation(Command command) {
|
||||
return command.getFooter()
|
||||
.filter(footer -> anyComponent(footer, Predicate.isEqual(DEPRECATION_MARKER)))
|
||||
.map(footer -> Optional.of(
|
||||
replaceDeprecation(footer)
|
||||
))
|
||||
.orElseGet(command::getFooter);
|
||||
}
|
||||
|
||||
public static Optional<Component> deprecationWarning(Command command) {
|
||||
return command.getFooter()
|
||||
.map(CommandUtil::extractDeprecation)
|
||||
.orElseGet(command::getFooter);
|
||||
}
|
||||
|
||||
public static boolean isDeprecated(Command command) {
|
||||
return command.getFooter()
|
||||
.filter(footer -> anyComponent(footer, Predicate.isEqual(DEPRECATION_MARKER)))
|
||||
.isPresent();
|
||||
}
|
||||
|
||||
private static boolean anyComponent(Component component, Predicate<Component> test) {
|
||||
return test.test(component) || component.children().stream()
|
||||
.anyMatch(x -> anyComponent(x, test));
|
||||
}
|
||||
|
||||
private static Component replaceDeprecation(Component component) {
|
||||
if (component.children().stream().anyMatch(Predicate.isEqual(DEPRECATION_MARKER))) {
|
||||
return TextComponent.empty();
|
||||
}
|
||||
return component.children(
|
||||
component.children().stream()
|
||||
.map(CommandUtil::replaceDeprecation)
|
||||
.collect(toList())
|
||||
);
|
||||
}
|
||||
|
||||
private static Optional<Component> extractDeprecation(Component component) {
|
||||
if (component.children().stream().anyMatch(Predicate.isEqual(DEPRECATION_MARKER))) {
|
||||
return Optional.of(component);
|
||||
}
|
||||
return component.children().stream()
|
||||
.map(CommandUtil::extractDeprecation)
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.findAny();
|
||||
}
|
||||
|
||||
private static int deprecatedCommandWarning(
|
||||
CommandParameters parameters,
|
||||
Command command,
|
||||
|
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* WorldEdit, a Minecraft world manipulation toolkit
|
||||
* Copyright (C) sk89q <http://www.sk89q.com>
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.sk89q.worldedit.util.formatting;
|
||||
|
||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||
import org.enginehub.piston.config.ConfigHolder;
|
||||
import org.enginehub.piston.config.TextConfig;
|
||||
import org.enginehub.piston.util.TextHelper;
|
||||
|
||||
public class WorldEditText {
|
||||
public static final ConfigHolder CONFIG_HOLDER = ConfigHolder.create();
|
||||
|
||||
static {
|
||||
CONFIG_HOLDER.getConfig(TextConfig.commandPrefix()).setValue("/");
|
||||
}
|
||||
|
||||
public static Component format(Component component) {
|
||||
return CONFIG_HOLDER.replace(component);
|
||||
}
|
||||
|
||||
public static String reduceToText(Component component) {
|
||||
return TextHelper.reduceToText(format(component));
|
||||
}
|
||||
|
||||
private WorldEditText() {
|
||||
}
|
||||
|
||||
}
|
@ -24,9 +24,9 @@ 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.TextDecoration;
|
||||
import org.enginehub.piston.ColorConfig;
|
||||
import org.enginehub.piston.Command;
|
||||
import org.enginehub.piston.CommandParameters;
|
||||
import org.enginehub.piston.config.ColorConfig;
|
||||
import org.enginehub.piston.util.HelpGenerator;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
@ -72,15 +72,13 @@ public class CommandUsageBox extends TextComponentProducer {
|
||||
.append(HelpGenerator.create(commands).getFullHelp());
|
||||
if (getSubCommands(Iterables.getLast(commands)).size() > 0) {
|
||||
boxContent.append(TextComponent.newline())
|
||||
.append(TextComponent.builder("> ")
|
||||
.color(ColorConfig.getHelpText())
|
||||
.append(TextComponent.builder("List Subcommands")
|
||||
.color(ColorConfig.getMainText())
|
||||
.append(ColorConfig.helpText().wrap(TextComponent.builder("> ")
|
||||
.append(ColorConfig.mainText().wrap(TextComponent.builder("List Subcommands")
|
||||
.decoration(TextDecoration.ITALIC, true)
|
||||
.clickEvent(ClickEvent.runCommand(helpRootCommand + " -s " + commandString))
|
||||
.hoverEvent(HoverEvent.showText(TextComponent.of("List all subcommands of this command")))
|
||||
.build())
|
||||
.build());
|
||||
.build()))
|
||||
.build()));
|
||||
}
|
||||
MessageBox box = new MessageBox("Help for " + commandString,
|
||||
boxContent);
|
||||
|
Reference in New Issue
Block a user