1
mirror of https://github.com/CarmJos/UserPrefix.git synced 2026-07-16 08:51:09 +08:00

多语言支持

This commit is contained in:
carm
2021-09-17 19:10:23 +08:00
parent 3dd6398afa
commit 43a4fb08a6
9 changed files with 201 additions and 15 deletions
@@ -1,5 +1,6 @@
package cc.carm.plugin.userprefix.command;
import cc.carm.plugin.userprefix.configuration.PrefixConfig;
import cc.carm.plugin.userprefix.manager.ConfigManager;
import cc.carm.plugin.userprefix.manager.PrefixManager;
import cc.carm.plugin.userprefix.manager.UserManager;
@@ -21,11 +22,21 @@ public class UserPrefixAdminCommand implements CommandExecutor {
if (args.length == 1) {
String aim = args[0];
if (aim.equalsIgnoreCase("list")) {
MessageUtil.send(sender, "&3&l用户前缀系统 &f前缀列表");
MessageUtil.sendWithPlaceholders(sender, PrefixConfig.Messages.LIST_TITLE.get());
for (ConfiguredPrefix value : PrefixManager.getPrefixes().values()) {
MessageUtil.send(sender, "&8#" + value.getWeight() + " &f" + value.getIdentifier());
MessageUtil.send(sender, "&8- &7显示名 &r" + value.getName() + (value.isPublic() ? "" : " &7权限&r " + value.getPermission()));
MessageUtil.send(sender, "&8- &7内容示例&r " + value.getContent() + sender.getName());
MessageUtil.sendWithPlaceholders(
sender, PrefixConfig.Messages.LIST_VALUE.get(),
new String[]{
"%(weight)", "%(identifier)",
"%(name)", "%(permission)",
"%(content)", "%(sender_name)"
},
new Object[]{
value.getWeight(), value.getIdentifier(),
value.getName(), value.getPermission(),
value.getContent(), sender.getName()
}
);
}
return true;
} else if (aim.equalsIgnoreCase("reload")) {
@@ -42,7 +53,10 @@ public class UserPrefixAdminCommand implements CommandExecutor {
*/
UserManager.updatePrefixView(onlinePlayer, false);
}
MessageUtil.send(sender, "&a&l重载完成!&7共耗时 &f" + (System.currentTimeMillis() - s1) + " ms&7。");
MessageUtil.sendWithPlaceholders(
sender, PrefixConfig.Messages.RELOAD.get(),
new String[]{"%(time)"}, new Object[]{(System.currentTimeMillis() - s1)}
);
return true;
}
return help(sender);
@@ -51,11 +65,7 @@ public class UserPrefixAdminCommand implements CommandExecutor {
}
public static boolean help(CommandSender sender) {
MessageUtil.send(sender, "&3&l用户前缀系统 &f帮助");
MessageUtil.send(sender, "&8#&f list");
MessageUtil.send(sender, "&8- &7查看当前前缀列表。");
MessageUtil.send(sender, "&8#&f reload");
MessageUtil.send(sender, "&8- &7重载前缀配置。");
MessageUtil.send(sender, PrefixConfig.Messages.HELP.get());
return true;
}
@@ -26,7 +26,11 @@ public class PrefixConfig {
public static ConfigValueList<String> SELECTED = new ConfigValueList<>("messages.selected", String.class);
public static ConfigValueList<String> EXPIRED = new ConfigValueList<>("messages.expired", String.class);
public static ConfigValueList<String> RELOAD = new ConfigValueList<>("messages.reload", String.class);
public static ConfigValueList<String> HELP = new ConfigValueList<>("messages.help", String.class);
public static ConfigValueList<String> LIST_TITLE = new ConfigValueList<>("messages.list-title", String.class);
public static ConfigValueList<String> LIST_VALUE = new ConfigValueList<>("messages.list-value", String.class);
}
public static class Sounds {
@@ -42,7 +42,7 @@ public class PrefixManager {
ConfigurationSection configuredPrefixSection = prefixesSection.getConfigurationSection(prefixIdentifier);
if (configuredPrefixSection == null) continue;
try {
String name = configuredPrefixSection.getString("name", "前缀名配置错误");
String name = configuredPrefixSection.getString("name", "ERROR");
String content = configuredPrefixSection.getString("content", "&r");
String permission = configuredPrefixSection.getString("permission");
int weight = configuredPrefixSection.getInt("weight", 1);
@@ -58,7 +58,7 @@ public class PrefixManager {
dataPrefixes.put(prefixIdentifier, new ConfiguredPrefix(prefixIdentifier, name, content, weight, permission, itemHasPermission, itemNoPermission, itemUsing));
} catch (Exception exception) {
Main.log("在加载前缀 " + prefixIdentifier + " 时出错,请检查配置!");
Main.log("Error occurred when loading prefix #" + prefixIdentifier + " !");
exception.printStackTrace();
}
}
@@ -28,6 +28,7 @@ public class MessageUtil {
}
public static void sendWithPlaceholders(CommandSender sender, List<String> messages) {
if (messages == null || messages.isEmpty()) return;
if (hasPlaceholderAPI() && sender instanceof Player) {
send(sender, PlaceholderAPI.setPlaceholders((Player) sender, messages));
} else {