Skip to content

Commit

Permalink
item display name: fix accidental double-subcomponent
Browse files Browse the repository at this point in the history
slightly more spigot-like format but still not spigot's format
  • Loading branch information
mcmonkey4eva committed Jan 21, 2021
1 parent cb32c1c commit 0e4df60
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
Expand Up @@ -249,7 +249,9 @@ public static BaseComponent[] parse(String str, ChatColor baseColor, boolean cle
base.setUnderlined(false);
base.setObfuscated(false);
base.setColor(baseColor);
root.setText(str.substring(0, firstChar));
if (firstChar > 0) {
root.addExtra(new TextComponent(str.substring(0, firstChar)));
}
}
else {
base.setText(str.substring(0, firstChar));
Expand All @@ -260,9 +262,6 @@ public static BaseComponent[] parse(String str, ChatColor baseColor, boolean cle
int started = 0;
TextComponent nextText = new TextComponent();
TextComponent lastText = new TextComponent();
if (!str.contains(ChatColor.COLOR_CHAR + "[")) {

}
for (int i = 0; i < chars.length; i++) {
if (chars[i] == ChatColor.COLOR_CHAR && i + 1 < chars.length) {
char code = chars[i + 1];
Expand Down
Expand Up @@ -15,7 +15,6 @@
import com.denizenscript.denizencore.utilities.CoreUtilities;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import net.minecraft.server.v1_16_R3.*;
import org.bukkit.Bukkit;
Expand Down Expand Up @@ -309,11 +308,7 @@ public void setDisplayName(ItemTag item, String name) {
return;
}
BaseComponent[] components = FormattedTextHelper.parse(name, ChatColor.WHITE);
TextComponent actualComponent = new TextComponent();
for (BaseComponent component : components) {
actualComponent.addExtra(component);
}
display.set("Name", NBTTagString.a(ComponentSerializer.toString(actualComponent)));
display.set("Name", NBTTagString.a(ComponentSerializer.toString(components)));
item.setItemStack(CraftItemStack.asBukkitCopy(nmsItemStack));
}

Expand Down

0 comments on commit 0e4df60

Please sign in to comment.