From 43a4fb08a6c068239f0d2d8a35e4f27916f98566 Mon Sep 17 00:00:00 2001 From: carm Date: Fri, 17 Sep 2021 19:10:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E8=AF=AD=E8=A8=80=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-en.md | 22 +++- README.md | 19 ++- pom.xml | 2 +- .../command/UserPrefixAdminCommand.java | 30 +++-- .../configuration/PrefixConfig.java | 4 + .../userprefix/manager/PrefixManager.java | 4 +- .../plugin/userprefix/util/MessageUtil.java | 1 + src/main/resources/config-en.yml | 120 ++++++++++++++++++ src/main/resources/config.yml | 14 ++ 9 files changed, 201 insertions(+), 15 deletions(-) create mode 100644 src/main/resources/config-en.yml diff --git a/README-en.md b/README-en.md index 3c4b2d8..83bae6d 100644 --- a/README-en.md +++ b/README-en.md @@ -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] diff --git a/README.md b/README.md index 7266643..3522ffe 100644 --- a/README.md +++ b/README.md @@ -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: #相关的声音,注释掉则不播放声音 # 格式为 【声音名:音量:音调】 或 【声音名:音量】 或 【声音名】 diff --git a/pom.xml b/pom.xml index 9bbec78..33281fb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ cc.carm.plugin UserPrefix - 1.2.4 + 1.2.5 8 diff --git a/src/main/java/cc/carm/plugin/userprefix/command/UserPrefixAdminCommand.java b/src/main/java/cc/carm/plugin/userprefix/command/UserPrefixAdminCommand.java index 3f61ca8..ac092f7 100644 --- a/src/main/java/cc/carm/plugin/userprefix/command/UserPrefixAdminCommand.java +++ b/src/main/java/cc/carm/plugin/userprefix/command/UserPrefixAdminCommand.java @@ -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; } diff --git a/src/main/java/cc/carm/plugin/userprefix/configuration/PrefixConfig.java b/src/main/java/cc/carm/plugin/userprefix/configuration/PrefixConfig.java index b711f5a..7052a8b 100644 --- a/src/main/java/cc/carm/plugin/userprefix/configuration/PrefixConfig.java +++ b/src/main/java/cc/carm/plugin/userprefix/configuration/PrefixConfig.java @@ -26,7 +26,11 @@ public class PrefixConfig { public static ConfigValueList SELECTED = new ConfigValueList<>("messages.selected", String.class); public static ConfigValueList EXPIRED = new ConfigValueList<>("messages.expired", String.class); + public static ConfigValueList RELOAD = new ConfigValueList<>("messages.reload", String.class); + public static ConfigValueList HELP = new ConfigValueList<>("messages.help", String.class); + public static ConfigValueList LIST_TITLE = new ConfigValueList<>("messages.list-title", String.class); + public static ConfigValueList LIST_VALUE = new ConfigValueList<>("messages.list-value", String.class); } public static class Sounds { diff --git a/src/main/java/cc/carm/plugin/userprefix/manager/PrefixManager.java b/src/main/java/cc/carm/plugin/userprefix/manager/PrefixManager.java index 0a70f1d..7aab37d 100644 --- a/src/main/java/cc/carm/plugin/userprefix/manager/PrefixManager.java +++ b/src/main/java/cc/carm/plugin/userprefix/manager/PrefixManager.java @@ -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(); } } diff --git a/src/main/java/cc/carm/plugin/userprefix/util/MessageUtil.java b/src/main/java/cc/carm/plugin/userprefix/util/MessageUtil.java index 8de2d23..fe6f0ea 100644 --- a/src/main/java/cc/carm/plugin/userprefix/util/MessageUtil.java +++ b/src/main/java/cc/carm/plugin/userprefix/util/MessageUtil.java @@ -28,6 +28,7 @@ public class MessageUtil { } public static void sendWithPlaceholders(CommandSender sender, List messages) { + if (messages == null || messages.isEmpty()) return; if (hasPlaceholderAPI() && sender instanceof Player) { send(sender, PlaceholderAPI.setPlaceholders((Player) sender, messages)); } else { diff --git a/src/main/resources/config-en.yml b/src/main/resources/config-en.yml new file mode 100644 index 0000000..13d724a --- /dev/null +++ b/src/main/resources/config-en.yml @@ -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 it’s 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!" \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0aad95e..f45eff7 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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"