虚浮 TLocaleTitle 无法使用变量的问题
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
50
src/main/java/me/skymc/taboolib/json/JSONReader.java
Normal file
50
src/main/java/me/skymc/taboolib/json/JSONReader.java
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user