From a872c37f6cb172a9485bbfa5c82a455ae220af68 Mon Sep 17 00:00:00 2001 From: Octavia Togami Date: Tue, 11 Aug 2020 03:00:34 -0700 Subject: [PATCH] WorldEdit goes on an adventure --- buildSrc/src/main/kotlin/LibsConfig.kt | 2 +- buildSrc/src/main/kotlin/Versions.kt | 4 +- settings.gradle.kts | 5 ++ .../bukkit/BukkitBlockCommandSender.java | 15 ++-- .../worldedit/bukkit/BukkitCommandSender.java | 11 ++- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 11 ++- .../sk89q/worldedit/cli/CLICommandSender.java | 2 +- .../java/com/sk89q/worldedit/WorldEdit.java | 6 +- .../worldedit/command/ApplyBrushCommands.java | 4 +- .../worldedit/command/ChunkCommands.java | 6 +- .../worldedit/command/GeneralCommands.java | 6 +- .../command/LegacySnapshotCommands.java | 6 +- .../worldedit/command/PaintBrushCommands.java | 4 +- .../worldedit/command/SchematicCommands.java | 10 +-- .../worldedit/command/SelectionCommands.java | 22 +++--- .../worldedit/command/SnapshotCommands.java | 6 +- .../worldedit/command/UtilityCommands.java | 4 +- .../worldedit/command/WorldEditCommands.java | 10 +-- .../worldedit/command/tool/QueryTool.java | 14 ++-- .../command/util/AsyncCommandBuilder.java | 4 +- .../worldedit/extension/platform/Actor.java | 8 +- .../platform/PlatformCommandManager.java | 4 +- .../worldedit/function/factory/Deform.java | 4 +- .../function/operation/ForwardExtentCopy.java | 8 +- .../function/visitor/BreadthFirstSearch.java | 4 +- .../function/visitor/EntityVisitor.java | 4 +- .../function/visitor/FlatRegionVisitor.java | 4 +- .../function/visitor/RegionVisitor.java | 4 +- .../internal/command/CommandUtil.java | 8 +- .../worldedit/regions/RegionSelector.java | 4 +- .../util/formatting/component/CodeFormat.java | 4 +- .../formatting/component/CommandListBox.java | 4 +- .../formatting/component/ErrorFormat.java | 4 +- .../formatting/component/LabelFormat.java | 4 +- .../util/formatting/component/MessageBox.java | 3 +- .../formatting/component/PaginationBox.java | 12 +-- .../formatting/component/SideEffectBox.java | 6 +- .../formatting/component/SubtleFormat.java | 4 +- .../util/translation/TranslationManager.java | 76 ++++++++++--------- .../sk89q/worldedit/fabric/FabricPlayer.java | 2 +- .../sk89q/worldedit/forge/ForgePlayer.java | 2 +- worldedit-libs/bukkit/build.gradle.kts | 2 +- worldedit-libs/core/build.gradle.kts | 8 +- worldedit-libs/sponge/build.gradle.kts | 1 - .../worldedit/sponge/SpongeCommandSender.java | 5 +- .../sk89q/worldedit/sponge/SpongePlayer.java | 5 +- .../worldedit/sponge/SpongeTextAdapter.java | 3 +- 47 files changed, 182 insertions(+), 167 deletions(-) diff --git a/buildSrc/src/main/kotlin/LibsConfig.kt b/buildSrc/src/main/kotlin/LibsConfig.kt index 29c5bfa3a8..b73e4ce345 100644 --- a/buildSrc/src/main/kotlin/LibsConfig.kt +++ b/buildSrc/src/main/kotlin/LibsConfig.kt @@ -27,7 +27,7 @@ fun Project.applyLibrariesConfiguration() { group = "${rootProject.group}.worldedit-libs" val relocations = mapOf( - "net.kyori.text" to "com.sk89q.worldedit.util.formatting.text", + "net.kyori.adventure.text" to "com.sk89q.worldedit.util.formatting.text", "net.kyori.minecraft" to "com.sk89q.worldedit.util.kyori" ) diff --git a/buildSrc/src/main/kotlin/Versions.kt b/buildSrc/src/main/kotlin/Versions.kt index 14054d450c..e8906de70b 100644 --- a/buildSrc/src/main/kotlin/Versions.kt +++ b/buildSrc/src/main/kotlin/Versions.kt @@ -1,8 +1,8 @@ import org.gradle.api.Project object Versions { - const val TEXT = "3.0.4" - const val TEXT_EXTRAS = "3.0.6" + const val ADVENTURE = "4.0.0-SNAPSHOT" + const val ADVENTURE_EXTRAS = "4.0.0-SNAPSHOT" const val PISTON = "0.5.6" const val AUTO_VALUE = "1.7" const val JUNIT = "5.6.1" diff --git a/settings.gradle.kts b/settings.gradle.kts index 2a4044c958..8ce774e60c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -9,3 +9,8 @@ listOf("bukkit", "core", "forge", "sponge", "fabric", "cli").forEach { include("worldedit-libs:core:ap") include("worldedit-core:doctools") + +includeBuild("../Piston") { + dependencySubstitution { + } +} diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java index 8a1c7bf160..4be26be8e0 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitBlockCommandSender.java @@ -29,8 +29,9 @@ 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.adapter.bukkit.TextAdapter; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.block.Block; @@ -46,6 +47,7 @@ public class BukkitBlockCommandSender extends AbstractNonPlayerActor implements private static final String UUID_PREFIX = "CMD"; + private final Audience audience; private final BlockCommandSender sender; private final WorldEditPlugin plugin; private final Location location; @@ -55,6 +57,7 @@ public BukkitBlockCommandSender(WorldEditPlugin plugin, BlockCommandSender sende checkNotNull(plugin); checkNotNull(sender); + this.audience = BukkitAudiences.create(plugin).audience(sender); this.plugin = plugin; this.sender = sender; this.location = BukkitAdapter.adapt(sender.getBlock().getLocation()); @@ -78,7 +81,7 @@ public void printRaw(String msg) { @Deprecated public void print(String msg) { for (String part : msg.split("\n")) { - print(TextComponent.of(part, TextColor.LIGHT_PURPLE)); + print(TextComponent.of(part, NamedTextColor.LIGHT_PURPLE)); } } @@ -86,7 +89,7 @@ public void print(String msg) { @Deprecated public void printDebug(String msg) { for (String part : msg.split("\n")) { - print(TextComponent.of(part, TextColor.GRAY)); + print(TextComponent.of(part, NamedTextColor.GRAY)); } } @@ -94,13 +97,13 @@ public void printDebug(String msg) { @Deprecated public void printError(String msg) { for (String part : msg.split("\n")) { - print(TextComponent.of(part, TextColor.RED)); + print(TextComponent.of(part, NamedTextColor.RED)); } } @Override public void print(Component component) { - TextAdapter.sendMessage(sender, WorldEditText.format(component, getLocale())); + audience.sendMessage(WorldEditText.format(component, getLocale())); } @Override diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java index fbdfa004ef..aaa9e73a4c 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitCommandSender.java @@ -24,13 +24,13 @@ import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.formatting.WorldEditText; import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import java.util.Locale; import java.util.UUID; -import javax.annotation.Nullable; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @@ -42,15 +42,15 @@ public class BukkitCommandSender extends AbstractNonPlayerActor { */ private static final UUID DEFAULT_ID = UUID.fromString("a233eb4b-4cab-42cd-9fd9-7e7b9a3f74be"); + private final Audience audience; private final CommandSender sender; - private final WorldEditPlugin plugin; public BukkitCommandSender(WorldEditPlugin plugin, CommandSender sender) { checkNotNull(plugin); checkNotNull(sender); checkArgument(!(sender instanceof Player), "Cannot wrap a player"); - this.plugin = plugin; + this.audience = BukkitAudiences.create(plugin).audience(sender); this.sender = sender; } @@ -98,7 +98,7 @@ public void printError(String msg) { @Override public void print(Component component) { - TextAdapter.sendMessage(sender, WorldEditText.format(component, getLocale())); + audience.sendMessage(WorldEditText.format(component, getLocale())); } @Override @@ -127,7 +127,6 @@ public CommandSender getSender() { @Override public SessionKey getSessionKey() { return new SessionKey() { - @Nullable @Override public String getName() { return sender.getName(); diff --git a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java index 42a7e364dc..64296408d6 100644 --- a/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java +++ b/worldedit-bukkit/src/main/java/com/sk89q/worldedit/bukkit/BukkitPlayer.java @@ -36,15 +36,16 @@ 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.adapter.bukkit.TextAdapter; 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.NamedTextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; +import net.kyori.adventure.audience.Audience; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -58,6 +59,7 @@ public class BukkitPlayer extends AbstractPlayerActor { private final Player player; private final WorldEditPlugin plugin; + private final Audience audience; public BukkitPlayer(Player player) { this(WorldEditPlugin.getInstance(), player); @@ -66,6 +68,7 @@ public BukkitPlayer(Player player) { public BukkitPlayer(WorldEditPlugin plugin, Player player) { this.plugin = plugin; this.player = player; + this.audience = BukkitAudiences.create(plugin).player(player); } @Override @@ -138,7 +141,7 @@ public void printError(String msg) { @Override public void print(Component component) { - TextAdapter.sendMessage(player, WorldEditText.format(component, getLocale())); + audience.sendMessage(WorldEditText.format(component, getLocale())); } @Override @@ -233,7 +236,7 @@ public Locale getLocale() { public void sendAnnouncements() { if (WorldEditPlugin.getInstance().getBukkitImplAdapter() == null) { printError(TranslatableComponent.of("worldedit.version.bukkit.unsupported-adapter", - TextComponent.of("https://enginehub.org/worldedit/#downloads", TextColor.AQUA) + TextComponent.of("https://enginehub.org/worldedit/#downloads", NamedTextColor.AQUA) .clickEvent(ClickEvent.openUrl("https://enginehub.org/worldedit/#downloads")))); } } diff --git a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLICommandSender.java b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLICommandSender.java index 80608a22e6..30c2599d3d 100644 --- a/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLICommandSender.java +++ b/worldedit-cli/src/main/java/com/sk89q/worldedit/cli/CLICommandSender.java @@ -103,7 +103,7 @@ public void printError(String msg) { @Override public void print(Component component) { - print(PlainComponentSerializer.INSTANCE.serialize(WorldEditText.format(component, getLocale()))); + print(PlainComponentSerializer.plain().serialize(WorldEditText.format(component, getLocale()))); } @Override diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java index d86ead34da..7e7a4bff64 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/WorldEdit.java @@ -57,7 +57,7 @@ import com.sk89q.worldedit.util.eventbus.EventBus; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.util.io.file.FileSelectionAbortedException; import com.sk89q.worldedit.util.io.file.FilenameException; import com.sk89q.worldedit.util.io.file.FilenameResolutionException; @@ -736,14 +736,14 @@ public void runScript(Player player, File f, String[] args) throws WorldEditExce } catch (ScriptException e) { // non-exceptional return check if (!(Throwables.getRootCause(e) instanceof ReturnException)) { - player.printError(TranslatableComponent.of("worldedit.script.failed", TextComponent.of(e.getMessage(), TextColor.WHITE))); + player.printError(TranslatableComponent.of("worldedit.script.failed", TextComponent.of(e.getMessage(), NamedTextColor.WHITE))); logger.warn("Failed to execute script", e); } } catch (NumberFormatException | WorldEditException e) { throw e; } catch (Throwable e) { player.printError(TranslatableComponent.of("worldedit.script.failed-console", TextComponent.of(e.getClass().getCanonicalName(), - TextColor.WHITE))); + NamedTextColor.WHITE))); logger.warn("Failed to execute script", e); } finally { for (EditSession editSession : scriptContext.getEditSessions()) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java index 4a80e5b569..4063cb873b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/ApplyBrushCommands.java @@ -41,7 +41,7 @@ import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.util.formatting.text.format.TextDecoration; import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandManagerService; @@ -124,7 +124,7 @@ public void item(CommandParameters parameters, @Arg(desc = "The direction in which the item will be applied", def = "up") @Direction(includeDiagonals = true) com.sk89q.worldedit.util.Direction direction) throws WorldEditException { - player.print(TextComponent.builder().append("WARNING: ", TextColor.RED, TextDecoration.BOLD) + player.print(TextComponent.builder().append("WARNING: ", NamedTextColor.RED, TextDecoration.BOLD) .append(TranslatableComponent.of("worldedit.brush.apply.item.warning")).build()); setApplyBrush(parameters, player, localSession, new ItemUseFactory(item, direction)); } 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 311b0ac5dc..caeb380868 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 @@ -40,7 +40,7 @@ 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.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.storage.LegacyChunkStore; import com.sk89q.worldedit.world.storage.McRegionChunkStore; @@ -175,8 +175,8 @@ public void deleteChunks(Actor actor, World world, LocalSession session, currentInfo.batches.stream().mapToInt(ChunkDeletionInfo.ChunkBatch::getChunkCount).sum()) )); } - actor.print(TextComponent.of("You can mark more chunks for deletion, or to stop now, run: ", TextColor.LIGHT_PURPLE) - .append(TextComponent.of("/stop", TextColor.AQUA) + actor.print(TextComponent.of("You can mark more chunks for deletion, or to stop now, run: ", NamedTextColor.LIGHT_PURPLE) + .append(TextComponent.of("/stop", NamedTextColor.AQUA) .clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "/stop")))); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java index bf1804cd33..19e3acc8c1 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/GeneralCommands.java @@ -43,7 +43,7 @@ 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.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.item.ItemType; import org.enginehub.piston.CommandManager; @@ -163,7 +163,7 @@ public void limit(Actor actor, LocalSession session, session.setBlockChangeLimit(limit); Component component = TextComponent.empty().append(TranslatableComponent.of("worldedit.limit.set", TextComponent.of(limit))); if (limit != config.defaultChangeLimit) { - component.append(TextComponent.space()).append(TranslatableComponent.of("worldedit.limit.return-to-default", TextColor.GRAY)); + component.append(TextComponent.space()).append(TranslatableComponent.of("worldedit.limit.return-to-default", NamedTextColor.GRAY)); } actor.printInfo(component); } @@ -190,7 +190,7 @@ public void timeout(Actor actor, LocalSession session, session.setTimeout(limit); Component component = TextComponent.empty().append(TranslatableComponent.of("worldedit.timeout.set", TextComponent.of(limit))); if (limit != config.calculationTimeout) { - component.append(TranslatableComponent.of("worldedit.timeout.return-to-default", TextColor.GRAY)); + component.append(TranslatableComponent.of("worldedit.timeout.return-to-default", NamedTextColor.GRAY)); } actor.printInfo(component); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/LegacySnapshotCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/LegacySnapshotCommands.java index ee423a1bdf..aa3467c295 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/LegacySnapshotCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/LegacySnapshotCommands.java @@ -32,7 +32,7 @@ import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; 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.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.snapshot.InvalidSnapshotException; import com.sk89q.worldedit.world.snapshot.Snapshot; @@ -189,8 +189,8 @@ private static class SnapshotListBox extends PaginationBox { @Override public Component getComponent(int number) { final Snapshot snapshot = snapshots.get(number); - return TextComponent.of(number + 1 + ". ", TextColor.GOLD) - .append(TextComponent.of(snapshot.getName(), TextColor.LIGHT_PURPLE) + return TextComponent.of(number + 1 + ". ", NamedTextColor.GOLD) + .append(TextComponent.of(snapshot.getName(), NamedTextColor.LIGHT_PURPLE) .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to use"))) .clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/snap use " + snapshot.getName()))); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/PaintBrushCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/PaintBrushCommands.java index 964d1ae659..b384e0c6d3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/PaintBrushCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/PaintBrushCommands.java @@ -41,7 +41,7 @@ import com.sk89q.worldedit.util.TreeGenerator; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.util.formatting.text.format.TextDecoration; import org.enginehub.piston.CommandManager; import org.enginehub.piston.CommandManagerService; @@ -130,7 +130,7 @@ public void item(CommandParameters parameters, @Arg(desc = "The direction in which the item will be applied", def = "up") @Direction(includeDiagonals = true) com.sk89q.worldedit.util.Direction direction) throws WorldEditException { - player.print(TextComponent.builder().append("WARNING: ", TextColor.RED, TextDecoration.BOLD) + player.print(TextComponent.builder().append("WARNING: ", NamedTextColor.RED, TextDecoration.BOLD) .append(TranslatableComponent.of("worldedit.brush.paint.item.warning")).build()); setPaintBrush(parameters, player, localSession, new ItemUseFactory(item, direction)); } 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 a80bbcc77b..5f29419116 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 @@ -51,7 +51,7 @@ import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; 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.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.util.io.Closer; import com.sk89q.worldedit.util.io.file.FilenameException; import org.enginehub.piston.annotation.Command; @@ -133,8 +133,8 @@ public void load(Actor actor, LocalSession session, AsyncCommandBuilder.wrap(task, actor) .registerWithSupervisor(worldEdit.getSupervisor(), "Loading schematic " + filename) .sendMessageAfterDelay(TranslatableComponent.of("worldedit.schematic.load.loading")) - .onSuccess(TextComponent.of(filename, TextColor.GOLD) - .append(TextComponent.of(" loaded. Paste it with ", TextColor.LIGHT_PURPLE)) + .onSuccess(TextComponent.of(filename, NamedTextColor.GOLD) + .append(TextComponent.of(" loaded. Paste it with ", NamedTextColor.LIGHT_PURPLE)) .append(CodeFormat.wrap("//paste").clickEvent(ClickEvent.of(ClickEvent.Action.SUGGEST_COMMAND, "//paste"))), session::setClipboard) .onFailure("Failed to load schematic", worldEdit.getPlatformManager().getPlatformCommandManager().getExceptionConverter()) @@ -446,12 +446,12 @@ public Component getComponent(int number) { return TextComponent.builder() .content("") .append(TextComponent.of("[L]") - .color(TextColor.GOLD) + .color(NamedTextColor.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) + .color(NamedTextColor.DARK_GREEN) .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of(format)))) .build(); } 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 2336f30a0f..8e7fa34848 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 @@ -69,7 +69,7 @@ import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; 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.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockType; @@ -315,13 +315,13 @@ public void wand(Player player, LocalSession session, @CommandPermissions("worldedit.wand.toggle") public void toggleWand(Player player) { player.printInfo(TextComponent.of("The selection wand is now a normal tool. You can disable it with ") - .append(TextComponent.of("/none", TextColor.AQUA).clickEvent( + .append(TextComponent.of("/none", NamedTextColor.AQUA).clickEvent( ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "/none"))) .append(TextComponent.of(" and rebind it to any item with ")) - .append(TextComponent.of("//selwand", TextColor.AQUA).clickEvent( + .append(TextComponent.of("//selwand", NamedTextColor.AQUA).clickEvent( ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "//selwand"))) .append(TextComponent.of(" or get a new wand with ")) - .append(TextComponent.of("//wand", TextColor.AQUA).clickEvent( + .append(TextComponent.of("//wand", NamedTextColor.AQUA).clickEvent( ClickEvent.of(ClickEvent.Action.RUN_COMMAND, "//wand")))); } @@ -669,20 +669,20 @@ public Component getComponent(int number) { 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); + line.append(String.format("%s%.3f%% ", perc < 10 ? " " : "", perc), NamedTextColor.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); + line.append(String.format("%s%s", count, pad), NamedTextColor.YELLOW); final BlockState state = c.getID(); final BlockType blockType = state.getBlockType(); - Component blockName = blockType.getRichName().color(TextColor.LIGHT_PURPLE); + Component blockName = blockType.getRichName().color(NamedTextColor.LIGHT_PURPLE); TextComponent toolTip; if (separateStates && state != blockType.getDefaultState()) { - toolTip = TextComponent.of(state.getAsString(), TextColor.GRAY); - blockName = blockName.append(TextComponent.of("*", TextColor.LIGHT_PURPLE)); + toolTip = TextComponent.of(state.getAsString(), NamedTextColor.GRAY); + blockName = blockName.append(TextComponent.of("*", NamedTextColor.LIGHT_PURPLE)); } else { - toolTip = TextComponent.of(blockType.getId(), TextColor.GRAY); + toolTip = TextComponent.of(blockType.getId(), NamedTextColor.GRAY); } blockName = blockName.hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, toolTip)); line.append(blockName); @@ -697,7 +697,7 @@ public int getComponentsSize() { @Override public Component create(int page) throws InvalidComponentException { - super.getContents().append(TranslatableComponent.of("worldedit.distr.total", TextColor.GRAY, TextComponent.of(totalBlocks))) + super.getContents().append(TranslatableComponent.of("worldedit.distr.total", NamedTextColor.GRAY, TextComponent.of(totalBlocks))) .append(TextComponent.newline()); return super.create(page); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotCommands.java index 22d7582878..866eabfc41 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/SnapshotCommands.java @@ -34,7 +34,7 @@ import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; 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.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.snapshot.experimental.Snapshot; import com.sk89q.worldedit.world.snapshot.experimental.fs.FileSystemSnapshotDatabase; @@ -330,8 +330,8 @@ private static class SnapshotListBox extends PaginationBox { public Component getComponent(int number) { final Snapshot snapshot = snapshots.get(number); String displayName = snapshot.getInfo().getDisplayName(); - return TextComponent.of(number + 1 + ". ", TextColor.GOLD) - .append(TextComponent.builder(displayName, TextColor.LIGHT_PURPLE) + return TextComponent.of(number + 1 + ". ", NamedTextColor.GOLD) + .append(TextComponent.builder(displayName, NamedTextColor.LIGHT_PURPLE) .hoverEvent(HoverEvent.showText(TextComponent.of("Click to use"))) .clickEvent(ClickEvent.runCommand("/snap use " + displayName))); } 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 0d50cea55a..99f3ba2687 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 @@ -55,7 +55,7 @@ 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.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockTypes; import org.enginehub.piston.annotation.Command; @@ -534,7 +534,7 @@ public void calc(Actor actor, double result = expression.evaluate( new double[]{}, WorldEdit.getInstance().getSessionManager().get(actor).getTimeout()); String formatted = Double.isNaN(result) ? "NaN" : formatForLocale(actor.getLocale()).format(result); - return SubtleFormat.wrap(input + " = ").append(TextComponent.of(formatted, TextColor.LIGHT_PURPLE)); + return SubtleFormat.wrap(input + " = ").append(TextComponent.of(formatted, NamedTextColor.LIGHT_PURPLE)); }, (Component) null); } 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 3246ebac4d..5125d46b30 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 @@ -37,7 +37,7 @@ import com.sk89q.worldedit.util.formatting.component.TextComponentProducer; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.util.paste.ActorCallbackPaste; import com.sk89q.worldedit.util.report.ConfigReport; import com.sk89q.worldedit.util.report.ReportList; @@ -82,23 +82,23 @@ public void version(Actor actor) { TextComponentProducer producer = new TextComponentProducer(); for (Platform platform : pm.getPlatforms()) { producer.append( - TextComponent.of("* ", TextColor.GRAY) + TextComponent.of("* ", NamedTextColor.GRAY) .append(TextComponent.of(platform.getPlatformName())) .append(TextComponent.of("(" + platform.getPlatformVersion() + ")")) ).newline(); } - actor.print(new MessageBox("Platforms", producer, TextColor.GRAY).create()); + actor.print(new MessageBox("Platforms", producer, NamedTextColor.GRAY).create()); producer.reset(); for (Capability capability : Capability.values()) { Platform platform = pm.queryCapability(capability); producer.append( - TextComponent.of(capability.name(), TextColor.GRAY) + TextComponent.of(capability.name(), NamedTextColor.GRAY) .append(TextComponent.of(": ") .append(TextComponent.of(platform != null ? platform.getPlatformName() : "NONE"))) ).newline(); } - actor.print(new MessageBox("Capabilities", producer, TextColor.GRAY).create()); + actor.print(new MessageBox("Capabilities", producer, NamedTextColor.GRAY).create()); } @Command( diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java index 53f18ec92a..f12bc905d0 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/tool/QueryTool.java @@ -32,7 +32,7 @@ import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.registry.LegacyMapper; @@ -58,23 +58,23 @@ public boolean actPrimary(Platform server, LocalConfiguration config, Player pla BaseBlock block = editSession.getFullBlock(blockPoint); TextComponent.Builder builder = TextComponent.builder(); - builder.append(TextComponent.of("@" + clicked.toVector().toBlockPoint() + ": ", TextColor.BLUE)); - builder.append(block.getBlockType().getRichName().color(TextColor.YELLOW)); - builder.append(TextComponent.of(" (" + block + ") ", TextColor.GRAY) + builder.append(TextComponent.of("@" + clicked.toVector().toBlockPoint() + ": ", NamedTextColor.BLUE)); + builder.append(block.getBlockType().getRichName().color(NamedTextColor.YELLOW)); + builder.append(TextComponent.of(" (" + block + ") ", NamedTextColor.GRAY) .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of("worldedit.tool.info.blockstate.hover")))); final int internalId = BlockStateIdAccess.getBlockStateId(block.toImmutableState()); if (BlockStateIdAccess.isValidInternalId(internalId)) { - builder.append(TextComponent.of(" (" + internalId + ") ", TextColor.DARK_GRAY) + builder.append(TextComponent.of(" (" + internalId + ") ", NamedTextColor.DARK_GRAY) .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of("worldedit.tool.info.internalid.hover")))); } final int[] legacy = LegacyMapper.getInstance().getLegacyFromBlock(block.toImmutableState()); if (legacy != null) { - builder.append(TextComponent.of(" (" + legacy[0] + ":" + legacy[1] + ") ", TextColor.DARK_GRAY) + builder.append(TextComponent.of(" (" + legacy[0] + ":" + legacy[1] + ") ", NamedTextColor.DARK_GRAY) .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of("worldedit.tool.info.legacy.hover")))); } builder.append(TextComponent.of(" (" + world.getBlockLightLevel(blockPoint) + "/" - + world.getBlockLightLevel(blockPoint.add(0, 1, 0)) + ")", TextColor.WHITE) + + world.getBlockLightLevel(blockPoint.add(0, 1, 0)) + ")", NamedTextColor.WHITE) .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of("worldedit.tool.info.light.hover")))); player.print(builder.build()); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandBuilder.java index 99ebddb13c..06de9d6703 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/util/AsyncCommandBuilder.java @@ -28,7 +28,7 @@ import com.sk89q.worldedit.util.formatting.component.ErrorFormat; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.util.task.FutureForwardingTask; import com.sk89q.worldedit.util.task.Supervisor; import org.enginehub.piston.exception.CommandException; @@ -103,7 +103,7 @@ public AsyncCommandBuilder onSuccess(@Nullable Component message, @Nullable C public AsyncCommandBuilder onSuccess(@Nullable String message, @Nullable Consumer consumer) { checkArgument(message != null || consumer != null, "Can't have null message AND consumer"); - this.successMessage = message == null ? null : TextComponent.of(message, TextColor.LIGHT_PURPLE); + this.successMessage = message == null ? null : TextComponent.of(message, NamedTextColor.LIGHT_PURPLE); this.consumer = consumer; return this; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Actor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Actor.java index a76a0040d5..19e9a7a6bc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Actor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/Actor.java @@ -24,7 +24,7 @@ import com.sk89q.worldedit.util.Identifiable; import com.sk89q.worldedit.util.auth.Subject; import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import java.io.File; import java.util.Locale; @@ -92,7 +92,7 @@ default String getDisplayName() { * @param component The component to print */ default void printError(Component component) { - print(component.color(TextColor.RED)); + print(component.color(NamedTextColor.RED)); } /** @@ -101,7 +101,7 @@ default void printError(Component component) { * @param component The component to print */ default void printInfo(Component component) { - print(component.color(TextColor.LIGHT_PURPLE)); + print(component.color(NamedTextColor.LIGHT_PURPLE)); } /** @@ -110,7 +110,7 @@ default void printInfo(Component component) { * @param component The component to print */ default void printDebug(Component component) { - print(component.color(TextColor.GRAY)); + print(component.color(NamedTextColor.GRAY)); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java index 8324ebd332..cc66697e9d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlatformCommandManager.java @@ -104,7 +104,7 @@ import com.sk89q.worldedit.util.eventbus.Subscribe; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.util.logging.DynamicStreamHandler; import com.sk89q.worldedit.util.logging.LogFormat; import com.sk89q.worldedit.world.World; @@ -511,7 +511,7 @@ public void handleCommand(CommandEvent event) { } } catch (UsageException e) { actor.print(TextComponent.builder("") - .color(TextColor.RED) + .color(NamedTextColor.RED) .append(e.getRichMessage()) .build()); ImmutableList cmd = e.getCommands(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java index 679f5a3e37..bca2ed1811 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/factory/Deform.java @@ -38,7 +38,7 @@ 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.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import static com.google.common.base.Preconditions.checkNotNull; import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull; @@ -193,7 +193,7 @@ public void cancel() { @Override public Iterable getStatusMessages() { return ImmutableList.of(TranslatableComponent.of("worldedit.operation.deform.expression", - TextComponent.of(expression.getSource()).color(TextColor.LIGHT_PURPLE))); + TextComponent.of(expression.getSource()).color(NamedTextColor.LIGHT_PURPLE))); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java index b66fbd7fb4..cb38a6bebd 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/operation/ForwardExtentCopy.java @@ -42,7 +42,7 @@ 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.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import java.util.List; @@ -336,11 +336,11 @@ public void cancel() { public Iterable getStatusMessages() { return ImmutableList.of( TranslatableComponent.of("worldedit.operation.affected.block", - TextComponent.of(affectedBlocks)).color(TextColor.LIGHT_PURPLE), + TextComponent.of(affectedBlocks)).color(NamedTextColor.LIGHT_PURPLE), TranslatableComponent.of("worldedit.operation.affected.biome", - TextComponent.of(affectedBiomeCols)).color(TextColor.LIGHT_PURPLE), + TextComponent.of(affectedBiomeCols)).color(NamedTextColor.LIGHT_PURPLE), TranslatableComponent.of("worldedit.operation.affected.entity", - TextComponent.of(affectedEntities)).color(TextColor.LIGHT_PURPLE) + TextComponent.of(affectedEntities)).color(NamedTextColor.LIGHT_PURPLE) ); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java index 5ec2d5789c..ea4fd46564 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/BreadthFirstSearch.java @@ -29,7 +29,7 @@ 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.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import java.util.ArrayDeque; import java.util.ArrayList; @@ -190,7 +190,7 @@ public Iterable getStatusMessages() { return ImmutableList.of(TranslatableComponent.of( "worldedit.operation.affected.block", TextComponent.of(getAffected()) - ).color(TextColor.LIGHT_PURPLE)); + ).color(NamedTextColor.LIGHT_PURPLE)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java index fc465a4d3b..1e92739041 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/EntityVisitor.java @@ -28,7 +28,7 @@ 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.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import java.util.Iterator; @@ -85,7 +85,7 @@ public Iterable getStatusMessages() { return ImmutableList.of(TranslatableComponent.of( "worldedit.operation.affected.entity", TextComponent.of(getAffected()) - ).color(TextColor.LIGHT_PURPLE)); + ).color(NamedTextColor.LIGHT_PURPLE)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java index 41fd7d05aa..7204faea21 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/FlatRegionVisitor.java @@ -29,7 +29,7 @@ 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.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import static com.google.common.base.Preconditions.checkNotNull; @@ -85,7 +85,7 @@ public Iterable getStatusMessages() { return ImmutableList.of(TranslatableComponent.of( "worldedit.operation.affected.column", TextComponent.of(getAffected()) - ).color(TextColor.LIGHT_PURPLE)); + ).color(NamedTextColor.LIGHT_PURPLE)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java index c9ae145a79..1001ce52fa 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/function/visitor/RegionVisitor.java @@ -29,7 +29,7 @@ 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.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; /** * Utility class to apply region functions to {@link com.sk89q.worldedit.regions.Region}. @@ -74,7 +74,7 @@ public Iterable getStatusMessages() { return ImmutableList.of(TranslatableComponent.of( "worldedit.operation.affected.block", TextComponent.of(getAffected()) - ).color(TextColor.LIGHT_PURPLE)); + ).color(NamedTextColor.LIGHT_PURPLE)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandUtil.java b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandUtil.java index 202d60d5f7..a9b7f9c141 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandUtil.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/internal/command/CommandUtil.java @@ -27,7 +27,7 @@ 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; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.util.formatting.text.format.TextDecoration; import org.enginehub.piston.Command; import org.enginehub.piston.CommandParameters; @@ -57,7 +57,7 @@ private static Component makeDeprecatedFooter(String reason, Component replaceme .append(DEPRECATION_MARKER) .append(" " + reason + ".") .append(TextComponent.newline()) - .append(replacement.color(TextColor.GOLD).decoration(TextDecoration.ITALIC, true)) + .append(replacement.color(NamedTextColor.GOLD).decoration(TextDecoration.ITALIC, true)) .build(); } @@ -85,7 +85,7 @@ static ReplacementMessageGenerator forNewCommand(NewCommandGenerator generator) } public static Component createNewCommandReplacementText(String suggestedCommand) { - return TextComponent.builder("Please use ", TextColor.GOLD) + return TextComponent.builder("Please use ", NamedTextColor.GOLD) .append(TextComponent.of(suggestedCommand) .decoration(TextDecoration.UNDERLINED, true) .clickEvent(ClickEvent.suggestCommand(suggestedCommand))) @@ -183,7 +183,7 @@ private static void sendDeprecationMessage( ) { Component replacement = generator.getReplacement(command, parameters); actor.print( - TextComponent.builder(reason + ". ", TextColor.GOLD) + TextComponent.builder(reason + ". ", NamedTextColor.GOLD) .append(replacement) .build() ); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java index 04cb90dfe7..d6f2ed220a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/regions/RegionSelector.java @@ -29,7 +29,7 @@ import com.sk89q.worldedit.regions.selector.limit.SelectorLimits; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.world.World; import java.util.List; @@ -193,7 +193,7 @@ default List getInformationLines() { */ default List getSelectionInfoLines() { return getInformationLines().stream() - .map(line -> TextComponent.of(line, TextColor.LIGHT_PURPLE)) + .map(line -> TextComponent.of(line, NamedTextColor.LIGHT_PURPLE)) .collect(Collectors.toList()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CodeFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CodeFormat.java index ee98348a1e..67aaa12751 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CodeFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CodeFormat.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.util.formatting.component; import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; /** * Represents a fragment representing a command that is to be typed. @@ -28,7 +28,7 @@ public class CodeFormat extends TextComponentProducer { private CodeFormat() { - getBuilder().content("").color(TextColor.AQUA); + getBuilder().content("").color(NamedTextColor.AQUA); } /** 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 a5d1b63fa5..a4467b8736 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 @@ -24,7 +24,7 @@ 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.formatting.text.format.NamedTextColor; import java.util.List; @@ -93,7 +93,7 @@ Component createComponent(boolean hideHelp) { .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); + TextComponent command = TextComponent.of(alias, NamedTextColor.GOLD); if (insertion == null) { line.append(command); } else { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/ErrorFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/ErrorFormat.java index 55745d92dc..3dc6add2d9 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/ErrorFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/ErrorFormat.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.util.formatting.component; import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; /** * Represents a fragment representing an error. @@ -31,7 +31,7 @@ public class ErrorFormat extends TextComponentProducer { * Create a new instance. */ private ErrorFormat() { - getBuilder().content("").color(TextColor.RED); + getBuilder().content("").color(NamedTextColor.RED); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/LabelFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/LabelFormat.java index 6761970357..f4fd07f69d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/LabelFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/LabelFormat.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.util.formatting.component; import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; /** * Represents a fragment representing a label. @@ -31,7 +31,7 @@ public class LabelFormat extends TextComponentProducer { * Create a new instance. */ private LabelFormat() { - getBuilder().content("").color(TextColor.YELLOW); + getBuilder().content("").color(NamedTextColor.YELLOW); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/MessageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/MessageBox.java index 98dbd84b6e..4336cb3b41 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/MessageBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/MessageBox.java @@ -23,6 +23,7 @@ import com.google.common.collect.Sets; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.util.formatting.text.format.TextDecoration; @@ -42,7 +43,7 @@ public class MessageBox extends TextComponentProducer { * Create a new box. */ public MessageBox(String title, TextComponentProducer contents) { - this(title, contents, TextColor.YELLOW); + this(title, contents, NamedTextColor.YELLOW); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/PaginationBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/PaginationBox.java index ab450d6a75..f55c79775c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/PaginationBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/PaginationBox.java @@ -24,7 +24,7 @@ import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; 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.formatting.text.format.NamedTextColor; import java.util.List; import java.util.stream.Collectors; @@ -99,21 +99,21 @@ public Component create(int page) throws InvalidComponentException { return super.create(); } getContents().newline(); - TextComponent pageNumberComponent = TextComponent.of("Page ", TextColor.YELLOW) - .append(TextComponent.of(String.valueOf(page), TextColor.GOLD)) + TextComponent pageNumberComponent = TextComponent.of("Page ", NamedTextColor.YELLOW) + .append(TextComponent.of(String.valueOf(page), NamedTextColor.GOLD)) .append(TextComponent.of(" of ")) - .append(TextComponent.of(String.valueOf(pageCount), TextColor.GOLD)); + .append(TextComponent.of(String.valueOf(pageCount), NamedTextColor.GOLD)); if (pageCommand != null) { TextComponentProducer navProducer = new TextComponentProducer(); if (page > 1) { - TextComponent prevComponent = TextComponent.of("<<< ", TextColor.GOLD) + TextComponent prevComponent = TextComponent.of("<<< ", NamedTextColor.GOLD) .clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, pageCommand.replace("%page%", String.valueOf(page - 1)))) .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to navigate"))); navProducer.append(prevComponent); } navProducer.append(pageNumberComponent); if (page < pageCount) { - TextComponent nextComponent = TextComponent.of(" >>>", TextColor.GOLD) + TextComponent nextComponent = TextComponent.of(" >>>", NamedTextColor.GOLD) .clickEvent(ClickEvent.of(ClickEvent.Action.RUN_COMMAND, pageCommand.replace("%page%", String.valueOf(page + 1)))) .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to navigate"))); navProducer.append(nextComponent); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SideEffectBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SideEffectBox.java index 569d5cf303..b81ff26d97 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SideEffectBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SideEffectBox.java @@ -29,7 +29,7 @@ import com.sk89q.worldedit.util.formatting.text.TranslatableComponent; 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.formatting.text.format.NamedTextColor; import java.util.Comparator; import java.util.List; @@ -70,11 +70,11 @@ public Component getComponent(int number) { SideEffect.State state = this.sideEffectSet.getState(effect); TextComponent.Builder builder = TextComponent.builder(); - builder = builder.append(TranslatableComponent.of(effect.getDisplayName(), TextColor.YELLOW) + builder = builder.append(TranslatableComponent.of(effect.getDisplayName(), NamedTextColor.YELLOW) .hoverEvent(HoverEvent.of(HoverEvent.Action.SHOW_TEXT, TranslatableComponent.of(effect.getDescription())))); for (SideEffect.State uiState : SHOWN_VALUES) { builder = builder.append(TextComponent.space()); - builder = builder.append(TranslatableComponent.of(uiState.getDisplayName(), uiState == state ? TextColor.WHITE : TextColor.GRAY) + builder = builder.append(TranslatableComponent.of(uiState.getDisplayName(), uiState == state ? NamedTextColor.WHITE : NamedTextColor.GRAY) .clickEvent(ClickEvent.runCommand("//perf -h " + effect.name().toLowerCase(Locale.US) + " " + uiState.name().toLowerCase(Locale.US))) .hoverEvent(HoverEvent.showText(uiState == state ? TranslatableComponent.of("worldedit.sideeffect.box.current") diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SubtleFormat.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SubtleFormat.java index d00c01a09f..aeac129e5c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SubtleFormat.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SubtleFormat.java @@ -20,7 +20,7 @@ package com.sk89q.worldedit.util.formatting.component; import com.sk89q.worldedit.util.formatting.text.TextComponent; -import com.sk89q.worldedit.util.formatting.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.format.NamedTextColor; /** * Represents a subtle part of the message. @@ -31,7 +31,7 @@ public class SubtleFormat extends TextComponentProducer { * Create a new instance. */ private SubtleFormat() { - getBuilder().content("").color(TextColor.GRAY); + getBuilder().content("").color(NamedTextColor.GRAY); } /** diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java index 9a984c57dc..15a7b755b4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/translation/TranslationManager.java @@ -26,6 +26,7 @@ import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.renderer.TranslatableComponentRenderer; import com.sk89q.worldedit.util.io.ResourceLoader; +import net.kyori.adventure.translation.TranslationRegistry; import java.io.IOException; import java.io.InputStream; @@ -73,17 +74,7 @@ public static String makeTranslationKey(String type, String id) { return type + '.' + parts[0] + '.' + parts[1].replace('/', '.'); } - private final Map> translationMap = new ConcurrentHashMap<>(); - private final TranslatableComponentRenderer friendlyComponentRenderer = TranslatableComponentRenderer.from( - (locale, key) -> { - String translation = getTranslationMap(locale).get(key); - if (translation == null) { - // let it pass through (for e.g. MC messages) - return null; - } - return new MessageFormat(translation, locale); - } - ); + private final Map> translationMap = new ConcurrentHashMap<>(); private Locale defaultLocale = Locale.ENGLISH; private final ResourceLoader resourceLoader; @@ -99,27 +90,27 @@ public void setDefaultLocale(Locale defaultLocale) { this.defaultLocale = defaultLocale; } - private Map filterTranslations(Map translations) { + private Map filterTranslations(Locale locale, Map translations) { return translations.entrySet().stream() .filter(e -> !e.getValue().isEmpty()) .map(e -> Maps.immutableEntry(e.getKey(), e.getValue().replace("'", "''"))) - .collect(toMap(Map.Entry::getKey, Map.Entry::getValue)); + .collect(toMap(Map.Entry::getKey, e -> new MessageFormat(e.getValue(), locale))); } - private Map parseTranslationFile(InputStream inputStream) throws IOException { + private Map parseTranslationFile(Locale locale, InputStream inputStream) throws IOException { try (Reader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) { - return filterTranslations(gson.fromJson(reader, STRING_MAP_TYPE)); + return filterTranslations(locale, gson.fromJson(reader, STRING_MAP_TYPE)); } } - private Optional> loadTranslationFile(String filename) { - Map baseTranslations = new ConcurrentHashMap<>(); + private Optional> loadTranslationFile(Locale locale, String filename) { + Map baseTranslations = new ConcurrentHashMap<>(); try { URL resource = resourceLoader.getRootResource("lang/" + filename); if (resource != null) { try (InputStream stream = resource.openStream()) { - baseTranslations = parseTranslationFile(stream); + baseTranslations = parseTranslationFile(locale, stream); } } } catch (IOException e) { @@ -129,7 +120,7 @@ private Optional> loadTranslationFile(String filename) { Path localFile = resourceLoader.getLocalResource("lang/" + filename); if (Files.exists(localFile)) { try (InputStream stream = Files.newInputStream(localFile)) { - baseTranslations.putAll(parseTranslationFile(stream)); + baseTranslations.putAll(parseTranslationFile(locale, stream)); } catch (IOException e) { // Failed to parse custom language file. Worth printing. e.printStackTrace(); @@ -145,16 +136,16 @@ private boolean tryLoadTranslations(Locale locale) { } checkedLocales.add(locale); // Make a copy of the default language file - Map baseTranslations = new ConcurrentHashMap<>(); + Map baseTranslations = new ConcurrentHashMap<>(); if (!locale.equals(defaultLocale)) { baseTranslations.putAll(getTranslationMap(defaultLocale)); } - Optional> langData = Optional.empty(); + Optional> langData = Optional.empty(); if (!locale.getCountry().isEmpty()) { - langData = loadTranslationFile(locale.getLanguage() + "-" + locale.getCountry() + "/strings.json"); + langData = loadTranslationFile(locale, locale.getLanguage() + "-" + locale.getCountry() + "/strings.json"); } if (!langData.isPresent()) { - langData = loadTranslationFile(locale.getLanguage() + "/strings.json"); + langData = loadTranslationFile(locale, locale.getLanguage() + "/strings.json"); } if (langData.isPresent()) { baseTranslations.putAll(langData.get()); @@ -162,7 +153,7 @@ private boolean tryLoadTranslations(Locale locale) { return true; } if (locale.equals(defaultLocale)) { - translationMap.put(Locale.ENGLISH, loadTranslationFile("strings.json").orElseThrow( + translationMap.put(Locale.ENGLISH, loadTranslationFile(defaultLocale, "strings.json").orElseThrow( () -> new RuntimeException("Failed to load WorldEdit strings!") )); return true; @@ -170,21 +161,36 @@ private boolean tryLoadTranslations(Locale locale) { return false; } - private Map getTranslationMap(Locale locale) { - Map translations = translationMap.get(locale); - if (translations == null) { - if (tryLoadTranslations(locale)) { - return getTranslationMap(locale); - } - if (!locale.equals(defaultLocale)) { - translations = getTranslationMap(defaultLocale); - } + private Map getTranslationMap(Locale locale) { + Map existing = translationMap.get(locale); + if (existing != null) { + return existing; + } + + if (tryLoadTranslations(locale)) { + return translationMap.get(locale); } - return translations; + if (locale.equals(defaultLocale)) { + throw new IllegalStateException("Missing default locale translations: " + defaultLocale); + } + + return translationMap.get(defaultLocale); + } + + private void initializeTranslations(Locale locale) { + if (translationMap.get(locale) == null) { + Map map = getTranslationMap(locale); + translationMap.put(locale, map); + TranslationRegistry.get().registerAll( + locale, + map + ); + } } public Component convertText(Component component, Locale locale) { - return friendlyComponentRenderer.render(component, locale); + initializeTranslations(locale); + return TranslatableComponentRenderer.get().render(component, locale); } } diff --git a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricPlayer.java b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricPlayer.java index 646164c7f7..80b49d46f0 100644 --- a/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricPlayer.java +++ b/worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricPlayer.java @@ -166,7 +166,7 @@ public void printError(String msg) { @Override public void print(Component component) { - this.player.sendMessage(Text.Serializer.fromJson(GsonComponentSerializer.INSTANCE.serialize(WorldEditText.format(component, getLocale()))), false); + this.player.sendMessage(Text.Serializer.fromJson(GsonComponentSerializer.gson().serialize(WorldEditText.format(component, getLocale()))), false); } private void sendColorized(String msg, Formatting formatting) { diff --git a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java index 7cb95e3cd8..4edf700590 100644 --- a/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java +++ b/worldedit-forge/src/main/java/com/sk89q/worldedit/forge/ForgePlayer.java @@ -165,7 +165,7 @@ public void printError(String msg) { @Override public void print(Component component) { - sendMessage(ITextComponent.Serializer.func_240643_a_(GsonComponentSerializer.INSTANCE.serialize(WorldEditText.format(component, getLocale())))); + sendMessage(ITextComponent.Serializer.func_240643_a_(GsonComponentSerializer.gson().serialize(WorldEditText.format(component, getLocale())))); } private void sendColorized(String msg, TextFormatting formatting) { diff --git a/worldedit-libs/bukkit/build.gradle.kts b/worldedit-libs/bukkit/build.gradle.kts index a9d1c255e1..8c4ffa5f99 100644 --- a/worldedit-libs/bukkit/build.gradle.kts +++ b/worldedit-libs/bukkit/build.gradle.kts @@ -9,5 +9,5 @@ repositories { } dependencies { - "shade"("net.kyori:text-adapter-bukkit:${Versions.TEXT_EXTRAS}") + "shade"("net.kyori:adventure-platform-bukkit:${Versions.ADVENTURE_EXTRAS}") } diff --git a/worldedit-libs/core/build.gradle.kts b/worldedit-libs/core/build.gradle.kts index d669216d6d..d938ccb1f2 100644 --- a/worldedit-libs/core/build.gradle.kts +++ b/worldedit-libs/core/build.gradle.kts @@ -1,10 +1,10 @@ applyLibrariesConfiguration() dependencies { - "shade"("net.kyori:text-api:${Versions.TEXT}") - "shade"("net.kyori:text-serializer-gson:${Versions.TEXT}") - "shade"("net.kyori:text-serializer-legacy:${Versions.TEXT}") - "shade"("net.kyori:text-serializer-plain:${Versions.TEXT}") + "shade"("net.kyori:adventure-api:${Versions.ADVENTURE}") + "shade"("net.kyori:adventure-text-serializer-gson:${Versions.ADVENTURE}") + "shade"("net.kyori:adventure-text-serializer-legacy:${Versions.ADVENTURE}") + "shade"("net.kyori:adventure-text-serializer-plain:${Versions.ADVENTURE}") "shade"("com.sk89q:jchronic:0.2.4a") { exclude(group = "junit", module = "junit") } diff --git a/worldedit-libs/sponge/build.gradle.kts b/worldedit-libs/sponge/build.gradle.kts index 47bd7e59c5..7f10cf0124 100644 --- a/worldedit-libs/sponge/build.gradle.kts +++ b/worldedit-libs/sponge/build.gradle.kts @@ -8,5 +8,4 @@ repositories { } } dependencies { - "shade"("net.kyori:text-adapter-spongeapi:${Versions.TEXT_EXTRAS}") } diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeCommandSender.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeCommandSender.java index 35ff77199f..d0d71b7f26 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeCommandSender.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeCommandSender.java @@ -24,9 +24,7 @@ import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.session.SessionKey; 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.adapter.spongeapi.TextAdapter; import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.text.Text; @@ -96,7 +94,8 @@ public void printError(String msg) { @Override public void print(Component component) { - TextAdapter.sendMessage(sender, WorldEditText.format(component, getLocale())); + /// TODO sponge 8 this is native + // TextAdapter.sendMessage(sender, WorldEditText.format(component, getLocale())); } @SuppressWarnings("deprecation") diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java index 90ba89bf6d..8043ec8467 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongePlayer.java @@ -31,9 +31,7 @@ import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; 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.adapter.spongeapi.TextAdapter; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; @@ -155,7 +153,8 @@ public void printError(String msg) { @Override public void print(Component component) { - TextAdapter.sendMessage(player, WorldEditText.format(component, getLocale())); + // TODO sponge 8 this is native + // TextAdapter.sendMessage(player, WorldEditText.format(component, getLocale())); } private void sendColorized(String msg, TextColor formatting) { diff --git a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeTextAdapter.java b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeTextAdapter.java index 7b8a127e4f..079234a275 100644 --- a/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeTextAdapter.java +++ b/worldedit-sponge/src/main/java/com/sk89q/worldedit/sponge/SpongeTextAdapter.java @@ -29,9 +29,10 @@ public class SpongeTextAdapter { + // TODO this should become native in sponge 8? public static Text convert(Component component, Locale locale) { component = WorldEditText.format(component, locale); - return TextSerializers.JSON.deserialize(GsonComponentSerializer.INSTANCE.serialize(component)); + return TextSerializers.JSON.deserialize(GsonComponentSerializer.gson().serialize(component)); } private SpongeTextAdapter() {