From 3e4004ad9e3376c4a30ab7d53a29eb4a4228cb54 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Sun, 14 Apr 2019 19:33:44 +1000 Subject: [PATCH 01/13] Start work on improving the formatting system. May switch to Kashike's as Bukkit is shit --- .../worldedit/bukkit/BukkitCommandSender.java | 7 ++ .../sk89q/worldedit/bukkit/BukkitPlayer.java | 7 ++ .../worldedit/extension/platform/Actor.java | 8 ++ .../extension/platform/PlayerProxy.java | 6 ++ .../util/formatting/ColorCodeBuilder.java | 3 + .../worldedit/util/formatting/Fragment.java | 31 +++++++- .../worldedit/util/formatting/Style.java | 4 +- .../worldedit/util/formatting/StyleSet.java | 75 ++++++++++++++++++- .../util/formatting/StyledFragment.java | 31 +------- .../util/formatting/component/Error.java | 37 +++++++++ 10 files changed, 173 insertions(+), 36 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java 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 55929af02..7f48b193d 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 @@ -26,6 +26,7 @@ import com.sk89q.worldedit.extension.platform.Actor; 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.Fragment; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -91,6 +92,12 @@ public class BukkitCommandSender implements Actor { } } + @Override + public void print(Fragment fragment) { + // TODO Bukkit is bad and the API is somewhat lacking + printRaw(fragment.toString()); + } + @Override public boolean canDestroyBedrock() { return true; 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 d814cc7ba..8ef240f2c 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 @@ -31,6 +31,7 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; +import com.sk89q.worldedit.util.formatting.Fragment; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; @@ -125,6 +126,12 @@ public class BukkitPlayer extends AbstractPlayerActor { } } + @Override + public void print(Fragment fragment) { + // TODO Bukkit is bad and the API is somewhat lacking + printRaw(fragment.toString()); + } + @Override public void setPosition(Vector3 pos, float pitch, float yaw) { player.teleport(new Location(player.getWorld(), pos.getX(), pos.getY(), 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 cf64b5974..c5fb1b6b1 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 @@ -23,6 +23,7 @@ import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.session.SessionOwner; import com.sk89q.worldedit.util.Identifiable; import com.sk89q.worldedit.util.auth.Subject; +import com.sk89q.worldedit.util.formatting.Fragment; import java.io.File; @@ -75,6 +76,13 @@ public interface Actor extends Identifiable, SessionOwner, Subject { */ void printError(String msg); + /** + * Print a {@link Fragment}. + * + * @param fragment The fragment to print + */ + void print(Fragment fragment); + /** * Returns true if the actor can destroy bedrock. * diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java index 48173abbc..54700aeea 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java @@ -31,6 +31,7 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.util.formatting.Fragment; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.gamemode.GameMode; @@ -132,6 +133,11 @@ class PlayerProxy extends AbstractPlayerActor { basePlayer.printError(msg); } + @Override + public void print(Fragment fragment) { + basePlayer.print(fragment); + } + @Override public String[] getGroups() { return permActor.getGroups(); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java index dbaa904ce..14e8ddbca 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java @@ -90,6 +90,9 @@ public class ColorCodeBuilder { if (style.isStrikethrough()) { builder.append(Style.STRIKETHROUGH); } + if (style.isObfuscated()) { + builder.append(Style.OBFUSCATED); + } return builder.toString(); } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Fragment.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Fragment.java index 3d1add7f4..e49d7c678 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Fragment.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Fragment.java @@ -19,16 +19,45 @@ package com.sk89q.worldedit.util.formatting; +import java.util.ArrayList; +import java.util.List; + /** * A fragment of text. */ public class Fragment { private final StringBuilder builder = new StringBuilder(); - + private final List children = new ArrayList<>(); + private Fragment lastText; + Fragment() { } + public List getChildren() { + return children; + } + + protected Fragment lastText() { + Fragment text; + if (!children.isEmpty()) { + text = children.get(children.size() - 1); + if (text == lastText) { + return text; + } + } + + text = new Fragment(); + this.lastText = text; + children.add(text); + return text; + } + + public Fragment append(Fragment fragment) { + children.add(fragment); + return this; + } + public Fragment append(String str) { builder.append(Style.stripColor(str)); return this; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Style.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Style.java index d6c70eeb8..d81774009 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Style.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Style.java @@ -29,8 +29,6 @@ import java.util.regex.Pattern; /** * All supported color values for chat. - * - *

From Bukkit.

