Fix a component builder error in 1.12

This commit is contained in:
libraryaddict 2021-05-15 14:10:01 +12:00
parent 8fad4a5b46
commit c3783b9bf0
4 changed files with 17 additions and 14 deletions

View File

@ -9,6 +9,7 @@ import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -95,7 +96,7 @@ public class LDJson implements LDCommand {
int start = 0; int start = 0;
int msg = 1; int msg = 1;
ComponentBuilder builder = new ComponentBuilder("").appendLegacy(prefix.get()); ComponentBuilder builder = new ComponentBuilder("").append(TextComponent.fromLegacyText(prefix.get()));
while (start < string.length()) { while (start < string.length()) {
int end = Math.min(256, string.length() - start); int end = Math.min(256, string.length() - start);
@ -105,10 +106,10 @@ public class LDJson implements LDCommand {
builder.append(" "); builder.append(" ");
if (string.length() <= 256) { if (string.length() <= 256) {
builder.appendLegacy(LibsMsg.CLICK_TO_COPY_DATA.get()); builder.append(TextComponent.fromLegacyText(LibsMsg.CLICK_TO_COPY_DATA.get()));
} else { } else {
builder.reset(); builder.reset();
builder.appendLegacy(LibsMsg.CLICK_COPY.get(msg)); builder.append(TextComponent.fromLegacyText(LibsMsg.CLICK_COPY.get(msg)));
} }
start += end; start += end;

View File

@ -5,6 +5,7 @@ import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import java.util.ArrayList; import java.util.ArrayList;
@ -47,20 +48,19 @@ public class LDMetaInfo implements LDCommand {
names.sort(String::compareToIgnoreCase); names.sort(String::compareToIgnoreCase);
// if (NmsVersion.v1_13.isSupported()) { // if (NmsVersion.v1_13.isSupported()) {
ComponentBuilder builder = new ComponentBuilder("").appendLegacy(LibsMsg.META_VALUES.get()); ComponentBuilder builder = new ComponentBuilder("").append(TextComponent.fromLegacyText(LibsMsg.META_VALUES.get()));
Iterator<String> itel = names.iterator(); Iterator<String> itel = names.iterator();
while (itel.hasNext()) { while (itel.hasNext()) {
String name = itel.next(); String name = itel.next();
builder.appendLegacy(name); builder.append(TextComponent.fromLegacyText(name));
builder.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/libsdisguises metainfo " + name)); builder.event(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/libsdisguises metainfo " + name));
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.fromLegacyText(LibsMsg.META_CLICK_SHOW.get(name))));
new ComponentBuilder("").appendLegacy(LibsMsg.META_CLICK_SHOW.get(name)).create()));
if (itel.hasNext()) { if (itel.hasNext()) {
builder.appendLegacy(LibsMsg.META_VALUE_SEPERATOR.get()); builder.append(TextComponent.fromLegacyText(LibsMsg.META_VALUE_SEPERATOR.get()));
} }
} }

View File

@ -13,6 +13,7 @@ import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -93,7 +94,7 @@ public class CopyDisguiseCommand implements CommandExecutor {
return; return;
}*/ }*/
ComponentBuilder builder = new ComponentBuilder("").appendLegacy(msg.get()).append(" "); ComponentBuilder builder = new ComponentBuilder("").append(TextComponent.fromLegacyText(msg.get())).append(" ");
if (string.length() > 256 || forceAbbrev) { if (string.length() > 256 || forceAbbrev) {
String[] split = DisguiseUtilities.split(string); String[] split = DisguiseUtilities.split(string);
@ -135,7 +136,7 @@ public class CopyDisguiseCommand implements CommandExecutor {
sections++; sections++;
builder.appendLegacy(LibsMsg.CLICK_COPY.get(sections)); builder.append(TextComponent.fromLegacyText(LibsMsg.CLICK_COPY.get(sections)));
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, current.toString())); builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, current.toString()));
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder(LibsMsg.CLICK_TO_COPY_HOVER.get() + " " + sections).create())); new ComponentBuilder(LibsMsg.CLICK_TO_COPY_HOVER.get() + " " + sections).create()));
@ -143,7 +144,7 @@ public class CopyDisguiseCommand implements CommandExecutor {
current = new StringBuilder(); current = new StringBuilder();
} }
} else { } else {
builder.appendLegacy(LibsMsg.CLICK_COPY.get(string)); builder.append(TextComponent.fromLegacyText(LibsMsg.CLICK_COPY.get(string)));
builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, string)); builder.event(new ClickEvent(ClickEvent.Action.SUGGEST_COMMAND, string));
builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT, builder.event(new HoverEvent(HoverEvent.Action.SHOW_TEXT,
new ComponentBuilder(LibsMsg.CLICK_TO_COPY_HOVER.get()).create())); new ComponentBuilder(LibsMsg.CLICK_TO_COPY_HOVER.get()).create()));

View File

@ -11,6 +11,7 @@ import me.libraryaddict.disguise.utilities.translations.LibsMsg;
import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.ClickEvent;
import net.md_5.bungee.api.chat.ComponentBuilder; import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.HoverEvent; import net.md_5.bungee.api.chat.HoverEvent;
import net.md_5.bungee.api.chat.TextComponent;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -114,7 +115,7 @@ public class GrabSkinCommand implements CommandExecutor {
int msg = 1; int msg = 1;
//if (NmsVersion.v1_13.isSupported()) { //if (NmsVersion.v1_13.isSupported()) {
ComponentBuilder builder = new ComponentBuilder("").appendLegacy(LibsMsg.CLICK_TO_COPY.get()); ComponentBuilder builder = new ComponentBuilder("").append(TextComponent.fromLegacyText(LibsMsg.CLICK_TO_COPY.get()));
while (start < string.length()) { while (start < string.length()) {
int end = Math.min(256, string.length() - start); int end = Math.min(256, string.length() - start);
@ -124,10 +125,10 @@ public class GrabSkinCommand implements CommandExecutor {
builder.append(" "); builder.append(" ");
if (string.length() <= 256) { if (string.length() <= 256) {
builder.appendLegacy(LibsMsg.CLICK_TO_COPY_DATA.get()); builder.append(TextComponent.fromLegacyText(LibsMsg.CLICK_TO_COPY_DATA.get()));
} else { } else {
builder.reset(); builder.reset();
builder.appendLegacy(LibsMsg.CLICK_COPY.get(msg)); builder.append(TextComponent.fromLegacyText(LibsMsg.CLICK_COPY.get(msg)));
} }
start += end; start += end;