版本更新至 3.54

大更新!
新增:Language2 工具, wiki已添加该工具使用帮助
This commit is contained in:
坏黑 2018-02-13 21:27:09 +08:00
parent a41d43b080
commit 757e44e87a
11 changed files with 890 additions and 16 deletions

View File

@ -28,6 +28,7 @@ import me.skymc.taboolib.anvil.AnvilContainerAPI;
import me.skymc.taboolib.bstats.Metrics; import me.skymc.taboolib.bstats.Metrics;
import me.skymc.taboolib.client.LogClient; import me.skymc.taboolib.client.LogClient;
import me.skymc.taboolib.commands.MainCommands; import me.skymc.taboolib.commands.MainCommands;
import me.skymc.taboolib.commands.language.Language2Command;
import me.skymc.taboolib.commands.sub.itemlist.listener.ItemLibraryPatch; import me.skymc.taboolib.commands.sub.itemlist.listener.ItemLibraryPatch;
import me.skymc.taboolib.database.PlayerDataManager; import me.skymc.taboolib.database.PlayerDataManager;
import me.skymc.taboolib.database.GlobalDataManager; import me.skymc.taboolib.database.GlobalDataManager;
@ -45,6 +46,7 @@ import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.mysql.protect.MySQLConnection; import me.skymc.taboolib.mysql.protect.MySQLConnection;
import me.skymc.taboolib.sign.SignUtils; import me.skymc.taboolib.sign.SignUtils;
import me.skymc.taboolib.string.StringUtils; import me.skymc.taboolib.string.StringUtils;
import me.skymc.taboolib.string.language2.Language2;
import me.skymc.taboolib.support.SupportPlaceholder; import me.skymc.taboolib.support.SupportPlaceholder;
import me.skymc.taboolib.team.TagUtils; import me.skymc.taboolib.team.TagUtils;
import me.skymc.taboolib.timecycle.TimeCycleManager; import me.skymc.taboolib.timecycle.TimeCycleManager;
@ -80,6 +82,8 @@ public class Main extends JavaPlugin implements Listener {
private FileConfiguration config = null; private FileConfiguration config = null;
@Getter @Getter
private static LogClient client; private static LogClient client;
@Getter
private static Language2 exampleLangauge2;
public static Random getRandom() { public static Random getRandom() {
return NumberUtils.getRand(); return NumberUtils.getRand();
@ -163,6 +167,7 @@ public class Main extends JavaPlugin implements Listener {
public void onEnable() { public void onEnable() {
// 注册指令 // 注册指令
getCommand("taboolib").setExecutor(new MainCommands()); getCommand("taboolib").setExecutor(new MainCommands());
getCommand("language2").setExecutor(new Language2Command());
// 注册监听 // 注册监听
registerListener(); registerListener();
@ -178,6 +183,8 @@ public class Main extends JavaPlugin implements Listener {
TimeCycleManager.load(); TimeCycleManager.load();
// 启动脚本 // 启动脚本
JavaShell.javaShellSetup(); JavaShell.javaShellSetup();
// 载入语言文件
exampleLangauge2 = new Language2("Language2", this);
// 启动数据库储存方法 // 启动数据库储存方法
if (getStorageType() == StorageType.SQL) { if (getStorageType() == StorageType.SQL) {

View File

@ -56,56 +56,54 @@ public class MainCommands implements CommandExecutor{
sender.sendMessage("§f"); sender.sendMessage("§f");
sender.sendMessage("§c /taboolib importdata §f- §4向数据库导入本地数据 §8(该操作将会清空数据库)"); sender.sendMessage("§c /taboolib importdata §f- §4向数据库导入本地数据 §8(该操作将会清空数据库)");
sender.sendMessage("§f"); sender.sendMessage("§f");
return false;
} }
else if (args[0].equalsIgnoreCase("itemreload") || args[0].equalsIgnoreCase("ireload")) { else if (args[0].equalsIgnoreCase("itemreload") || args[0].equalsIgnoreCase("ireload")) {
ItemUtils.reloadItemCache(); ItemUtils.reloadItemCache();
ItemUtils.reloadItemName(); ItemUtils.reloadItemName();
MsgUtils.send(sender, "重载成功"); MsgUtils.send(sender, "重载成功");
return true;
} }
else if (args[0].equalsIgnoreCase("save")) { else if (args[0].equalsIgnoreCase("save")) {
return new SaveCommand(sender, args).command(); new SaveCommand(sender, args);
} }
else if (args[0].equalsIgnoreCase("enchants")) { else if (args[0].equalsIgnoreCase("enchants")) {
return new EnchantCommand(sender, args).command(); new EnchantCommand(sender, args);
} }
else if (args[0].equalsIgnoreCase("potions")) { else if (args[0].equalsIgnoreCase("potions")) {
return new PotionCommand(sender, args).command(); new PotionCommand(sender, args);
} }
else if (args[0].equalsIgnoreCase("flags")) { else if (args[0].equalsIgnoreCase("flags")) {
return new FlagCommand(sender, args).command(); new FlagCommand(sender, args);
} }
else if (args[0].equalsIgnoreCase("attributes")) { else if (args[0].equalsIgnoreCase("attributes")) {
return new AttributesCommand(sender, args).command(); new AttributesCommand(sender, args);
} }
else if (args[0].equalsIgnoreCase("slots")) { else if (args[0].equalsIgnoreCase("slots")) {
return new SlotCommand(sender, args).command(); new SlotCommand(sender, args);
} }
else if (args[0].equalsIgnoreCase("importdata")) { else if (args[0].equalsIgnoreCase("importdata")) {
return new ImportCommand(sender, args).command(); new ImportCommand(sender, args);
} }
else if (args[0].equalsIgnoreCase("iteminfo")) { else if (args[0].equalsIgnoreCase("iteminfo")) {
return new InfoCommand(sender, args).command(); new InfoCommand(sender, args);
} }
else if (args[0].equalsIgnoreCase("itemlist")) { else if (args[0].equalsIgnoreCase("itemlist")) {
return new ItemListCommand(sender, args).command(); new ItemListCommand(sender, args);
} }
else if (args[0].equalsIgnoreCase("item") || args[0].equalsIgnoreCase("i")) { else if (args[0].equalsIgnoreCase("item") || args[0].equalsIgnoreCase("i")) {
return new ItemCommand(sender, args).command(); new ItemCommand(sender, args);
} }
else if (args[0].equalsIgnoreCase("setvariable")) { else if (args[0].equalsIgnoreCase("setvariable")) {
return new VariableSetCommand(sender, args).command(); new VariableSetCommand(sender, args);
} }
else if (args[0].equalsIgnoreCase("getvariable")) { else if (args[0].equalsIgnoreCase("getvariable")) {
return new VariableGetCommand(sender, args).command(); new VariableGetCommand(sender, args);
} }
else if (args[0].equalsIgnoreCase("shell") || args[0].equalsIgnoreCase("s")) { else if (args[0].equalsIgnoreCase("shell") || args[0].equalsIgnoreCase("s")) {
return new ShellCommand(sender, args).command(); new ShellCommand(sender, args);
} }
else { else {
MsgUtils.send(sender, "&4指令错误"); MsgUtils.send(sender, "&4指令错误");
} }
return false; return true;
} }
} }

View File

@ -0,0 +1,74 @@
package me.skymc.taboolib.commands.language;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.string.language2.Language2Value;
/**
* @author sky
* @since 2018年2月13日 下午5:11:01
*/
public class Language2Command implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (args.length == 0) {
sender.sendMessage("§f");
sender.sendMessage("§b§l----- §3§lTabooLib Commands §b§l-----");
sender.sendMessage("§f");
sender.sendMessage("§7 /language2 reload §f- §8重载语言库");
sender.sendMessage("§7 /language2 send [玩家] [语言] <变量> §f- §8发送语言提示");
sender.sendMessage("§f");
}
else if (args[0].equalsIgnoreCase("reload")) {
MsgUtils.send(sender, "§7重载中..");
long time = System.currentTimeMillis();
Main.getExampleLangauge2().reload();
MsgUtils.send(sender, "§7重载完成! 耗时: &f" + (System.currentTimeMillis() - time) + "ms");
}
else if (args[0].equalsIgnoreCase("send")) {
if (args.length < 3) {
MsgUtils.send(sender, "§4参数错误");
}
else {
// 获取玩家
Player player = Bukkit.getPlayerExact(args[1]);
if (player == null) {
MsgUtils.send(sender, "§4玩家不在线");
}
else {
// 时间
long time = System.currentTimeMillis();
// 获取语言文件
Language2Value value = Main.getExampleLangauge2().get(args[2]);
// 如果有变量参数
if (args.length > 3) {
int i = 0;
for (String variable : args[3].split("\\|")) {
value.addPlaceholder("$" + i, variable);
i++;
}
}
// 发送信息
value.send(player);
// 如果发送者是玩家
if (sender instanceof Player && ((Player) sender).getItemInHand().getType().equals(Material.COMMAND)) {
MsgUtils.send(sender, "§7信息已发送, 本次计算耗时: &f" + (System.currentTimeMillis() - time) + "ms");
}
}
}
}
return true;
}
}

View File

@ -0,0 +1,142 @@
package me.skymc.taboolib.string.language2;
import java.io.File;
import java.io.FileNotFoundException;
import org.bukkit.Bukkit;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import lombok.Getter;
import me.clip.placeholderapi.PlaceholderAPI;
import me.skymc.taboolib.fileutils.ConfigUtils;
/**
* @author sky
* @since 2018年2月13日 下午2:37:07
*/
public class Language2 {
@Getter
private FileConfiguration configuration;
@Getter
private File languageFile;
@Getter
private File languageFolder;
@Getter
private Plugin plugin;
@Getter
private String languageName;
/**
* 构造方法
*
* @param plugin 插件
*/
public Language2(Plugin plugin) {
this("zh_CN", plugin);
}
/**
* 构造方法
*
* @param languageName 语言文件
* @param plugin 插件
*/
public Language2(String languageName, Plugin plugin) {
this.languageName = languageName;
this.plugin = plugin;
// 重载语言文件
reload(languageName);
}
/**
* 获取语言文件
*
* @param key
* @return {@link Language2Value}
*/
public Language2Value get(String key) {
return new Language2Value(this, key);
}
/**
* 重载语言文件
*/
public void reload() {
reload(this.languageName);
}
/**
* 重载语言文件
*
* @param languageName 新语言文件名称
*/
public void reload(String languageName) {
// 初始化文件夹
createFolder(plugin);
// 格式化配置名
languageName = formatName(languageName);
// 获取文件
languageFile = new File(languageFolder, languageName);
// 文件不存在
if (!languageFile.exists()) {
// 如果语言文件不存在
if (plugin.getResource("Language2/" + languageName) == null) {
try {
throw new FileNotFoundException("语言文件 " + languageName + " 不存在");
}
catch (Exception e) {
// TODO: handle exception
}
}
else {
// 释放资源
plugin.saveResource("Language2/" + languageName, true);
}
}
// 载入配置
configuration = ConfigUtils.load(plugin, languageFile);
}
/**
* PlaceholderAPI 变量识别
*
* @param player 玩家
* @param string 文本
* @return String
*/
public String setPlaceholderAPI(Player player, String string) {
if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null && player != null) {
return PlaceholderAPI.setPlaceholders(player, string);
}
return string;
}
/**
* 语言文件名称格式化
*
* @param name 语言文件名称
* @return String
*/
private String formatName(String name) {
return name.contains(".yml") ? name : name + ".yml";
}
/**
* 语言文件夹初始化
*
* @param plugin
*/
private void createFolder(Plugin plugin) {
languageFolder = new File(plugin.getDataFolder(), "Language2");
if (!languageFolder.exists()) {
languageFolder.mkdir();
}
}
}

View File

@ -0,0 +1,29 @@
package me.skymc.taboolib.string.language2;
/**
* @author sky
* @since 2018年2月13日 下午3:14:00
*/
public enum Language2Type {
/**
* 一般文本
*/
TEXT,
/**
* JSON 文本
*/
JSON,
/**
* 大标题
*/
TITLE,
/**
* 小标题
*/
ACTION,
}

View File

@ -0,0 +1,227 @@
package me.skymc.taboolib.string.language2;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import lombok.Getter;
import me.skymc.taboolib.string.language2.type.Language2Action;
import me.skymc.taboolib.string.language2.type.Language2Json;
import me.skymc.taboolib.string.language2.type.Language2Title;
/**
* @author sky
* @since 2018年2月13日 下午3:05:15
*/
public class Language2Value {
@Getter
private Language2 language;
@Getter
private String languageKey;
@Getter
private List<String> languageValue;
@Getter
private Language2Type languageType;
@Getter
private LinkedHashMap<String, String> placeholder = new LinkedHashMap<>();
@Getter
private boolean enablePlaceholderAPI;
/**
* 构造方法
*/
public Language2Value(Language2 language, String languageKey) {
// 如果语言文件不存在
if (language == null || languageKey == null) {
languageValue = Arrays.asList(ChatColor.DARK_RED + "[<ERROR-0>]");
return;
}
// 如果语言文本不存在
if (!language.getConfiguration().contains(languageKey)) {
languageValue = Arrays.asList(ChatColor.DARK_RED + "[<ERROR-1: " + languageKey + ">]");
return;
}
// 如果不是集合类型
if (language.getConfiguration().get(languageKey) instanceof List) {
// 设置文本
languageValue = asColored(language.getConfiguration().getStringList(languageKey));
// 获取类型
String type = languageValue.get(0).toLowerCase();
// 判断类型
if (type.contains("[json]")) {
languageType = Language2Type.JSON;
}
else if (type.contains("[title]")) {
languageType = Language2Type.TITLE;
}
else if (type.contains("[action]")) {
languageType = Language2Type.ACTION;
}
else {
languageType = Language2Type.TEXT;
}
// 是否启用PAPI
if (type.contains("[papi]")) {
enablePlaceholderAPI = true;
}
else {
enablePlaceholderAPI = false;
}
// 删除类型
languageValue.remove(0);
}
else {
// 设置文本
languageValue = Arrays.asList(ChatColor.translateAlternateColorCodes('&', language.getConfiguration().getString(languageKey)));
// 设置类型
languageType = Language2Type.TEXT;
}
// 初始化变量
this.language = language;
this.languageKey = languageKey;
}
/**
* 向玩家发送信息
*
* @param player
*/
public void send(Player player) {
// 标题类型
if (languageType == Language2Type.TITLE) {
// 识别文本
Language2Title title = new Language2Title(this);
// 发送文本
title.send(player);
}
// 动作栏类型
else if (languageType == Language2Type.ACTION) {
// 识别文本
Language2Action action = new Language2Action(this);
// 发送文本
action.send(player);
}
// JSON类型
else if (languageType == Language2Type.JSON) {
// 识别文本
Language2Json json = new Language2Json(this, player);
// 发送文本
json.send(player);
}
else {
// 遍历文本
for (String message : languageValue) {
// 发送信息
if (player != null) {
player.sendMessage(setPlaceholder(message, player));
}
else {
Bukkit.getConsoleSender().sendMessage(setPlaceholder(message, player));
}
}
}
}
/**
* 向玩家发送信息
*
* @param players 玩家
*/
public void send(List<Player> players) {
// 标题类型
if (languageType == Language2Type.TITLE) {
// 识别文本
Language2Title title = new Language2Title(this);
// 发送文本
players.forEach(x -> title.send(x));
}
// 动作栏类型
else if (languageType == Language2Type.ACTION) {
// 识别文本
Language2Action action = new Language2Action(this);
// 发送文本
players.forEach(x -> action.send(x));
}
// JSON类型
else if (languageType == Language2Type.JSON) {
for (Player player : players) {
// 识别文本
Language2Json json = new Language2Json(this, player);
// 发送文本
json.send(player);
}
}
else {
for (Player player : players) {
// 遍历文本
for (String message : languageValue) {
// 发送信息
if (player != null) {
player.sendMessage(setPlaceholder(message, player));
}
else {
Bukkit.getConsoleSender().sendMessage(setPlaceholder(message, player));
}
}
}
}
}
/**
* 变量替换
*
* @param value 替换文本
* @param player 检测玩家
* @return String
*/
public String setPlaceholder(String value, Player player) {
for (Entry<String, String> entry : placeholder.entrySet()) {
value = value.replace(entry.getKey(), entry.getValue());
}
return isEnablePlaceholderAPI() ? this.language.setPlaceholderAPI(player, value) : value;
}
/**
* 变量替换构造
*
* @param key
* @param value
* @return {@link Language2Value}
*/
public Language2Value addPlaceholder(String key, String value) {
this.placeholder.put(key, value);
return this;
}
/**
* 替换颜色
*
* @param list
* @return
*/
public List<String> asColored(List<String> list) {
for (int i = 0 ; i < list.size() ; i++) {
list.set(i, ChatColor.translateAlternateColorCodes('&', list.get(i)));
}
return list;
}
}

View File

@ -0,0 +1,93 @@
package me.skymc.taboolib.string.language2.type;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
import lombok.Getter;
import me.skymc.taboolib.Main;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.display.ActionUtils;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.other.NumberUtils;
import me.skymc.taboolib.string.language2.Language2Value;
/**
* @author sky
* @since 2018年2月13日 下午3:58:07
*/
public class Language2Action {
private static final String KEY_TEXT = " text: ";
private static final String KEY_STAY = " repeat: ";
@Getter
private String text = "";
@Getter
private int repeat = 1;
@Getter
private Language2Value value;
public Language2Action(Language2Value value) {
// 变量初始化
this.value = value;
// 遍历文本
for (String message : value.getLanguageValue()) {
try {
// 动作栏提示
if (message.startsWith(KEY_TEXT)) {
text = message.substring(KEY_TEXT.length());
}
// 持续时间
if (message.startsWith(KEY_STAY)) {
repeat = NumberUtils.getInteger(message.substring(KEY_STAY.length()));
}
}
catch (Exception e) {
// 识别异常
text = ChatColor.DARK_RED + "[<ERROR-11: " + value.getLanguageKey() + ">]";
}
}
// 检查重复次数
if (repeat < 0) {
repeat = 1;
text = ChatColor.DARK_RED + "[<ERROR-12: " + value.getLanguageKey() + ">]";
}
}
/**
* 发送给玩家
*
* @param player 玩家
*/
public void send(Player player) {
// 检查版本
if (TabooLib.getVerint() < 10800) {
player.sendMessage(ChatColor.DARK_RED + "[<ERROR-30: " + value.getLanguageKey() + ">]");
}
// 检查玩家
else if (player != null) {
new BukkitRunnable() {
int times = 0;
@Override
public void run() {
ActionUtils.send(player, value.setPlaceholder(text, player));
if ((times += 1) >= repeat) {
cancel();
}
}
}.runTaskTimer(Main.getInst(), 0, 20);
}
else {
Bukkit.getConsoleSender().sendMessage(value.setPlaceholder(text, player));
}
}
}

View File

@ -0,0 +1,142 @@
package me.skymc.taboolib.string.language2.type;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import lombok.Getter;
import me.skymc.taboolib.jsonformatter.JSONFormatter;
import me.skymc.taboolib.jsonformatter.click.ClickEvent;
import me.skymc.taboolib.jsonformatter.click.RunCommandEvent;
import me.skymc.taboolib.jsonformatter.click.SuggestCommandEvent;
import me.skymc.taboolib.jsonformatter.hover.HoverEvent;
import me.skymc.taboolib.jsonformatter.hover.ShowTextEvent;
import me.skymc.taboolib.string.language2.Language2Value;
/**
* @author sky
* @since 2018年2月13日 下午4:11:33
*/
public class Language2Json {
private static final String KEY_TEXT = " text: ";
private static final String KEY_COMMAND = " command: ";
private static final String KEY_SUGGEST = " suggest: ";
@Getter
private Player player;
@Getter
private Language2Value value;
@Getter
private JSONFormatter json = new JSONFormatter();
@Getter
private StringBuffer text = new StringBuffer();
public Language2Json(Language2Value value, Player player) {
// 文本初始化
String current = ChatColor.DARK_RED + "[<ERROR-20: " + value.getLanguageKey() + ">]";
// 首次检测
boolean isFirst = true;
boolean isBreak = false;
// 变量初始化
this.value = value;
this.player = player;
// 动作初始化
ClickEvent clickEvent = null;
HoverEvent hoverEvent = null;
// 遍历文本
for (String message : value.getLanguageValue()) {
try {
// 如果是显示文本
if (message.startsWith(KEY_TEXT)) {
hoverEvent = new ShowTextEvent(message.replace("||", "\n").substring(KEY_TEXT.length()));
}
// 执行指令
else if (message.startsWith(KEY_COMMAND)) {
clickEvent = new RunCommandEvent(message.substring(KEY_COMMAND.length()));
}
// 打印指令
else if (message.startsWith(KEY_SUGGEST)) {
clickEvent = new SuggestCommandEvent(message.substring(KEY_SUGGEST.length()));
}
// 换行
else if (message.equals("[break]")) {
append(current, clickEvent, hoverEvent);
// 删除动作
clickEvent = null;
hoverEvent = null;
// 换行
json.newLine();
// 标记
isBreak = true;
}
// 新内容
else {
if (!isFirst && !isBreak) {
append(current, clickEvent, hoverEvent);
// 删除动作
clickEvent = null;
hoverEvent = null;
}
// 更新
current = message;
// 标记
isFirst = false;
isBreak = false;
}
}
catch (Exception e) {
// 识别异常
json.append(ChatColor.DARK_RED + "[<ERROR-21: " + value.getLanguageKey() + ">]");
}
}
// 追加
append(current, clickEvent, hoverEvent);
}
/**
* 发送给玩家
*
* @param player 玩家
*/
public void send(Player player) {
if (player != null) {
json.send(player);
}
else {
Bukkit.getConsoleSender().sendMessage(text.toString());
}
}
/**
* 追加 JSON 内容
*
* @param current 文本
* @param clickevent 点击动作
* @param hoverEvent 显示动作
*/
private void append(String current, ClickEvent clickEvent, HoverEvent hoverEvent) {
if (clickEvent == null && hoverEvent == null) {
// 纯文本
json.append(value.setPlaceholder(current, player));
} else if (clickEvent != null && hoverEvent == null) {
// 纯点击
json.appendClick(value.setPlaceholder(current, player), clickEvent);
} else if (clickEvent == null && hoverEvent != null) {
// 纯显示
json.appendHover(value.setPlaceholder(current, player), hoverEvent);
} else {
// 全部
json.appendHoverClick(value.setPlaceholder(current, player), hoverEvent, clickEvent);
}
// 追加显示文本
text.append(current);
}
}

View File

@ -0,0 +1,93 @@
package me.skymc.taboolib.string.language2.type;
import java.util.Collection;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import lombok.Getter;
import me.skymc.taboolib.TabooLib;
import me.skymc.taboolib.display.TitleUtils;
import me.skymc.taboolib.message.MsgUtils;
import me.skymc.taboolib.string.language2.Language2Value;
/**
* @author sky
* @since 2018年2月13日 下午3:58:07
*/
public class Language2Title {
private static final String KEY_TITLE = " title: ";
private static final String KEY_SUBTITLE = " subtitle: ";
private static final String KEY_STAYRULE = " stay: ";
@Getter
private String title = "";
@Getter
private String subtitle = "";
@Getter
private int fade1 = 0;
@Getter
private int fade2 = 0;
@Getter
private int stay = 20;
@Getter
private Language2Value value;
public Language2Title(Language2Value value) {
// 变量初始化
this.value = value;
// 遍历文本
for (String message : value.getLanguageValue()) {
try {
// 大标题
if (message.startsWith(KEY_TITLE)) {
title = message.substring(KEY_TITLE.length());
}
// 小标题
else if (message.startsWith(KEY_SUBTITLE)) {
subtitle = message.substring(KEY_SUBTITLE.length());
}
// 持续时间
else if (message.startsWith(KEY_STAYRULE)) {
String rule = message.substring(KEY_STAYRULE.length());
fade1 = Integer.valueOf(rule.split("\\|")[0]);
stay = Integer.valueOf(rule.split("\\|")[1]);
fade2 = Integer.valueOf(rule.split("\\|")[2]);
}
}
catch (Exception e) {
// 识别异常
title = ChatColor.DARK_RED + "[<ERROR-10: " + value.getLanguageKey() + ">]";
subtitle = ChatColor.DARK_RED + "[<ERROR-10: " + value.getLanguageKey() + ">]";
}
}
}
/**
* 发送给玩家
*
* @param player 玩家
*/
public void send(Player player) {
// 检查版本
if (TabooLib.getVerint() < 10800) {
player.sendMessage(ChatColor.DARK_RED + "[<ERROR-31: " + value.getLanguageKey() + ">]");
}
// 检查玩家
else if (player != null) {
TitleUtils.sendTitle(player, value.setPlaceholder(title, player), value.setPlaceholder(subtitle, player), fade1, stay, fade2);
}
else {
Bukkit.getConsoleSender().sendMessage(value.setPlaceholder(title, player) + ", " + value.setPlaceholder(subtitle, player));
}
}
}

View File

@ -0,0 +1,66 @@
# UTF-8
# 错误代码:
# 0语言文件不存在
# 1语言文本不存在
# 10: 大标题语言类型识别异常
# 11: 动作栏语言类型识别异常
# 12: 动作栏重复次数异常
# 20: JSON 空文本异常
# 21: JSON 语言类型识别异常
# 30: 大标题不兼容当前版本服务器
# 31: 动作栏不兼容当前版本服务器
# 正常提示
TEXT: '&f正常的提示'
# JSON提示 + 占位符
# 占位符注释可以追加到任何类型之后
PAPI-TEXT:
- '[json][papi]'
- '&f变量提示, 玩家名称: %player_name%'
# JSON提示
JSON-NORMAL-TEXT:
- '[json]'
- '提示信息 - 1'
- ' text: 这是一个一般提示'
# JSON提示
JSON-COMMAND-TEXT:
- '[json]'
- '提示信息 - 2'
- ' text: 点击执行指令'
- ' command: /say %player% 牛逼'
# JSON提示
JSON-SUGGEST-TEXT:
- '[json]'
- '提示信息 - 3'
- ' text: 点击打印指令'
- ' suggest: /say %player% 牛逼'
# JSON提示
# [breka] 注释为 JSON 提示类型中的换行符
JSON-MULTILINE-TEXT:
- '[json]'
- '提示信息 - 4'
- ' text: 这是一段换行提示1'
- '&a (单行追加内容)'
- '[break]'
- '提示信息 - 6'
- ' text: 这是一段换行提示3'
- '&a (单行追加内容)'
# 大标题提示
TITLE-TEXT:
- '[title]'
- ' title: 大标题'
- ' subtitle: 小标题'
- ' stay: 10|40|10'
# 动作栏提示
ACTION-TEXT:
- '[action]'
- ' text: 动作栏提示'
- ' repeat: 10'

View File

@ -12,6 +12,9 @@ commands:
taboolib: taboolib:
aliases: [tlib] aliases: [tlib]
permission: taboolib.admin permission: taboolib.admin
language2:
aliases: [lang2]
permission: taboolib.admin
loadbefore: [Vault] loadbefore: [Vault]
soft-depend: [PlaceholderAPI] soft-depend: [PlaceholderAPI]