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

feat: 为物品配置支持变量与描述插入。

This commit is contained in:
2025-07-19 20:38:16 +08:00
parent 748335a962
commit 8e8427a937
6 changed files with 64 additions and 24 deletions
@@ -139,6 +139,11 @@ public class PluginConfig implements Configuration {
@HeaderComments("默认前缀的显示名称,用于在消息提示中显示。")
public static final ConfiguredValue<String> NAME = ConfiguredValue.of(String.class, "默认前缀");
@HeaderComments({"默认前缀的描述信息。"})
public static final ConfiguredList<String> DESCRIPTION = ConfiguredList.builderOf(String.class).fromString()
.defaults("&7这是一个默认前缀", "&7您可以在前缀列表中选择其他前缀")
.build();
@HeaderComments({"默认前缀的权重,默认为0。"})
public static final ConfiguredValue<Integer> WEIGHT = ConfiguredValue.of(Integer.class, 0);
@@ -157,7 +162,7 @@ public class PluginConfig implements Configuration {
public static final ConfiguredItem NOT_USING = ConfiguredItem.create()
.defaultType(Material.NAME_TAG)
.defaultName("&f默认玩家前缀 &f(点击切换)")
.defaultLore("", "&a➥ 点击切换到该前缀")
.defaultLore("","{&f&o }#description#{1,1}", "&a➥ 点击切换到该前缀")
.build();
@HeaderComments({"当选择了默认前缀时显示的物品"})
@@ -166,7 +171,7 @@ public class PluginConfig implements Configuration {
.defaultEnchant(MajorUtil.getEnchantProtection(), 1) // 附魔改过名
.defaultFlags(ItemFlag.HIDE_ENCHANTS)
.defaultName("&f默认玩家前缀")
.defaultLore("", "&a✔ 您正在使用该前缀")
.defaultLore("","{&f&o }#description#{1,1}", "&a✔ 您正在使用该前缀")
.build();
}
@@ -13,6 +13,7 @@ import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
public class PrefixConfig {
@@ -21,6 +22,7 @@ public class PrefixConfig {
protected final @NotNull String name;
protected final @NotNull String content;
protected final @NotNull List<String> description;
protected final int weight;
@@ -38,8 +40,23 @@ public class PrefixConfig {
@NotNull ItemStack itemHasPermission,
@Nullable ItemStack itemWhenUsing,
@Nullable ItemStack itemNoPermission) {
this(
identifier, name, new ArrayList<>(),
content, weight, permission, actions,
itemHasPermission, itemWhenUsing, itemNoPermission
);
}
public PrefixConfig(@NotNull String identifier,
@NotNull String name, @NotNull List<String> description,
@NotNull String content, int weight, @Nullable String permission,
@NotNull List<GUIActionConfiguration> actions,
@NotNull ItemStack itemHasPermission,
@Nullable ItemStack itemWhenUsing,
@Nullable ItemStack itemNoPermission) {
this.identifier = identifier;
this.name = name;
this.description = description;
this.content = content;
this.weight = weight;
this.permission = permission;
@@ -59,6 +76,11 @@ public class PrefixConfig {
return name;
}
@NotNull
public List<String> getDescription() {
return description;
}
@NotNull
public String getContent(CommandSender viewer) {
return MessageUtils.setPlaceholders(viewer, content);
@@ -90,7 +112,23 @@ public class PrefixConfig {
@Contract("_,!null->!null")
protected @Nullable ItemStack getItem(@Nullable Player player, @Nullable ItemStack item) {
return PreparedItem.of(item).get(player);
PreparedItem prepared = PreparedItem.of(item);
if (!getDescription().isEmpty()) {
prepared.insert("description", getDescription());
prepared.placeholder("description", String.join("\n", getDescription()));
}
prepared.placeholder("name", getName());
prepared.placeholder("identifier", getIdentifier());
prepared.placeholder("content", getContent(player));
prepared.placeholder("permission", getPermission());
prepared.placeholder("weight", String.valueOf(getWeight()));
prepared.placeholder("hasPermission", String.valueOf(checkPermission(player)));
prepared.placeholder("public", String.valueOf(isPublic()));
prepared.placeholder("visible", String.valueOf(isVisible(player)));
return prepared.get(player);
}
@@ -77,6 +77,7 @@ public class PrefixManager {
this.defaultPrefix = new PrefixConfig(
"default",
PluginConfig.DEFAULT_PREFIX.NAME.getNotNull(),
PluginConfig.DEFAULT_PREFIX.DESCRIPTION.getNotNull(),
PluginConfig.DEFAULT_PREFIX.CONTENT.getNotNull(),
PluginConfig.DEFAULT_PREFIX.WEIGHT.getNotNull(),
null,
@@ -135,6 +136,7 @@ public class PrefixManager {
return new PrefixConfig(
identifier, name,
conf.getStringList("description"),
conf.getString("content", "&r"),
conf.getInt("weight", 1),
conf.getString("permission"),
@@ -20,7 +20,7 @@ public class PrefixSelectGUI extends AutoPagedGUI {
public static HashSet<Player> openingUsers = new HashSet<>();
Player player;
protected final Player player;
public PrefixSelectGUI(Player player) {
super(GUIType.SIX_BY_NINE, PluginConfig.GUI.TITLE.get(), 10, 43);
+14 -19
View File
@@ -5,7 +5,7 @@ identifier: "pro"
# 名字 [必须]
# 切换的时候左下角会弹提示 用的就是这个名字
name: "&b&lPro&b"
name: "&b&lPro &b会员"
# 内容 [必须]
# 显示在名字前面的内容
@@ -29,6 +29,11 @@ permission: "yc.pro"
actions:
- "[CONSOLE] say %player_name% 选择了 Pro会员前缀 "
description: # 描述 [非必须]
- "&f尊贵的Pro会员专属称号。"
- "&f您将获得多种特权与更好的游戏体验。"
- "&f您可以输入 &b/vip &f指令查看详细特权!"
# 该前缀的GUI物品配置
# 物品配置方式详见 https://github.com/CryptoMorin/XSeries/wiki/XItemStack
item:
@@ -37,30 +42,24 @@ item:
# 当用户有权限且未选中时,会显示该物品
has-perm:
material: DIAMOND
name: "&b&lPro &b会员前缀"
name: "%(name)"
lore:
- "&7Pro会员专属称号"
- ""
- "&f尊贵的Pro会员专属称号。"
- "&f您将获得多种特权与更好的游戏体验。"
- ""
- "#desciption#{1,1}"
- "&a➥ 点击切换到该前缀"
# 正在使用时显示的物品 [非必需]
# 当用户正在使用时会显示这个物品,不配置即自动加载“itemHasPermission”
using:
material: DIAMOND
name: "&b&lPro &b会员前缀"
name: "%(name)"
flags:
- HIDE_ENCHANTS # 隐藏附魔显示
enchants:
PROTECTION_ENVIRONMENTAL: 1 #加一个附魔这样看上去就像是选中了的
lore:
- "&7Pro会员专属称号"
- ""
- "&f尊贵的Pro会员专属称号。"
- "&f您将获得多种特权与更好的游戏体验。"
- ""
- "#desciption#{1,1}"
- "&a✔ 您正在使用该前缀"
# 没有权限时显示的物品 [非必需]
@@ -68,12 +67,8 @@ item:
no-perm:
material: INK_SACK
data: 8
name: "&b&lPro+ &b会员前缀 &c(未拥有)"
name: "%(name) &c(未拥有)"
lore:
- "&7Pro+会员专属称号"
- ""
- "&f尊贵的Pro会员专属称号。"
- "&f您将获得多种特权与更好的游戏体验。"
- "&f您可以输入 &b/vip &f指令查看详细特权!"
- ""
- "&e✯ 加入Pro+会员以使用该前缀!"
- "&7Pro 会员专属称号"
- "#desciption#{1,1}"
- "&e✯ 加入Pro会员以使用该前缀!"