*/ public enum Style { /** @@ -100,7 +98,7 @@ public enum Style { /** * Represents magical characters that change around randomly */ - RANDOMIZE('k', 0x10, true), + OBFUSCATED('k', 0x10, true), /** * Makes the text bold. */ diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyleSet.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyleSet.java index 408dc1e43..2a1c0cf46 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyleSet.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyleSet.java @@ -19,6 +19,8 @@ package com.sk89q.worldedit.util.formatting; +import java.util.Objects; + /** * Represents set of styles, such as color, bold, etc. */ @@ -28,6 +30,8 @@ public class StyleSet { private Boolean italic; private Boolean underline; private Boolean strikethrough; + private Boolean obfuscated; + private String insertion; private Style color; /** @@ -55,6 +59,8 @@ public class StyleSet { underline = true; } else if (style == Style.STRIKETHROUGH) { strikethrough = true; + } else if (style == Style.OBFUSCATED) { + obfuscated = true; } } } @@ -167,6 +173,60 @@ public class StyleSet { this.strikethrough = strikethrough; } + /** + * Get whether this style set is obfuscated. + * + * @return true, false, or null if unset + */ + public Boolean getObfuscated() { + return obfuscated; + } + + /** + * Get whether this style set is obfuscated. + * + * @return true if there is obfuscation applied + */ + public boolean isObfuscated() { + return getObfuscated() != null && getObfuscated(); + } + + /** + * Set whether the text is obfuscated. + * + * @param obfuscated false, or null to unset + */ + public void setObfuscated(Boolean obfuscated) { + this.obfuscated = obfuscated; + } + + /** + * Get this style set's insertion, if present. + * + * @return the insertion, or null if unset + */ + public String getInsertion() { + return insertion; + } + + /** + * Get whether this style set has an insertion. + * + * @return true if there is an insertion + */ + public boolean hasInsertion() { + return insertion != null; + } + + /** + * Set the style set's insertion. + * + * @param insertion the insertion, or null to unset + */ + public void setInsertion(String insertion) { + this.insertion = insertion; + } + /** * Get the color of the text. * @@ -192,7 +252,8 @@ public class StyleSet { */ public boolean hasFormatting() { return getBold() != null || getItalic() != null - || getUnderline() != null || getStrikethrough() != null; + || getUnderline() != null || getStrikethrough() != null + || getObfuscated() != null || getInsertion() != null; } /** @@ -205,7 +266,9 @@ public class StyleSet { public boolean hasEqualFormatting(StyleSet other) { return getBold() == other.getBold() && getItalic() == other.getItalic() && getUnderline() == other.getUnderline() && - getStrikethrough() == other.getStrikethrough(); + getStrikethrough() == other.getStrikethrough() && + getObfuscated() == other.getObfuscated() && + Objects.equals(getInsertion(), other.getInsertion()); } /** @@ -229,6 +292,12 @@ public class StyleSet { if (style.getStrikethrough() != null) { newStyle.setStrikethrough(style.getStrikethrough()); } + if (style.getObfuscated() != null) { + newStyle.setObfuscated(style.getObfuscated()); + } + if (style.getInsertion() != null) { + newStyle.setInsertion(style.getInsertion()); + } if (style.getColor() != null) { newStyle.setColor(style.getColor()); } @@ -242,6 +311,8 @@ public class StyleSet { style.setItalic(getItalic()); style.setUnderline(getUnderline()); style.setStrikethrough(getStrikethrough()); + style.setObfuscated(getObfuscated()); + style.setInsertion(getInsertion()); style.setColor(getColor()); return style; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyledFragment.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyledFragment.java index 9ef38446b..ec0578d47 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyledFragment.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyledFragment.java @@ -19,18 +19,13 @@ package com.sk89q.worldedit.util.formatting; -import java.util.ArrayList; -import java.util.List; - /** * A fragment of text that can be styled. */ public class StyledFragment extends Fragment { - private final List children = new ArrayList<>(); private StyleSet style; - private Fragment lastText; - + public StyledFragment() { style = new StyleSet(); } @@ -51,36 +46,12 @@ public class StyledFragment extends Fragment { this.style = style; } - public List getChildren() { - return children; - } - - protected Fragment lastText() { - Fragment text; - if (!children.isEmpty()) { - text = children.get(children.size() - 1); - if (text == lastText) { - return text; - } - } - - text = new Fragment(); - this.lastText = text; - children.add(text); - return text; - } - public StyledFragment createFragment(Style... styles) { StyledFragment fragment = new StyledFragment(styles); append(fragment); return fragment; } - public StyledFragment append(StyledFragment fragment) { - children.add(fragment); - return this; - } - @Override public StyledFragment append(String str) { lastText().append(str); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java new file mode 100644 index 000000000..056c99c18 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java @@ -0,0 +1,37 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.util.formatting.component; + +import com.sk89q.worldedit.util.formatting.Style; +import com.sk89q.worldedit.util.formatting.StyledFragment; + +/** + * Represents a fragment representing an error. + */ +public class Error extends StyledFragment { + + /** + * Create a new instance. + */ + public Error() { + super(Style.RED); + } + +} From 55348346e92a6ec548a70aed29084396f461054c Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 19 Apr 2019 14:49:29 +1000 Subject: [PATCH 02/13] Shade in Kashike's lib --- build.gradle | 3 +++ config/checkstyle/import-control.xml | 1 + worldedit-bukkit/build.gradle | 1 + .../com/sk89q/worldedit/bukkit/BukkitCommandSender.java | 8 ++++---- .../java/com/sk89q/worldedit/bukkit/BukkitPlayer.java | 9 ++++----- worldedit-core/build.gradle | 3 ++- .../com/sk89q/worldedit/extension/platform/Actor.java | 8 ++++---- .../sk89q/worldedit/extension/platform/PlayerProxy.java | 6 +++--- worldedit-forge/build.gradle | 1 + .../main/java/com/sk89q/worldedit/forge/ForgePlayer.java | 6 ++++++ worldedit-sponge/build.gradle | 1 + .../com/sk89q/worldedit/sponge/SpongeCommandSender.java | 7 +++++++ .../java/com/sk89q/worldedit/sponge/SpongePlayer.java | 7 +++++++ 13 files changed, 44 insertions(+), 17 deletions(-) diff --git a/build.gradle b/build.gradle index 8bdb1a122..57570e2ff 100644 --- a/build.gradle +++ b/build.gradle @@ -142,6 +142,9 @@ subprojects { include(dependency('com.sk89q:jchronic:0.2.4a')) include(dependency('com.thoughtworks.paranamer:paranamer:2.6')) include(dependency('com.sk89q.lib:jlibnoise:1.0.0')) + relocate('net.kyori.text', 'com.sk89q.worldedit.util.formatting') { + include(dependency('net.kyori:text-api:2.0.0')) + } } exclude 'GradleStart**' exclude '.cache' diff --git a/config/checkstyle/import-control.xml b/config/checkstyle/import-control.xml index 28ccad1e4..b4a2f4808 100644 --- a/config/checkstyle/import-control.xml +++ b/config/checkstyle/import-control.xml @@ -16,6 +16,7 @@ + diff --git a/worldedit-bukkit/build.gradle b/worldedit-bukkit/build.gradle index 335b96c0a..af7f00114 100644 --- a/worldedit-bukkit/build.gradle +++ b/worldedit-bukkit/build.gradle @@ -15,6 +15,7 @@ dependencies { compile 'org.bstats:bstats-bukkit:1.4' compile "io.papermc:paperlib:1.0.1" compile 'org.slf4j:slf4j-jdk14:1.7.26' + compile 'net.kyori:text-adapter-bukkit:1.0.3' testCompile 'org.mockito:mockito-core:1.9.0-rc1' } 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 7f48b193d..21d08d726 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 @@ -26,7 +26,8 @@ import com.sk89q.worldedit.extension.platform.Actor; 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.Fragment; +import net.kyori.text.TextComponent; +import net.kyori.text.adapter.bukkit.TextAdapter; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -93,9 +94,8 @@ public class BukkitCommandSender implements Actor { } @Override - public void print(Fragment fragment) { - // TODO Bukkit is bad and the API is somewhat lacking - printRaw(fragment.toString()); + public void print(TextComponent component) { + TextAdapter.sendComponent(sender, component); } @Override 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 8ef240f2c..ca15daa91 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 @@ -31,14 +31,14 @@ import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; -import com.sk89q.worldedit.util.formatting.Fragment; 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.text.TextComponent; +import net.kyori.text.adapter.bukkit.TextAdapter; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -127,9 +127,8 @@ public class BukkitPlayer extends AbstractPlayerActor { } @Override - public void print(Fragment fragment) { - // TODO Bukkit is bad and the API is somewhat lacking - printRaw(fragment.toString()); + public void print(TextComponent component) { + TextAdapter.sendComponent(player, component); } @Override diff --git a/worldedit-core/build.gradle b/worldedit-core/build.gradle index f91186083..e47c27f02 100644 --- a/worldedit-core/build.gradle +++ b/worldedit-core/build.gradle @@ -13,6 +13,7 @@ dependencies { compile 'com.sk89q.lib:jlibnoise:1.0.0' compile 'com.googlecode.json-simple:json-simple:1.1.1' compile 'org.slf4j:slf4j-api:1.7.26' + compile 'net.kyori:text-api:2.0.0' //compile 'net.sf.trove4j:trove4j:3.0.3' testCompile 'org.mockito:mockito-core:1.9.0-rc1' } @@ -29,4 +30,4 @@ sourceSets { } } -build.dependsOn(shadowJar) +build.dependsOn(shadowJar { classifier = null }) 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 c5fb1b6b1..86bae5934 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 @@ -23,7 +23,7 @@ import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.session.SessionOwner; import com.sk89q.worldedit.util.Identifiable; import com.sk89q.worldedit.util.auth.Subject; -import com.sk89q.worldedit.util.formatting.Fragment; +import net.kyori.text.TextComponent; import java.io.File; @@ -77,11 +77,11 @@ public interface Actor extends Identifiable, SessionOwner, Subject { void printError(String msg); /** - * Print a {@link Fragment}. + * Print a {@link TextComponent}. * - * @param fragment The fragment to print + * @param component The component to print */ - void print(Fragment fragment); + void print(TextComponent component); /** * Returns true if the actor can destroy bedrock. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java index 54700aeea..5211e1380 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java @@ -31,10 +31,10 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.Fragment; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.gamemode.GameMode; +import net.kyori.text.TextComponent; import java.util.UUID; @@ -134,8 +134,8 @@ class PlayerProxy extends AbstractPlayerActor { } @Override - public void print(Fragment fragment) { - basePlayer.print(fragment); + public void print(TextComponent component) { + basePlayer.print(component); } @Override diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index 8fe3fb9af..41c798310 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -19,6 +19,7 @@ def forgeVersion = "25.0.76" dependencies { compile project(':worldedit-core') compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.11.2' + compile 'net.kyori:text-serializer-gson:2.0.0' minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}" 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 5b3b2ca84..57734f43a 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 @@ -34,6 +34,7 @@ import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; +import net.kyori.text.TextComponent; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; @@ -141,6 +142,11 @@ public class ForgePlayer extends AbstractPlayerActor { sendColorized(msg, TextFormatting.RED); } + @Override + public void print(TextComponent component) { + // TODO + } + private void sendColorized(String msg, TextFormatting formatting) { for (String part : msg.split("\n")) { TextComponentString component = new TextComponentString(part); diff --git a/worldedit-sponge/build.gradle b/worldedit-sponge/build.gradle index 0ef1e5361..f65952c91 100644 --- a/worldedit-sponge/build.gradle +++ b/worldedit-sponge/build.gradle @@ -19,6 +19,7 @@ dependencies { compile project(':worldedit-core') compile 'org.spongepowered:spongeapi:7.1.0' compile 'org.bstats:bstats-sponge:1.4' + compile 'net.kyori:text-adapter-spongeapi:1.0.3' testCompile group: 'org.mockito', name: 'mockito-core', version:'1.9.0-rc1' } 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 bf1ceb7bd..fe5c626a3 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 @@ -26,6 +26,8 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.auth.AuthorizationException; +import net.kyori.text.TextComponent; +import net.kyori.text.adapter.spongeapi.TextAdapter; import org.spongepowered.api.command.CommandSource; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.text.Text; @@ -89,6 +91,11 @@ public class SpongeCommandSender implements Actor { sendColorized(msg, TextColors.RED); } + @Override + public void print(TextComponent component) { + TextAdapter.sendComponent(sender, component); + } + private void sendColorized(String msg, TextColor formatting) { for (String part : msg.split("\n")) { sender.sendMessage(Text.of(formatting, TextSerializers.LEGACY_FORMATTING_CODE.deserialize(part))); 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 3793ffb87..10b1f47e8 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 @@ -36,6 +36,8 @@ import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemTypes; +import net.kyori.text.TextComponent; +import net.kyori.text.adapter.spongeapi.TextAdapter; import org.spongepowered.api.Sponge; import org.spongepowered.api.data.type.HandTypes; import org.spongepowered.api.entity.living.player.Player; @@ -149,6 +151,11 @@ public class SpongePlayer extends AbstractPlayerActor { sendColorized(msg, TextColors.RED); } + @Override + public void print(TextComponent component) { + TextAdapter.sendComponent(player, component); + } + private void sendColorized(String msg, TextColor formatting) { for (String part : msg.split("\n")) { this.player.sendMessage(Text.of(formatting, TextSerializers.FORMATTING_CODE.deserialize(part))); From d56cd962829b2a323ed05aad09bf145202d8403a Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 19 Apr 2019 16:38:33 +1000 Subject: [PATCH 03/13] Fixed builds --- build.gradle | 2 +- worldedit-core/build.gradle | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 57570e2ff..f31f5b6a8 100644 --- a/build.gradle +++ b/build.gradle @@ -142,7 +142,7 @@ subprojects { include(dependency('com.sk89q:jchronic:0.2.4a')) include(dependency('com.thoughtworks.paranamer:paranamer:2.6')) include(dependency('com.sk89q.lib:jlibnoise:1.0.0')) - relocate('net.kyori.text', 'com.sk89q.worldedit.util.formatting') { + relocate('net.kyori.text', 'com.sk89q.worldedit.util.formatting.text') { include(dependency('net.kyori:text-api:2.0.0')) } } diff --git a/worldedit-core/build.gradle b/worldedit-core/build.gradle index e47c27f02..a83565dfc 100644 --- a/worldedit-core/build.gradle +++ b/worldedit-core/build.gradle @@ -1,3 +1,5 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + apply plugin: 'eclipse' apply plugin: 'idea' @@ -30,4 +32,7 @@ sourceSets { } } -build.dependsOn(shadowJar { classifier = null }) +task jar(type: ShadowJar, overwrite: true) { + from sourceSets.main.output + configurations = [project.configurations.runtime] +} \ No newline at end of file From 5b1573a24ebff8d1e11ba3255336fdf4ba8af1db Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 19 Apr 2019 23:06:00 +1000 Subject: [PATCH 04/13] Replace the message system --- build.gradle | 8 +- worldedit-bukkit/build.gradle | 1 + worldedit-core/build.gradle | 2 + .../worldedit/command/SelectionCommands.java | 12 +- .../worldedit/command/UtilityCommands.java | 23 +- .../extension/platform/CommandManager.java | 3 +- .../util/formatting/ColorCodeBuilder.java | 274 --------------- .../worldedit/util/formatting/Fragment.java | 121 ------- .../worldedit/util/formatting/Style.java | 274 --------------- .../worldedit/util/formatting/StyleSet.java | 320 ------------------ .../util/formatting/StyledFragment.java | 121 ------- .../util/formatting/component/Code.java | 10 +- .../formatting/component/CommandListBox.java | 10 +- .../formatting/component/CommandUsageBox.java | 22 +- .../util/formatting/component/Error.java | 10 +- .../util/formatting/component/Label.java | 10 +- .../util/formatting/component/MessageBox.java | 29 +- .../util/formatting/component/Subtle.java | 10 +- worldedit-forge/build.gradle | 1 + worldedit-sponge/build.gradle | 1 + 20 files changed, 82 insertions(+), 1180 deletions(-) delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Fragment.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Style.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyleSet.java delete mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyledFragment.java diff --git a/build.gradle b/build.gradle index f31f5b6a8..090626cc5 100644 --- a/build.gradle +++ b/build.gradle @@ -142,9 +142,11 @@ subprojects { include(dependency('com.sk89q:jchronic:0.2.4a')) include(dependency('com.thoughtworks.paranamer:paranamer:2.6')) include(dependency('com.sk89q.lib:jlibnoise:1.0.0')) - relocate('net.kyori.text', 'com.sk89q.worldedit.util.formatting.text') { - include(dependency('net.kyori:text-api:2.0.0')) - } + include(dependency('net.kyori:text-api:2.0.0')) + include(dependency("net.kyori:text-serializer-gson:2.0.0")) + include(dependency("net.kyori:text-serializer-legacy:2.0.0")) + + relocate('net.kyori.text', 'com.sk89q.worldedit.util.formatting.text') } exclude 'GradleStart**' exclude '.cache' diff --git a/worldedit-bukkit/build.gradle b/worldedit-bukkit/build.gradle index af7f00114..67ca5e43b 100644 --- a/worldedit-bukkit/build.gradle +++ b/worldedit-bukkit/build.gradle @@ -43,6 +43,7 @@ shadowJar { include(dependency(':worldedit-core')) include(dependency('org.slf4j:slf4j-api')) include(dependency("org.slf4j:slf4j-jdk14")) + include(dependency("net.kyori:text-adapter-bukkit:1.0.3")) relocate ("org.bstats", "com.sk89q.worldedit.bukkit.bstats") { include(dependency("org.bstats:bstats-bukkit:1.4")) } diff --git a/worldedit-core/build.gradle b/worldedit-core/build.gradle index a83565dfc..9d8176407 100644 --- a/worldedit-core/build.gradle +++ b/worldedit-core/build.gradle @@ -16,6 +16,8 @@ dependencies { compile 'com.googlecode.json-simple:json-simple:1.1.1' compile 'org.slf4j:slf4j-api:1.7.26' compile 'net.kyori:text-api:2.0.0' + compile 'net.kyori:text-serializer-gson:2.0.0' + compile 'net.kyori:text-serializer-legacy:2.0.0' //compile 'net.sf.trove4j:trove4j:3.0.3' testCompile 'org.mockito:mockito-core:1.9.0-rc1' } 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 24e92070b..ee93e847c 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 @@ -55,15 +55,14 @@ import com.sk89q.worldedit.regions.selector.SphereRegionSelector; import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.Location; -import com.sk89q.worldedit.util.formatting.ColorCodeBuilder; -import com.sk89q.worldedit.util.formatting.Style; -import com.sk89q.worldedit.util.formatting.StyledFragment; import com.sk89q.worldedit.util.formatting.component.CommandListBox; +import com.sk89q.worldedit.util.formatting.component.Subtle; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.storage.ChunkStore; +import net.kyori.text.Component; import java.util.ArrayList; import java.util.List; @@ -754,9 +753,8 @@ public class SelectionCommands { limit.ifPresent(integer -> player.print(integer + " points maximum.")); } else { CommandListBox box = new CommandListBox("Selection modes"); - StyledFragment contents = box.getContents(); - StyledFragment tip = contents.createFragment(Style.RED); - tip.append("Select one of the modes below:").newLine(); + Component contents = box.getContents(); + contents.append(new Subtle("Select one of the modes below:").append(Component.newline())); box.appendCommand("cuboid", "Select two corners of a cuboid"); box.appendCommand("extend", "Fast cuboid selection mode"); @@ -766,7 +764,7 @@ public class SelectionCommands { box.appendCommand("cyl", "Select a cylinder"); box.appendCommand("convex", "Select a convex polyhedral"); - player.printRaw(ColorCodeBuilder.asColorCodes(box)); + player.print(box); return; } 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 8768be6c8..e8ee6275f 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 @@ -58,15 +58,16 @@ import com.sk89q.worldedit.util.command.CommandMapping; import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.util.command.PrimaryAliasComparator; import com.sk89q.worldedit.util.command.binding.Text; -import com.sk89q.worldedit.util.formatting.ColorCodeBuilder; -import com.sk89q.worldedit.util.formatting.Style; -import com.sk89q.worldedit.util.formatting.StyledFragment; import com.sk89q.worldedit.util.formatting.component.Code; import com.sk89q.worldedit.util.formatting.component.CommandListBox; import com.sk89q.worldedit.util.formatting.component.CommandUsageBox; +import com.sk89q.worldedit.util.formatting.component.Error; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; +import net.kyori.text.Component; +import net.kyori.text.TextComponent; +import net.kyori.text.format.TextColor; import java.util.ArrayList; import java.util.List; @@ -669,17 +670,17 @@ public class UtilityCommands { // Box CommandListBox box = new CommandListBox(String.format("Help: page %d/%d ", page + 1, pageTotal)); - StyledFragment contents = box.getContents(); - StyledFragment tip = contents.createFragment(Style.GRAY); + Component contents = box.getContents(); + Component tip = contents.append(TextComponent.of("", TextColor.GRAY)); if (offset >= aliases.size()) { - tip.createFragment(Style.RED).append(String.format("There is no page %d (total number of pages is %d).", page + 1, pageTotal)).newLine(); + tip.append(new Error(String.format("There is no page %d (total number of pages is %d).", page + 1, pageTotal))).append(Component.newline()); } else { List list = aliases.subList(offset, Math.min(offset + perPage, aliases.size())); - tip.append("Type "); - tip.append(new Code().append("//help ").append(" []")); - tip.append(" for more information.").newLine(); + tip.append(TextComponent.of("Type ")); + tip.append(new Code("//help ").append(TextComponent.of(" []"))); + tip.append(TextComponent.of(" for more information.")).append(Component.newline()); // Add each command for (CommandMapping mapping : list) { @@ -696,10 +697,10 @@ public class UtilityCommands { } } - actor.printRaw(ColorCodeBuilder.asColorCodes(box)); + actor.print(box); } else { CommandUsageBox box = new CommandUsageBox(callable, Joiner.on(" ").join(visited)); - actor.printRaw(ColorCodeBuilder.asColorCodes(box)); + actor.print(box); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java index a0be07b65..11257efdf 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java @@ -77,7 +77,6 @@ import com.sk89q.worldedit.util.command.parametric.ExceptionConverter; import com.sk89q.worldedit.util.command.parametric.LegacyCommandsHandler; import com.sk89q.worldedit.util.command.parametric.ParametricBuilder; import com.sk89q.worldedit.util.eventbus.Subscribe; -import com.sk89q.worldedit.util.formatting.ColorCodeBuilder; import com.sk89q.worldedit.util.formatting.component.CommandUsageBox; import com.sk89q.worldedit.util.logging.DynamicStreamHandler; import com.sk89q.worldedit.util.logging.LogFormat; @@ -300,7 +299,7 @@ public final class CommandManager { actor.printError("You are not permitted to do that. Are you in the right mode?"); } catch (InvalidUsageException e) { if (e.isFullHelpSuggested()) { - actor.printRaw(ColorCodeBuilder.asColorCodes(new CommandUsageBox(e.getCommand(), e.getCommandUsed("/", ""), locals))); + actor.print(new CommandUsageBox(e.getCommand(), e.getCommandUsed("/", ""), locals)); String message = e.getMessage(); if (message != null) { actor.printError(message); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java deleted file mode 100644 index 14e8ddbca..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/ColorCodeBuilder.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.util.formatting; - -import com.google.common.base.Joiner; - -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -public class ColorCodeBuilder { - - private static final ColorCodeBuilder instance = new ColorCodeBuilder(); - private static final Joiner newLineJoiner = Joiner.on("\n"); - public static final int GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH = 47; - - /** - * Convert a message into color-coded text. - * - * @param message the message - * @return a list of lines - */ - public String[] build(StyledFragment message) { - StringBuilder builder = new StringBuilder(); - buildFragment(builder, message, message.getStyle(), new StyleSet()); - return builder.toString().split("\r?\n"); - } - - /** - * Build a fragment. - * - * @param builder the string builder - * @param message the message - * @param parentStyle the parent style - * @param lastStyle the last style - * @return the last style used - */ - private StyleSet buildFragment(StringBuilder builder, StyledFragment message, StyleSet parentStyle, StyleSet lastStyle) { - for (Fragment node : message.getChildren()) { - if (node instanceof StyledFragment) { - StyledFragment fragment = (StyledFragment) node; - lastStyle = buildFragment( - builder, fragment, - parentStyle.extend(message.getStyle()), lastStyle); - } else { - StyleSet style = parentStyle.extend(message.getStyle()); - builder.append(getAdditive(style, lastStyle)); - builder.append(node); - lastStyle = style; - } - } - - return lastStyle; - } - - /** - * Get the formatting codes. - * - * @param style the style - * @return the color codes - */ - public static String getFormattingCode(StyleSet style) { - StringBuilder builder = new StringBuilder(); - if (style.isBold()) { - builder.append(Style.BOLD); - } - if (style.isItalic()) { - builder.append(Style.ITALIC); - } - if (style.isUnderline()) { - builder.append(Style.UNDERLINE); - } - if (style.isStrikethrough()) { - builder.append(Style.STRIKETHROUGH); - } - if (style.isObfuscated()) { - builder.append(Style.OBFUSCATED); - } - return builder.toString(); - } - - /** - * Get the formatting and color codes. - * - * @param style the style - * @return the color codes - */ - public static String getCode(StyleSet style) { - StringBuilder builder = new StringBuilder(); - builder.append(getFormattingCode(style)); - if (style.getColor() != null) { - builder.append(style.getColor()); - } - return builder.toString(); - } - - /** - * Get the additional color codes needed to set the given style when the current - * style is the other given one. - * - * @param resetTo the style to reset to - * @param resetFrom the style to reset from - * @return the color codes - */ - public static String getAdditive(StyleSet resetTo, StyleSet resetFrom) { - if (!resetFrom.hasFormatting() && resetTo.hasFormatting()) { - StringBuilder builder = new StringBuilder(); - builder.append(getFormattingCode(resetTo)); - if (resetFrom.getColor() != resetTo.getColor()) { - builder.append(resetTo.getColor()); - } - return builder.toString(); - } else if (!resetFrom.hasEqualFormatting(resetTo) || - (resetFrom.getColor() != null && resetTo.getColor() == null)) { - // Have to set reset code and add back all the formatting codes - return Style.RESET + getCode(resetTo); - } else { - if (resetFrom.getColor() != resetTo.getColor()) { - return String.valueOf(resetTo.getColor()); - } - } - - return ""; - } - - /** - * Word wrap the given text and maintain color codes throughout lines. - * - *

This is borrowed from Bukkit.

- * - * @param rawString the raw string - * @param lineLength the maximum line length - * @return a list of lines - */ - private String[] wordWrap(String rawString, int lineLength) { - // A null string is a single line - if (rawString == null) { - return new String[] {""}; - } - - // A string shorter than the lineWidth is a single line - if (rawString.length() <= lineLength && !rawString.contains("\n")) { - return new String[] {rawString}; - } - - char[] rawChars = (rawString + ' ').toCharArray(); // add a trailing space to trigger pagination - StringBuilder word = new StringBuilder(); - StringBuilder line = new StringBuilder(); - List lines = new LinkedList<>(); - int lineColorChars = 0; - - for (int i = 0; i < rawChars.length; i++) { - char c = rawChars[i]; - - // skip chat color modifiers - if (c == Style.COLOR_CHAR) { - word.append(Style.getByChar(rawChars[i + 1])); - lineColorChars += 2; - i++; // Eat the next character as we have already processed it - continue; - } - - if (c == ' ' || c == '\n') { - if (line.length() == 0 && word.length() > lineLength) { // special case: extremely long word begins a line - String wordStr = word.toString(); - String transformed; - if ((transformed = transform(wordStr)) != null) { - line.append(transformed); - } else { - lines.addAll(Arrays.asList(word.toString().split("(?<=\\G.{" + lineLength + "})"))); - } - } else if (line.length() + word.length() - lineColorChars == lineLength) { // Line exactly the correct length...newline - line.append(' '); - line.append(word); - lines.add(line.toString()); - line = new StringBuilder(); - lineColorChars = 0; - } else if (line.length() + 1 + word.length() - lineColorChars > lineLength) { // Line too long...break the line - String wordStr = word.toString(); - String transformed; - if (word.length() > lineLength && (transformed = transform(wordStr)) != null) { - if (line.length() + 1 + transformed.length() - lineColorChars > lineLength) { - lines.add(line.toString()); - line = new StringBuilder(transformed); - lineColorChars = 0; - } else { - if (line.length() > 0) { - line.append(' '); - } - line.append(transformed); - } - } else { - for (String partialWord : wordStr.split("(?<=\\G.{" + lineLength + "})")) { - lines.add(line.toString()); - line = new StringBuilder(partialWord); - } - lineColorChars = 0; - } - } else { - if (line.length() > 0) { - line.append(' '); - } - line.append(word); - } - word = new StringBuilder(); - - if (c == '\n') { // Newline forces the line to flush - lines.add(line.toString()); - line = new StringBuilder(); - } - } else { - word.append(c); - } - } - - if(line.length() > 0) { // Only add the last line if there is anything to add - lines.add(line.toString()); - } - - // Iterate over the wrapped lines, applying the last color from one line to the beginning of the next - if (lines.get(0).isEmpty() || lines.get(0).charAt(0) != Style.COLOR_CHAR) { - lines.set(0, Style.WHITE + lines.get(0)); - } - for (int i = 1; i < lines.size(); i++) { - final String pLine = lines.get(i-1); - final String subLine = lines.get(i); - - char color = pLine.charAt(pLine.lastIndexOf(Style.COLOR_CHAR) + 1); - if (subLine.isEmpty() || subLine.charAt(0) != Style.COLOR_CHAR) { - lines.set(i, Style.getByChar(color) + subLine); - } - } - - return lines.toArray(new String[lines.size()]); - } - - /** - * Callback for transforming a word, such as a URL. - * - * @param word the word - * @return the transformed value, or null to do nothing - */ - protected String transform(String word) { - return null; - } - - /** - * Convert the given styled fragment into color codes. - * - * @param fragment the fragment - * @return color codes - */ - public static String asColorCodes(StyledFragment fragment) { - return newLineJoiner.join(instance.build(fragment)); - } - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Fragment.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Fragment.java deleted file mode 100644 index e49d7c678..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Fragment.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.util.formatting; - -import java.util.ArrayList; -import java.util.List; - -/** - * A fragment of text. - */ -public class Fragment { - - private final StringBuilder builder = new StringBuilder(); - private final List children = new ArrayList<>(); - private Fragment lastText; - - Fragment() { - } - - public List getChildren() { - return children; - } - - protected Fragment lastText() { - Fragment text; - if (!children.isEmpty()) { - text = children.get(children.size() - 1); - if (text == lastText) { - return text; - } - } - - text = new Fragment(); - this.lastText = text; - children.add(text); - return text; - } - - public Fragment append(Fragment fragment) { - children.add(fragment); - return this; - } - - public Fragment append(String str) { - builder.append(Style.stripColor(str)); - return this; - } - - public Fragment append(Object obj) { - append(String.valueOf(obj)); - return this; - } - - public Fragment append(StringBuffer sb) { - append(String.valueOf(sb)); - return this; - } - - public Fragment append(CharSequence s) { - append(String.valueOf(s)); - return this; - } - - public Fragment append(boolean b) { - append(String.valueOf(b)); - return this; - } - - public Fragment append(char c) { - append(String.valueOf(c)); - return this; - } - - public Fragment append(int i) { - append(String.valueOf(i)); - return this; - } - - public Fragment append(long lng) { - append(String.valueOf(lng)); - return this; - } - - public Fragment append(float f) { - append(String.valueOf(f)); - return this; - } - - public Fragment append(double d) { - append(String.valueOf(d)); - return this; - } - - public Fragment newLine() { - append("\n"); - return this; - } - - @Override - public String toString() { - return builder.toString(); - } - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Style.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Style.java deleted file mode 100644 index d81774009..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/Style.java +++ /dev/null @@ -1,274 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.util.formatting; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import com.google.common.collect.Maps; - -import java.util.Map; -import java.util.regex.Pattern; - -/** - * All supported color values for chat. - */ -public enum Style { - /** - * Represents black - */ - BLACK('0', 0x00), - /** - * Represents dark blue - */ - BLUE_DARK('1', 0x1), - /** - * Represents dark green - */ - GREEN_DARK('2', 0x2), - /** - * Represents dark blue (aqua) - */ - CYAN_DARK('3', 0x3), - /** - * Represents dark red - */ - RED_DARK('4', 0x4), - /** - * Represents dark purple - */ - PURPLE_DARK('5', 0x5), - /** - * Represents gold - */ - YELLOW_DARK('6', 0x6), - /** - * Represents gray - */ - GRAY('7', 0x7), - /** - * Represents dark gray - */ - GRAY_DARK('8', 0x8), - /** - * Represents blue - */ - BLUE('9', 0x9), - /** - * Represents green - */ - GREEN('a', 0xA), - /** - * Represents aqua - */ - CYAN('b', 0xB), - /** - * Represents red - */ - RED('c', 0xC), - /** - * Represents light purple - */ - PURPLE('d', 0xD), - /** - * Represents yellow - */ - YELLOW('e', 0xE), - /** - * Represents white - */ - WHITE('f', 0xF), - /** - * Represents magical characters that change around randomly - */ - OBFUSCATED('k', 0x10, true), - /** - * Makes the text bold. - */ - BOLD('l', 0x11, true), - /** - * Makes a line appear through the text. - */ - STRIKETHROUGH('m', 0x12, true), - /** - * Makes the text appear underlined. - */ - UNDERLINE('n', 0x13, true), - /** - * Makes the text italic. - */ - ITALIC('o', 0x14, true), - /** - * Resets all previous chat colors or formats. - */ - RESET('r', 0x15); - - /** - * The special character which prefixes all chat color codes. Use this if you need to dynamically - * convert color codes from your custom format. - */ - public static final char COLOR_CHAR = '\u00A7'; - private static final Pattern STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + COLOR_CHAR + "[0-9A-FK-OR]"); - - private final int intCode; - private final char code; - private final boolean isFormat; - private final String toString; - private final static Map BY_ID = Maps.newHashMap(); - private final static Map BY_CHAR = Maps.newHashMap(); - - Style(char code, int intCode) { - this(code, intCode, false); - } - - Style(char code, int intCode, boolean isFormat) { - this.code = code; - this.intCode = intCode; - this.isFormat = isFormat; - this.toString = new String(new char[] {COLOR_CHAR, code}); - } - - /** - * Gets the char value associated with this color - * - * @return A char value of this color code - */ - public char getChar() { - return code; - } - - @Override - public String toString() { - return toString; - } - - /** - * Checks if this code is a format code as opposed to a color code. - * - * @return the if the code is a formatting code - */ - public boolean isFormat() { - return isFormat; - } - - /** - * Checks if this code is a color code as opposed to a format code. - * - * @return the if the code is a color - */ - public boolean isColor() { - return !isFormat && this != RESET; - } - - /** - * Gets the color represented by the specified color code - * - * @param code Code to check - * @return Associative Style with the given code, or null if it doesn't exist - */ - public static Style getByChar(char code) { - return BY_CHAR.get(code); - } - - /** - * Gets the color represented by the specified color code - * - * @param code Code to check - * @return Associative Style with the given code, or null if it doesn't exist - */ - public static Style getByChar(String code) { - checkNotNull(code); - checkArgument(!code.isEmpty(), "Code must have at least one character"); - - return BY_CHAR.get(code.charAt(0)); - } - - /** - * Strips the given message of all color codes - * - * @param input String to strip of color - * @return A copy of the input string, without any coloring - */ - public static String stripColor(final String input) { - if (input == null) { - return null; - } - - return STRIP_COLOR_PATTERN.matcher(input).replaceAll(""); - } - - /** - * Translates a string using an alternate color code character into a string that uses the internal - * ChatColor.COLOR_CODE color code character. The alternate color code character will only be replaced - * if it is immediately followed by 0-9, A-F, a-f, K-O, k-o, R or r. - * - * @param altColorChar The alternate color code character to replace. Ex: & - * @param textToTranslate Text containing the alternate color code character. - * @return Text containing the ChatColor.COLOR_CODE color code character. - */ - public static String translateAlternateColorCodes(char altColorChar, String textToTranslate) { - char[] b = textToTranslate.toCharArray(); - for (int i = 0; i < b.length - 1; i++) { - if (b[i] == altColorChar && "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b[i+1]) > -1) { - b[i] = Style.COLOR_CHAR; - b[i+1] = Character.toLowerCase(b[i+1]); - } - } - return new String(b); - } - - /** - * Gets the ChatColors used at the end of the given input string. - * - * @param input Input string to retrieve the colors from. - * @return Any remaining ChatColors to pass onto the next line. - */ - public static String getLastColors(String input) { - String result = ""; - int length = input.length(); - - // Search backwards from the end as it is faster - for (int index = length - 1; index > -1; index--) { - char section = input.charAt(index); - if (section == COLOR_CHAR && index < length - 1) { - char c = input.charAt(index + 1); - Style color = getByChar(c); - - if (color != null) { - result = color + result; - - // Once we find a color or reset we can stop searching - if (color.isColor() || color == RESET) { - break; - } - } - } - } - - return result; - } - - static { - for (Style color : values()) { - BY_ID.put(color.intCode, color); - BY_CHAR.put(color.code, color); - } - } -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyleSet.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyleSet.java deleted file mode 100644 index 2a1c0cf46..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyleSet.java +++ /dev/null @@ -1,320 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.util.formatting; - -import java.util.Objects; - -/** - * Represents set of styles, such as color, bold, etc. - */ -public class StyleSet { - - private Boolean bold; - private Boolean italic; - private Boolean underline; - private Boolean strikethrough; - private Boolean obfuscated; - private String insertion; - private Style color; - - /** - * Create a new style set with no properties set. - */ - public StyleSet() { - } - - /** - * Create a new style set with the given styles. - * - *

{@link Style#RESET} will be ignored if provided.

- * - * @param styles a list of styles - */ - public StyleSet(Style... styles) { - for (Style style : styles) { - if (style.isColor()) { - color = style; - } else if (style == Style.BOLD) { - bold = true; - } else if (style == Style.ITALIC) { - italic = true; - } else if (style == Style.UNDERLINE) { - underline = true; - } else if (style == Style.STRIKETHROUGH) { - strikethrough = true; - } else if (style == Style.OBFUSCATED) { - obfuscated = true; - } - } - } - - /** - * Get whether this style set is bold. - * - * @return true, false, or null if unset - */ - public Boolean getBold() { - return bold; - } - - /** - * Get whether the text is bold. - * - * @return true if bold - */ - public boolean isBold() { - return getBold() != null && getBold(); - } - - /** - * Set whether the text is bold. - * - * @param bold true, false, or null to unset - */ - public void setBold(Boolean bold) { - this.bold = bold; - } - - /** - * Get whether this style set is italicized. - * - * @return true, false, or null if unset - */ - public Boolean getItalic() { - return italic; - } - - /** - * Get whether the text is italicized. - * - * @return true if italicized - */ - public boolean isItalic() { - return getItalic() != null && getItalic(); - } - - /** - * Set whether the text is italicized. - * - * @param italic false, or null to unset - */ - public void setItalic(Boolean italic) { - this.italic = italic; - } - - /** - * Get whether this style set is underlined. - * - * @return true, false, or null if unset - */ - public Boolean getUnderline() { - return underline; - } - - /** - * Get whether the text is underlined. - * - * @return true if underlined - */ - public boolean isUnderline() { - return getUnderline() != null && getUnderline(); - } - - /** - * Set whether the text is underline. - * - * @param underline false, or null to unset - */ - public void setUnderline(Boolean underline) { - this.underline = underline; - } - - /** - * Get whether this style set is stricken through. - * - * @return true, false, or null if unset - */ - public Boolean getStrikethrough() { - return strikethrough; - } - - /** - * Get whether the text is stricken through. - * - * @return true if there is strikethrough applied - */ - public boolean isStrikethrough() { - return getStrikethrough() != null && getStrikethrough(); - } - - /** - * Set whether the text is stricken through. - * - * @param strikethrough false, or null to unset - */ - public void setStrikethrough(Boolean strikethrough) { - this.strikethrough = strikethrough; - } - - /** - * Get whether this style set is obfuscated. - * - * @return true, false, or null if unset - */ - public Boolean getObfuscated() { - return obfuscated; - } - - /** - * Get whether this style set is obfuscated. - * - * @return true if there is obfuscation applied - */ - public boolean isObfuscated() { - return getObfuscated() != null && getObfuscated(); - } - - /** - * Set whether the text is obfuscated. - * - * @param obfuscated false, or null to unset - */ - public void setObfuscated(Boolean obfuscated) { - this.obfuscated = obfuscated; - } - - /** - * Get this style set's insertion, if present. - * - * @return the insertion, or null if unset - */ - public String getInsertion() { - return insertion; - } - - /** - * Get whether this style set has an insertion. - * - * @return true if there is an insertion - */ - public boolean hasInsertion() { - return insertion != null; - } - - /** - * Set the style set's insertion. - * - * @param insertion the insertion, or null to unset - */ - public void setInsertion(String insertion) { - this.insertion = insertion; - } - - /** - * Get the color of the text. - * - * @return true, false, or null if unset - */ - public Style getColor() { - return color; - } - - /** - * Set the color of the text. - * - * @param color the color - */ - public void setColor(Style color) { - this.color = color; - } - - /** - * Return whether text formatting (bold, italics, underline, strikethrough) is set. - * - * @return true if formatting is set - */ - public boolean hasFormatting() { - return getBold() != null || getItalic() != null - || getUnderline() != null || getStrikethrough() != null - || getObfuscated() != null || getInsertion() != null; - } - - /** - * Return where the text formatting of the given style set is different from - * that assigned to this one. - * - * @param other the other style set - * @return true if there is a difference - */ - public boolean hasEqualFormatting(StyleSet other) { - return getBold() == other.getBold() && getItalic() == other.getItalic() - && getUnderline() == other.getUnderline() && - getStrikethrough() == other.getStrikethrough() && - getObfuscated() == other.getObfuscated() && - Objects.equals(getInsertion(), other.getInsertion()); - } - - /** - * Create a new instance with styles inherited from this one but with new styles - * from the given style set. - * - * @param style the style set - * @return a new style set instance - */ - public StyleSet extend(StyleSet style) { - StyleSet newStyle = clone(); - if (style.getBold() != null) { - newStyle.setBold(style.getBold()); - } - if (style.getItalic() != null) { - newStyle.setItalic(style.getItalic()); - } - if (style.getUnderline() != null) { - newStyle.setUnderline(style.getUnderline()); - } - if (style.getStrikethrough() != null) { - newStyle.setStrikethrough(style.getStrikethrough()); - } - if (style.getObfuscated() != null) { - newStyle.setObfuscated(style.getObfuscated()); - } - if (style.getInsertion() != null) { - newStyle.setInsertion(style.getInsertion()); - } - if (style.getColor() != null) { - newStyle.setColor(style.getColor()); - } - return newStyle; - } - - @Override - public StyleSet clone() { - StyleSet style = new StyleSet(); - style.setBold(getBold()); - style.setItalic(getItalic()); - style.setUnderline(getUnderline()); - style.setStrikethrough(getStrikethrough()); - style.setObfuscated(getObfuscated()); - style.setInsertion(getInsertion()); - style.setColor(getColor()); - return style; - } - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyledFragment.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyledFragment.java deleted file mode 100644 index ec0578d47..000000000 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/StyledFragment.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * WorldEdit, a Minecraft world manipulation toolkit - * Copyright (C) sk89q - * Copyright (C) WorldEdit team and contributors - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License as published by the - * Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License - * for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see . - */ - -package com.sk89q.worldedit.util.formatting; - -/** - * A fragment of text that can be styled. - */ -public class StyledFragment extends Fragment { - - private StyleSet style; - - public StyledFragment() { - style = new StyleSet(); - } - - public StyledFragment(StyleSet style) { - this.style = style; - } - - public StyledFragment(Style... styles) { - this.style = new StyleSet(styles); - } - - public StyleSet getStyle() { - return style; - } - - public void setStyles(StyleSet style) { - this.style = style; - } - - public StyledFragment createFragment(Style... styles) { - StyledFragment fragment = new StyledFragment(styles); - append(fragment); - return fragment; - } - - @Override - public StyledFragment append(String str) { - lastText().append(str); - return this; - } - - @Override - public StyledFragment append(Object obj) { - append(String.valueOf(obj)); - return this; - } - - @Override - public StyledFragment append(StringBuffer sb) { - append(String.valueOf(sb)); - return this; - } - - @Override - public StyledFragment append(CharSequence s) { - append(String.valueOf(s)); - return this; - } - - @Override - public StyledFragment append(boolean b) { - append(String.valueOf(b)); - return this; - } - - @Override - public StyledFragment append(char c) { - append(String.valueOf(c)); - return this; - } - - @Override - public StyledFragment append(int i) { - append(String.valueOf(i)); - return this; - } - - @Override - public StyledFragment append(long lng) { - append(String.valueOf(lng)); - return this; - } - - @Override - public StyledFragment append(float f) { - append(String.valueOf(f)); - return this; - } - - @Override - public StyledFragment append(double d) { - append(String.valueOf(d)); - return this; - } - - @Override - public StyledFragment newLine() { - append("\n"); - return this; - } - -} diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java index 953d83fe3..ec9164c72 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java @@ -19,19 +19,19 @@ package com.sk89q.worldedit.util.formatting.component; -import com.sk89q.worldedit.util.formatting.Style; -import com.sk89q.worldedit.util.formatting.StyledFragment; +import net.kyori.text.TextComponent; +import net.kyori.text.format.TextColor; /** * Represents a fragment representing a command that is to be typed. */ -public class Code extends StyledFragment { +public class Code extends TextComponent { /** * Create a new instance. */ - public Code() { - super(Style.CYAN); + public Code(String message) { + super(builder(message).color(TextColor.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 145b6baca..2767ff920 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 @@ -19,7 +19,9 @@ package com.sk89q.worldedit.util.formatting.component; -import com.sk89q.worldedit.util.formatting.Style; +import net.kyori.text.Component; +import net.kyori.text.TextComponent; +import net.kyori.text.format.TextColor; public class CommandListBox extends MessageBox { @@ -36,10 +38,10 @@ public class CommandListBox extends MessageBox { public CommandListBox appendCommand(String alias, String description) { if (!first) { - getContents().newLine(); + getContents().append(Component.newline()); } - getContents().createFragment(Style.YELLOW_DARK).append(alias).append(": "); - getContents().append(description); + getContents().append(TextComponent.of(alias, TextColor.GOLD).append(TextComponent.of(": "))); + getContents().append(TextComponent.of(description)); first = false; return this; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java index 00a16c24e..fb0cc5c60 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java @@ -28,7 +28,8 @@ import com.sk89q.worldedit.util.command.CommandMapping; import com.sk89q.worldedit.util.command.Description; import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.util.command.PrimaryAliasComparator; -import com.sk89q.worldedit.util.formatting.StyledFragment; +import net.kyori.text.Component; +import net.kyori.text.TextComponent; import java.util.ArrayList; import java.util.List; @@ -38,7 +39,7 @@ import javax.annotation.Nullable; /** * A box to describe usage of a command. */ -public class CommandUsageBox extends StyledFragment { +public class CommandUsageBox extends TextComponent { /** * Create a new usage box. @@ -58,6 +59,7 @@ public class CommandUsageBox extends StyledFragment { * @param locals list of locals to use */ public CommandUsageBox(CommandCallable command, String commandString, @Nullable CommandLocals locals) { + super(builder()); checkNotNull(command); checkNotNull(commandString); if (command instanceof Dispatcher) { @@ -85,23 +87,23 @@ public class CommandUsageBox extends StyledFragment { private void attachCommandUsage(Description description, String commandString) { MessageBox box = new MessageBox("Help for " + commandString); - StyledFragment contents = box.getContents(); + Component contents = box.getContents(); if (description.getUsage() != null) { - contents.append(new Label().append("Usage: ")); - contents.append(description.getUsage()); + contents.append(new Label("Usage: ")); + contents.append(TextComponent.of(description.getUsage())); } else { - contents.append(new Subtle().append("Usage information is not available.")); + contents.append(new Subtle("Usage information is not available.")); } - contents.newLine(); + contents.append(Component.newline()); if (description.getHelp() != null) { - contents.append(description.getHelp()); + contents.append(TextComponent.of(description.getHelp())); } else if (description.getDescription() != null) { - contents.append(description.getDescription()); + contents.append(TextComponent.of(description.getDescription())); } else { - contents.append(new Subtle().append("No further help is available.")); + contents.append(new Subtle("No further help is available.")); } append(box); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java index 056c99c18..5042a3804 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java @@ -19,19 +19,19 @@ package com.sk89q.worldedit.util.formatting.component; -import com.sk89q.worldedit.util.formatting.Style; -import com.sk89q.worldedit.util.formatting.StyledFragment; +import net.kyori.text.TextComponent; +import net.kyori.text.format.TextColor; /** * Represents a fragment representing an error. */ -public class Error extends StyledFragment { +public class Error extends TextComponent { /** * Create a new instance. */ - public Error() { - super(Style.RED); + public Error(String message) { + super(builder(message).color(TextColor.RED)); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java index 8a59732b0..bc0e46527 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java @@ -19,19 +19,19 @@ package com.sk89q.worldedit.util.formatting.component; -import com.sk89q.worldedit.util.formatting.Style; -import com.sk89q.worldedit.util.formatting.StyledFragment; +import net.kyori.text.TextComponent; +import net.kyori.text.format.TextColor; /** * Represents a fragment representing a label. */ -public class Label extends StyledFragment { +public class Label extends TextComponent { /** * Create a new instance. */ - public Label() { - super(Style.YELLOW); + public Label(String message) { + super(builder(message).color(TextColor.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 086ce05e9..7b2dcc72e 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 @@ -21,36 +21,39 @@ package com.sk89q.worldedit.util.formatting.component; import static com.google.common.base.Preconditions.checkNotNull; -import com.sk89q.worldedit.util.formatting.ColorCodeBuilder; -import com.sk89q.worldedit.util.formatting.Style; -import com.sk89q.worldedit.util.formatting.StyledFragment; +import net.kyori.text.Component; +import net.kyori.text.TextComponent; +import net.kyori.text.format.TextColor; /** * Makes for a box with a border above and below. */ -public class MessageBox extends StyledFragment { +public class MessageBox extends TextComponent { - private final StyledFragment contents = new StyledFragment(); + public static final int GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH = 47; + + private final Component contents = Component.empty(); /** * Create a new box. */ public MessageBox(String title) { + super(builder()); checkNotNull(title); - int leftOver = ColorCodeBuilder.GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - title.length() - 2; + int leftOver = GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - title.length() - 2; int leftSide = (int) Math.floor(leftOver * 1.0/3); int rightSide = (int) Math.floor(leftOver * 2.0/3); if (leftSide > 0) { - createFragment(Style.YELLOW).append(createBorder(leftSide)); + append(TextComponent.of(createBorder(leftSide), TextColor.YELLOW)); } - append(" "); - append(title); - append(" "); + append(Component.space()); + append(TextComponent.of(title)); + append(Component.space()); if (rightSide > 0) { - createFragment(Style.YELLOW).append(createBorder(rightSide)); + append(TextComponent.of(createBorder(rightSide), TextColor.YELLOW)); } - newLine(); + append(Component.newline()); append(contents); } @@ -67,7 +70,7 @@ public class MessageBox extends StyledFragment { * * @return the contents */ - public StyledFragment getContents() { + public Component getContents() { return contents; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java index 34316c087..68600f0a3 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java @@ -19,19 +19,19 @@ package com.sk89q.worldedit.util.formatting.component; -import com.sk89q.worldedit.util.formatting.Style; -import com.sk89q.worldedit.util.formatting.StyledFragment; +import net.kyori.text.TextComponent; +import net.kyori.text.format.TextColor; /** * Represents a subtle part of the message. */ -public class Subtle extends StyledFragment { +public class Subtle extends TextComponent { /** * Create a new instance. */ - public Subtle() { - super(Style.GRAY); + public Subtle(String message) { + super(builder(message).color(TextColor.GRAY)); } } diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index 41c798310..c1ce166c1 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -91,6 +91,7 @@ shadowJar { include(dependency(':worldedit-core')) include(dependency('org.slf4j:slf4j-api')) include(dependency("org.apache.logging.log4j:log4j-slf4j-impl")) + include(dependency("net.kyori:text-serializer-gson:2.0.0")) } } diff --git a/worldedit-sponge/build.gradle b/worldedit-sponge/build.gradle index f65952c91..762557b6e 100644 --- a/worldedit-sponge/build.gradle +++ b/worldedit-sponge/build.gradle @@ -43,6 +43,7 @@ shadowJar { dependencies { include(dependency(':worldedit-core')) include(dependency('org.bstats:bstats-sponge:1.4')) + include(dependency("net.kyori:text-adapter-spongeapi:1.0.3")) } } From 1e7b4fc835ac202dc3b0d4e8a44362b2251ed692 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sat, 20 Apr 2019 23:11:39 -0700 Subject: [PATCH 05/13] Move shaded libraries to their own artifacts --- build.gradle | 44 ++++----- settings.gradle | 7 +- worldedit-bukkit/build.gradle | 3 +- .../worldedit/bukkit/BukkitCommandSender.java | 4 +- .../sk89q/worldedit/bukkit/BukkitPlayer.java | 4 +- worldedit-core/build.gradle | 7 +- .../worldedit/command/SelectionCommands.java | 10 +- .../worldedit/command/UtilityCommands.java | 10 +- .../worldedit/extension/platform/Actor.java | 2 +- .../extension/platform/PlayerProxy.java | 2 +- .../util/formatting/component/Code.java | 4 +- .../formatting/component/CommandListBox.java | 6 +- .../formatting/component/CommandUsageBox.java | 4 +- .../util/formatting/component/Error.java | 4 +- .../util/formatting/component/Label.java | 4 +- .../util/formatting/component/MessageBox.java | 8 +- .../util/formatting/component/Subtle.java | 4 +- .../sk89q/worldedit/forge/ForgePlayer.java | 2 +- worldedit-libs/build.gradle | 97 +++++++++++++++++++ worldedit-sponge/build.gradle | 3 +- .../worldedit/sponge/SpongeCommandSender.java | 4 +- .../sk89q/worldedit/sponge/SpongePlayer.java | 4 +- 22 files changed, 165 insertions(+), 72 deletions(-) create mode 100644 worldedit-libs/build.gradle diff --git a/build.gradle b/build.gradle index 090626cc5..16fd983db 100644 --- a/build.gradle +++ b/build.gradle @@ -82,6 +82,14 @@ artifactory { artifactoryPublish.skip = true subprojects { + repositories { + mavenCentral() + maven { url "http://maven.sk89q.com/repo/" } + maven { url "http://repo.maven.apache.org/maven2" } + } +} + +configure(['core', 'bukkit', 'forge', 'sponge'].collect { project(":worldedit-$it") }) { apply plugin: 'java' apply plugin: 'maven' apply plugin: 'checkstyle' @@ -97,12 +105,6 @@ subprojects { checkstyle.configFile = new File(rootProject.projectDir, "config/checkstyle/checkstyle.xml") checkstyle.toolVersion = '7.6.1' - repositories { - mavenCentral() - maven { url "http://maven.sk89q.com/repo/" } - maven { url "http://repo.maven.apache.org/maven2" } - } - if (JavaVersion.current().isJava8Compatible()) { // Java 8 turns on doclint which we fail tasks.withType(Javadoc) { @@ -136,23 +138,6 @@ subprojects { build.dependsOn(checkstyleTest) build.dependsOn(javadocJar) - shadowJar { - classifier 'dist' - dependencies { - include(dependency('com.sk89q:jchronic:0.2.4a')) - include(dependency('com.thoughtworks.paranamer:paranamer:2.6')) - include(dependency('com.sk89q.lib:jlibnoise:1.0.0')) - include(dependency('net.kyori:text-api:2.0.0')) - include(dependency("net.kyori:text-serializer-gson:2.0.0")) - include(dependency("net.kyori:text-serializer-legacy:2.0.0")) - - relocate('net.kyori.text', 'com.sk89q.worldedit.util.formatting.text') - } - exclude 'GradleStart**' - exclude '.cache' - exclude 'LICENSE*' - } - artifactoryPublish { publishConfigs('archives') } @@ -162,3 +147,16 @@ subprojects { include '**/*.java' } } + +configure(['bukkit', 'forge', 'sponge'].collect { project(":worldedit-$it") }) { + shadowJar { + classifier 'dist' + dependencies { + include(project(":worldedit-libs")) + include(project(":worldedit-core")) + } + exclude 'GradleStart**' + exclude '.cache' + exclude 'LICENSE*' + } +} diff --git a/settings.gradle b/settings.gradle index 576283ecc..efbda026f 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,8 @@ rootProject.name = 'worldedit' -include 'worldedit-core', 'worldedit-bukkit', 'worldedit-forge', 'worldedit-sponge' \ No newline at end of file +include 'worldedit-libs' + +['bukkit', 'core', 'forge', 'sponge'].forEach { + include "worldedit-libs:$it" + include "worldedit-$it" +} \ No newline at end of file diff --git a/worldedit-bukkit/build.gradle b/worldedit-bukkit/build.gradle index 67ca5e43b..79ec8f5c5 100644 --- a/worldedit-bukkit/build.gradle +++ b/worldedit-bukkit/build.gradle @@ -10,12 +10,11 @@ repositories { dependencies { compile project(':worldedit-core') + compile project(':worldedit-libs:bukkit') compile 'com.sk89q:dummypermscompat:1.10' compile 'org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT' // zzz - compile 'org.bstats:bstats-bukkit:1.4' compile "io.papermc:paperlib:1.0.1" compile 'org.slf4j:slf4j-jdk14:1.7.26' - compile 'net.kyori:text-adapter-bukkit:1.0.3' testCompile 'org.mockito:mockito-core:1.9.0-rc1' } 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 21d08d726..b82dfe458 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 @@ -26,8 +26,8 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.auth.AuthorizationException; -import net.kyori.text.TextComponent; -import net.kyori.text.adapter.bukkit.TextAdapter; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; 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 ca15daa91..71941a69d 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 @@ -37,8 +37,8 @@ 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.text.TextComponent; -import net.kyori.text.adapter.bukkit.TextAdapter; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.adapter.bukkit.TextAdapter; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; diff --git a/worldedit-core/build.gradle b/worldedit-core/build.gradle index 9d8176407..c401d5b06 100644 --- a/worldedit-core/build.gradle +++ b/worldedit-core/build.gradle @@ -4,20 +4,15 @@ apply plugin: 'eclipse' apply plugin: 'idea' dependencies { + compile project(':worldedit-libs:core') compile 'de.schlichtherle:truezip:6.8.3' compile 'rhino:js:1.7R2' compile 'org.yaml:snakeyaml:1.9' compile 'com.google.guava:guava:21.0' - compile 'com.sk89q:jchronic:0.2.4a' compile 'com.google.code.findbugs:jsr305:1.3.9' - compile 'com.thoughtworks.paranamer:paranamer:2.6' compile 'com.google.code.gson:gson:2.8.0' - compile 'com.sk89q.lib:jlibnoise:1.0.0' compile 'com.googlecode.json-simple:json-simple:1.1.1' compile 'org.slf4j:slf4j-api:1.7.26' - compile 'net.kyori:text-api:2.0.0' - compile 'net.kyori:text-serializer-gson:2.0.0' - compile 'net.kyori:text-serializer-legacy:2.0.0' //compile 'net.sf.trove4j:trove4j:3.0.3' testCompile 'org.mockito:mockito-core:1.9.0-rc1' } 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 ee93e847c..7c1b1889c 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 @@ -62,7 +62,7 @@ import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.item.ItemTypes; import com.sk89q.worldedit.world.storage.ChunkStore; -import net.kyori.text.Component; +import com.sk89q.worldedit.util.formatting.text.Component; import java.util.ArrayList; import java.util.List; @@ -75,7 +75,7 @@ import java.util.Set; public class SelectionCommands { private final WorldEdit we; - + public SelectionCommands(WorldEdit we) { this.we = we; } @@ -294,7 +294,7 @@ public class SelectionCommands { ) @CommandPermissions("worldedit.wand.toggle") public void toggleWand(Player player, LocalSession session, CommandContext args) throws WorldEditException { - + session.setToolControl(!session.isToolControlEnabled()); if (session.isToolControlEnabled()) { @@ -393,7 +393,7 @@ public class SelectionCommands { session.getRegionSelector(player.getWorld()).learnChanges(); int newSize = region.getArea(); - + session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); player.print("Region expanded " + (newSize - oldSize) + " blocks."); @@ -464,7 +464,7 @@ public class SelectionCommands { } session.getRegionSelector(player.getWorld()).learnChanges(); int newSize = region.getArea(); - + session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); 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 e8ee6275f..989fbad6b 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 @@ -65,9 +65,9 @@ import com.sk89q.worldedit.util.formatting.component.Error; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; +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 java.util.ArrayList; import java.util.List; @@ -207,7 +207,7 @@ public class UtilityCommands { @CommandPermissions("worldedit.removeabove") @Logging(PLACEMENT) public void removeAbove(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { - + int size = args.argsLength() > 0 ? Math.max(1, args.getInteger(0)) : 1; we.checkMaxRadius(size); World world = player.getWorld(); @@ -275,7 +275,7 @@ public class UtilityCommands { @CommandPermissions("worldedit.replacenear") @Logging(PLACEMENT) public void replaceNear(Player player, LocalSession session, EditSession editSession, CommandContext args) throws WorldEditException { - + int size = Math.max(1, args.getInteger(0)); we.checkMaxRadius(size); int affected; 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 86bae5934..45160de66 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 @@ -23,7 +23,7 @@ import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.session.SessionOwner; import com.sk89q.worldedit.util.Identifiable; import com.sk89q.worldedit.util.auth.Subject; -import net.kyori.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.TextComponent; import java.io.File; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java index 5211e1380..2159a2fce 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/PlayerProxy.java @@ -34,7 +34,7 @@ import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.gamemode.GameMode; -import net.kyori.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.TextComponent; import java.util.UUID; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java index ec9164c72..a1491551e 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.util.formatting.component; -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.format.TextColor; /** * Represents a fragment representing a command that is to be typed. 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 2767ff920..9e6ec3295 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 @@ -19,9 +19,9 @@ package com.sk89q.worldedit.util.formatting.component; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; +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; public class CommandListBox extends MessageBox { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java index fb0cc5c60..13eee701c 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java @@ -28,8 +28,8 @@ import com.sk89q.worldedit.util.command.CommandMapping; import com.sk89q.worldedit.util.command.Description; import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.util.command.PrimaryAliasComparator; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.formatting.text.TextComponent; import java.util.ArrayList; import java.util.List; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java index 5042a3804..52d9d7044 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.util.formatting.component; -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.format.TextColor; /** * Represents a fragment representing an error. diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java index bc0e46527..a38adc7bb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.util.formatting.component; -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.format.TextColor; /** * Represents a fragment representing a label. 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 7b2dcc72e..b32c00995 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 @@ -21,9 +21,9 @@ package com.sk89q.worldedit.util.formatting.component; import static com.google.common.base.Preconditions.checkNotNull; -import net.kyori.text.Component; -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; +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; /** * Makes for a box with a border above and below. @@ -67,7 +67,7 @@ public class MessageBox extends TextComponent { /** * Get the internal contents. - * + * * @return the contents */ public Component getContents() { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java index 68600f0a3..a512138d4 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java @@ -19,8 +19,8 @@ package com.sk89q.worldedit.util.formatting.component; -import net.kyori.text.TextComponent; -import net.kyori.text.format.TextColor; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.format.TextColor; /** * Represents a subtle part of the message. 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 57734f43a..5dc11aaf6 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 @@ -34,7 +34,7 @@ import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; -import net.kyori.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.TextComponent; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; diff --git a/worldedit-libs/build.gradle b/worldedit-libs/build.gradle new file mode 100644 index 000000000..51b307019 --- /dev/null +++ b/worldedit-libs/build.gradle @@ -0,0 +1,97 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +subprojects { + apply plugin: 'maven' + apply plugin: 'com.github.johnrengelman.shadow' + apply plugin: 'com.jfrog.artifactory' + configurations { + create("shade") + } + + group = rootProject.group + ".worldedit-libs" + + tasks.register("jar", ShadowJar) { + configurations = [project.configurations.shade] + classifier = "" + + relocate('net.kyori.text', 'com.sk89q.worldedit.util.formatting.text') + } + def altConfigFiles = { String artifactType -> + def deps = configurations.shade.incoming.dependencies + .collect { it.copy() } + .collect { dependency -> + dependency.artifact { artifact -> + artifact.name = dependency.name + artifact.type = artifactType + artifact.extension = 'jar' + artifact.classifier = artifactType + } + dependency + } + + return files(configurations.detachedConfiguration(deps as Dependency[]) + .resolvedConfiguration.lenientConfiguration.getArtifacts() + .findAll { it.classifier == artifactType } + .collect { zipTree(it.file) }) + } + tasks.register("sourcesJar", Jar) { + from { + altConfigFiles('sources') + } + def filePattern = ~'(.*)net/kyori/text((?:/|$).*)' + def textPattern = ~/net\.kyori\.text/ + eachFile { + it.filter { String line -> + line.replaceFirst(textPattern, 'com.sk89q.worldedit.util.formatting.text') + } + it.path = it.path.replaceFirst(filePattern, '$1com/sk89q/worldedit/util/formatting/text$2') + } + classifier = "sources" + } + + artifacts { + add("default", jar) + add("default", sourcesJar) + } + + tasks.register("install", Upload) { + configuration = configurations.default + repositories.mavenInstaller { + pom.version = project.version + pom.artifactId = project.name + } + } + + artifactoryPublish { + publishConfigs('default') + } + + build.dependsOn(jar, sourcesJar) +} + +project("core") { + dependencies { + shade 'net.kyori:text-api:2.0.0' + shade 'net.kyori:text-serializer-gson:2.0.0' + shade 'net.kyori:text-serializer-legacy:2.0.0' + shade 'com.sk89q:jchronic:0.2.4a' + shade 'com.thoughtworks.paranamer:paranamer:2.6' + shade 'com.sk89q.lib:jlibnoise:1.0.0' + } +} +project("bukkit") { + dependencies { + shade 'net.kyori:text-adapter-bukkit:1.0.3' + shade 'org.bstats:bstats-bukkit:1.4' + } +} +project("sponge") { + dependencies { + shade 'net.kyori:text-adapter-spongeapi:1.0.3' + shade 'org.bstats:bstats-sponge:1.4' + } +} + +tasks.register("build") { + dependsOn(subprojects.collect { it.tasks.named("build") }) +} diff --git a/worldedit-sponge/build.gradle b/worldedit-sponge/build.gradle index 762557b6e..422913966 100644 --- a/worldedit-sponge/build.gradle +++ b/worldedit-sponge/build.gradle @@ -17,9 +17,8 @@ repositories { dependencies { compile project(':worldedit-core') + compile project(':worldedit-libs:sponge') compile 'org.spongepowered:spongeapi:7.1.0' - compile 'org.bstats:bstats-sponge:1.4' - compile 'net.kyori:text-adapter-spongeapi:1.0.3' testCompile group: 'org.mockito', name: 'mockito-core', version:'1.9.0-rc1' } 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 fe5c626a3..e44146b3c 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 @@ -26,8 +26,8 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.internal.cui.CUIEvent; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.auth.AuthorizationException; -import net.kyori.text.TextComponent; -import net.kyori.text.adapter.spongeapi.TextAdapter; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +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; 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 10b1f47e8..099780b3d 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 @@ -36,8 +36,8 @@ import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemTypes; -import net.kyori.text.TextComponent; -import net.kyori.text.adapter.spongeapi.TextAdapter; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.adapter.spongeapi.TextAdapter; import org.spongepowered.api.Sponge; import org.spongepowered.api.data.type.HandTypes; import org.spongepowered.api.entity.living.player.Player; From 5c19866809a7c5a4856eb2e1ed079fdb86e1a9d5 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sat, 20 Apr 2019 23:33:54 -0700 Subject: [PATCH 06/13] Some fixes for new libs shading --- build.gradle | 3 ++- worldedit-bukkit/build.gradle | 1 + worldedit-core/build.gradle | 7 ------- worldedit-forge/build.gradle | 2 -- worldedit-libs/build.gradle | 11 ++++++----- worldedit-sponge/build.gradle | 11 ++++------- 6 files changed, 13 insertions(+), 22 deletions(-) diff --git a/build.gradle b/build.gradle index 16fd983db..eaa4a49b5 100644 --- a/build.gradle +++ b/build.gradle @@ -152,7 +152,8 @@ configure(['bukkit', 'forge', 'sponge'].collect { project(":worldedit-$it") }) { shadowJar { classifier 'dist' dependencies { - include(project(":worldedit-libs")) + include(project(":worldedit-libs:core")) + include(project(":worldedit-libs:${project.name.replace("worldedit-", "")}")) include(project(":worldedit-core")) } exclude 'GradleStart**' diff --git a/worldedit-bukkit/build.gradle b/worldedit-bukkit/build.gradle index 79ec8f5c5..14550bdb5 100644 --- a/worldedit-bukkit/build.gradle +++ b/worldedit-bukkit/build.gradle @@ -15,6 +15,7 @@ dependencies { compile 'org.bukkit:bukkit:1.13.2-R0.1-SNAPSHOT' // zzz compile "io.papermc:paperlib:1.0.1" compile 'org.slf4j:slf4j-jdk14:1.7.26' + compile 'org.bstats:bstats-bukkit:1.4' testCompile 'org.mockito:mockito-core:1.9.0-rc1' } diff --git a/worldedit-core/build.gradle b/worldedit-core/build.gradle index c401d5b06..828833d9a 100644 --- a/worldedit-core/build.gradle +++ b/worldedit-core/build.gradle @@ -1,5 +1,3 @@ -import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar - apply plugin: 'eclipse' apply plugin: 'idea' @@ -28,8 +26,3 @@ sourceSets { } } } - -task jar(type: ShadowJar, overwrite: true) { - from sourceSets.main.output - configurations = [project.configurations.runtime] -} \ No newline at end of file diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index c1ce166c1..d398d05d1 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -88,10 +88,8 @@ shadowJar { relocate "org.slf4j", "com.sk89q.worldedit.slf4j" relocate "org.apache.logging.slf4j", "com.sk89q.worldedit.log4jbridge" - include(dependency(':worldedit-core')) include(dependency('org.slf4j:slf4j-api')) include(dependency("org.apache.logging.log4j:log4j-slf4j-impl")) - include(dependency("net.kyori:text-serializer-gson:2.0.0")) } } diff --git a/worldedit-libs/build.gradle b/worldedit-libs/build.gradle index 51b307019..983d2dc41 100644 --- a/worldedit-libs/build.gradle +++ b/worldedit-libs/build.gradle @@ -6,6 +6,7 @@ subprojects { apply plugin: 'com.jfrog.artifactory' configurations { create("shade") + getByName("archives").extendsFrom(getByName("default")) } group = rootProject.group + ".worldedit-libs" @@ -51,11 +52,11 @@ subprojects { artifacts { add("default", jar) - add("default", sourcesJar) + add("archives", sourcesJar) } tasks.register("install", Upload) { - configuration = configurations.default + configuration = configurations.archives repositories.mavenInstaller { pom.version = project.version pom.artifactId = project.name @@ -74,7 +75,9 @@ project("core") { shade 'net.kyori:text-api:2.0.0' shade 'net.kyori:text-serializer-gson:2.0.0' shade 'net.kyori:text-serializer-legacy:2.0.0' - shade 'com.sk89q:jchronic:0.2.4a' + shade('com.sk89q:jchronic:0.2.4a') { + exclude(group: "junit", module: "junit") + } shade 'com.thoughtworks.paranamer:paranamer:2.6' shade 'com.sk89q.lib:jlibnoise:1.0.0' } @@ -82,13 +85,11 @@ project("core") { project("bukkit") { dependencies { shade 'net.kyori:text-adapter-bukkit:1.0.3' - shade 'org.bstats:bstats-bukkit:1.4' } } project("sponge") { dependencies { shade 'net.kyori:text-adapter-spongeapi:1.0.3' - shade 'org.bstats:bstats-sponge:1.4' } } diff --git a/worldedit-sponge/build.gradle b/worldedit-sponge/build.gradle index 422913966..6d75c4d84 100644 --- a/worldedit-sponge/build.gradle +++ b/worldedit-sponge/build.gradle @@ -19,6 +19,7 @@ dependencies { compile project(':worldedit-core') compile project(':worldedit-libs:sponge') compile 'org.spongepowered:spongeapi:7.1.0' + compile 'org.bstats:bstats-sponge:1.4' testCompile group: 'org.mockito', name: 'mockito-core', version:'1.9.0-rc1' } @@ -40,16 +41,12 @@ jar { shadowJar { dependencies { - include(dependency(':worldedit-core')) - include(dependency('org.bstats:bstats-sponge:1.4')) - include(dependency("net.kyori:text-adapter-spongeapi:1.0.3")) + relocate ("org.bstats", "com.sk89q.worldedit.sponge.bstats") { + include(dependency('org.bstats:bstats-sponge:1.4')) + } } } -artifacts { - archives shadowJar -} - if (project.hasProperty("signing")) { apply plugin: 'signing' From 73d56819269eeb730fb99373f482513f75aeb1b9 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sat, 20 Apr 2019 23:36:44 -0700 Subject: [PATCH 07/13] Add a note about which libraries get shaded where --- worldedit-libs/build.gradle | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/worldedit-libs/build.gradle b/worldedit-libs/build.gradle index 983d2dc41..81d44c28c 100644 --- a/worldedit-libs/build.gradle +++ b/worldedit-libs/build.gradle @@ -1,5 +1,17 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +/* +This project shades API libraries, i.e. those libraries +whose classes are publicly referenced from `-core` classes. + +This project does not shade implementation libraries, i.e. +those libraries whose classes are internally depended on. + +This is because the main reason for shading those libraries is for +their internal usage in each platform, not because we need them available to +dependents of `-core` to compile and work with WorldEdit's API. + + */ subprojects { apply plugin: 'maven' apply plugin: 'com.github.johnrengelman.shadow' From 5a18ed275ff3ab3707c39cf8b9e76e5ad4f746e9 Mon Sep 17 00:00:00 2001 From: Kenzie Togami Date: Sun, 21 Apr 2019 00:01:06 -0700 Subject: [PATCH 08/13] Drop provided / compileOnly dependencies from shadow --- worldedit-libs/build.gradle | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/worldedit-libs/build.gradle b/worldedit-libs/build.gradle index 81d44c28c..f0a2359b5 100644 --- a/worldedit-libs/build.gradle +++ b/worldedit-libs/build.gradle @@ -27,6 +27,12 @@ subprojects { configurations = [project.configurations.shade] classifier = "" + dependencies { + exclude(dependency("com.google.guava:guava")) + exclude(dependency("com.google.code.gson:gson")) + exclude(dependency("org.checkerframework:checker-qual")) + } + relocate('net.kyori.text', 'com.sk89q.worldedit.util.formatting.text') } def altConfigFiles = { String artifactType -> From c52eb59d7f702dbcc90c47ad9aae7fedacf72e1b Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Mon, 22 Apr 2019 22:05:20 +1000 Subject: [PATCH 09/13] Get it all working --- build.gradle | 1 + worldedit-bukkit/build.gradle | 1 - .../worldedit/command/SelectionCommands.java | 21 +++++---- .../worldedit/command/UtilityCommands.java | 20 ++++---- .../extension/platform/CommandManager.java | 2 +- .../util/formatting/component/Code.java | 5 +- .../formatting/component/CommandListBox.java | 16 ++++++- .../formatting/component/CommandUsageBox.java | 17 ++++--- .../util/formatting/component/Error.java | 5 +- .../util/formatting/component/Label.java | 5 +- .../util/formatting/component/MessageBox.java | 22 +++++---- .../util/formatting/component/Subtle.java | 5 +- .../component/TextComponentProducer.java | 47 +++++++++++++++++++ worldedit-libs/build.gradle | 4 +- 14 files changed, 116 insertions(+), 55 deletions(-) create mode 100644 worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextComponentProducer.java diff --git a/build.gradle b/build.gradle index eaa4a49b5..63b4d9537 100644 --- a/build.gradle +++ b/build.gradle @@ -86,6 +86,7 @@ subprojects { mavenCentral() maven { url "http://maven.sk89q.com/repo/" } maven { url "http://repo.maven.apache.org/maven2" } + maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } } diff --git a/worldedit-bukkit/build.gradle b/worldedit-bukkit/build.gradle index 14550bdb5..975aee9d9 100644 --- a/worldedit-bukkit/build.gradle +++ b/worldedit-bukkit/build.gradle @@ -43,7 +43,6 @@ shadowJar { include(dependency(':worldedit-core')) include(dependency('org.slf4j:slf4j-api')) include(dependency("org.slf4j:slf4j-jdk14")) - include(dependency("net.kyori:text-adapter-bukkit:1.0.3")) relocate ("org.bstats", "com.sk89q.worldedit.bukkit.bstats") { include(dependency("org.bstats:bstats-bukkit:1.4")) } 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 7c1b1889c..cd15be1ff 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 @@ -57,6 +57,7 @@ import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.formatting.component.CommandListBox; import com.sk89q.worldedit.util.formatting.component.Subtle; +import com.sk89q.worldedit.util.formatting.component.TextComponentProducer; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockState; @@ -753,18 +754,18 @@ public class SelectionCommands { limit.ifPresent(integer -> player.print(integer + " points maximum.")); } else { CommandListBox box = new CommandListBox("Selection modes"); - Component contents = box.getContents(); - contents.append(new Subtle("Select one of the modes below:").append(Component.newline())); + TextComponentProducer contents = box.getContents(); + contents.append(new Subtle("Select one of the modes below:").append(Component.newline()).create()); - box.appendCommand("cuboid", "Select two corners of a cuboid"); - box.appendCommand("extend", "Fast cuboid selection mode"); - box.appendCommand("poly", "Select a 2D polygon with height"); - box.appendCommand("ellipsoid", "Select an ellipsoid"); - box.appendCommand("sphere", "Select a sphere"); - box.appendCommand("cyl", "Select a cylinder"); - box.appendCommand("convex", "Select a convex polyhedral"); + box.appendCommand("cuboid", "Select two corners of a cuboid", "//sel cuboid"); + box.appendCommand("extend", "Fast cuboid selection mode", "//sel extend"); + box.appendCommand("poly", "Select a 2D polygon with height", "//sel poly"); + box.appendCommand("ellipsoid", "Select an ellipsoid", "//sel ellipsoid"); + box.appendCommand("sphere", "Select a sphere", "//sel sphere"); + box.appendCommand("cyl", "Select a cylinder", "//sel cyl"); + box.appendCommand("convex", "Select a convex polyhedral", "//sel convex"); - player.print(box); + player.print(box.create()); return; } 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 989fbad6b..bd0c8ba53 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 @@ -62,12 +62,13 @@ import com.sk89q.worldedit.util.formatting.component.Code; import com.sk89q.worldedit.util.formatting.component.CommandListBox; import com.sk89q.worldedit.util.formatting.component.CommandUsageBox; import com.sk89q.worldedit.util.formatting.component.Error; +import com.sk89q.worldedit.util.formatting.component.Subtle; +import com.sk89q.worldedit.util.formatting.component.TextComponentProducer; +import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; -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 java.util.ArrayList; import java.util.List; @@ -670,16 +671,16 @@ public class UtilityCommands { // Box CommandListBox box = new CommandListBox(String.format("Help: page %d/%d ", page + 1, pageTotal)); - Component contents = box.getContents(); - Component tip = contents.append(TextComponent.of("", TextColor.GRAY)); + TextComponentProducer tip = new Subtle(""); + TextComponentProducer contents = box.getContents(); if (offset >= aliases.size()) { - tip.append(new Error(String.format("There is no page %d (total number of pages is %d).", page + 1, pageTotal))).append(Component.newline()); + tip.append(new Error(String.format("There is no page %d (total number of pages is %d).", page + 1, pageTotal)).create()).append(Component.newline()); } else { List list = aliases.subList(offset, Math.min(offset + perPage, aliases.size())); tip.append(TextComponent.of("Type ")); - tip.append(new Code("//help ").append(TextComponent.of(" []"))); + tip.append(new Code("//help ").append(TextComponent.of(" []")).create()); tip.append(TextComponent.of(" for more information.")).append(Component.newline()); // Add each command @@ -697,10 +698,11 @@ public class UtilityCommands { } } - actor.print(box); + contents.append(tip.create()); + actor.print(box.create()); } else { CommandUsageBox box = new CommandUsageBox(callable, Joiner.on(" ").join(visited)); - actor.print(box); + actor.print(box.create()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java index 11257efdf..45b5265bb 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/extension/platform/CommandManager.java @@ -299,7 +299,7 @@ public final class CommandManager { actor.printError("You are not permitted to do that. Are you in the right mode?"); } catch (InvalidUsageException e) { if (e.isFullHelpSuggested()) { - actor.print(new CommandUsageBox(e.getCommand(), e.getCommandUsed("/", ""), locals)); + actor.print(new CommandUsageBox(e.getCommand(), e.getCommandUsed("/", ""), locals).create()); String message = e.getMessage(); if (message != null) { actor.printError(message); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java index a1491551e..6cbad7f3a 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java @@ -19,19 +19,18 @@ package com.sk89q.worldedit.util.formatting.component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; /** * Represents a fragment representing a command that is to be typed. */ -public class Code extends TextComponent { +public class Code extends TextComponentProducer { /** * Create a new instance. */ public Code(String message) { - super(builder(message).color(TextColor.AQUA)); + getBuilder().content(message).color(TextColor.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 9e6ec3295..846d08853 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 @@ -21,6 +21,8 @@ package com.sk89q.worldedit.util.formatting.component; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; +import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; public class CommandListBox extends MessageBox { @@ -33,14 +35,24 @@ public class CommandListBox extends MessageBox { * @param title the title */ public CommandListBox(String title) { - super(title); + super(title, new TextComponentProducer()); } public CommandListBox appendCommand(String alias, String description) { + return appendCommand(alias, description, null); + } + + public CommandListBox appendCommand(String alias, String description, String insertion) { if (!first) { getContents().append(Component.newline()); } - getContents().append(TextComponent.of(alias, TextColor.GOLD).append(TextComponent.of(": "))); + TextComponent commandName = TextComponent.of(alias, TextColor.GOLD); + if (insertion != null) { + commandName = commandName + .clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, insertion)) + .hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to select"))); + } + getContents().append(commandName.append(TextComponent.of(": "))); getContents().append(TextComponent.of(description)); first = false; return this; diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java index 13eee701c..e15d862cc 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java @@ -39,7 +39,7 @@ import javax.annotation.Nullable; /** * A box to describe usage of a command. */ -public class CommandUsageBox extends TextComponent { +public class CommandUsageBox extends TextComponentProducer { /** * Create a new usage box. @@ -59,7 +59,6 @@ public class CommandUsageBox extends TextComponent { * @param locals list of locals to use */ public CommandUsageBox(CommandCallable command, String commandString, @Nullable CommandLocals locals) { - super(builder()); checkNotNull(command); checkNotNull(commandString); if (command instanceof Dispatcher) { @@ -82,18 +81,17 @@ public class CommandUsageBox extends TextComponent { } } - append(box); + append(box.create()); } private void attachCommandUsage(Description description, String commandString) { - MessageBox box = new MessageBox("Help for " + commandString); - Component contents = box.getContents(); + TextComponentProducer contents = new TextComponentProducer(); if (description.getUsage() != null) { - contents.append(new Label("Usage: ")); + contents.append(new Label("Usage: ").create()); contents.append(TextComponent.of(description.getUsage())); } else { - contents.append(new Subtle("Usage information is not available.")); + contents.append(new Subtle("Usage information is not available.").create()); } contents.append(Component.newline()); @@ -103,10 +101,11 @@ public class CommandUsageBox extends TextComponent { } else if (description.getDescription() != null) { contents.append(TextComponent.of(description.getDescription())); } else { - contents.append(new Subtle("No further help is available.")); + contents.append(new Subtle("No further help is available.").create()); } - append(box); + MessageBox box = new MessageBox("Help for " + commandString, contents); + append(box.create()); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java index 52d9d7044..50cef22f2 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java @@ -19,19 +19,18 @@ package com.sk89q.worldedit.util.formatting.component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; /** * Represents a fragment representing an error. */ -public class Error extends TextComponent { +public class Error extends TextComponentProducer { /** * Create a new instance. */ public Error(String message) { - super(builder(message).color(TextColor.RED)); + getBuilder().content(message).color(TextColor.RED); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java index a38adc7bb..02d438f8d 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java @@ -19,19 +19,18 @@ package com.sk89q.worldedit.util.formatting.component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; /** * Represents a fragment representing a label. */ -public class Label extends TextComponent { +public class Label extends TextComponentProducer { /** * Create a new instance. */ public Label(String message) { - super(builder(message).color(TextColor.YELLOW)); + getBuilder().content(message).color(TextColor.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 b32c00995..5193f0e6b 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 @@ -28,17 +28,16 @@ import com.sk89q.worldedit.util.formatting.text.format.TextColor; /** * Makes for a box with a border above and below. */ -public class MessageBox extends TextComponent { +public class MessageBox extends TextComponentProducer { - public static final int GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH = 47; + private static final int GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH = 47; - private final Component contents = Component.empty(); + private final TextComponentProducer contents; /** * Create a new box. */ - public MessageBox(String title) { - super(builder()); + public MessageBox(String title, TextComponentProducer contents) { checkNotNull(title); int leftOver = GUARANTEED_NO_WRAP_CHAT_PAGE_WIDTH - title.length() - 2; @@ -54,7 +53,7 @@ public class MessageBox extends TextComponent { append(TextComponent.of(createBorder(rightSide), TextColor.YELLOW)); } append(Component.newline()); - append(contents); + this.contents = contents; } private String createBorder(int count) { @@ -66,12 +65,17 @@ public class MessageBox extends TextComponent { } /** - * Get the internal contents. + * Gets the message box contents producer. * - * @return the contents + * @return The contents producer */ - public Component getContents() { + public TextComponentProducer getContents() { return contents; } + @Override + public TextComponent create() { + append(contents.create()); + return super.create(); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java index a512138d4..609824838 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java @@ -19,19 +19,18 @@ package com.sk89q.worldedit.util.formatting.component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.format.TextColor; /** * Represents a subtle part of the message. */ -public class Subtle extends TextComponent { +public class Subtle extends TextComponentProducer { /** * Create a new instance. */ public Subtle(String message) { - super(builder(message).color(TextColor.GRAY)); + getBuilder().color(TextColor.GRAY).content(message); } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextComponentProducer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextComponentProducer.java new file mode 100644 index 000000000..2c3228ee2 --- /dev/null +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextComponentProducer.java @@ -0,0 +1,47 @@ +/* + * WorldEdit, a Minecraft world manipulation toolkit + * Copyright (C) sk89q + * Copyright (C) WorldEdit team and contributors + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by the + * Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package com.sk89q.worldedit.util.formatting.component; + +import com.sk89q.worldedit.util.formatting.text.Component; +import com.sk89q.worldedit.util.formatting.text.TextComponent; + +public class TextComponentProducer { + + private TextComponent.Builder builder = TextComponent.builder().content(""); + + public TextComponent.Builder getBuilder() { + return builder; + } + + /** + * Adds a component as a child to this Producer + * + * @param component The component + * @return The producer, for chaining + */ + public TextComponentProducer append(Component component) { + getBuilder().append(component); + return this; + } + + public TextComponent create() { + return builder.build(); + } +} diff --git a/worldedit-libs/build.gradle b/worldedit-libs/build.gradle index f0a2359b5..b05c601e8 100644 --- a/worldedit-libs/build.gradle +++ b/worldedit-libs/build.gradle @@ -102,12 +102,12 @@ project("core") { } project("bukkit") { dependencies { - shade 'net.kyori:text-adapter-bukkit:1.0.3' + shade 'net.kyori:text-adapter-bukkit:2.0.0-SNAPSHOT' } } project("sponge") { dependencies { - shade 'net.kyori:text-adapter-spongeapi:1.0.3' + shade 'net.kyori:text-adapter-spongeapi:2.0.0-SNAPSHOT' } } From 0434bcf48cd1eaa32eed5f841d0ffe7a8cff3354 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Mon, 22 Apr 2019 23:59:31 +1000 Subject: [PATCH 10/13] Remove unnecessary gradle entries --- build.gradle | 1 - worldedit-forge/build.gradle | 1 - 2 files changed, 2 deletions(-) diff --git a/build.gradle b/build.gradle index 63b4d9537..41de17bb8 100644 --- a/build.gradle +++ b/build.gradle @@ -85,7 +85,6 @@ subprojects { repositories { mavenCentral() maven { url "http://maven.sk89q.com/repo/" } - maven { url "http://repo.maven.apache.org/maven2" } maven { url "https://oss.sonatype.org/content/repositories/snapshots/" } } } diff --git a/worldedit-forge/build.gradle b/worldedit-forge/build.gradle index d398d05d1..2cbab094f 100644 --- a/worldedit-forge/build.gradle +++ b/worldedit-forge/build.gradle @@ -19,7 +19,6 @@ def forgeVersion = "25.0.76" dependencies { compile project(':worldedit-core') compile 'org.apache.logging.log4j:log4j-slf4j-impl:2.11.2' - compile 'net.kyori:text-serializer-gson:2.0.0' minecraft "net.minecraftforge:forge:${minecraftVersion}-${forgeVersion}" From 5606e752c2ead3f3904d1c45afb48f6388409f78 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Thu, 25 Apr 2019 19:11:58 +1000 Subject: [PATCH 11/13] Use wrappers for the Format-type components --- config/checkstyle/import-control.xml | 1 - .../worldedit/command/SelectionCommands.java | 4 ++-- .../worldedit/command/UtilityCommands.java | 19 ++++++++------- .../component/{Code.java => CodeFormat.java} | 24 ++++++++++++++----- .../formatting/component/CommandListBox.java | 5 ++-- .../formatting/component/CommandUsageBox.java | 13 +++++----- .../{Error.java => ErrorFormat.java} | 21 +++++++++++++--- .../{Label.java => LabelFormat.java} | 21 +++++++++++++--- .../util/formatting/component/MessageBox.java | 4 ++-- .../{Subtle.java => SubtleFormat.java} | 21 +++++++++++++--- .../component/TextComponentProducer.java | 23 +++++++++++++++++- 11 files changed, 117 insertions(+), 39 deletions(-) rename worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/{Code.java => CodeFormat.java} (66%) rename worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/{Error.java => ErrorFormat.java} (65%) rename worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/{Label.java => LabelFormat.java} (65%) rename worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/{Subtle.java => SubtleFormat.java} (65%) diff --git a/config/checkstyle/import-control.xml b/config/checkstyle/import-control.xml index b4a2f4808..28ccad1e4 100644 --- a/config/checkstyle/import-control.xml +++ b/config/checkstyle/import-control.xml @@ -16,7 +16,6 @@ - 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 cd15be1ff..3c1be05fd 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 @@ -56,7 +56,7 @@ import com.sk89q.worldedit.session.ClipboardHolder; import com.sk89q.worldedit.util.Countable; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.formatting.component.CommandListBox; -import com.sk89q.worldedit.util.formatting.component.Subtle; +import com.sk89q.worldedit.util.formatting.component.SubtleFormat; import com.sk89q.worldedit.util.formatting.component.TextComponentProducer; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; @@ -755,7 +755,7 @@ public class SelectionCommands { } else { CommandListBox box = new CommandListBox("Selection modes"); TextComponentProducer contents = box.getContents(); - contents.append(new Subtle("Select one of the modes below:").append(Component.newline()).create()); + contents.append(SubtleFormat.wrap("Select one of the modes below:")).newline(); box.appendCommand("cuboid", "Select two corners of a cuboid", "//sel cuboid"); box.appendCommand("extend", "Fast cuboid selection mode", "//sel extend"); 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 bd0c8ba53..2e2defc19 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 @@ -58,14 +58,15 @@ import com.sk89q.worldedit.util.command.CommandMapping; import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.util.command.PrimaryAliasComparator; import com.sk89q.worldedit.util.command.binding.Text; -import com.sk89q.worldedit.util.formatting.component.Code; +import com.sk89q.worldedit.util.formatting.component.CodeFormat; import com.sk89q.worldedit.util.formatting.component.CommandListBox; import com.sk89q.worldedit.util.formatting.component.CommandUsageBox; -import com.sk89q.worldedit.util.formatting.component.Error; -import com.sk89q.worldedit.util.formatting.component.Subtle; +import com.sk89q.worldedit.util.formatting.component.ErrorFormat; +import com.sk89q.worldedit.util.formatting.component.SubtleFormat; import com.sk89q.worldedit.util.formatting.component.TextComponentProducer; import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.format.TextColor; import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; @@ -671,17 +672,19 @@ public class UtilityCommands { // Box CommandListBox box = new CommandListBox(String.format("Help: page %d/%d ", page + 1, pageTotal)); - TextComponentProducer tip = new Subtle(""); + TextComponentProducer tip = new TextComponentProducer(); + tip.getBuilder().content("").color(TextColor.GRAY); TextComponentProducer contents = box.getContents(); if (offset >= aliases.size()) { - tip.append(new Error(String.format("There is no page %d (total number of pages is %d).", page + 1, pageTotal)).create()).append(Component.newline()); + tip.append(ErrorFormat.wrap(String.format("There is no page %d (total number of pages is %d).", page + 1, pageTotal))).newline(); } else { List list = aliases.subList(offset, Math.min(offset + perPage, aliases.size())); - tip.append(TextComponent.of("Type ")); - tip.append(new Code("//help ").append(TextComponent.of(" []")).create()); - tip.append(TextComponent.of(" for more information.")).append(Component.newline()); + tip.append("Type "); + tip.append(CodeFormat.wrap("//help ")); + tip.append(" [] for more information."); + tip.newline(); // Add each command for (CommandMapping mapping : list) { diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CodeFormat.java similarity index 66% rename from worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CodeFormat.java index 6cbad7f3a..134239546 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Code.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CodeFormat.java @@ -19,18 +19,30 @@ package com.sk89q.worldedit.util.formatting.component; +import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.format.TextColor; /** * Represents a fragment representing a command that is to be typed. */ -public class Code extends TextComponentProducer { +public class CodeFormat extends TextComponentProducer { - /** - * Create a new instance. - */ - public Code(String message) { - getBuilder().content(message).color(TextColor.AQUA); + private CodeFormat() { + getBuilder().content("").color(TextColor.AQUA); } + /** + * Creates a CodeFormat with the given message. + * + * @param texts The text + * @return The Component + */ + public static Component wrap(String ... texts) { + CodeFormat code = new CodeFormat(); + for (String text: texts) { + code.append(text); + } + + return code.create(); + } } 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 846d08853..ac360e99c 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 @@ -19,7 +19,6 @@ package com.sk89q.worldedit.util.formatting.component; -import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.TextComponent; import com.sk89q.worldedit.util.formatting.text.event.ClickEvent; import com.sk89q.worldedit.util.formatting.text.event.HoverEvent; @@ -44,7 +43,7 @@ public class CommandListBox extends MessageBox { public CommandListBox appendCommand(String alias, String description, String insertion) { if (!first) { - getContents().append(Component.newline()); + getContents().newline(); } TextComponent commandName = TextComponent.of(alias, TextColor.GOLD); if (insertion != null) { @@ -53,7 +52,7 @@ public class CommandListBox extends MessageBox { .hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("Click to select"))); } getContents().append(commandName.append(TextComponent.of(": "))); - getContents().append(TextComponent.of(description)); + getContents().append(description); first = false; return this; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java index e15d862cc..04a31df3b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/CommandUsageBox.java @@ -29,7 +29,6 @@ import com.sk89q.worldedit.util.command.Description; import com.sk89q.worldedit.util.command.Dispatcher; import com.sk89q.worldedit.util.command.PrimaryAliasComparator; import com.sk89q.worldedit.util.formatting.text.Component; -import com.sk89q.worldedit.util.formatting.text.TextComponent; import java.util.ArrayList; import java.util.List; @@ -88,20 +87,20 @@ public class CommandUsageBox extends TextComponentProducer { TextComponentProducer contents = new TextComponentProducer(); if (description.getUsage() != null) { - contents.append(new Label("Usage: ").create()); - contents.append(TextComponent.of(description.getUsage())); + contents.append(LabelFormat.wrap("Usage: ")); + contents.append(description.getUsage()); } else { - contents.append(new Subtle("Usage information is not available.").create()); + contents.append(SubtleFormat.wrap("Usage information is not available.")); } contents.append(Component.newline()); if (description.getHelp() != null) { - contents.append(TextComponent.of(description.getHelp())); + contents.append(description.getHelp()); } else if (description.getDescription() != null) { - contents.append(TextComponent.of(description.getDescription())); + contents.append(description.getDescription()); } else { - contents.append(new Subtle("No further help is available.").create()); + contents.append(SubtleFormat.wrap("No further help is available.")); } MessageBox box = new MessageBox("Help for " + commandString, contents); diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/ErrorFormat.java similarity index 65% rename from worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/ErrorFormat.java index 50cef22f2..b30ad8324 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Error.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/ErrorFormat.java @@ -19,18 +19,33 @@ package com.sk89q.worldedit.util.formatting.component; +import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.format.TextColor; /** * Represents a fragment representing an error. */ -public class Error extends TextComponentProducer { +public class ErrorFormat extends TextComponentProducer { /** * Create a new instance. */ - public Error(String message) { - getBuilder().content(message).color(TextColor.RED); + private ErrorFormat() { + getBuilder().content("").color(TextColor.RED); } + /** + * Creates an ErrorFormat with the given message. + * + * @param texts The text + * @return The Component + */ + public static Component wrap(String ... texts) { + ErrorFormat error = new ErrorFormat(); + for (String component : texts) { + error.append(component); + } + + return error.create(); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/LabelFormat.java similarity index 65% rename from worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/LabelFormat.java index 02d438f8d..4dda69349 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Label.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/LabelFormat.java @@ -19,18 +19,33 @@ package com.sk89q.worldedit.util.formatting.component; +import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.format.TextColor; /** * Represents a fragment representing a label. */ -public class Label extends TextComponentProducer { +public class LabelFormat extends TextComponentProducer { /** * Create a new instance. */ - public Label(String message) { - getBuilder().content(message).color(TextColor.YELLOW); + private LabelFormat() { + getBuilder().content("").color(TextColor.YELLOW); } + /** + * Creates a LabelFormat with the given message. + * + * @param texts The text + * @return The Component + */ + public static Component wrap(String ... texts) { + LabelFormat label = new LabelFormat(); + for (String component : texts) { + label.append(component); + } + + return label.create(); + } } 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 5193f0e6b..6828589bc 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 @@ -47,12 +47,12 @@ public class MessageBox extends TextComponentProducer { append(TextComponent.of(createBorder(leftSide), TextColor.YELLOW)); } append(Component.space()); - append(TextComponent.of(title)); + append(title); append(Component.space()); if (rightSide > 0) { append(TextComponent.of(createBorder(rightSide), TextColor.YELLOW)); } - append(Component.newline()); + newline(); this.contents = contents; } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SubtleFormat.java similarity index 65% rename from worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java rename to worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SubtleFormat.java index 609824838..5987675f7 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/Subtle.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/SubtleFormat.java @@ -19,18 +19,33 @@ package com.sk89q.worldedit.util.formatting.component; +import com.sk89q.worldedit.util.formatting.text.Component; import com.sk89q.worldedit.util.formatting.text.format.TextColor; /** * Represents a subtle part of the message. */ -public class Subtle extends TextComponentProducer { +public class SubtleFormat extends TextComponentProducer { /** * Create a new instance. */ - public Subtle(String message) { - getBuilder().color(TextColor.GRAY).content(message); + private SubtleFormat() { + getBuilder().content("").color(TextColor.GRAY); } + /** + * Creates a SubtleFormat with the given message. + * + * @param texts The text + * @return The Component + */ + public static Component wrap(String ... texts) { + SubtleFormat subtle = new SubtleFormat(); + for (String component : texts) { + subtle.append(component); + } + + return subtle.create(); + } } diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextComponentProducer.java b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextComponentProducer.java index 2c3228ee2..32a9f8d30 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextComponentProducer.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/util/formatting/component/TextComponentProducer.java @@ -31,7 +31,7 @@ public class TextComponentProducer { } /** - * Adds a component as a child to this Producer + * Adds a component as a child to this Producer. * * @param component The component * @return The producer, for chaining @@ -41,6 +41,27 @@ public class TextComponentProducer { return this; } + /** + * Adds a string as a child to this Producer. + * + * @param string The text + * @return The producer, for chaining + */ + public TextComponentProducer append(String string) { + getBuilder().append(TextComponent.of(string)); + return this; + } + + /** + * Adds a newline as a child to this Producer. + * + * @return The producer, for chaining + */ + public TextComponentProducer newline() { + getBuilder().append(Component.newline()); + return this; + } + public TextComponent create() { return builder.build(); } From b1e43b7561906c9cbab24b04095b314412353bbe Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Thu, 25 Apr 2019 19:20:29 +1000 Subject: [PATCH 12/13] wrap to TextComponent --- .../sk89q/worldedit/util/formatting/component/CodeFormat.java | 4 ++-- .../worldedit/util/formatting/component/ErrorFormat.java | 4 ++-- .../worldedit/util/formatting/component/LabelFormat.java | 4 ++-- .../worldedit/util/formatting/component/SubtleFormat.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) 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 134239546..a92590bac 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 @@ -19,7 +19,7 @@ package com.sk89q.worldedit.util.formatting.component; -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; /** @@ -37,7 +37,7 @@ public class CodeFormat extends TextComponentProducer { * @param texts The text * @return The Component */ - public static Component wrap(String ... texts) { + public static TextComponent wrap(String ... texts) { CodeFormat code = new CodeFormat(); for (String text: texts) { code.append(text); 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 b30ad8324..35343ca56 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 @@ -19,7 +19,7 @@ package com.sk89q.worldedit.util.formatting.component; -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; /** @@ -40,7 +40,7 @@ public class ErrorFormat extends TextComponentProducer { * @param texts The text * @return The Component */ - public static Component wrap(String ... texts) { + public static TextComponent wrap(String ... texts) { ErrorFormat error = new ErrorFormat(); for (String component : texts) { error.append(component); 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 4dda69349..f0a487114 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 @@ -19,7 +19,7 @@ package com.sk89q.worldedit.util.formatting.component; -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; /** @@ -40,7 +40,7 @@ public class LabelFormat extends TextComponentProducer { * @param texts The text * @return The Component */ - public static Component wrap(String ... texts) { + public static TextComponent wrap(String ... texts) { LabelFormat label = new LabelFormat(); for (String component : texts) { label.append(component); 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 5987675f7..310cc4e01 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 @@ -19,7 +19,7 @@ package com.sk89q.worldedit.util.formatting.component; -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; /** @@ -40,7 +40,7 @@ public class SubtleFormat extends TextComponentProducer { * @param texts The text * @return The Component */ - public static Component wrap(String ... texts) { + public static TextComponent wrap(String ... texts) { SubtleFormat subtle = new SubtleFormat(); for (String component : texts) { subtle.append(component); From 4f5f9c8a5df016734b4500c28864984a47eb6104 Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Thu, 25 Apr 2019 19:38:32 +1000 Subject: [PATCH 13/13] Add forge support to the text system. --- .../java/com/sk89q/worldedit/forge/ForgePlayer.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 5dc11aaf6..edc5275ab 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 @@ -31,10 +31,11 @@ import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.session.SessionKey; import com.sk89q.worldedit.util.HandSide; import com.sk89q.worldedit.util.Location; +import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.util.formatting.text.serializer.gson.GsonComponentSerializer; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockStateHolder; - -import com.sk89q.worldedit.util.formatting.text.TextComponent; +import io.netty.buffer.Unpooled; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.network.PacketBuffer; @@ -43,6 +44,7 @@ import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextFormatting; @@ -50,8 +52,6 @@ import java.util.UUID; import javax.annotation.Nullable; -import io.netty.buffer.Unpooled; - public class ForgePlayer extends AbstractPlayerActor { private final EntityPlayerMP player; @@ -144,7 +144,7 @@ public class ForgePlayer extends AbstractPlayerActor { @Override public void print(TextComponent component) { - // TODO + this.player.sendMessage(ITextComponent.Serializer.fromJson(GsonComponentSerializer.INSTANCE.serialize(component))); } private void sendColorized(String msg, TextFormatting formatting) {