1
mirror of https://github.com/CarmJos/UserPrefix.git synced 2024-09-19 20:15:47 +00: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

View File

@ -95,13 +95,19 @@ type `/papi info UserPrefix` to see all the placeholders.
- Determine whether the player has a certain prefix(true/false)
```
## Sample configuration file
## Sample [configuration file](https://github.com/CarmJos/UserPrefix/blob/master/src/main/resources/config-en.yml)
Notice: The default configuration is based on Chinese.
You can find the [English Version here](https://github.com/CarmJos/UserPrefix/blob/master/src/main/resources/config-en.yml).
```yaml
version: 1.0.0-SNAPSHOT # DO NOT EDIT IT
debug: false #DEBUG OUT PUT
GUI:
title: "&f&lMy Prefixes List" # Title of the GUI
functions:
# Whether to add a prefix to the top of the head,
# this method uses the scoreboard above the head,
@ -118,6 +124,20 @@ messages:
expired:
- "&7Your prefix &f%(oldName) &7has expired,"
- "&7Now the prefix is changed to &f%(newName) &7."
reload:
- "&a&lReload completed&7costs &f%(time)ms&7."
help:
- "&3&lUserPrefixAdmin &fHelp"
- "&8#/upa&f list"
- "&8- &7Show configured prefixes."
- "&8#/upa&f reload"
- "&8- &7Reload configuration."
list-title:
- "&3&lUserPrefixAdmin &fList"
list-value:
- "&8#%(weight) &f%(identifier)"
- "&8- &7Name &r%(name) &7Perm &r%(permission)"
- "&8- &7Example&r %(content) %(sender_name)"
Sounds:
# Format is [SOUND_NAME:Volume:Pitch] or [SOUND_NAME:Volume] or [SOUND_NAME]

View File

@ -90,7 +90,7 @@ The English version of the introduction is [here](https://github.com/CarmJos/Use
- 判断玩家是否拥有某个前缀(true/false)
```
## 配置文件示例
## [配置文件](https://github.com/CarmJos/UserPrefix/blob/master/src/main/resources/config.yml)示例
```yaml
version: 1.0.0-SNAPSHOT # 配置文件版本,一般不会动。
@ -101,12 +101,29 @@ functions:
OnNamePrefix: true # 是否给头顶上添加前缀,该方法用到了头顶的那个计分板,如有冲突请关掉哦~
autoUsePrefix: true # 自动前缀显示 当玩家没有自己选择一个前缀的时候,会自动使用所拥有的的前缀中权重最高的那一个
GUI:
title: "&f&l我的前缀 &8| 列表"
messages:
selected:
- "&7您选择了 &f%(name) &7作为当前显示的前缀。"
expired:
- "&7您先前使用的前缀 &f%(oldName) &7已到期。"
- "&7现在已为您重新调整为 &f%(newName) &7。"
reload:
- "&a&l重载完成&7共耗时 &f%(time)ms&7。"
help:
- "&3&l用户前缀系统 &f帮助"
- "&8#/upa&f list"
- "&8- &7查看当前前缀列表。"
- "&8#/upa&f reload"
- "&8- &7重载前缀配置。"
list-title:
- "&3&l用户前缀系统 &f前缀列表"
list-value:
- "&8#%(weight) &f%(identifier)"
- "&8- &7显示名 &r%(name) &7权限 &r%(permission)"
- "&8- &7内容示例&r %(content) %(sender_name)"
Sounds: #相关的声音,注释掉则不播放声音
# 格式为 【声音名:音量:音调】 或 【声音名:音量】 或 【声音名】

View File

@ -6,7 +6,7 @@
<groupId>cc.carm.plugin</groupId>
<artifactId>UserPrefix</artifactId>
<version>1.2.4</version>
<version>1.2.5</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@ -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;
}

View File

@ -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 {

View File

@ -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();
}
}

View File

