Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-19 09:20:08 +01: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
Dieser Commit ist enthalten in:
Ursprung
d8d25fbff1
Commit
03c0cce53e
@ -3,7 +3,7 @@ import org.gradle.api.Project
|
|||||||
object Versions {
|
object Versions {
|
||||||
const val TEXT = "3.0.1"
|
const val TEXT = "3.0.1"
|
||||||
const val TEXT_EXTRAS = "3.0.2"
|
const val TEXT_EXTRAS = "3.0.2"
|
||||||
const val PISTON = "0.4.3"
|
const val PISTON = "0.5.2"
|
||||||
const val AUTO_VALUE = "1.6.5"
|
const val AUTO_VALUE = "1.6.5"
|
||||||
const val JUNIT = "5.5.0"
|
const val JUNIT = "5.5.0"
|
||||||
const val MOCKITO = "3.0.0"
|
const val MOCKITO = "3.0.0"
|
||||||
|
@ -27,6 +27,7 @@ import com.sk89q.worldedit.extent.Extent;
|
|||||||
import com.sk89q.worldedit.session.SessionKey;
|
import com.sk89q.worldedit.session.SessionKey;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
||||||
|
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
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.adapter.bukkit.TextAdapter;
|
import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter;
|
||||||
@ -90,7 +91,7 @@ public class BukkitBlockCommandSender extends AbstractNonPlayerActor implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print(Component component) {
|
public void print(Component component) {
|
||||||
TextAdapter.sendComponent(sender, component);
|
TextAdapter.sendComponent(sender, WorldEditText.format(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -33,7 +33,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static com.sk89q.worldedit.bukkit.BukkitTextAdapter.reduceToText;
|
import static com.sk89q.worldedit.util.formatting.WorldEditText.reduceToText;
|
||||||
|
|
||||||
class BukkitCommandInspector implements CommandInspector {
|
class BukkitCommandInspector implements CommandInspector {
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||||||
import com.sk89q.worldedit.extension.platform.AbstractNonPlayerActor;
|
import com.sk89q.worldedit.extension.platform.AbstractNonPlayerActor;
|
||||||
import com.sk89q.worldedit.session.SessionKey;
|
import com.sk89q.worldedit.session.SessionKey;
|
||||||
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
||||||
|
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter;
|
import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
@ -93,7 +94,7 @@ public class BukkitCommandSender extends AbstractNonPlayerActor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print(Component component) {
|
public void print(Component component) {
|
||||||
TextAdapter.sendComponent(sender, component);
|
TextAdapter.sendComponent(sender, WorldEditText.format(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -31,6 +31,7 @@ import com.sk89q.worldedit.math.BlockVector3;
|
|||||||
import com.sk89q.worldedit.math.Vector3;
|
import com.sk89q.worldedit.math.Vector3;
|
||||||
import com.sk89q.worldedit.session.SessionKey;
|
import com.sk89q.worldedit.session.SessionKey;
|
||||||
import com.sk89q.worldedit.util.HandSide;
|
import com.sk89q.worldedit.util.HandSide;
|
||||||
|
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
import com.sk89q.worldedit.world.block.BaseBlock;
|
import com.sk89q.worldedit.world.block.BaseBlock;
|
||||||
@ -129,7 +130,7 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print(Component component) {
|
public void print(Component component) {
|
||||||
TextAdapter.sendComponent(player, component);
|
TextAdapter.sendComponent(player, WorldEditText.format(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -47,7 +47,7 @@ import java.util.Map;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static com.sk89q.worldedit.bukkit.BukkitTextAdapter.reduceToText;
|
import static com.sk89q.worldedit.util.formatting.WorldEditText.reduceToText;
|
||||||
|
|
||||||
public class BukkitServerInterface implements MultiUserPlatform {
|
public class BukkitServerInterface implements MultiUserPlatform {
|
||||||
public Server server;
|
public Server server;
|
||||||
|
@ -26,6 +26,7 @@ import com.sk89q.worldedit.internal.cui.CUIEvent;
|
|||||||
import com.sk89q.worldedit.session.SessionKey;
|
import com.sk89q.worldedit.session.SessionKey;
|
||||||
import com.sk89q.worldedit.util.FileDialogUtil;
|
import com.sk89q.worldedit.util.FileDialogUtil;
|
||||||
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
||||||
|
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.serializer.plain.PlainComponentSerializer;
|
import com.sk89q.worldedit.util.formatting.text.serializer.plain.PlainComponentSerializer;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@ -96,7 +97,7 @@ public class CLICommandSender implements Actor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print(Component component) {
|
public void print(Component component) {
|
||||||
print(PlainComponentSerializer.INSTANCE.serialize(component));
|
print(PlainComponentSerializer.INSTANCE.serialize(WorldEditText.format(component)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,7 +24,6 @@ import com.sk89q.worldedit.WorldEdit
|
|||||||
import com.sk89q.worldedit.command.BiomeCommands
|
import com.sk89q.worldedit.command.BiomeCommands
|
||||||
import com.sk89q.worldedit.command.ChunkCommands
|
import com.sk89q.worldedit.command.ChunkCommands
|
||||||
import com.sk89q.worldedit.command.ClipboardCommands
|
import com.sk89q.worldedit.command.ClipboardCommands
|
||||||
import com.sk89q.worldedit.command.ExpandCommands
|
|
||||||
import com.sk89q.worldedit.command.GeneralCommands
|
import com.sk89q.worldedit.command.GeneralCommands
|
||||||
import com.sk89q.worldedit.command.GenerationCommands
|
import com.sk89q.worldedit.command.GenerationCommands
|
||||||
import com.sk89q.worldedit.command.HistoryCommands
|
import com.sk89q.worldedit.command.HistoryCommands
|
||||||
@ -37,11 +36,10 @@ import com.sk89q.worldedit.command.ToolCommands
|
|||||||
import com.sk89q.worldedit.command.ToolUtilCommands
|
import com.sk89q.worldedit.command.ToolUtilCommands
|
||||||
import com.sk89q.worldedit.command.UtilityCommands
|
import com.sk89q.worldedit.command.UtilityCommands
|
||||||
import com.sk89q.worldedit.command.util.PermissionCondition
|
import com.sk89q.worldedit.command.util.PermissionCondition
|
||||||
|
import com.sk89q.worldedit.internal.command.CommandUtil
|
||||||
import com.sk89q.worldedit.util.formatting.text.TextComponent
|
import com.sk89q.worldedit.util.formatting.text.TextComponent
|
||||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent
|
|
||||||
import com.sk89q.worldedit.util.formatting.text.serializer.plain.PlainComponentSerializer
|
|
||||||
import org.enginehub.piston.Command
|
import org.enginehub.piston.Command
|
||||||
import org.enginehub.piston.TextConfig
|
import org.enginehub.piston.config.TextConfig
|
||||||
import org.enginehub.piston.part.SubCommandPart
|
import org.enginehub.piston.part.SubCommandPart
|
||||||
import org.enginehub.piston.util.HelpGenerator
|
import org.enginehub.piston.util.HelpGenerator
|
||||||
import java.nio.file.Files
|
import java.nio.file.Files
|
||||||
@ -52,7 +50,6 @@ import kotlin.streams.toList
|
|||||||
class DocumentationPrinter private constructor() {
|
class DocumentationPrinter private constructor() {
|
||||||
|
|
||||||
private val nameRegex = Regex("name = \"(.+?)\"")
|
private val nameRegex = Regex("name = \"(.+?)\"")
|
||||||
private val serializer = PlainComponentSerializer({ "" }, TranslatableComponent::key)
|
|
||||||
private val commands = WorldEdit.getInstance().platformManager.platformCommandManager.commandManager.allCommands
|
private val commands = WorldEdit.getInstance().platformManager.platformCommandManager.commandManager.allCommands
|
||||||
.map { it.name to it }.toList().toMap()
|
.map { it.name to it }.toList().toMap()
|
||||||
private val cmdOutput = StringBuilder()
|
private val cmdOutput = StringBuilder()
|
||||||
@ -111,6 +108,7 @@ class DocumentationPrinter private constructor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dumpSection("Tool Commands") {
|
dumpSection("Tool Commands") {
|
||||||
|
yield("tool")
|
||||||
yieldAllCommandsIn<ToolCommands>()
|
yieldAllCommandsIn<ToolCommands>()
|
||||||
yieldAllCommandsIn<ToolUtilCommands>()
|
yieldAllCommandsIn<ToolUtilCommands>()
|
||||||
}
|
}
|
||||||
@ -216,7 +214,7 @@ Other Permissions
|
|||||||
private fun dumpSection(title: String, addCommandNames: suspend SequenceScope<String>.() -> Unit) {
|
private fun dumpSection(title: String, addCommandNames: suspend SequenceScope<String>.() -> Unit) {
|
||||||
cmdOutput.append("\n").append(title).append("\n").append(Strings.repeat("~", title.length)).append("\n")
|
cmdOutput.append("\n").append(title).append("\n").append(Strings.repeat("~", title.length)).append("\n")
|
||||||
|
|
||||||
val prefix = TextConfig.getCommandPrefix()
|
val prefix = reduceToRst(TextConfig.commandPrefixValue())
|
||||||
val commands = sequence(addCommandNames).map { this.commands.getValue(it) }.toList()
|
val commands = sequence(addCommandNames).map { this.commands.getValue(it) }.toList()
|
||||||
matchedCommands.addAll(commands.map { it.name })
|
matchedCommands.addAll(commands.map { it.name })
|
||||||
|
|
||||||
@ -269,14 +267,19 @@ Other Permissions
|
|||||||
}
|
}
|
||||||
cmdOutput.appendln()
|
cmdOutput.appendln()
|
||||||
cmdOutput.appendln(" :class: command-topic").appendln()
|
cmdOutput.appendln(" :class: command-topic").appendln()
|
||||||
|
CommandUtil.deprecationWarning(command).ifPresent { warning ->
|
||||||
|
cmdOutput.appendln("""
|
||||||
|
| .. WARNING::
|
||||||
|
| ${reduceToRst(warning).makeRstSafe("\n\n")}
|
||||||
|
""".trimMargin())
|
||||||
|
}
|
||||||
cmdOutput.appendln("""
|
cmdOutput.appendln("""
|
||||||
| .. csv-table::
|
| .. csv-table::
|
||||||
| :widths: 8, 15
|
| :widths: 8, 15
|
||||||
""".trimMargin())
|
""".trimMargin())
|
||||||
cmdOutput.appendln()
|
cmdOutput.appendln()
|
||||||
for ((k, v) in entries) {
|
for ((k, v) in entries) {
|
||||||
val rstSafe = v.trim().replace("\"", "\\\"").replace("\n", "\n" + " ".repeat(2))
|
val rstSafe = v.makeRstSafe("\n")
|
||||||
.lineSequence().map { line -> line.ifBlank { "" } }.joinToString(separator = "\n")
|
|
||||||
cmdOutput.append(" ".repeat(2))
|
cmdOutput.append(" ".repeat(2))
|
||||||
.append(k)
|
.append(k)
|
||||||
.append(",")
|
.append(",")
|
||||||
@ -287,32 +290,39 @@ Other Permissions
|
|||||||
cmdOutput.appendln()
|
cmdOutput.appendln()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun String.makeRstSafe(lineJoiner: String) = trim()
|
||||||
|
.replace("\"", "\\\"").replace("\n", "\n" + " ".repeat(2))
|
||||||
|
.lineSequence()
|
||||||
|
.map { line -> line.ifBlank { "" } }
|
||||||
|
.joinToString(separator = lineJoiner)
|
||||||
|
|
||||||
private fun linkSafe(text: String) = text.replace(" ", "-")
|
private fun linkSafe(text: String) = text.replace(" ", "-")
|
||||||
|
|
||||||
private fun commandTableEntries(command: Command, parents: Stream<Command>): Map<String, String> {
|
private fun commandTableEntries(command: Command, parents: Stream<Command>): Map<String, String> {
|
||||||
return sequence {
|
return sequence {
|
||||||
val desc = command.description.run {
|
val desc = command.description.run {
|
||||||
|
val footer = CommandUtil.footerWithoutDeprecation(command)
|
||||||
when {
|
when {
|
||||||
command.footer.isPresent -> append(
|
footer.isPresent -> append(
|
||||||
TextComponent.builder("\n\n").append(command.footer.get())
|
TextComponent.builder("\n\n").append(footer.get())
|
||||||
)
|
)
|
||||||
else -> this
|
else -> this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
yield("**Description**" to serializer.serialize(desc))
|
yield("**Description**" to reduceToRst(desc))
|
||||||
val cond = command.condition
|
val cond = command.condition
|
||||||
if (cond is PermissionCondition && cond.permissions.isNotEmpty()) {
|
if (cond is PermissionCondition && cond.permissions.isNotEmpty()) {
|
||||||
val perms = cond.permissions.joinToString(", ") { "``$it``" }
|
val perms = cond.permissions.joinToString(", ") { "``$it``" }
|
||||||
yield("**Permissions**" to perms)
|
yield("**Permissions**" to perms)
|
||||||
}
|
}
|
||||||
val usage = serializer.serialize(HelpGenerator.create(Stream.concat(parents, Stream.of(command)).toList()).usage)
|
val usage = reduceToRst(HelpGenerator.create(Stream.concat(parents, Stream.of(command)).toList()).usage)
|
||||||
yield("**Usage**" to "``$usage``")
|
yield("**Usage**" to "``$usage``")
|
||||||
|
|
||||||
// Part descriptions
|
// Part descriptions
|
||||||
command.parts.filterNot { it is SubCommandPart }
|
command.parts.filterNot { it is SubCommandPart }
|
||||||
.forEach {
|
.forEach {
|
||||||
val title = "\u2001\u2001``" + serializer.serialize(it.textRepresentation) + "``"
|
val title = "\u2001\u2001``" + reduceToRst(it.textRepresentation) + "``"
|
||||||
yield(title to serializer.serialize(it.description))
|
yield(title to reduceToRst(it.description))
|
||||||
}
|
}
|
||||||
}.toMap()
|
}.toMap()
|
||||||
}
|
}
|
||||||
@ -324,13 +334,15 @@ Other Permissions
|
|||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
val printer = DocumentationPrinter()
|
try {
|
||||||
|
val printer = DocumentationPrinter()
|
||||||
|
|
||||||
printer.writeAllCommands()
|
printer.writeAllCommands()
|
||||||
writeOutput("commands.rst", printer.cmdOutput.toString())
|
writeOutput("commands.rst", printer.cmdOutput.toString())
|
||||||
writeOutput("permissions.rst", printer.permsOutput.toString())
|
writeOutput("permissions.rst", printer.permsOutput.toString())
|
||||||
|
} finally {
|
||||||
WorldEdit.getInstance().sessionManager.unload()
|
WorldEdit.getInstance().sessionManager.unload()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun writeOutput(file: String, output: String) {
|
private fun writeOutput(file: String, output: String) {
|
||||||
|
@ -0,0 +1,69 @@
|
|||||||
|
package com.sk89q.worldedit.internal.util
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.util.formatting.WorldEditText
|
||||||
|
import com.sk89q.worldedit.util.formatting.text.Component
|
||||||
|
import com.sk89q.worldedit.util.formatting.text.TextComponent
|
||||||
|
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent
|
||||||
|
import com.sk89q.worldedit.util.formatting.text.event.ClickEvent
|
||||||
|
import com.sk89q.worldedit.util.formatting.text.format.TextDecoration
|
||||||
|
import org.enginehub.piston.util.TextHelper
|
||||||
|
|
||||||
|
fun reduceToRst(component: Component): String {
|
||||||
|
val formatted = WorldEditText.format(component)
|
||||||
|
return formatAsRst(formatted).toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun formatAsRst(component: Component, currentDeco: String? = null): CharSequence {
|
||||||
|
return when (component) {
|
||||||
|
is TextComponent -> {
|
||||||
|
val content = StringBuilder(component.content())
|
||||||
|
|
||||||
|
val deco = when {
|
||||||
|
// Actions that suggest themselves as commands are marked as code
|
||||||
|
component.isSuggestingAsCommand(content.toString()) -> "``"
|
||||||
|
component.decorations().any { it == TextDecoration.BOLD } -> "**"
|
||||||
|
component.decorations().any { it == TextDecoration.ITALIC } -> "*"
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
|
||||||
|
component.children().joinTo(content, separator = "") {
|
||||||
|
formatAsRst(it, deco ?: currentDeco)
|
||||||
|
}
|
||||||
|
|
||||||
|
deco?.let {
|
||||||
|
require(currentDeco == null) {
|
||||||
|
"Nested decorations are hell in RST. \n" +
|
||||||
|
"Existing: $currentDeco; New: $deco\n" +
|
||||||
|
"Offender: ${TextHelper.reduceToText(component)}"
|
||||||
|
}
|
||||||
|
content.rstDeco(deco)
|
||||||
|
}
|
||||||
|
|
||||||
|
content
|
||||||
|
}
|
||||||
|
is TranslatableComponent -> {
|
||||||
|
val content = StringBuilder(component.key())
|
||||||
|
component.children().joinTo(content, separator = "") { formatAsRst(it, currentDeco) }
|
||||||
|
content
|
||||||
|
}
|
||||||
|
else -> component.children().joinToString(separator = "") { formatAsRst(it, currentDeco) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun Component.isSuggestingAsCommand(text: String): Boolean {
|
||||||
|
val ce = clickEvent()
|
||||||
|
return when (ce?.action()) {
|
||||||
|
ClickEvent.Action.RUN_COMMAND,
|
||||||
|
ClickEvent.Action.SUGGEST_COMMAND ->
|
||||||
|
ce.value() == text
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun StringBuilder.rstDeco(deco: String): StringBuilder = apply {
|
||||||
|
ensureCapacity(length + deco.length * 2)
|
||||||
|
val insertionPoint = indexOfFirst { !it.isWhitespace() }.coerceAtLeast(0)
|
||||||
|
insert(insertionPoint, deco)
|
||||||
|
val insertionPointEnd = (indexOfLast { !it.isWhitespace() } + 1).takeUnless { it < 1 } ?: length
|
||||||
|
insert(insertionPointEnd, deco)
|
||||||
|
}
|
@ -88,7 +88,7 @@ public class ToolCommands {
|
|||||||
).build();
|
).build();
|
||||||
}
|
}
|
||||||
commandManager.register(CommandUtil.deprecate(
|
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
|
"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 com.sk89q.worldedit.world.World;
|
||||||
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.config.ConfigHolder;
|
||||||
|
import org.enginehub.piston.config.TextConfig;
|
||||||
import org.enginehub.piston.converter.ArgumentConverters;
|
import org.enginehub.piston.converter.ArgumentConverters;
|
||||||
import org.enginehub.piston.exception.CommandException;
|
import org.enginehub.piston.exception.CommandException;
|
||||||
import org.enginehub.piston.exception.CommandExecutionException;
|
import org.enginehub.piston.exception.CommandExecutionException;
|
||||||
@ -152,10 +153,6 @@ public final class PlatformCommandManager {
|
|||||||
private static final java.util.logging.Logger COMMAND_LOG =
|
private static final java.util.logging.Logger COMMAND_LOG =
|
||||||
java.util.logging.Logger.getLogger("com.sk89q.worldedit.CommandLog");
|
java.util.logging.Logger.getLogger("com.sk89q.worldedit.CommandLog");
|
||||||
|
|
||||||
static {
|
|
||||||
TextConfig.setCommandPrefix("/");
|
|
||||||
}
|
|
||||||
|
|
||||||
private final WorldEdit worldEdit;
|
private final WorldEdit worldEdit;
|
||||||
private final PlatformManager platformManager;
|
private final PlatformManager platformManager;
|
||||||
private final CommandManagerServiceImpl commandManagerService;
|
private final CommandManagerServiceImpl commandManagerService;
|
||||||
|
@ -42,6 +42,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
@ -49,11 +50,16 @@ import static java.util.stream.Collectors.toList;
|
|||||||
|
|
||||||
public class CommandUtil {
|
public class CommandUtil {
|
||||||
|
|
||||||
private static Component makeDeprecatedFooter(Component newCommand) {
|
private static final Component DEPRECATION_MARKER = TextComponent.of("This command is deprecated.");
|
||||||
return TextComponent.builder("This command is deprecated. Use ", TextColor.GOLD)
|
|
||||||
.decoration(TextDecoration.ITALIC, true)
|
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(newCommand)
|
||||||
.append(" instead.")
|
.append(TextComponent.of(" instead.", TextColor.GOLD, TextDecoration.ITALIC))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,6 +72,7 @@ public class CommandUtil {
|
|||||||
public static Command deprecate(Command command, String reason,
|
public static Command deprecate(Command command, String reason,
|
||||||
NewCommandGenerator newCommandGenerator) {
|
NewCommandGenerator newCommandGenerator) {
|
||||||
Component deprecatedWarning = makeDeprecatedFooter(
|
Component deprecatedWarning = makeDeprecatedFooter(
|
||||||
|
reason,
|
||||||
newCommandSuggestion(newCommandGenerator,
|
newCommandSuggestion(newCommandGenerator,
|
||||||
NoInputCommandParameters.builder().build(),
|
NoInputCommandParameters.builder().build(),
|
||||||
command)
|
command)
|
||||||
@ -80,6 +87,54 @@ public class CommandUtil {
|
|||||||
.build();
|
.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(
|
private static int deprecatedCommandWarning(
|
||||||
CommandParameters parameters,
|
CommandParameters parameters,
|
||||||
Command command,
|
Command command,
|
||||||
|
@ -17,32 +17,29 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.sk89q.worldedit.bukkit;
|
package com.sk89q.worldedit.util.formatting;
|
||||||
|
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.TextComponent;
|
import org.enginehub.piston.config.ConfigHolder;
|
||||||
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
|
import org.enginehub.piston.config.TextConfig;
|
||||||
|
import org.enginehub.piston.util.TextHelper;
|
||||||
|
|
||||||
public class BukkitTextAdapter {
|
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) {
|
public static String reduceToText(Component component) {
|
||||||
StringBuilder text = new StringBuilder();
|
return TextHelper.reduceToText(format(component));
|
||||||
appendTextTo(text, component);
|
|
||||||
return text.toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void appendTextTo(StringBuilder builder, Component component) {
|
private WorldEditText() {
|
||||||
if (component instanceof TextComponent) {
|
|
||||||
builder.append(((TextComponent) component).content());
|
|
||||||
} else if (component instanceof TranslatableComponent) {
|
|
||||||
builder.append(((TranslatableComponent) component).key());
|
|
||||||
}
|
|
||||||
for (Component child : component.children()) {
|
|
||||||
appendTextTo(builder, child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private BukkitTextAdapter() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -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.ClickEvent;
|
||||||
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
|
import com.sk89q.worldedit.util.formatting.text.event.HoverEvent;
|
||||||
import com.sk89q.worldedit.util.formatting.text.format.TextDecoration;
|
import com.sk89q.worldedit.util.formatting.text.format.TextDecoration;
|
||||||
import org.enginehub.piston.ColorConfig;
|
|
||||||
import org.enginehub.piston.Command;
|
import org.enginehub.piston.Command;
|
||||||
import org.enginehub.piston.CommandParameters;
|
import org.enginehub.piston.CommandParameters;
|
||||||
|
import org.enginehub.piston.config.ColorConfig;
|
||||||
import org.enginehub.piston.util.HelpGenerator;
|
import org.enginehub.piston.util.HelpGenerator;
|
||||||
|
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
@ -72,15 +72,13 @@ public class CommandUsageBox extends TextComponentProducer {
|
|||||||
.append(HelpGenerator.create(commands).getFullHelp());
|
.append(HelpGenerator.create(commands).getFullHelp());
|
||||||
if (getSubCommands(Iterables.getLast(commands)).size() > 0) {
|
if (getSubCommands(Iterables.getLast(commands)).size() > 0) {
|
||||||
boxContent.append(TextComponent.newline())
|
boxContent.append(TextComponent.newline())
|
||||||
.append(TextComponent.builder("> ")
|
.append(ColorConfig.helpText().wrap(TextComponent.builder("> ")
|
||||||
.color(ColorConfig.getHelpText())
|
.append(ColorConfig.mainText().wrap(TextComponent.builder("List Subcommands")
|
||||||
.append(TextComponent.builder("List Subcommands")
|
|
||||||
.color(ColorConfig.getMainText())
|
|
||||||
.decoration(TextDecoration.ITALIC, true)
|
.decoration(TextDecoration.ITALIC, true)
|
||||||
.clickEvent(ClickEvent.runCommand(helpRootCommand + " -s " + commandString))
|
.clickEvent(ClickEvent.runCommand(helpRootCommand + " -s " + commandString))
|
||||||
.hoverEvent(HoverEvent.showText(TextComponent.of("List all subcommands of this command")))
|
.hoverEvent(HoverEvent.showText(TextComponent.of("List all subcommands of this command")))
|
||||||
.build())
|
.build()))
|
||||||
.build());
|
.build()));
|
||||||
}
|
}
|
||||||
MessageBox box = new MessageBox("Help for " + commandString,
|
MessageBox box = new MessageBox("Help for " + commandString,
|
||||||
boxContent);
|
boxContent);
|
||||||
|
@ -32,6 +32,7 @@ import com.sk89q.worldedit.math.Vector3;
|
|||||||
import com.sk89q.worldedit.session.SessionKey;
|
import com.sk89q.worldedit.session.SessionKey;
|
||||||
import com.sk89q.worldedit.util.HandSide;
|
import com.sk89q.worldedit.util.HandSide;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
|
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer;
|
import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
@ -151,7 +152,7 @@ public class FabricPlayer extends AbstractPlayerActor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print(Component component) {
|
public void print(Component component) {
|
||||||
this.player.sendMessage(Text.Serializer.fromJson(GsonComponentSerializer.INSTANCE.serialize(component)));
|
this.player.sendMessage(Text.Serializer.fromJson(GsonComponentSerializer.INSTANCE.serialize(WorldEditText.format(component))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendColorized(String msg, Formatting formatting) {
|
private void sendColorized(String msg, Formatting formatting) {
|
||||||
|
@ -32,6 +32,7 @@ import com.sk89q.worldedit.math.Vector3;
|
|||||||
import com.sk89q.worldedit.session.SessionKey;
|
import com.sk89q.worldedit.session.SessionKey;
|
||||||
import com.sk89q.worldedit.util.HandSide;
|
import com.sk89q.worldedit.util.HandSide;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
|
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer;
|
import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer;
|
||||||
import com.sk89q.worldedit.world.World;
|
import com.sk89q.worldedit.world.World;
|
||||||
@ -152,7 +153,7 @@ public class ForgePlayer extends AbstractPlayerActor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print(Component component) {
|
public void print(Component component) {
|
||||||
this.player.sendMessage(ITextComponent.Serializer.fromJson(GsonComponentSerializer.INSTANCE.serialize(component)));
|
this.player.sendMessage(ITextComponent.Serializer.fromJson(GsonComponentSerializer.INSTANCE.serialize(WorldEditText.format(component))));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendColorized(String msg, TextFormatting formatting) {
|
private void sendColorized(String msg, TextFormatting formatting) {
|
||||||
|
@ -26,6 +26,7 @@ import com.sk89q.worldedit.extension.platform.Actor;
|
|||||||
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
import com.sk89q.worldedit.internal.cui.CUIEvent;
|
||||||
import com.sk89q.worldedit.session.SessionKey;
|
import com.sk89q.worldedit.session.SessionKey;
|
||||||
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
import com.sk89q.worldedit.util.auth.AuthorizationException;
|
||||||
|
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.adapter.spongeapi.TextAdapter;
|
import com.sk89q.worldedit.util.formatting.text.adapter.spongeapi.TextAdapter;
|
||||||
import org.spongepowered.api.command.CommandSource;
|
import org.spongepowered.api.command.CommandSource;
|
||||||
@ -93,7 +94,7 @@ public class SpongeCommandSender implements Actor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print(Component component) {
|
public void print(Component component) {
|
||||||
TextAdapter.sendComponent(sender, component);
|
TextAdapter.sendComponent(sender, WorldEditText.format(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendColorized(String msg, TextColor formatting) {
|
private void sendColorized(String msg, TextColor formatting) {
|
||||||
|
@ -31,6 +31,7 @@ import com.sk89q.worldedit.math.Vector3;
|
|||||||
import com.sk89q.worldedit.session.SessionKey;
|
import com.sk89q.worldedit.session.SessionKey;
|
||||||
import com.sk89q.worldedit.util.HandSide;
|
import com.sk89q.worldedit.util.HandSide;
|
||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
|
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.adapter.spongeapi.TextAdapter;
|
import com.sk89q.worldedit.util.formatting.text.adapter.spongeapi.TextAdapter;
|
||||||
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
import com.sk89q.worldedit.world.block.BlockStateHolder;
|
||||||
@ -153,7 +154,7 @@ public class SpongePlayer extends AbstractPlayerActor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void print(Component component) {
|
public void print(Component component) {
|
||||||
TextAdapter.sendComponent(player, component);
|
TextAdapter.sendComponent(player, WorldEditText.format(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendColorized(String msg, TextColor formatting) {
|
private void sendColorized(String msg, TextColor formatting) {
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.sponge;
|
package com.sk89q.worldedit.sponge;
|
||||||
|
|
||||||
|
import com.sk89q.worldedit.util.formatting.WorldEditText;
|
||||||
import com.sk89q.worldedit.util.formatting.text.Component;
|
import com.sk89q.worldedit.util.formatting.text.Component;
|
||||||
import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer;
|
import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer;
|
||||||
import org.spongepowered.api.text.Text;
|
import org.spongepowered.api.text.Text;
|
||||||
@ -27,6 +28,7 @@ import org.spongepowered.api.text.serializer.TextSerializers;
|
|||||||
public class SpongeTextAdapter {
|
public class SpongeTextAdapter {
|
||||||
|
|
||||||
public static Text convert(Component component) {
|
public static Text convert(Component component) {
|
||||||
|
component = WorldEditText.format(component);
|
||||||
return TextSerializers.JSON.deserialize(GsonComponentSerializer.INSTANCE.serialize(component));
|
return TextSerializers.JSON.deserialize(GsonComponentSerializer.INSTANCE.serialize(component));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren