diff --git a/pom.xml b/pom.xml index 0b6faf7..8faa289 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ me.skymc TabooLib - 4.10 + 4.11 UTF-8 diff --git a/src/main/java/com/ilummc/tlib/resources/type/TLocaleTitle.java b/src/main/java/com/ilummc/tlib/resources/type/TLocaleTitle.java index 59fcf6e..fb90a40 100644 --- a/src/main/java/com/ilummc/tlib/resources/type/TLocaleTitle.java +++ b/src/main/java/com/ilummc/tlib/resources/type/TLocaleTitle.java @@ -42,13 +42,7 @@ public class TLocaleTitle extends TLocaleSerialize { public static TLocaleTitle valueOf(Map map) { TLocaleTitle title; try { - title = new TLocaleTitle( - getStringOrDefault(map, "title", ""), - getStringOrDefault(map, "subtitle", ""), - getIntegerOrDefault(map, "fadein", 10), - getIntegerOrDefault(map, "fadeout", 10), - getIntegerOrDefault(map, "stay", 10), - isPlaceholderEnabled(map)); + title = new TLocaleTitle(getStringOrDefault(map, "title", ""), getStringOrDefault(map, "subtitle", ""), getIntegerOrDefault(map, "fadein", 10), getIntegerOrDefault(map, "fadeout", 10), getIntegerOrDefault(map, "stay", 10), isPlaceholderEnabled(map)); } catch (Exception e) { title = new TLocaleTitle("Empty Title message.", e.getMessage(), 10, 20, 10, false); } @@ -58,7 +52,7 @@ public class TLocaleTitle extends TLocaleSerialize { @Override public void sendTo(CommandSender sender, String... args) { if (sender instanceof Player) { - TitleUtils.sendTitle((Player) sender, replaceText(sender, title), replaceText(sender, subtitle), fadein, stay, fadeout); + TitleUtils.sendTitle((Player) sender, replaceText(sender, Strings.replaceWithOrder(title, args)), replaceText(sender, Strings.replaceWithOrder(subtitle, args)), fadein, stay, fadeout); } else { TLocale.Logger.error("LOCALE.TITLE-SEND-TO-NON-PLAYER", asString(args)); } @@ -86,7 +80,7 @@ public class TLocaleTitle extends TLocaleSerialize { return map; } - private String replaceText(CommandSender sender, String args) { - return usePlaceholder ? TLocale.Translate.setPlaceholders(sender, args) : TLocale.Translate.setColored(args); + private String replaceText(CommandSender sender, String text, String... args) { + return usePlaceholder ? TLocale.Translate.setPlaceholders(sender, text) : TLocale.Translate.setColored(text); } } diff --git a/src/main/java/me/skymc/taboolib/commands/taboolib/InfoCommand.java b/src/main/java/me/skymc/taboolib/commands/taboolib/InfoCommand.java index 31b880d..1eae955 100644 --- a/src/main/java/me/skymc/taboolib/commands/taboolib/InfoCommand.java +++ b/src/main/java/me/skymc/taboolib/commands/taboolib/InfoCommand.java @@ -4,6 +4,7 @@ import com.ilummc.tlib.resources.TLocale; import me.skymc.taboolib.commands.SubCommand; import me.skymc.taboolib.inventory.ItemUtils; import me.skymc.taboolib.itemnbtapi.NBTItem; +import me.skymc.taboolib.json.JSONReader; import org.bukkit.Material; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @@ -23,7 +24,7 @@ public class InfoCommand extends SubCommand { player.getItemInHand().getType().name(), ItemUtils.getCustomName(player.getItemInHand()), player.getItemInHand().getTypeId() + ":" + player.getItemInHand().getDurability(), - nbt.toString()); + JSONReader.formatJson(nbt.asNBTString())); } } } diff --git a/src/main/java/me/skymc/taboolib/json/JSONReader.java b/src/main/java/me/skymc/taboolib/json/JSONReader.java new file mode 100644 index 0000000..393cdd0 --- /dev/null +++ b/src/main/java/me/skymc/taboolib/json/JSONReader.java @@ -0,0 +1,50 @@ +package me.skymc.taboolib.json; + +import java.util.regex.Pattern; + +/** + * @Author sky + * @Since 2018-07-01 11:10 + */ +public class JSONReader { + + private static Pattern pattern = Pattern.compile("[\t\n]"); + + public static String formatJson(String content) { + StringBuilder builder = new StringBuilder(); + int index = 0; + int count = 0; + while (index < content.length()) { + char ch = content.charAt(index); + if (ch == '{' || ch == '[') { + builder.append(ch); + builder.append('\n'); + count++; + for (int i = 0; i < count; i++) { + builder.append('\t'); + } + } else if (ch == '}' || ch == ']') { + builder.append('\n'); + count--; + for (int i = 0; i < count; i++) { + builder.append('\t'); + } + builder.append(ch); + } else if (ch == ',') { + builder.append(ch); + builder.append('\n'); + for (int i = 0; i < count; i++) { + builder.append('\t'); + } + } else { + builder.append(ch); + } + index++; + } + return compactJson(builder.toString()); + } + + private static String compactJson(String content) { + return pattern.matcher(content).replaceAll("").trim(); + } +}