@ -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 {

View File

@ -0,0 +1,120 @@
version: ${project.version} # DO NOT EDIT IT
debug: false #DEBUG OUT PUT
GUI:
title: "&f&lMy Prefixes List" # Title of the GUI
functions:
# Whether to add a prefix to the top of the head,
# this method uses the scoreboard above the head,
# please turn it off if there is a conflict.
OnNamePrefix: true
# Automatic prefix select.
# When the player does not choose a prefix by himself,
# the prefix with the highest weight will be used automatically
autoUsePrefix: true
messages:
selected:
- "&7You have selected the &f%(name) &7as current prefix."
expired:
- "&7Your prefix &f%(oldName) &7has expired,"
- "&7Now the prefix is changed to &f%(newName) &7."
reload:
- "&a&lReload completed&7costs &f%(time)ms&7."
help:
- "&3&lUserPrefixAdmin &fHelp"
- "&8#/upa&f list"
- "&8- &7Show configured prefixes."
- "&8#/upa&f reload"
- "&8- &7Reload configuration."
list-title:
- "&3&lUserPrefixAdmin &fList"
list-value:
- "&8#%(weight) &f%(identifier)"
- "&8- &7Name &r%(name) &7Perm &r%(permission)"
- "&8- &7Example&r %(content) %(sender_name)"
Sounds:
# Format is [SOUND_NAME:Volume:Pitch] or [SOUND_NAME:Volume] or [SOUND_NAME]
openGUI: "BLOCK_NOTE_BLOCK_PLING:1:1"
guiClick: "UI_BUTTON_CLICK"
prefixChange: "ENTITY_VILLAGER_YES"
prefixExpired: "ENTITY_VILLAGER_NO"
# The default prefix's weight is 0.
defaultPrefix:
name: "Default prefix"
content: "&b"
itemNotUsing:
==: org.bukkit.inventory.ItemStack
type: NAME_TAG
meta:
==: ItemMeta
meta-type: UNSPECIFIC
display-name: "§fThe default prefix §f(Click to select)"
lore:
- ""
- "§a➥ Click to use"
itemUsing:
==: org.bukkit.inventory.ItemStack
type: NAME_TAG
meta:
==: ItemMeta
meta-type: UNSPECIFIC
display-name: "§fThe default prefix"
lore:
- ""
- "§a✔ Selected"
prefixes:
VIP:
name: "&b&lPro&b" # [Necessary] Name (Using in messages)
content: "§b§lPro §b" # [Necessary] What to display before the name
# [Necessary] Weight, used for sorting in the GUI
# (the larger is displayed at the back) and the automatic prefix display
weight: 1
# [Necessary] If there is no permission for detection, everyone can use it,
# which means there is no need to configure "itemNoPermission"
# (because it is impossible to display items without permission at all)
permission: "yc.pro"
itemHasPermission:
# [Necessary] This Item will be displayed when player has permission
==: org.bukkit.inventory.ItemStack
type: DIAMOND
meta:
==: ItemMeta
meta-type: UNSPECIFIC
display-name: "§b§lVIP Prefix"
lore:
- ""
- "§a➥ Click to use"
itemUsing:
# [Not Necessary] This Item will be displayed when the prefix is selected.
# If there is no such configuration, it will automatically display "itemHasPermission".
==: org.bukkit.inventory.ItemStack
type: DIAMOND
meta:
==: ItemMeta
meta-type: UNSPECIFIC
display-name: "§b§lVIP Prefix"
enchants:
PROTECTION_ENVIRONMENTAL: 1 #Add an enchantment so it looks like its selected
lore:
- ""
- "§a✔ Selected"
itemNoPermission:
# [Not Necessary] If player doesn't have the permission,this item will be displayed.
# If this item is not configured, it will not be displayed in the GUI when the player does not have permission to use it.
==: org.bukkit.inventory.ItemStack
type: INK_SACK
damage: 8
meta:
==: ItemMeta
meta-type: UNSPECIFIC
display-name: "§b§lVIP §c(Buy it!)"
lore:
- ""
- "§e✯ Buy the VIP to use it!"

View File

@ -15,6 +15,20 @@ messages:
expired:
- "&7您先前使用的前缀 &f%(oldName) &7已到期。"
- "&7现在已为您重新调整为 &f%(newName) &7。"
reload:
- "&a&l重载完成&7共耗时 &f%(time)ms&7。"
help:
- "&3&l用户前缀系统 &f帮助"
- "&8#/upa&f list"
- "&8- &7查看当前前缀列表。"
- "&8#/upa&f reload"
- "&8- &7重载前缀配置。"
list-title:
- "&3&l用户前缀系统 &f前缀列表"
list-value:
- "&8#%(weight) &f%(identifier)"
- "&8- &7显示名 &r%(name) &7权限 &r%(permission)"
- "&8- &7内容示例&r %(content) %(sender_name)"
Sounds: #相关的声音,注释掉则不播放声音 格式为 【声音名:音量:音调】 或 【声音名:音量】 或 【声音名】
openGUI: "BLOCK_NOTE_BLOCK_PLING:1:1"