虚浮 TLocaleTitle 无法使用变量的问题
This commit is contained in:
parent
bb75dfbe68
commit
9c1d434434
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>me.skymc</groupId>
|
<groupId>me.skymc</groupId>
|
||||||
<artifactId>TabooLib</artifactId>
|
<artifactId>TabooLib</artifactId>
|
||||||
<version>4.10</version>
|
<version>4.11</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
@ -42,13 +42,7 @@ public class TLocaleTitle extends TLocaleSerialize {
|
|||||||
public static TLocaleTitle valueOf(Map<String, Object> map) {
|
public static TLocaleTitle valueOf(Map<String, Object> map) {
|
||||||
TLocaleTitle title;
|
TLocaleTitle title;
|
||||||
try {
|
try {
|
||||||
title = new TLocaleTitle(
|
title = new TLocaleTitle(getStringOrDefault(map, "title", ""), getStringOrDefault(map, "subtitle", ""), getIntegerOrDefault(map, "fadein", 10), getIntegerOrDefault(map, "fadeout", 10), getIntegerOrDefault(map, "stay", 10), isPlaceholderEnabled(map));
|
||||||
getStringOrDefault(map, "title", ""),
|
|
||||||
getStringOrDefault(map, "subtitle", ""),
|
|
||||||
getIntegerOrDefault(map, "fadein", 10),
|
|
||||||
getIntegerOrDefault(map, "fadeout", 10),
|
|
||||||
getIntegerOrDefault(map, "stay", 10),
|
|
||||||
isPlaceholderEnabled(map));
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
title = new TLocaleTitle("Empty Title message.", e.getMessage(), 10, 20, 10, false);
|
title = new TLocaleTitle("Empty Title message.", e.getMessage(), 10, 20, 10, false);
|
||||||
}
|
}
|
||||||
@ -58,7 +52,7 @@ public class TLocaleTitle extends TLocaleSerialize {
|
|||||||
@Override
|
@Override
|
||||||
public void sendTo(CommandSender sender, String... args) {
|
public void sendTo(CommandSender sender, String... args) {
|
||||||
if (sender instanceof Player) {
|
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 {
|
} else {
|
||||||
TLocale.Logger.error("LOCALE.TITLE-SEND-TO-NON-PLAYER", asString(args));
|
TLocale.Logger.error("LOCALE.TITLE-SEND-TO-NON-PLAYER", asString(args));
|
||||||
}
|
}
|
||||||
@ -86,7 +80,7 @@ public class TLocaleTitle extends TLocaleSerialize {
|
|||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String replaceText(CommandSender sender, String args) {
|
private String replaceText(CommandSender sender, String text, String... args) {
|
||||||
return usePlaceholder ? TLocale.Translate.setPlaceholders(sender, args) : TLocale.Translate.setColored(args);
|
return usePlaceholder ? TLocale.Translate.setPlaceholders(sender, text) : TLocale.Translate.setColored(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import com.ilummc.tlib.resources.TLocale;
|
|||||||
import me.skymc.taboolib.commands.SubCommand;
|
import me.skymc.taboolib.commands.SubCommand;
|
||||||
import me.skymc.taboolib.inventory.ItemUtils;
|
import me.skymc.taboolib.inventory.ItemUtils;
|
||||||
import me.skymc.taboolib.itemnbtapi.NBTItem;
|
import me.skymc.taboolib.itemnbtapi.NBTItem;
|
||||||
|
import me.skymc.taboolib.json.JSONReader;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@ -23,7 +24,7 @@ public class InfoCommand extends SubCommand {
|
|||||||
player.getItemInHand().getType().name(),
|
player.getItemInHand().getType().name(),
|
||||||
ItemUtils.getCustomName(player.getItemInHand()),
|
ItemUtils.getCustomName(player.getItemInHand()),
|
||||||
player.getItemInHand().getTypeId() + ":" + player.getItemInHand().getDurability(),
|
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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user