mirror of
https://github.com/CarmJos/UserPrefix.git
synced 2026-06-05 00:35:02 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ea993a31b | |||
| 8ce82ec7fd | |||
| 6fb9daa3d3 | |||
| da23eaa8fe | |||
| 36cc4bf7ce |
@@ -117,11 +117,10 @@ README LANGUAGES [ [**中文**](README.md) | [English](README-en.md) ]
|
||||
本项目由 [YourCraft(你的世界)](https://www.ycraft.cn) 团队提供长期支持与维护。
|
||||

|
||||
|
||||
若您觉得本插件做的不错,您可以捐赠支持我!
|
||||
若您觉得本插件做的不错,您可以捐赠支持我!感谢您成为开源项目的支持者!
|
||||
|
||||
感谢您成为开源项目的支持者!
|
||||
|
||||
<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://www.jetbrains.com/?from=https://github.com/CarmJos/UserPrefix)
|
||||
|
||||
## 开源协议
|
||||
|
||||
@@ -145,4 +144,6 @@ README LANGUAGES [ [**中文**](README.md) | [English](README-en.md) ]
|
||||
> 协议,你必须在源代码代码中包含相应信息,以及协议本身。
|
||||
>
|
||||
> *以上文字来自 [五种开源协议GPL,LGPL,BSD,MIT,Apache](https://www.oschina.net/question/54100_9455) 。*
|
||||
</details>
|
||||
</details>
|
||||
|
||||
## Project supported by JetBrains
|
||||
|
||||
@@ -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.2</deps.easyplugin.version>
|
||||
<deps.mineconfig.version>2.4.0</deps.mineconfig.version>
|
||||
</properties>
|
||||
|
||||
<groupId>cc.carm.plugin</groupId>
|
||||
<artifactId>userprefix</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>3.2.0</version>
|
||||
|
||||
<name>UserPrefix</name>
|
||||
<description>轻便、高效、实时的用户前缀系统。</description>
|
||||
@@ -108,7 +108,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 +116,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 +124,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,7 +149,7 @@
|
||||
<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>
|
||||
</dependency>
|
||||
|
||||
@@ -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::getItem);
|
||||
AutoPagedGUI.defaultPreviousPage = (PluginConfig.GUI.BOTTOMS.PREV_PAGE::getItem);
|
||||
|
||||
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.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({"开发者查错模式"})
|
||||
@@ -57,7 +52,7 @@ public class PluginConfig extends ConfigurationRoot {
|
||||
|
||||
@ConfigPath("on-name-prefix")
|
||||
@HeaderComment({"头顶与TabList前缀功能,该方法用到了玩家名计分板接口,如有冲突请关掉哦~"})
|
||||
public static final class NAME_PREFIX {
|
||||
public static final class NAME_PREFIX extends ConfigurationRoot {
|
||||
|
||||
@HeaderComment("是否开启本功能")
|
||||
public static final ConfigValue<Boolean> ENABLE = ConfiguredValue.of(Boolean.class, true);
|
||||
@@ -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
|
||||
.builder(GUIItems.class).fromSection()
|
||||
.defaults(GUIItems::defaults)
|
||||
.serializeValue(GUIItems::serialize)
|
||||
.parseValue((v, d) -> GUIItems.parse(v))
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
@HeaderComment({"相关的声音,留空则不播放声音", "格式为 【声音名:音量:音调】 或 【声音名:音量】 或 【声音名】"})
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,92 +1,69 @@
|
||||
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);
|
||||
|
||||
public UserPrefixExpansion(@NotNull Main plugin) {
|
||||
this.plugin = plugin;
|
||||
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)
|
||||
);
|
||||
|
||||
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>"));
|
||||
|
||||
}
|
||||
|
||||
public PlaceholderHandler handlePrefix(Function<PrefixConfig, Object> handler) {
|
||||
return handlePlayer((player, args) -> handler.apply(UserPrefixAPI.getUserManager().getPrefix(player)));
|
||||
}
|
||||
|
||||
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 List<String> getPlaceholders() {
|
||||
return this.placeholders;
|
||||
public String onErrorParams(@Nullable OfflinePlayer player) {
|
||||
return "参数不足";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRegister() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull String getAuthor() {
|
||||
return plugin.getDescription().getAuthors().toString();
|
||||
}
|
||||
|
||||
@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) {
|
||||
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: {
|
||||
return "参数错误";
|
||||
}
|
||||
}
|
||||
public String onException(@Nullable OfflinePlayer player, @NotNull SubExpansion<?> expansion,
|
||||
@NotNull Exception exception) {
|
||||
exception.printStackTrace();
|
||||
return "参数错误";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
||||
setPreviousPageSlot(18);
|
||||
setNextPageSlot(26);
|
||||
|
||||
loadBackButton();
|
||||
loadExtraIcons();
|
||||
loadItems();
|
||||
}
|
||||
|
||||
@@ -36,8 +36,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() {
|
||||
|
||||
Reference in New Issue
Block a user