1
mirror of https://github.com/CarmJos/UserPrefix.git synced 2026-06-05 00:35:02 +08:00

Compare commits

...

21 Commits

Author SHA1 Message Date
carm 675bbe4cf2 chore(deps): 升级依赖版本 2024-09-26 22:40:43 +08:00
carm 3b8fd6febf chore(deps): 升级依赖版本 2024-09-26 22:35:24 +08:00
carm d8282b9641 chore(deps): 升级依赖版本 2024-09-26 21:46:20 +08:00
carm ad616e5470 chore(deps): 支持1.21版本 2024-07-20 19:17:56 +08:00
carm f741723204 chore(deps): 更新 XSeries 尝试解决 #51 2024-07-17 06:40:34 +08:00
carm 54f526300a chore(deps): 更新 XSeries 尝试解决 #51 2024-07-17 06:35:53 +08:00
carm 5a0e5b8e96 chore(deps): 更新 XSeries 尝试解决 #51 2024-07-17 06:35:44 +08:00
skylandnewmc c89a9c6ccc Update ejemplo-prefijo.yml (#49) 2023-12-21 15:06:02 +08:00
skylandnewmc e321a1ec66 Update ejemplo-prefijo.yml (#48) 2023-11-06 00:41:40 +08:00
carm 9054161135 fix(msg): 修复消息占位符顺序错误 #47 2023-10-23 13:00:59 +08:00
carm 53281b80e3 chore(item): 更换物品的配置逻辑,支持跨版本的物品读取、保存。
BREAKING-CHANGE: 旧的配置文件需要进行变更。
2023-10-12 20:15:30 +08:00
carm 12489fe1a8 chore(item): 更换物品的配置逻辑,支持跨版本的物品读取、保存。
BREAKING-CHANGE: 旧的配置文件需要进行变更。
2023-10-12 20:09:24 +08:00
carm 7d62f68662 chore(item): 更换物品的配置逻辑,支持跨版本的物品读取、保存。
BREAKING-CHANGE: 旧的配置文件需要进行变更。
2023-10-10 15:20:40 +08:00
carm 4cc50c21d5 chore(item): 更换物品的配置逻辑,支持跨版本的物品读取、保存。
BREAKING-CHANGE: 旧的配置文件需要进行变更。
2023-10-10 15:01:51 +08:00
skylandnewmc 0d25490d0f feat(i18n): example-prefix.yml translated to Spanish 2023-09-28 12:57:12 +08:00
carm a805aba42e fix(auto): 修复自动前缀判断错误的问题 2023-09-21 22:26:21 +08:00
Snowball_233 2a0d6b8582 fix(papi): 添加“持久”标签 避免卸载。
Co-authored-by: Carm <KarmunJ@outlook.com>
2023-07-16 23:22:18 +08:00
carm 1ea993a31b feat(gui): 支持配置更多GUI按钮。(#44) 2023-02-23 22:27:22 +08:00
carm 8ce82ec7fd chore(expansion): 适配新版EasyPlugin提供的解析器 2023-02-19 04:19:51 +08:00
carm 6fb9daa3d3 docs(donate): Thanks for Jetbrains! 2023-02-15 00:33:08 +08:00
carm da23eaa8fe fix(placeholder): 修复PlaceholderAPI重载后变量失效的问题 2023-02-01 15:32:08 +08:00
16 changed files with 313 additions and 166 deletions
+2 -1
View File
@@ -37,7 +37,8 @@ jobs:
cp -vrf asset/*.jar artifacts
- name: "Upload artifact"
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Artifact
path: artifacts
include-hidden-files: true
+5 -4
View File
@@ -117,11 +117,10 @@ README LANGUAGES [ [**中文**](README.md) | [English](README-en.md) ]
本项目由 [YourCraft(你的世界)](https://www.ycraft.cn) 团队提供长期支持与维护。
![TeamLogo](.documentation/images/team-logo.png)
若您觉得本插件做的不错,您可以捐赠支持我!
若您觉得本插件做的不错,您可以捐赠支持我!感谢您成为开源项目的支持者!
感谢您成为开源项目的支持者!
<img height=25% width=25% src="https://raw.githubusercontent.com/CarmJos/CarmJos/main/img/donate-code.jpg" alt=""/>
Many thanks to Jetbrains for kindly providing a license for me to work on this and other open-source projects.
[![](https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.svg)](https://www.jetbrains.com/?from=https://github.com/CarmJos/UserPrefix)
## 开源协议
@@ -146,3 +145,5 @@ README LANGUAGES [ [**中文**](README.md) | [English](README-en.md) ]
>
> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。*
</details>
## Project supported by JetBrains
+53 -9
View File
@@ -13,13 +13,13 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<easyplugin.version>1.4.18</easyplugin.version>
<mineconfig.version>2.3.0</mineconfig.version>
<deps.easyplugin.version>1.5.8</deps.easyplugin.version>
<deps.mineconfig.version>2.8.6</deps.mineconfig.version>
</properties>
<groupId>cc.carm.plugin</groupId>
<artifactId>userprefix</artifactId>
<version>3.1.1</version>
<version>3.2.5</version>
<name>UserPrefix</name>
<description>轻便、高效、实时的用户前缀系统。</description>
@@ -81,6 +81,12 @@
<url>https://repo.lucko.me/</url>
</repository>
<repository>
<id>minecraft-libraries</id>
<name>Minecraft Libraries</name>
<url>https://libraries.minecraft.net/</url>
</repository>
<repository>
<id>EasyPlugin</id>
<url>https://raw.githubusercontent.com/CarmJos/EasyPlugin/repo/</url>
@@ -108,7 +114,7 @@
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-main</artifactId>
<version>${easyplugin.version}</version>
<version>${deps.easyplugin.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
@@ -116,7 +122,7 @@
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-command</artifactId>
<version>${easyplugin.version}</version>
<version>${deps.easyplugin.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
@@ -124,15 +130,24 @@
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-gui</artifactId>
<version>${easyplugin.version}</version>
<version>${deps.easyplugin.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<!--suppress VulnerableLibrariesLocal -->
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-githubchecker</artifactId>
<version>${deps.easyplugin.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>easyplugin-githubchecker</artifactId>
<version>${easyplugin.version}</version>
<artifactId>easyplugin-placeholderapi</artifactId>
<version>${deps.easyplugin.version}</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
@@ -140,9 +155,34 @@
<dependency>
<groupId>cc.carm.lib</groupId>
<artifactId>mineconfiguration-bukkit</artifactId>
<version>${mineconfig.version}</version>
<version>${deps.mineconfig.version}</version>
<scope>compile</scope>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>com.cryptomorin.xseries</groupId>
<artifactId>XSeries</artifactId>
</exclusion>
<exclusion>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.cryptomorin</groupId>
<artifactId>XSeries</artifactId>
<version>v11.2.2</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>6.0.54</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -272,6 +312,10 @@
<pattern>org.json</pattern>
<shadedPattern>${project.package}.lib.json</shadedPattern>
</relocation>
<relocation>
<pattern>com.cryptomorin.xseries</pattern>
<shadedPattern>${project.package}.lib.xseries</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
@@ -61,12 +61,12 @@ public class Main extends EasyPlugin {
log("初始化GUI管理器...");
GUI.initialize(this);
AutoPagedGUI.defaultNextPage = (PluginConfig.GUI.ITEMS.NEXT_PAGE::getItem);
AutoPagedGUI.defaultPreviousPage = (PluginConfig.GUI.ITEMS.PREV_PAGE::getItem);
AutoPagedGUI.defaultNextPage = (PluginConfig.GUI.BOTTOMS.NEXT_PAGE::get);
AutoPagedGUI.defaultPreviousPage = (PluginConfig.GUI.BOTTOMS.PREV_PAGE::get);
if (MessageUtils.hasPlaceholderAPI()) {
log("注册变量...");
new UserPrefixExpansion(getInstance()).register();
new UserPrefixExpansion(this, getName()).register();
} else {
log("未安装 PlaceholderAPI ,跳过变量注册...");
log("若您想使用变量进行前缀的显示,请安装PlaceholderAPI");
@@ -6,18 +6,13 @@ import cc.carm.lib.configuration.core.annotation.HeaderComment;
import cc.carm.lib.configuration.core.value.ConfigValue;
import cc.carm.lib.configuration.core.value.type.ConfiguredList;
import cc.carm.lib.configuration.core.value.type.ConfiguredValue;
import cc.carm.lib.easyplugin.gui.configuration.GUIActionConfiguration;
import cc.carm.lib.easyplugin.gui.configuration.GUIActionType;
import cc.carm.lib.easyplugin.gui.configuration.GUIItemConfiguration;
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredItem;
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredSound;
import cc.carm.lib.mineconfiguration.bukkit.value.item.ConfiguredItem;
import cc.carm.plugin.userprefix.conf.gui.GUIItems;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemFlag;
import java.util.Collections;
public class PluginConfig extends ConfigurationRoot {
@HeaderComment({"开发者查错模式"})
@@ -99,8 +94,8 @@ public class PluginConfig extends ConfigurationRoot {
@HeaderComment("GUI的标题")
public static final ConfigValue<String> TITLE = ConfiguredValue.of(String.class, "&f&l我的前缀 &8| 列表");
@HeaderComment("GUI中的按钮")
public static final class ITEMS extends ConfigurationRoot {
@HeaderComment("GUI中的基本按钮物品")
public static final class BOTTOMS extends ConfigurationRoot {
@HeaderComment("前往下一页的物品 (只有存在下一页时才会显示)")
public static final ConfiguredItem NEXT_PAGE = ConfiguredItem.create()
@@ -117,23 +112,16 @@ public class PluginConfig extends ConfigurationRoot {
.defaultLore("&7&o右键可前往第一页哦")
.build();
@HeaderComment("GUI中其他的物品配置")
public static final ConfigValue<GUIItemConfiguration> BACK = ConfiguredValue.builder(GUIItemConfiguration.class)
.fromSection()
.serializeValue(GUIItemConfiguration::serialize)
.parseValue((v, d) -> {
if (!(v instanceof CraftSectionWrapper)) return null;
return GUIItemConfiguration.readFrom(((CraftSectionWrapper) v).getSource());
})
.defaults(new GUIItemConfiguration(
Material.BARRIER, 1, 0, "&c&l返回",
Collections.singletonList("&f点击即可返回上一菜单"),
Collections.singletonList(GUIActionConfiguration.of(GUIActionType.CHAT, "/menu")),
Collections.singletonList(49)
)).build();
}
@HeaderComment("GUI中的其他按钮物品 (若与现有物品位置冲突,将被覆盖)")
public static final ConfigValue<GUIItems> ITEMS = ConfiguredValue
.builderOf(GUIItems.class).fromSection()
.defaults(GUIItems::defaults)
.serializeValue(GUIItems::serialize)
.parseValue((v, d) -> GUIItems.parse(v))
.build();
}
@HeaderComment({"相关的声音,留空则不播放声音", "格式为 【声音名:音量:音调】 或 【声音名:音量】 或 【声音名】"})
@@ -159,7 +147,7 @@ public class PluginConfig extends ConfigurationRoot {
public static final ConfigValue<String> CONTENT = ConfiguredValue.of(String.class, "&r");
@HeaderComment({"选择默认前缀时执行的操作"})
public static final ConfiguredList<String> ACTIONS = ConfiguredList.builder(String.class).fromString()
public static final ConfiguredList<String> ACTIONS = ConfiguredList.builderOf(String.class).fromString()
.defaults("[CONSOLE] " + "say %player_name% 选择了默认前缀")
.build();
@@ -8,11 +8,11 @@ public class PluginMessages extends ConfigurationRoot {
public static final class COMMAND_USAGE extends ConfigurationRoot {
public static ConfiguredMessageList<String> CONSOLE = ConfiguredMessageList.asStrings().defaults(
public static final ConfiguredMessageList<String> CONSOLE = ConfiguredMessageList.asStrings().defaults(
"&f请输入 &b/prefix <玩家ID> &f为指定玩家打开前缀GUI。"
).build();
public static ConfiguredMessageList<String> ADMIN = ConfiguredMessageList.asStrings().defaults(
public static final ConfiguredMessageList<String> ADMIN = ConfiguredMessageList.asStrings().defaults(
"&3&l用户前缀系统 &f帮助",
"&8# &f/upa list",
"&8- &7查看当前前缀列表。",
@@ -23,52 +23,52 @@ public class PluginMessages extends ConfigurationRoot {
"&8- &7重载前缀配置。"
).build();
public static ConfiguredMessageList<String> NO_PERM = ConfiguredMessageList.asStrings()
public static final ConfiguredMessageList<String> NO_PERM = ConfiguredMessageList.asStrings()
.defaults("&c&l抱歉!&f但您没有权限使用该指令。")
.build();
}
public static ConfiguredMessageList<String> NOT_ONLINE = ConfiguredMessageList.asStrings()
public static final ConfiguredMessageList<String> NOT_ONLINE = ConfiguredMessageList.asStrings()
.defaults("&7玩家 &b%(player) &7并不在线。")
.params("player").build();
public static ConfiguredMessageList<String> SELECTED = ConfiguredMessageList.asStrings()
public static final ConfiguredMessageList<String> SELECTED = ConfiguredMessageList.asStrings()
.defaults("&7您选择了 &f%(name) &7作为当前显示的前缀。")
.params("name").build();
public static ConfiguredMessageList<String> EXPIRED = ConfiguredMessageList.asStrings()
public static final ConfiguredMessageList<String> EXPIRED = ConfiguredMessageList.asStrings()
.defaults(
"&7您先前使用的前缀 &f%(oldName) &7已到期。",
"&7现在已为您重新调整为 &f%(newName) &7。"
).params("oldName", "newName").build();
public static ConfiguredMessageList<String> REMOVED = ConfiguredMessageList.asStrings()
public static final ConfiguredMessageList<String> REMOVED = ConfiguredMessageList.asStrings()
.defaults("&7您先前使用的前缀已被移除,现在已为您重新调整为 &f%(newName) &7。")
.params("newName").build();
public static final class RELOAD extends ConfigurationRoot {
public static ConfiguredMessageList<String> SUCCESS = ConfiguredMessageList.asStrings()
public static final ConfiguredMessageList<String> SUCCESS = ConfiguredMessageList.asStrings()
.defaults("&a&l重载完成!&7耗时 &f%(time)ms&7,共加载了 &b%(count) &7个前缀。")
.params("time", "count").build();
public static ConfiguredMessageList<String> FAILED = ConfiguredMessageList.asStrings()
public static final ConfiguredMessageList<String> FAILED = ConfiguredMessageList.asStrings()
.defaults("&c&l重载出错!&7错误提示为 &8“&r%(error)&8”。")
.params("error").build();
}
public static final class SET extends ConfigurationRoot {
public static ConfiguredMessageList<String> SUCCESS = ConfiguredMessageList.asStrings()
public static final ConfiguredMessageList<String> SUCCESS = ConfiguredMessageList.asStrings()
.defaults("&a&l设置成功!&7成功设定玩家 &b%(player) &f的前缀为 &r%(prefix) &f。")
.params("player", "prefix").build();
public static ConfiguredMessageList<String> PREFIX_NOT_FOUND = ConfiguredMessageList.asStrings()
public static final ConfiguredMessageList<String> PREFIX_NOT_FOUND = ConfiguredMessageList.asStrings()
.defaults("&c&l无法设置!&7不存在ID为 &b%(prefix) &7的前缀。")
.params("prefix").build();
public static ConfiguredMessageList<String> NO_PERM = ConfiguredMessageList.asStrings()
public static final ConfiguredMessageList<String> NO_PERM = ConfiguredMessageList.asStrings()
.defaults("&c&l无法设置!&7玩家 &b%(player) &7并没有前缀 &r%(prefix) &7的前缀。")
.params("player", "prefix")
.build();
@@ -79,10 +79,10 @@ public class PluginMessages extends ConfigurationRoot {
@HeaderComment("管理员使用的 “/upa list” 指令的格式")
public static final class LIST extends ConfigurationRoot {
public static ConfiguredMessageList<String> HEADER = ConfiguredMessageList.asStrings()
public static final ConfiguredMessageList<String> HEADER = ConfiguredMessageList.asStrings()
.defaults("&3&l用户前缀系统 &f前缀列表").build();
public static ConfiguredMessageList<String> VALUE = ConfiguredMessageList.asStrings().defaults(
public static final ConfiguredMessageList<String> VALUE = ConfiguredMessageList.asStrings().defaults(
"&8#%(weight) &f%(identifier)",
"&8- &7显示名 &r%(name) &7权限 &r%(permission)",
"&8- &7内容示例&r %(content) %(sender_name)"
@@ -0,0 +1,53 @@
package cc.carm.plugin.userprefix.conf.gui;
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
import cc.carm.lib.easyplugin.gui.configuration.GUIActionConfiguration;
import cc.carm.lib.easyplugin.gui.configuration.GUIActionType;
import cc.carm.lib.easyplugin.gui.configuration.GUIConfiguration;
import cc.carm.lib.easyplugin.gui.configuration.GUIItemConfiguration;
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
import org.bukkit.Material;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.stream.Collectors;
public class GUIItems {
protected final Map<String, GUIItemConfiguration> items;
public GUIItems(Map<String, GUIItemConfiguration> items) {
this.items = items;
}
public Map<String, GUIItemConfiguration> getItems() {
return items;
}
public Map<String, Object> serialize() {
return items.entrySet().stream().collect(Collectors.toMap(
Map.Entry::getKey,
entry -> entry.getValue().serialize(), (a, b) -> b,
LinkedHashMap::new
));
}
public static GUIItems parse(ConfigurationWrapper<?> section) {
if (!(section instanceof CraftSectionWrapper)) return new GUIItems(new LinkedHashMap<>());
CraftSectionWrapper craft = (CraftSectionWrapper) section;
return new GUIItems(GUIConfiguration.readItems(craft.getSource()));
}
public static GUIItems defaults() {
LinkedHashMap<String, GUIItemConfiguration> map = new LinkedHashMap<>();
map.put("back", new GUIItemConfiguration(
Material.BARRIER, 1, 0, "&c&l返回",
Collections.singletonList("&f点击即可返回上一菜单"),
Collections.singletonList(GUIActionConfiguration.of(GUIActionType.CHAT, "/menu")),
Collections.singletonList(49)
));
return new GUIItems(map);
}
}
@@ -2,10 +2,11 @@ package cc.carm.plugin.userprefix.conf.prefix;
import cc.carm.lib.easyplugin.gui.configuration.GUIActionConfiguration;
import cc.carm.lib.easyplugin.utils.ColorParser;
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
import cc.carm.lib.mineconfiguration.bukkit.value.item.PreparedItem;
import cc.carm.plugin.userprefix.manager.ServiceManager;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -24,16 +25,16 @@ public class PrefixConfig {
protected final @NotNull List<GUIActionConfiguration> actions;
protected final @NotNull ItemConfig itemHasPermission;
protected final @Nullable ItemConfig itemNoPermission;
protected final @Nullable ItemConfig itemWhenUsing;
protected final @NotNull ItemStack itemHasPermission;
protected final @Nullable ItemStack itemNoPermission;
protected final @Nullable ItemStack itemWhenUsing;
public PrefixConfig(@NotNull String identifier, @NotNull String name,
@NotNull String content, int weight, @Nullable String permission,
@NotNull List<GUIActionConfiguration> actions,
@NotNull ItemConfig itemHasPermission,
@Nullable ItemConfig itemWhenUsing,
@Nullable ItemConfig itemNoPermission) {
@NotNull ItemStack itemHasPermission,
@Nullable ItemStack itemWhenUsing,
@Nullable ItemStack itemNoPermission) {
this.identifier = identifier;
this.name = name;
this.content = content;
@@ -71,21 +72,25 @@ public class PrefixConfig {
@NotNull
public ItemStack getItemHasPermission(@Nullable Player player) {
return this.itemHasPermission.getItemStack(player);
return getItem(player, this.itemHasPermission);
}
@Nullable
public ItemStack getItemNoPermission(@Nullable Player player) {
if (this.itemNoPermission == null) return null;
return this.itemNoPermission.getItemStack(player);
return getItem(player, this.itemNoPermission);
}
@Nullable
public ItemStack getItemWhenUsing(@Nullable Player player) {
if (this.itemWhenUsing == null) return null;
else return this.itemWhenUsing.getItemStack(player);
return getItem(player, this.itemWhenUsing);
}
@Contract("_,!null->!null")
protected @Nullable ItemStack getItem(@Nullable Player player, @Nullable ItemStack item) {
return PreparedItem.of(item).get(player);
}
public boolean isPublic() {
return getPermission() == null;
}
@@ -1,92 +1,77 @@
package cc.carm.plugin.userprefix.hooker;
import cc.carm.plugin.userprefix.Main;
import cc.carm.lib.easyplugin.papi.EasyPlaceholder;
import cc.carm.lib.easyplugin.papi.expansion.SubExpansion;
import cc.carm.lib.easyplugin.papi.handler.PlaceholderHandler;
import cc.carm.plugin.userprefix.UserPrefixAPI;
import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig;
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.List;
import java.util.Collections;
import java.util.function.BiFunction;
import java.util.function.Function;
public class UserPrefixExpansion extends PlaceholderExpansion {
public class UserPrefixExpansion extends EasyPlaceholder {
protected final @NotNull Main plugin;
protected final @NotNull List<String> placeholders = Arrays.asList(
"%UserPrefix_prefix%", "%UserPrefix_amount%", "%UserPrefix_weight%",
"%UserPrefix_identifier%", "%UserPrefix_name%",
"%UserPrefix_has_<Identifier>%"
public UserPrefixExpansion(@NotNull JavaPlugin plugin, @NotNull String rootIdentifier) {
super(plugin, rootIdentifier);
handle("version", (player, args) -> getVersion());
handle("identifier", handlePrefix(PrefixConfig::getIdentifier), "id");
handle("prefix", handlePrefix(PrefixConfig::getContent));
handle("name", handlePrefix(PrefixConfig::getName));
handle("weight", handlePrefix(PrefixConfig::getWeight));
handle("amount", handlePlayer(
(player) -> UserPrefixAPI.getUserManager().getUsablePrefixes(player).size() + 1)
);
public UserPrefixExpansion(@NotNull Main plugin) {
this.plugin = plugin;
handle("has", handlePlayer((player, args) -> {
if (args.length < 1) return "参数不足";
PrefixConfig prefix = UserPrefixAPI.getPrefixManager().getPrefix(args[0]);
if (prefix == null) return "该前缀不存在";
return prefix.checkPermission(player);
}), Collections.singletonList("<前缀ID>"));
}
@Override
public @NotNull List<String> getPlaceholders() {
return this.placeholders;
public PlaceholderHandler handlePrefix(Function<PrefixConfig, Object> handler) {
return handlePlayer((player, args) -> handler.apply(UserPrefixAPI.getUserManager().getPrefix(player)));
}
/**
* This is required or else PlaceholderAPI will unregister the Expansion on reload
*/
@Override
public boolean canRegister() {
public boolean persist() {
return true;
}
@Override
public @NotNull String getAuthor() {
return plugin.getDescription().getAuthors().toString();
public PlaceholderHandler handlePlayer(BiFunction<Player, String[], Object> handler) {
return (player, args) -> {
if (player == null || !player.isOnline()) return "Loading...";
return handler.apply((Player) player, args);
};
}
public PlaceholderHandler handlePlayer(Function<Player, Object> handler) {
return handlePlayer((player, args) -> handler.apply(player));
}
@Override
public @NotNull String getIdentifier() {
return "UserPrefix";
}
@Override
public @NotNull String getVersion() {
return plugin.getDescription().getVersion();
}
@Override
public String onPlaceholderRequest(Player player, @NotNull String identifier) {
if (player == null) return "加载中...";
String[] args = identifier.split("_");
if (args.length < 1) {
public String onErrorParams(@Nullable OfflinePlayer player) {
return "参数不足";
}
switch (args[0].toLowerCase()) {
case "identifier": {
return UserPrefixAPI.getUserManager().getPrefix(player).getIdentifier();
}
case "prefix": {
return UserPrefixAPI.getUserManager().getPrefix(player).getContent();
}
case "amount": {
return String.valueOf(UserPrefixAPI.getUserManager().getUsablePrefixes(player).size() + 1);
}
case "name": {
return UserPrefixAPI.getUserManager().getPrefix(player).getName();
}
case "weight": {
return Integer.toString(UserPrefixAPI.getUserManager().getPrefix(player).getWeight());
}
case "has": {
if (args.length < 2) return "参数不足";
PrefixConfig prefix = UserPrefixAPI.getPrefixManager().getPrefix(args[1]);
if (prefix == null) return "该前缀不存在";
return Boolean.toString(prefix.checkPermission(player));
}
case "version": {
return getVersion();
}
default: {
@Override
public String onException(@Nullable OfflinePlayer player, @NotNull SubExpansion<?> expansion,
@NotNull Exception exception) {
exception.printStackTrace();
return "参数错误";
}
}
}
}
@@ -26,7 +26,7 @@ public class ConfigManager {
File configFile = new File(dataFolder, "config.yml");
if (!configFile.exists()) {
try {
JarResourceUtils.copyFolderFromJar("en_US", dataFolder, JarResourceUtils.CopyOption.COPY_IF_NOT_EXIST);
JarResourceUtils.copyFolderFromJar("i18n", dataFolder, JarResourceUtils.CopyOption.COPY_IF_NOT_EXIST);
JarResourceUtils.copyFolderFromJar("prefixes", dataFolder, JarResourceUtils.CopyOption.COPY_IF_NOT_EXIST);
} catch (IOException e) {
e.printStackTrace();
@@ -1,15 +1,17 @@
package cc.carm.plugin.userprefix.manager;
import cc.carm.lib.easyplugin.gui.configuration.GUIActionConfiguration;
import cc.carm.lib.mineconfiguration.bukkit.data.ItemConfig;
import cc.carm.lib.easyplugin.utils.ItemStackFactory;
import cc.carm.plugin.userprefix.Main;
import cc.carm.plugin.userprefix.conf.PluginConfig;
import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig;
import com.cryptomorin.xseries.XItemStack;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -80,8 +82,7 @@ public class PrefixManager {
null,
readActions(PluginConfig.DEFAULT_PREFIX.ACTIONS.get()),
PluginConfig.DEFAULT_PREFIX.ITEM.NOT_USING.getNotNull(),
PluginConfig.DEFAULT_PREFIX.ITEM.USING.get(),
null
PluginConfig.DEFAULT_PREFIX.ITEM.USING.get(), null
);
Main.debugging(" 完成默认前缀加载 " + defaultPrefix.getName());
}
@@ -124,34 +125,38 @@ public class PrefixManager {
}
public static @NotNull PrefixConfig addPrefix(@NotNull File file) throws Exception {
FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
String identifier = configuration.getString("identifier");
FileConfiguration conf = YamlConfiguration.loadConfiguration(file);
String identifier = conf.getString("identifier");
if (identifier == null)
throw new Exception("配置文件 " + file.getAbsolutePath() + " 中没有配置前缀的唯一标识。");
String name = configuration.getString("name");
String name = conf.getString("name");
if (name == null) throw new Exception("配置文件 " + file.getAbsolutePath() + " 中没有配置前缀的显示名称。");
return new PrefixConfig(
identifier, name,
configuration.getString("content", "&r"),
configuration.getInt("weight", 1),
configuration.getString("permission"),
readActions(configuration.getStringList("actions")),
conf.getString("content", "&r"),
conf.getInt("weight", 1),
conf.getString("permission"),
readActions(conf.getStringList("actions")),
readItem(
configuration.getConfigurationSection("item.has-perm"),
new ItemConfig(Material.STONE, name, Arrays.asList(" ", "§a➥ 点击切换到该前缀"))
conf.getConfigurationSection("item.has-perm"),
new ItemStackFactory(Material.STONE)
.setDisplayName(name)
.addLore("§a➥ 点击切换到该前缀")
.toItemStack()
),
readItem(configuration.getConfigurationSection("item.using"), null),
readItem(configuration.getConfigurationSection("item.no-perm"), null)
readItem(conf.getConfigurationSection("item.using"), null),
readItem(conf.getConfigurationSection("item.no-perm"), null)
);
}
@Contract("_,!null->!null")
protected static ItemConfig readItem(@Nullable ConfigurationSection section, @Nullable ItemConfig defaultValue) throws Exception {
protected static ItemStack readItem(@Nullable ConfigurationSection section,
@Nullable ItemStack defaultValue) throws Exception {
if (section == null) return defaultValue;
else return ItemConfig.deserialize(section);
else return XItemStack.deserialize(section);
}
protected static List<GUIActionConfiguration> readActions(@NotNull List<String> strings) {
@@ -131,13 +131,13 @@ public class UserManager {
UserPrefixExpireEvent.call(player, currentPrefix);
// 发送消息
PluginMessages.EXPIRED.send(player, newPrefix.getName(), currentPrefix.getName());
PluginMessages.EXPIRED.send(player, currentPrefix.getName(), newPrefix.getName());
// 播放声音
PluginConfig.SOUNDS.PREFIX_EXPIRED.playTo(player);
} else {
// 当前前缀为空,则代表是旧的前缀不存在了,
PluginMessages.REMOVED.send(player, newPrefix.getName(), currentPrefixData);
PluginMessages.REMOVED.send(player, newPrefix.getName());
}
UserPrefixChangeEvent.call(player, currentPrefix, newPrefix, (after) -> {
@@ -209,7 +209,7 @@ public class UserManager {
*/
@NotNull
public PrefixConfig getHighestPrefix(Player player) {
if (PluginConfig.FUNCTIONS.AUTO_USE.getNotNull()) {
if (!PluginConfig.FUNCTIONS.AUTO_USE.getNotNull()) {
// 关闭了自动选择,就直接给默认的前缀,让玩家自己去设置吧~
return UserPrefixAPI.getDefaultPrefix();
}
@@ -14,6 +14,7 @@ import org.bukkit.event.inventory.ClickType;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
public class PrefixSelectGUI extends AutoPagedGUI {
@@ -28,7 +29,7 @@ public class PrefixSelectGUI extends AutoPagedGUI {
setPreviousPageSlot(18);
setNextPageSlot(26);
loadBackButton();
loadExtraIcons();
loadItems();
}
@@ -36,8 +37,8 @@ public class PrefixSelectGUI extends AutoPagedGUI {
return player;
}
public void loadBackButton() {
PluginConfig.GUI.ITEMS.BACK.getOptional().ifPresent(item -> item.setupItems(player, this));
public void loadExtraIcons() {
PluginConfig.GUI.ITEMS.getNotNull().getItems().values().forEach(v -> v.setupItems(player, this));
}
public void loadItems() {
@@ -49,7 +50,10 @@ public class PrefixSelectGUI extends AutoPagedGUI {
for (PrefixConfig prefix : prefixList) {
if (prefix.getIdentifier().equals(usingPrefix.getIdentifier())) {
addItem(new GUIItem(prefix.getItemWhenUsing(player) != null ? prefix.getItemWhenUsing(player) : prefix.getItemHasPermission(player)));
addItem(new GUIItem(Optional
.ofNullable(prefix.getItemWhenUsing(player))
.orElse(prefix.getItemHasPermission(player))
));
} else if (prefix.checkPermission(player)) {
addItem(new GUIItem(prefix.getItemHasPermission(player)) {
@@ -27,11 +27,13 @@ permission: "yc.vip"
actions:
- "[CONSOLE] say %player_name% selected PRO "
# Display item configuration
# More details please see https://github.com/CryptoMorin/XSeries/wiki/XItemStack
item:
# itemHasPermission [Necessary]
# This Item will be displayed when player has permission
has-perm:
type: DIAMOND
material: DIAMOND
name: "&b&lVIP Prefix"
lore:
- ""
@@ -41,7 +43,7 @@ item:
# This Item will be displayed when the prefix is selected.
# If there is no such configuration, it will automatically display "itemHasPermission".
using:
type: DIAMOND
material: DIAMOND
name: "&b&lVIP Prefix"
enchants:
PROTECTION_ENVIRONMENTAL: 1 #Add an enchantment so it looks like its selected
@@ -53,7 +55,7 @@ item:
# 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.
no-perm:
type: INK_SACK
material: INK_SACK
data: 8
name: "&b&lVIP &c(Buy it!)"
lore:
@@ -0,0 +1,58 @@
# Nombre [Necesario]
# Uso en mensajes.
name: "&b&lPro&b"
# Contenido [Necesario]
# Uso en Placeholders
content: "&b&lPro &b"
# Weight [Necesario]
# utilizado para ordenar en la GUI y TabList
# En GUI : el más grande se muestra en la parte posterior
# En TabList : el más grande se muestra en la parte superior
weight: 1
# Permisos [Innecesario]
# Si no hay permiso para la detección, todo el mundo puede utilizarlo,
# lo que significa que no es necesario configurar "itemNoPermission"
# (porque es imposible mostrar elementos sin permiso en absoluto)
permission: "yc.vip"
# Acciones al seleccionar [Innecesario]
# Por favor, compruebe https://github.com/CarmJos/UserPrefix/tree/master/.documentation/ACTIONS.md
actions:
- "[CONSOLE] say %player_name% Has seleccionado La etiqueta PRO"
item:
# itemHasPermission [Necesario]
# Este elemento se mostrará cuando el jugador tenga permiso
has-perm:
material: DIAMOND
name: "&b&lVIP Prefix"
lore:
- ""
- "&a➥ Pulsa para utilizar"
# itemUsing [Innecesario]
# Este elemento se mostrará cuando se seleccione el prefijo.
# Si no existe tal configuración, se mostrará automáticamente "itemHasPermission".
using:
material: DIAMOND
name: "&b&lPrefix VIP"
enchants:
PROTECTION_ENVIRONMENTAL: 1 #Añade un encantamiento para que parezca que está seleccionado
lore:
- ""
- "&a✔ Seleccionado"
# itemNoPermission [Innecesario]
# Si el jugador no tiene el permiso,este item sera mostrado.
# Si este elemento no está configurado, no se mostrará en la GUI cuando el jugador no tenga permiso para usarlo.
no-perm:
material: INK_SACK
data: 8
name: "&b&lVIP &c(¡Cómpralo!)"
lore:
- ""
- "&e✯ Necesitas Comprar el VIP para utilizarlo!"
@@ -30,12 +30,13 @@ actions:
- "[CONSOLE] say %player_name% 选择了 Pro会员前缀 "
# 该前缀的GUI物品配置
# 物品配置方式详见 https://github.com/CryptoMorin/XSeries/wiki/XItemStack
item:
# 有权限时显示的物品 [必须]
# 当用户有权限且未选中时,会显示该物品
has-perm:
type: DIAMOND
material: DIAMOND
name: "&b&lPro &b会员前缀"
lore:
- "&7Pro会员专属称号"
@@ -48,7 +49,7 @@ item:
# 正在使用时显示的物品 [非必需]
# 当用户正在使用时会显示这个物品,不配置即自动加载“itemHasPermission”
using:
type: DIAMOND
material: DIAMOND
name: "&b&lPro &b会员前缀"
flags:
- HIDE_ENCHANTS # 隐藏附魔显示
@@ -65,7 +66,7 @@ item:
# 没有权限时显示的物品 [非必需]
# 如果没有权限就会显示这个item。如果不配置该物品,则玩家没有使用权限时不会显示在GUI里面。
no-perm:
type: INK_SACK
material: INK_SACK
data: 8
name: "&b&lPro+ &b会员前缀 &c(未拥有)"
lore: