From 13655c1efa536c90606ca8a45fdfb5890e143207 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Sat, 26 Nov 2016 19:00:43 +0100 Subject: [PATCH] =?UTF-8?q?R=C3=A9organisation=20des=20d=C3=A9pendances=20?= =?UTF-8?q?+=20configuration=20avanc=C3=A9e=20des=20projets?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + pom.xml | 13 +- .../fr/pandacube/java/util/ThrowableUtil.java | 23 ++ .../java/net/md_5/bungee/api/ChatColor.java | 82 ------- .../net/md_5/bungee/api/ChatMessageType.java | 10 - .../md_5/bungee/api/chat/BaseComponent.java | 215 ------------------ .../net/md_5/bungee/api/chat/ClickEvent.java | 37 --- .../bungee/api/chat/ComponentBuilder.java | 122 ---------- .../net/md_5/bungee/api/chat/HoverEvent.java | 38 ---- .../md_5/bungee/api/chat/TextComponent.java | 152 ------------- .../api/chat/TranslatableComponent.java | 173 -------------- 11 files changed, 30 insertions(+), 836 deletions(-) create mode 100644 src/main/java/fr/pandacube/java/util/ThrowableUtil.java delete mode 100644 src/main/java/net/md_5/bungee/api/ChatColor.java delete mode 100644 src/main/java/net/md_5/bungee/api/ChatMessageType.java delete mode 100644 src/main/java/net/md_5/bungee/api/chat/BaseComponent.java delete mode 100644 src/main/java/net/md_5/bungee/api/chat/ClickEvent.java delete mode 100644 src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java delete mode 100644 src/main/java/net/md_5/bungee/api/chat/HoverEvent.java delete mode 100644 src/main/java/net/md_5/bungee/api/chat/TextComponent.java delete mode 100644 src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java diff --git a/.gitignore b/.gitignore index b83d222..dc097ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /target/ +dependency-reduced-pom.xml diff --git a/pom.xml b/pom.xml index c618e72..d8eb271 100644 --- a/pom.xml +++ b/pom.xml @@ -21,6 +21,12 @@ 2.6 compile + + fr.pandacube.bungeecord + bungeecord-chat + 1.11-SNAPSHOT + compile + fr.pandacube.local_dependencies bungeeperms @@ -28,12 +34,5 @@ system ${project.basedir}/../libs/BungeePerms-3.0-alpha1-modif.jar - diff --git a/src/main/java/fr/pandacube/java/util/ThrowableUtil.java b/src/main/java/fr/pandacube/java/util/ThrowableUtil.java new file mode 100644 index 0000000..f2bf69d --- /dev/null +++ b/src/main/java/fr/pandacube/java/util/ThrowableUtil.java @@ -0,0 +1,23 @@ +package fr.pandacube.java.util; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +public class ThrowableUtil { + + + public static String stacktraceToString(Throwable t) { + if (t == null) return null; + try (ByteArrayOutputStream os = new ByteArrayOutputStream()) { + try (PrintStream ps = new PrintStream(os, false, "UTF-8")) { + t.printStackTrace(ps); + ps.flush(); + } + return os.toString("UTF-8"); + } catch (IOException e) { + return null; + } + } + +} diff --git a/src/main/java/net/md_5/bungee/api/ChatColor.java b/src/main/java/net/md_5/bungee/api/ChatColor.java deleted file mode 100644 index d188932..0000000 --- a/src/main/java/net/md_5/bungee/api/ChatColor.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Decompiled with CFR 0_114. - */ -package net.md_5.bungee.api; - -import java.util.HashMap; -import java.util.Map; -import java.util.regex.Pattern; - -public enum ChatColor { - BLACK('0', "black"), - DARK_BLUE('1', "dark_blue"), - DARK_GREEN('2', "dark_green"), - DARK_AQUA('3', "dark_aqua"), - DARK_RED('4', "dark_red"), - DARK_PURPLE('5', "dark_purple"), - GOLD('6', "gold"), - GRAY('7', "gray"), - DARK_GRAY('8', "dark_gray"), - BLUE('9', "blue"), - GREEN('a', "green"), - AQUA('b', "aqua"), - RED('c', "red"), - LIGHT_PURPLE('d', "light_purple"), - YELLOW('e', "yellow"), - WHITE('f', "white"), - MAGIC('k', "obfuscated"), - BOLD('l', "bold"), - STRIKETHROUGH('m', "strikethrough"), - UNDERLINE('n', "underline"), - ITALIC('o', "italic"), - RESET('r', "reset"); - - public static final char COLOR_CHAR = '\u00a7'; - public static final String ALL_CODES = "0123456789AaBbCcDdEeFfKkLlMmNnOoRr"; - public static final Pattern STRIP_COLOR_PATTERN; - private static final Map BY_CHAR; - private final char code; - private final String toString; - private final String name; - - private ChatColor(char code, String name) { - this.code = code; - this.name = name; - toString = new String(new char[] { '\u00a7', code }); - } - - @Override - public String toString() { - return toString; - } - - public static String stripColor(String input) { - if (input == null) return null; - return STRIP_COLOR_PATTERN.matcher(input).replaceAll(""); - } - - public static String translateAlternateColorCodes(char altColorChar, String textToTranslate) { - char[] b2 = textToTranslate.toCharArray(); - for (int i = 0; i < b2.length - 1; ++i) { - if (b2[i] != altColorChar || "0123456789AaBbCcDdEeFfKkLlMmNnOoRr".indexOf(b2[i + 1]) <= -1) continue; - b2[i] = 167; - b2[i + 1] = Character.toLowerCase(b2[i + 1]); - } - return new String(b2); - } - - public static ChatColor getByChar(char code) { - return BY_CHAR.get(Character.valueOf(code)); - } - - public String getName() { - return name; - } - - static { - STRIP_COLOR_PATTERN = Pattern.compile("(?i)" + String.valueOf('\u00a7') + "[0-9A-FK-OR]"); - BY_CHAR = new HashMap<>(); - for (ChatColor colour : ChatColor.values()) - BY_CHAR.put(Character.valueOf(colour.code), colour); - } -} diff --git a/src/main/java/net/md_5/bungee/api/ChatMessageType.java b/src/main/java/net/md_5/bungee/api/ChatMessageType.java deleted file mode 100644 index 88e2899..0000000 --- a/src/main/java/net/md_5/bungee/api/ChatMessageType.java +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Decompiled with CFR 0_114. - */ -package net.md_5.bungee.api; - -public enum ChatMessageType { - CHAT, SYSTEM, ACTION_BAR; - - private ChatMessageType() {} -} diff --git a/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java b/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java deleted file mode 100644 index 5b7978f..0000000 --- a/src/main/java/net/md_5/bungee/api/chat/BaseComponent.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Decompiled with CFR 0_114. - */ -package net.md_5.bungee.api.chat; - -import java.util.ArrayList; -import java.util.List; - -import net.md_5.bungee.api.ChatColor; - -public abstract class BaseComponent { - BaseComponent parent; - private ChatColor color; - private Boolean bold; - private Boolean italic; - private Boolean underlined; - private Boolean strikethrough; - private Boolean obfuscated; - private String insertion; - private List extra; - private ClickEvent clickEvent; - private HoverEvent hoverEvent; - - BaseComponent(BaseComponent old) { - setColor(old.getColorRaw()); - setBold(old.isBoldRaw()); - setItalic(old.isItalicRaw()); - setUnderlined(old.isUnderlinedRaw()); - setStrikethrough(old.isStrikethroughRaw()); - setObfuscated(old.isObfuscatedRaw()); - setInsertion(old.getInsertion()); - setClickEvent(old.getClickEvent()); - setHoverEvent(old.getHoverEvent()); - if (old.getExtra() != null) for (BaseComponent component : old.getExtra()) - this.addExtra(component.duplicate()); - } - - public abstract BaseComponent duplicate(); - - public static /* varargs */ String toLegacyText(BaseComponent... components) { - StringBuilder builder = new StringBuilder(); - for (BaseComponent msg : components) - builder.append(msg.toLegacyText()); - return builder.toString(); - } - - public static /* varargs */ String toPlainText(BaseComponent... components) { - StringBuilder builder = new StringBuilder(); - for (BaseComponent msg : components) - builder.append(msg.toPlainText()); - return builder.toString(); - } - - public ChatColor getColor() { - if (color == null) { - if (parent == null) return ChatColor.WHITE; - return parent.getColor(); - } - return color; - } - - public ChatColor getColorRaw() { - return color; - } - - public boolean isBold() { - if (bold == null) return parent != null && parent.isBold(); - return bold; - } - - public Boolean isBoldRaw() { - return bold; - } - - public boolean isItalic() { - if (italic == null) return parent != null && parent.isItalic(); - return italic; - } - - public Boolean isItalicRaw() { - return italic; - } - - public boolean isUnderlined() { - if (underlined == null) return parent != null && parent.isUnderlined(); - return underlined; - } - - public Boolean isUnderlinedRaw() { - return underlined; - } - - public boolean isStrikethrough() { - if (strikethrough == null) return parent != null && parent.isStrikethrough(); - return strikethrough; - } - - public Boolean isStrikethroughRaw() { - return strikethrough; - } - - public boolean isObfuscated() { - if (obfuscated == null) return parent != null && parent.isObfuscated(); - return obfuscated; - } - - public Boolean isObfuscatedRaw() { - return obfuscated; - } - - public void setExtra(List components) { - for (BaseComponent component : components) - component.parent = this; - extra = components; - } - - public void addExtra(String text) { - this.addExtra(new TextComponent(text)); - } - - public void addExtra(BaseComponent component) { - if (extra == null) extra = new ArrayList<>(); - component.parent = this; - extra.add(component); - } - - public boolean hasFormatting() { - return color != null || bold != null || italic != null || underlined != null || strikethrough != null - || obfuscated != null || hoverEvent != null || clickEvent != null; - } - - public String toPlainText() { - StringBuilder builder = new StringBuilder(); - this.toPlainText(builder); - return builder.toString(); - } - - void toPlainText(StringBuilder builder) { - if (extra != null) for (BaseComponent e2 : extra) - e2.toPlainText(builder); - } - - public String toLegacyText() { - StringBuilder builder = new StringBuilder(); - this.toLegacyText(builder); - return builder.toString(); - } - - void toLegacyText(StringBuilder builder) { - if (extra != null) for (BaseComponent e2 : extra) - e2.toLegacyText(builder); - } - - public void setColor(ChatColor color) { - this.color = color; - } - - public void setBold(Boolean bold) { - this.bold = bold; - } - - public void setItalic(Boolean italic) { - this.italic = italic; - } - - public void setUnderlined(Boolean underlined) { - this.underlined = underlined; - } - - public void setStrikethrough(Boolean strikethrough) { - this.strikethrough = strikethrough; - } - - public void setObfuscated(Boolean obfuscated) { - this.obfuscated = obfuscated; - } - - public void setInsertion(String insertion) { - this.insertion = insertion; - } - - public void setClickEvent(ClickEvent clickEvent) { - this.clickEvent = clickEvent; - } - - public void setHoverEvent(HoverEvent hoverEvent) { - this.hoverEvent = hoverEvent; - } - - @Override - public String toString() { - return "BaseComponent(color=" + (getColor()) + ", bold=" + bold + ", italic=" + italic + ", underlined=" - + underlined + ", strikethrough=" + strikethrough + ", obfuscated=" + obfuscated + ", insertion=" - + getInsertion() + ", extra=" + getExtra() + ", clickEvent=" + getClickEvent() + ", hoverEvent=" - + getHoverEvent() + ")"; - } - - public BaseComponent() {} - - public String getInsertion() { - return insertion; - } - - public List getExtra() { - return extra; - } - - public ClickEvent getClickEvent() { - return clickEvent; - } - - public HoverEvent getHoverEvent() { - return hoverEvent; - } -} diff --git a/src/main/java/net/md_5/bungee/api/chat/ClickEvent.java b/src/main/java/net/md_5/bungee/api/chat/ClickEvent.java deleted file mode 100644 index 4c473cf..0000000 --- a/src/main/java/net/md_5/bungee/api/chat/ClickEvent.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Decompiled with CFR 0_114. - */ -package net.md_5.bungee.api.chat; - -import java.beans.ConstructorProperties; - -public final class ClickEvent { - private final Action action; - private final String value; - - public Action getAction() { - return action; - } - - public String getValue() { - return value; - } - - @Override - public String toString() { - return "ClickEvent(action=" + (getAction()) + ", value=" + getValue() + ")"; - } - - @ConstructorProperties(value = { "action", "value" }) - public ClickEvent(Action action, String value) { - this.action = action; - this.value = value; - } - - public static enum Action { - OPEN_URL, OPEN_FILE, RUN_COMMAND, SUGGEST_COMMAND, CHANGE_PAGE; - - private Action() {} - } - -} diff --git a/src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java b/src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java deleted file mode 100644 index 766146c..0000000 --- a/src/main/java/net/md_5/bungee/api/chat/ComponentBuilder.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Decompiled with CFR 0_114. - */ -package net.md_5.bungee.api.chat; - -import java.util.ArrayList; -import java.util.List; - -import net.md_5.bungee.api.ChatColor; - -public class ComponentBuilder { - private TextComponent current; - private final List parts = new ArrayList<>(); - - public ComponentBuilder(ComponentBuilder original) { - current = new TextComponent(original.current); - for (BaseComponent baseComponent : original.parts) - parts.add(baseComponent.duplicate()); - } - - public ComponentBuilder(String text) { - current = new TextComponent(text); - } - - public ComponentBuilder append(String text) { - return this.append(text, FormatRetention.ALL); - } - - public ComponentBuilder append(String text, FormatRetention retention) { - parts.add(current); - current = new TextComponent(current); - current.setText(text); - retain(retention); - return this; - } - - public ComponentBuilder color(ChatColor color) { - current.setColor(color); - return this; - } - - public ComponentBuilder bold(boolean bold) { - current.setBold(bold); - return this; - } - - public ComponentBuilder italic(boolean italic) { - current.setItalic(italic); - return this; - } - - public ComponentBuilder underlined(boolean underlined) { - current.setUnderlined(underlined); - return this; - } - - public ComponentBuilder strikethrough(boolean strikethrough) { - current.setStrikethrough(strikethrough); - return this; - } - - public ComponentBuilder obfuscated(boolean obfuscated) { - current.setObfuscated(obfuscated); - return this; - } - - public ComponentBuilder insertion(String insertion) { - current.setInsertion(insertion); - return this; - } - - public ComponentBuilder event(ClickEvent clickEvent) { - current.setClickEvent(clickEvent); - return this; - } - - public ComponentBuilder event(HoverEvent hoverEvent) { - current.setHoverEvent(hoverEvent); - return this; - } - - public ComponentBuilder reset() { - return retain(FormatRetention.NONE); - } - - public ComponentBuilder retain(FormatRetention retention) { - TextComponent previous = current; - switch (retention) { - case NONE: { - current = new TextComponent(current.getText()); - break; - } - case ALL: { - break; - } - case EVENTS: { - current = new TextComponent(current.getText()); - current.setInsertion(previous.getInsertion()); - current.setClickEvent(previous.getClickEvent()); - current.setHoverEvent(previous.getHoverEvent()); - break; - } - case FORMATTING: { - current.setClickEvent(null); - current.setHoverEvent(null); - } - } - return this; - } - - public BaseComponent[] create() { - parts.add(current); - return parts.toArray(new BaseComponent[parts.size()]); - } - - public static enum FormatRetention { - NONE, FORMATTING, EVENTS, ALL; - - private FormatRetention() {} - } - -} diff --git a/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java b/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java deleted file mode 100644 index 7bba5e9..0000000 --- a/src/main/java/net/md_5/bungee/api/chat/HoverEvent.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Decompiled with CFR 0_114. - */ -package net.md_5.bungee.api.chat; - -import java.beans.ConstructorProperties; -import java.util.Arrays; - -public final class HoverEvent { - private final Action action; - private final BaseComponent[] value; - - public Action getAction() { - return action; - } - - public BaseComponent[] getValue() { - return value; - } - - @Override - public String toString() { - return "HoverEvent(action=" + (getAction()) + ", value=" + Arrays.deepToString(getValue()) + ")"; - } - - @ConstructorProperties(value = { "action", "value" }) - public HoverEvent(Action action, BaseComponent[] value) { - this.action = action; - this.value = value; - } - - public static enum Action { - SHOW_TEXT, SHOW_ACHIEVEMENT, SHOW_ITEM, SHOW_ENTITY; - - private Action() {} - } - -} diff --git a/src/main/java/net/md_5/bungee/api/chat/TextComponent.java b/src/main/java/net/md_5/bungee/api/chat/TextComponent.java deleted file mode 100644 index e013c03..0000000 --- a/src/main/java/net/md_5/bungee/api/chat/TextComponent.java +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Decompiled with CFR 0_114. - */ -package net.md_5.bungee.api.chat; - -import java.beans.ConstructorProperties; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import net.md_5.bungee.api.ChatColor; - -public class TextComponent extends BaseComponent { - private static final Pattern url = Pattern.compile("^(?:(https?)://)?([-\\w_\\.]{2,}\\.[a-z]{2,4})(/\\S*)?$"); - private String text; - - public static BaseComponent[] fromLegacyText(String message) { - ArrayList components = new ArrayList<>(); - StringBuilder builder = new StringBuilder(); - TextComponent component = new TextComponent(); - Matcher matcher = url.matcher(message); - block8: - for (int i = 0; i < message.length(); ++i) { - TextComponent old; - char c2 = message.charAt(i); - if (c2 == '\u00a7') { - ChatColor format; - if ((c2 = message.charAt(++i)) >= 'A' && c2 <= 'Z') c2 = (char) (c2 + 32); - if ((format = ChatColor.getByChar(c2)) == null) continue; - if (builder.length() > 0) { - old = component; - component = new TextComponent(old); - old.setText(builder.toString()); - builder = new StringBuilder(); - components.add(old); - } - switch (format) { - case BOLD: { - component.setBold(true); - continue block8; - } - case ITALIC: { - component.setItalic(true); - continue block8; - } - case UNDERLINE: { - component.setUnderlined(true); - continue block8; - } - case STRIKETHROUGH: { - component.setStrikethrough(true); - continue block8; - } - case MAGIC: { - component.setObfuscated(true); - continue block8; - } - case RESET: { - format = ChatColor.WHITE; - } - default: - } - component = new TextComponent(); - component.setColor(format); - continue; - } - int pos = message.indexOf(32, i); - if (pos == -1) pos = message.length(); - if (matcher.region(i, pos).find()) { - if (builder.length() > 0) { - old = component; - component = new TextComponent(old); - old.setText(builder.toString()); - builder = new StringBuilder(); - components.add(old); - } - old = component; - component = new TextComponent(old); - String urlString = message.substring(i, pos); - component.setText(urlString); - component.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, - urlString.startsWith("http") ? urlString : "http://" + urlString)); - components.add(component); - i += pos - i - 1; - component = old; - continue; - } - builder.append(c2); - } - if (builder.length() > 0) { - component.setText(builder.toString()); - components.add(component); - } - if (components.isEmpty()) components.add(new TextComponent("")); - return components.toArray(new BaseComponent[components.size()]); - } - - public TextComponent(TextComponent textComponent) { - super(textComponent); - setText(textComponent.getText()); - } - - public /* varargs */ TextComponent(BaseComponent... extras) { - setText(""); - setExtra(new ArrayList<>(Arrays.asList(extras))); - } - - @Override - public BaseComponent duplicate() { - return new TextComponent(this); - } - - @Override - protected void toPlainText(StringBuilder builder) { - builder.append(text); - super.toPlainText(builder); - } - - @Override - protected void toLegacyText(StringBuilder builder) { - builder.append(getColor()); - if (isBold()) builder.append(ChatColor.BOLD); - if (isItalic()) builder.append(ChatColor.ITALIC); - if (isUnderlined()) builder.append(ChatColor.UNDERLINE); - if (isStrikethrough()) builder.append(ChatColor.STRIKETHROUGH); - if (isObfuscated()) builder.append(ChatColor.MAGIC); - builder.append(text); - super.toLegacyText(builder); - } - - @Override - public String toString() { - return String.format("TextComponent{text=%s, %s}", text, super.toString()); - } - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - @ConstructorProperties(value = { "text" }) - public TextComponent(String text) { - this.text = text; - } - - public TextComponent() {} - -} diff --git a/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java b/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java deleted file mode 100644 index d5d7f11..0000000 --- a/src/main/java/net/md_5/bungee/api/chat/TranslatableComponent.java +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Decompiled with CFR 0_114. - */ -package net.md_5.bungee.api.chat; - -import java.util.ArrayList; -import java.util.List; -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import net.md_5.bungee.api.ChatColor; - -public class TranslatableComponent extends BaseComponent { - private final ResourceBundle locales = ResourceBundle.getBundle("mojang-translations/en_US"); - private final Pattern format = Pattern.compile("%(?:(\\d+)\\$)?([A-Za-z%]|$)"); - private String translate; - private List with; - - public TranslatableComponent(TranslatableComponent original) { - super(original); - setTranslate(original.getTranslate()); - if (original.getWith() != null) { - ArrayList temp = new ArrayList<>(); - for (BaseComponent baseComponent : original.getWith()) - temp.add(baseComponent.duplicate()); - setWith(temp); - } - } - - public /* varargs */ TranslatableComponent(String translate, Object... with) { - setTranslate(translate); - ArrayList temp = new ArrayList<>(); - for (Object w : with) { - if (w instanceof String) { - temp.add(new TextComponent((String) w)); - continue; - } - temp.add((BaseComponent) w); - } - setWith(temp); - } - - @Override - public BaseComponent duplicate() { - return new TranslatableComponent(this); - } - - public void setWith(List components) { - for (BaseComponent component : components) - component.parent = this; - with = components; - } - - public void addWith(String text) { - this.addWith(new TextComponent(text)); - } - - public void addWith(BaseComponent component) { - if (with == null) with = new ArrayList<>(); - component.parent = this; - with.add(component); - } - - @Override - protected void toPlainText(StringBuilder builder) { - String trans; - try { - trans = locales.getString(translate); - } catch (MissingResourceException ex) { - trans = translate; - } - Matcher matcher = format.matcher(trans); - int position = 0; - int i = 0; - while (matcher.find(position)) { - int pos = matcher.start(); - if (pos != position) builder.append(trans.substring(position, pos)); - position = matcher.end(); - String formatCode = matcher.group(2); - switch (formatCode.charAt(0)) { - case 'd': - case 's': { - String withIndex = matcher.group(1); - with.get(withIndex != null ? Integer.parseInt(withIndex) - 1 : i++).toPlainText(builder); - break; - } - case '%': { - builder.append('%'); - } - } - } - if (trans.length() != position) builder.append(trans.substring(position, trans.length())); - super.toPlainText(builder); - } - - @Override - protected void toLegacyText(StringBuilder builder) { - String trans; - try { - trans = locales.getString(translate); - } catch (MissingResourceException e) { - trans = translate; - } - Matcher matcher = format.matcher(trans); - int position = 0; - int i = 0; - while (matcher.find(position)) { - int pos = matcher.start(); - if (pos != position) { - addFormat(builder); - builder.append(trans.substring(position, pos)); - } - position = matcher.end(); - String formatCode = matcher.group(2); - switch (formatCode.charAt(0)) { - case 'd': - case 's': { - String withIndex = matcher.group(1); - with.get(withIndex != null ? Integer.parseInt(withIndex) - 1 : i++).toLegacyText(builder); - break; - } - case '%': { - addFormat(builder); - builder.append('%'); - } - } - } - if (trans.length() != position) { - addFormat(builder); - builder.append(trans.substring(position, trans.length())); - } - super.toLegacyText(builder); - } - - private void addFormat(StringBuilder builder) { - builder.append(getColor()); - if (isBold()) builder.append(ChatColor.BOLD); - if (isItalic()) builder.append(ChatColor.ITALIC); - if (isUnderlined()) builder.append(ChatColor.UNDERLINE); - if (isStrikethrough()) builder.append(ChatColor.STRIKETHROUGH); - if (isObfuscated()) builder.append(ChatColor.MAGIC); - } - - public ResourceBundle getLocales() { - return locales; - } - - public Pattern getFormat() { - return format; - } - - public String getTranslate() { - return translate; - } - - public List getWith() { - return with; - } - - public void setTranslate(String translate) { - this.translate = translate; - } - - @Override - public String toString() { - return "TranslatableComponent(locales=" + getLocales() + ", format=" + getFormat() + ", translate=" - + getTranslate() + ", with=" + getWith() + ")"; - } - - public TranslatableComponent() {} -}