Upstream changes (#717)

* Perform part of the move of //fast to //perf (#1377)

This re-adds a deprecated `//fast` and moves the current logic to
`//perf`. Later `//perf` will have its syntax reworked, when Piston
finally supports sub-commands properly!

* Names via Translation (#1268)

* Deprecate BiomeRegistry, etc.

* Update some libraries, e.g. text

* Move to new translation renderer

* Revert "Deprecate BiomeRegistry, etc."

This reverts commit 59a5d6c92aec52739a8dc68ac3d23898af7593dd.

This was not a good idea for potential mod shenanigans.

* Move BiomeData#getName to BiomeRegistry, use i18n

* Use getRichName instead of getName

* Implement getRichName for NullBiomeRegistry

* Add getRichName for blocks

* Relocate net.kyori.minecraft

* Update adapters for getRichBlockName

* Add getRichName for items

* Update adapters for getRichItemName

* Update adapters JAR for merge

(cherry picked from commit cfd26253b6fb59ff6c65a0157a6780be7db4ea5a)

* Follow-up fixes for 92f877679622a27b16b9e5cd61cfec1a6545be33

* Don't send deprecation warning and improve info message

* Fix click command for perf box

(cherry picked from commit 7ee60060c31df2f8b41212b430a0875312189339)

* update R3 adapter§

Co-authored-by: Octavia Togami <octavia.togami@gmail.com>
Co-authored-by: NotMyFault <mc.cache@web.de>
Co-authored-by: Aurora <21148213+aurorasmiles@users.noreply.github.com>
Co-authored-by: Aurora <aurora@relanet.eu>
This commit is contained in:
Hannes Greule
2020-11-09 10:38:10 +01:00
committed by GitHub
parent 49052d73ce
commit 428f8e201d
42 changed files with 660 additions and 303 deletions

View File

@ -52,14 +52,12 @@ public class CommandUtil {
private static final Component DEPRECATION_MARKER = TextComponent.of("This command is deprecated.");
private static Component makeDeprecatedFooter(String reason, Component newCommand) {
private static Component makeDeprecatedFooter(String reason, Component replacement) {
return TextComponent.builder()
.append(DEPRECATION_MARKER)
.append(" " + reason + ".")
.append(TextComponent.newline())
.append(TextComponent.of("Use ", TextColor.GOLD, TextDecoration.ITALIC))
.append(newCommand)
.append(TextComponent.of(" instead.", TextColor.GOLD, TextDecoration.ITALIC))
.append(replacement.color(TextColor.GOLD).decoration(TextDecoration.ITALIC, true))
.build();
}
@ -69,20 +67,48 @@ public class CommandUtil {
}
public interface ReplacementMessageGenerator {
/**
* Generate text that says "Please use [cmd] instead." and allows clicking to dump
* the command to the text box.
*/
static ReplacementMessageGenerator forNewCommand(NewCommandGenerator generator) {
return (oldCommand, oldParameters) -> {
String suggestedCommand = generator.newCommand(oldCommand, oldParameters);
return createNewCommandReplacementText(suggestedCommand);
};
}
Component getReplacement(Command oldCommand, CommandParameters oldParameters);
}
public static Component createNewCommandReplacementText(String suggestedCommand) {
return TextComponent.builder("Please use ", TextColor.GOLD)
.append(TextComponent.of(suggestedCommand)
.decoration(TextDecoration.UNDERLINED, true)
.clickEvent(ClickEvent.suggestCommand(suggestedCommand)))
.append(" instead.")
.build();
}
public static Command deprecate(Command command, String reason,
NewCommandGenerator newCommandGenerator) {
ReplacementMessageGenerator replacementMessageGenerator) {
Component deprecatedWarning = makeDeprecatedFooter(
reason,
newCommandSuggestion(newCommandGenerator,
NoInputCommandParameters.builder().build(),
command)
replacementMessageGenerator.getReplacement(
command,
NoInputCommandParameters.builder().build()
)
);
return command.toBuilder()
.action(parameters ->
deprecatedCommandWarning(parameters, command, reason, newCommandGenerator))
deprecatedCommandWarning(parameters, command, reason, replacementMessageGenerator))
.footer(command.getFooter()
.map(existingFooter -> existingFooter
.append(TextComponent.newline()).append(deprecatedWarning))
.append(TextComponent.newline())
.append(deprecatedWarning))
.orElse(deprecatedWarning))
.build();
}
@ -139,26 +165,28 @@ public class CommandUtil {
CommandParameters parameters,
Command command,
String reason,
NewCommandGenerator generator
ReplacementMessageGenerator generator
) throws Exception {
parameters.injectedValue(Key.of(Actor.class))
.ifPresent(actor -> {
Component suggestion = newCommandSuggestion(generator, parameters, command);
actor.print(TextComponent.of(reason + ". Please use ", TextColor.GOLD)
.append(suggestion)
.append(TextComponent.of(" instead."))
);
});
.ifPresent(actor ->
sendDeprecationMessage(parameters, command, reason, generator, actor)
);
return command.getAction().run(parameters);
}
private static Component newCommandSuggestion(NewCommandGenerator generator,
CommandParameters parameters,
Command command) {
String suggestedCommand = generator.newCommand(command, parameters);
return TextComponent.of(suggestedCommand)
.decoration(TextDecoration.UNDERLINED, true)
.clickEvent(ClickEvent.suggestCommand(suggestedCommand));
private static void sendDeprecationMessage(
CommandParameters parameters,
Command command,
String reason,
ReplacementMessageGenerator generator,
Actor actor
) {
Component replacement = generator.getReplacement(command, parameters);
actor.print(
TextComponent.builder(reason + ". ", TextColor.GOLD)
.append(replacement)
.build()
);
}
public static Map<String, Command> getSubCommands(Command currentCommand) {

View File

@ -36,6 +36,7 @@ import com.sk89q.worldedit.command.InsufficientArgumentsException;
import com.sk89q.worldedit.command.tool.InvalidToolBindException;
import com.sk89q.worldedit.internal.expression.ExpressionException;
import com.sk89q.worldedit.regions.RegionOperationException;
import com.sk89q.worldedit.util.formatting.text.Component;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException;
import com.sk89q.worldedit.util.io.file.FilenameResolutionException;
@ -62,7 +63,11 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
}
private CommandException newCommandException(String message, Throwable cause) {
return new CommandException(TextComponent.of(String.valueOf(message)), cause, ImmutableList.of());
return newCommandException(TextComponent.of(String.valueOf(message)), cause);
}
private CommandException newCommandException(Component message, Throwable cause) {
return new CommandException(message, cause, ImmutableList.of());
}
@ExceptionMatch
@ -158,7 +163,13 @@ public class WorldEditExceptionConverter extends ExceptionConverterHelper {
@ExceptionMatch
public void convert(InvalidToolBindException e) throws CommandException {
throw newCommandException("Can't bind tool to " + e.getItemType().getName() + ": " + e.getMessage(), e);
throw newCommandException(
TextComponent.builder("Can't bind tool to ")
.append(e.getItemType().getRichName())
.append(": " + e.getMessage())
.build(),
e
);
}
@ExceptionMatch