mirror of
https://github.com/CarmJos/UserPrefix.git
synced 2026-06-05 00:35:02 +08:00
Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 675bbe4cf2 | |||
| 3b8fd6febf | |||
| d8282b9641 | |||
| ad616e5470 | |||
| f741723204 | |||
| 54f526300a | |||
| 5a0e5b8e96 | |||
| c89a9c6ccc | |||
| e321a1ec66 | |||
| 9054161135 | |||
| 53281b80e3 | |||
| 12489fe1a8 | |||
| 7d62f68662 | |||
| 4cc50c21d5 | |||
| 0d25490d0f | |||
| a805aba42e | |||
| 2a0d6b8582 | |||
| 1ea993a31b | |||
| 8ce82ec7fd | |||
| 6fb9daa3d3 | |||
| da23eaa8fe | |||
| 36cc4bf7ce | |||
| 7cf9f3f9ee | |||
| 84bb41ab2f | |||
| 2fc2474f89 | |||
| 01a83d5c9e | |||
| f648e29ee2 | |||
| cc0122f9ba | |||
| e3c911d375 | |||
| dc14b0cd2e | |||
| a8908b6dd4 | |||
| fa9f3bc1ed | |||
| 7c2391a3b0 | |||
| cb384ca201 |
@@ -0,0 +1,31 @@
|
||||
# UserPrefix Actions 操作
|
||||
|
||||
## 使用方式
|
||||
|
||||
在 `actions` 配置节点下,可以配置多个操作,格式为 `[操作类型] {操作参数}`,例如:
|
||||
|
||||
- `[CHAT] HELLO %player_name%!`
|
||||
- `[SOUND] ENTITY_PLAYER_LEVELUP`
|
||||
|
||||
## 操作类型
|
||||
|
||||
目前支持以下操作类型:
|
||||
- `CHAT` 以玩家聊天的形式发送,若需要发送指令则添加“/”前缀
|
||||
- `CONSOLE` 以后台的形式发送指令
|
||||
- `MESSAGE` 向玩家发送一条消息
|
||||
- `SOUND` 向玩家发送声音
|
||||
- `CLOSE` 关闭当前打开的GUI
|
||||
|
||||
所有需要键入文本的类型均支持 [PlaceholderAPI](https://www.spigotmc.org/resources/6245/) 变量 。
|
||||
|
||||
## 限定点击类型
|
||||
|
||||
若您需要限定玩家点击的类型,如左键、右键等,则可以添加在操作类型后,以“`:`”分割,如:
|
||||
|
||||
- `[CLOSE:LEFT]` 代表左键点击关闭
|
||||
- `[MESSAGE:MIDDLE] HELLO WORLD` 代表鼠标中间点击发送消息
|
||||
|
||||
详细点击类型见 [`org.bukkit.event.inventory.ClickType`](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/inventory/ClickType.html) 。
|
||||
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
|
||||
- 使用示例
|
||||
- [前缀配置文件预设示例](../src/main/resources/prefixes/example-prefix.yml)
|
||||
- [操作(Actions)配置](ACTIONS.md)
|
||||
|
||||
## [开发文档](JAVADOC-README.md)
|
||||
|
||||
|
||||
@@ -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
|
||||
path: artifacts
|
||||
include-hidden-files: true
|
||||
@@ -92,11 +92,11 @@ README LANGUAGES [ [**中文**](README.md) | [English](README-en.md) ]
|
||||
|
||||
## 配置文件示例
|
||||
|
||||
### 基础配置文件 ([`config.yml`](src/main/java/cc/carm/plugin/userprefix/configuration/PluginConfig.java))
|
||||
### 基础配置文件 ([`config.yml`](src/main/java/cc/carm/plugin/userprefix/conf/PluginConfig.java))
|
||||
|
||||
将会在服务器首次启动时生成,如果您想要修改配置,请在服务器启动后打开配置文件。
|
||||
|
||||
### 消息配置文件 ([`messages.yml`](src/main/java/cc/carm/plugin/userprefix/configuration/PluginMessages.java))
|
||||
### 消息配置文件 ([`messages.yml`](src/main/java/cc/carm/plugin/userprefix/conf/PluginMessages.java))
|
||||
|
||||
将会在服务器首次启动时生成,如果您想要修改配置,请在服务器启动后打开配置文件 。
|
||||
|
||||
@@ -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.10</easyplugin.version>
|
||||
<mineconfig.version>2.0.1</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.0.1</version>
|
||||
<version>3.2.5</version>
|
||||
|
||||
<name>UserPrefix</name>
|
||||
<description>轻便、高效、实时的用户前缀系统。</description>
|
||||
@@ -61,6 +61,16 @@
|
||||
|
||||
<repositories>
|
||||
|
||||
<repository>
|
||||
<id>maven-central</id>
|
||||
<url>https://repo1.maven.org/maven2/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>spigot-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
@@ -72,13 +82,9 @@
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>maven-central</id>
|
||||
<url>https://repo1.maven.org/maven2/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>sonatype-repo</id>
|
||||
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
|
||||
<id>minecraft-libraries</id>
|
||||
<name>Minecraft Libraries</name>
|
||||
<url>https://libraries.minecraft.net/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
@@ -108,7 +114,15 @@
|
||||
<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>
|
||||
|
||||
<dependency>
|
||||
<groupId>cc.carm.lib</groupId>
|
||||
<artifactId>easyplugin-command</artifactId>
|
||||
<version>${deps.easyplugin.version}</version>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
@@ -116,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>
|
||||
@@ -132,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>
|
||||
@@ -154,7 +202,7 @@
|
||||
<dependency>
|
||||
<groupId>net.luckperms</groupId>
|
||||
<artifactId>api</artifactId>
|
||||
<version>5.3</version>
|
||||
<version>5.4</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -205,31 +253,6 @@
|
||||
</filesets>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<classifier>javadoc</classifier>
|
||||
<links>
|
||||
<!-- <link>https://javadoc.io/doc/org.jetbrains/annotations/</link>-->
|
||||
<link>https://hub.spigotmc.org/javadocs/bukkit/</link>
|
||||
</links>
|
||||
<detectJavaApiLink>true</detectJavaApiLink>
|
||||
<encoding>UTF-8</encoding>
|
||||
<charset>UTF-8</charset>
|
||||
<docencoding>UTF-8</docencoding>
|
||||
<locale>zh_CN</locale>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
@@ -275,6 +298,7 @@
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
<outputDirectory>${project.basedir}/asset/</outputDirectory>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<minimizeJar>true</minimizeJar>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
@@ -288,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>
|
||||
@@ -300,6 +328,33 @@
|
||||
</filters>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<classifier>javadoc</classifier>
|
||||
<links>
|
||||
<link>https://javadoc.io/doc/org.jetbrains/annotations/</link>
|
||||
<link>https://hub.spigotmc.org/javadocs/bukkit/</link>
|
||||
<link>https://carmjos.github.io/EasyPlugin/</link>
|
||||
<link>https://carmjos.github.io/MineConfiguration/</link>
|
||||
</links>
|
||||
<detectJavaApiLink>true</detectJavaApiLink>
|
||||
<encoding>UTF-8</encoding>
|
||||
<charset>UTF-8</charset>
|
||||
<docencoding>UTF-8</docencoding>
|
||||
<locale>zh_CN</locale>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
|
||||
@@ -2,19 +2,21 @@ package cc.carm.plugin.userprefix;
|
||||
|
||||
import cc.carm.lib.easyplugin.EasyPlugin;
|
||||
import cc.carm.lib.easyplugin.gui.GUI;
|
||||
import cc.carm.lib.easyplugin.gui.paged.AutoPagedGUI;
|
||||
import cc.carm.lib.easyplugin.updatechecker.GHUpdateChecker;
|
||||
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||
import cc.carm.plugin.userprefix.command.AdminCommand;
|
||||
import cc.carm.plugin.userprefix.command.UserCommand;
|
||||
import cc.carm.plugin.userprefix.configuration.PluginConfig;
|
||||
import cc.carm.plugin.userprefix.conf.PluginConfig;
|
||||
import cc.carm.plugin.userprefix.hooker.UserPrefixExpansion;
|
||||
import cc.carm.plugin.userprefix.listener.ChatListener;
|
||||
import cc.carm.plugin.userprefix.listener.UserListener;
|
||||
import cc.carm.plugin.userprefix.listener.processor.UserNodeUpdateProcessor;
|
||||
import cc.carm.plugin.userprefix.listener.UserPermListener;
|
||||
import cc.carm.plugin.userprefix.manager.ConfigManager;
|
||||
import cc.carm.plugin.userprefix.manager.PrefixManager;
|
||||
import cc.carm.plugin.userprefix.manager.ServiceManager;
|
||||
import cc.carm.plugin.userprefix.manager.UserManager;
|
||||
import cc.carm.plugin.userprefix.ui.PrefixSelectGUI;
|
||||
import net.luckperms.api.event.user.UserDataRecalculateEvent;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
@@ -47,20 +49,24 @@ public class Main extends EasyPlugin {
|
||||
|
||||
log("注册指令...");
|
||||
registerCommand("UserPrefix", new UserCommand());
|
||||
registerCommand("UserPrefixAdmin", new AdminCommand());
|
||||
registerCommand("UserPrefixAdmin", new AdminCommand(this));
|
||||
|
||||
log("注册监听器...");
|
||||
GUI.initialize(this);
|
||||
registerListener(new UserListener());
|
||||
registerListener(new ChatListener());
|
||||
ServiceManager.getService().getEventBus().subscribe(
|
||||
this, UserDataRecalculateEvent.class,
|
||||
UserNodeUpdateProcessor::process
|
||||
UserPermListener::process
|
||||
);
|
||||
|
||||
log("初始化GUI管理器...");
|
||||
GUI.initialize(this);
|
||||
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!");
|
||||
@@ -93,6 +99,20 @@ public class Main extends EasyPlugin {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutdown() {
|
||||
|
||||
log("关闭已被打开的GUI...");
|
||||
Bukkit.getOnlinePlayers().stream().filter(GUI::hasOpenedGUI).forEach(player -> {
|
||||
player.closeInventory();
|
||||
GUI.removeOpenedGUI(player);
|
||||
PrefixSelectGUI.removeOpening(player);
|
||||
});
|
||||
|
||||
log("&7感谢您使用 &3&lUserPrefix " + getDescription().getVersion() + "&7!");
|
||||
log("&7本插件由 &b&lYourCraft &7提供长期支持与维护。");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDebugging() {
|
||||
return PluginConfig.DEBUG.getNotNull();
|
||||
@@ -106,7 +126,7 @@ public class Main extends EasyPlugin {
|
||||
getInstance().debug(message);
|
||||
}
|
||||
|
||||
public static void serve(String... message) {
|
||||
public static void severe(String... message) {
|
||||
getInstance().error(message);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cc.carm.plugin.userprefix;
|
||||
|
||||
import cc.carm.plugin.userprefix.configuration.prefix.PrefixConfig;
|
||||
import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig;
|
||||
import cc.carm.plugin.userprefix.manager.ConfigManager;
|
||||
import cc.carm.plugin.userprefix.manager.PrefixManager;
|
||||
import cc.carm.plugin.userprefix.manager.UserManager;
|
||||
|
||||
@@ -1,63 +1,38 @@
|
||||
package cc.carm.plugin.userprefix.command;
|
||||
|
||||
import cc.carm.plugin.userprefix.UserPrefixAPI;
|
||||
import cc.carm.plugin.userprefix.configuration.PluginMessages;
|
||||
import cc.carm.plugin.userprefix.configuration.prefix.PrefixConfig;
|
||||
import cc.carm.plugin.userprefix.ui.PrefixSelectGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import cc.carm.lib.easyplugin.command.CommandHandler;
|
||||
import cc.carm.plugin.userprefix.command.admin.ListCommand;
|
||||
import cc.carm.plugin.userprefix.command.admin.ReloadCommand;
|
||||
import cc.carm.plugin.userprefix.command.admin.SetCommand;
|
||||
import cc.carm.plugin.userprefix.conf.PluginMessages;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AdminCommand implements CommandExecutor {
|
||||
public class AdminCommand extends CommandHandler {
|
||||
|
||||
|
||||
public AdminCommand(@NotNull JavaPlugin plugin) {
|
||||
super(plugin);
|
||||
registerSubCommand(new ListCommand(this, "list", "l"));
|
||||
registerSubCommand(new SetCommand(this, "set"));
|
||||
registerSubCommand(new ReloadCommand(this, "reload"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] args) {
|
||||
if (args.length == 1) {
|
||||
String aim = args[0];
|
||||
if (aim.equalsIgnoreCase("list")) {
|
||||
PluginMessages.LIST.HEADER.send(sender);
|
||||
for (PrefixConfig value : UserPrefixAPI.getPrefixManager().getPrefixes().values()) {
|
||||
PluginMessages.LIST.VALUE.send(sender,
|
||||
value.getWeight(), value.getIdentifier(),
|
||||
value.getName(), value.getPermission(),
|
||||
value.getContent(), sender.getName()
|
||||
);
|
||||
}
|
||||
return true;
|
||||
} else if (aim.equalsIgnoreCase("reload")) {
|
||||
long s1 = System.currentTimeMillis();
|
||||
PrefixSelectGUI.closeAll(); // 关掉所有正在显示的前缀列表
|
||||
try {
|
||||
UserPrefixAPI.getConfigManager().reload(); // 重载配置文件
|
||||
int num = UserPrefixAPI.getPrefixManager().loadPrefixes(); //加载重载后了的前缀配置
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
UserPrefixAPI.getUserManager().checkPrefix(onlinePlayer, false);
|
||||
/*
|
||||
* 这里关掉loadOthers(为其他玩家更新)了。
|
||||
* 因为每个玩家更新的时候会为其他人更新自己,
|
||||
* 全部走完一遍后,所有玩家都会加载最新的前缀内容。
|
||||
*/
|
||||
UserPrefixAPI.getUserManager().updatePrefixView(onlinePlayer, false);
|
||||
}
|
||||
PluginMessages.RELOAD.SUCCESS.send(sender, System.currentTimeMillis() - s1, num);
|
||||
} catch (Exception e) {
|
||||
PluginMessages.RELOAD.FAILED.send(sender, e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return help(sender);
|
||||
}
|
||||
public Void noArgs(CommandSender sender) {
|
||||
return help(sender);
|
||||
}
|
||||
|
||||
public static boolean help(CommandSender sender) {
|
||||
PluginMessages.COMMAND_USAGE.ADMIN.send(sender);
|
||||
return true;
|
||||
@Override
|
||||
public Void noPermission(CommandSender sender) {
|
||||
PluginMessages.COMMAND_USAGE.NO_PERM.send(sender);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Void help(CommandSender sender) {
|
||||
PluginMessages.COMMAND_USAGE.ADMIN.send(sender);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package cc.carm.plugin.userprefix.command;
|
||||
|
||||
import cc.carm.plugin.userprefix.configuration.PluginMessages;
|
||||
import cc.carm.plugin.userprefix.conf.PluginMessages;
|
||||
import cc.carm.plugin.userprefix.ui.PrefixSelectGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package cc.carm.plugin.userprefix.command.admin;
|
||||
|
||||
import cc.carm.lib.easyplugin.command.SubCommand;
|
||||
import cc.carm.plugin.userprefix.UserPrefixAPI;
|
||||
import cc.carm.plugin.userprefix.command.AdminCommand;
|
||||
import cc.carm.plugin.userprefix.conf.PluginMessages;
|
||||
import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ListCommand extends SubCommand<AdminCommand> {
|
||||
|
||||
public ListCommand(@NotNull AdminCommand parent, String name, String... aliases) {
|
||||
super(parent, name, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void execute(JavaPlugin plugin, CommandSender sender, String[] args) {
|
||||
PluginMessages.LIST.HEADER.send(sender);
|
||||
for (PrefixConfig value : UserPrefixAPI.getPrefixManager().getPrefixes().values()) {
|
||||
PluginMessages.LIST.VALUE.send(sender,
|
||||
value.getWeight(), value.getIdentifier(),
|
||||
value.getName(), value.getPermission(),
|
||||
value.getContent(), sender.getName()
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package cc.carm.plugin.userprefix.command.admin;
|
||||
|
||||
import cc.carm.lib.easyplugin.command.SubCommand;
|
||||
import cc.carm.plugin.userprefix.UserPrefixAPI;
|
||||
import cc.carm.plugin.userprefix.command.AdminCommand;
|
||||
import cc.carm.plugin.userprefix.conf.PluginMessages;
|
||||
import cc.carm.plugin.userprefix.ui.PrefixSelectGUI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ReloadCommand extends SubCommand<AdminCommand> {
|
||||
|
||||
public ReloadCommand(@NotNull AdminCommand parent, String name, String... aliases) {
|
||||
super(parent, name, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void execute(JavaPlugin plugin, CommandSender sender, String[] args) {
|
||||
long s1 = System.currentTimeMillis();
|
||||
PrefixSelectGUI.closeAll(); // 关掉所有正在显示的前缀列表
|
||||
try {
|
||||
UserPrefixAPI.getConfigManager().reload(); // 重载配置文件
|
||||
int num = UserPrefixAPI.getPrefixManager().loadPrefixes(); //加载重载后了的前缀配置
|
||||
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
UserPrefixAPI.getUserManager().checkPrefix(onlinePlayer, false);
|
||||
/*
|
||||
* 这里关掉loadOthers(为其他玩家更新)了。
|
||||
* 因为每个玩家更新的时候会为其他人更新自己,
|
||||
* 全部走完一遍后,所有玩家都会加载最新的前缀内容。
|
||||
*/
|
||||
UserPrefixAPI.getUserManager().updatePrefixView(onlinePlayer, false);
|
||||
}
|
||||
PluginMessages.RELOAD.SUCCESS.send(sender, System.currentTimeMillis() - s1, num);
|
||||
} catch (Exception e) {
|
||||
PluginMessages.RELOAD.FAILED.send(sender, e.getMessage());
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package cc.carm.plugin.userprefix.command.admin;
|
||||
|
||||
import cc.carm.lib.easyplugin.command.SubCommand;
|
||||
import cc.carm.plugin.userprefix.UserPrefixAPI;
|
||||
import cc.carm.plugin.userprefix.command.AdminCommand;
|
||||
import cc.carm.plugin.userprefix.conf.PluginMessages;
|
||||
import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SetCommand extends SubCommand<AdminCommand> {
|
||||
|
||||
public SetCommand(@NotNull AdminCommand parent, String name, String... aliases) {
|
||||
super(parent, name, aliases);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void execute(JavaPlugin plugin, CommandSender sender, String[] args) {
|
||||
if (args.length < 2) return getParent().noArgs(sender);
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
PluginMessages.NOT_ONLINE.send(sender, args[0]);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
PrefixConfig prefixConfig;
|
||||
String prefixInput = args[1];
|
||||
if (prefixInput.equalsIgnoreCase("default")) {
|
||||
prefixConfig = UserPrefixAPI.getDefaultPrefix();
|
||||
} else {
|
||||
prefixConfig = UserPrefixAPI.getPrefixManager().getPrefix(prefixInput);
|
||||
}
|
||||
|
||||
if (prefixConfig == null) {
|
||||
PluginMessages.SET.PREFIX_NOT_FOUND.send(sender, prefixInput);
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!prefixConfig.checkPermission(target)) {
|
||||
PluginMessages.SET.NO_PERM.send(sender, target.getName(), prefixConfig.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
UserPrefixAPI.getUserManager().setPrefix(target, prefixConfig, true);
|
||||
PluginMessages.SET.SUCCESS.send(sender, target.getName(), prefixConfig.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+29
-32
@@ -1,22 +1,18 @@
|
||||
package cc.carm.plugin.userprefix.configuration;
|
||||
package cc.carm.plugin.userprefix.conf;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||
import cc.carm.lib.configuration.core.annotation.ConfigPath;
|
||||
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.value.ConfiguredItem;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredSound;
|
||||
import cc.carm.plugin.userprefix.configuration.reader.GUIItemReader;
|
||||
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({"开发者查错模式"})
|
||||
@@ -37,7 +33,7 @@ public class PluginConfig extends ConfigurationRoot {
|
||||
public static final ConfigValue<Boolean> CHECK_UPDATE = ConfiguredValue.of(Boolean.class, true);
|
||||
|
||||
@HeaderComment({"自定义存储位置设定", "可以规定到远程文件夹中去加载前缀配置"})
|
||||
public static final class CUSTOM_STORAGE {
|
||||
public static final class CUSTOM_STORAGE extends ConfigurationRoot {
|
||||
|
||||
@HeaderComment({"是否启用自定义存储位置"})
|
||||
public static final ConfigValue<Boolean> ENABLE = ConfiguredValue.of(Boolean.class, false);
|
||||
@@ -52,11 +48,11 @@ public class PluginConfig extends ConfigurationRoot {
|
||||
}
|
||||
|
||||
@HeaderComment("功能设定")
|
||||
public static class FUNCTIONS {
|
||||
public static class FUNCTIONS 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);
|
||||
@@ -78,28 +74,28 @@ public class PluginConfig extends ConfigurationRoot {
|
||||
"- 注意聊天格式需要遵守Bukkit原格式,即不得缺失 “%1$s” 和 “%2$s” 。",
|
||||
"- 本插件的聊天功能不影响其他插件对聊天事件的操作。"
|
||||
})
|
||||
public static final class CHAT {
|
||||
public static final class CHAT extends ConfigurationRoot {
|
||||
|
||||
@HeaderComment("是否开启本功能")
|
||||
public static ConfigValue<Boolean> ENABLE = ConfiguredValue.of(Boolean.class, false);
|
||||
public static final ConfigValue<Boolean> ENABLE = ConfiguredValue.of(Boolean.class, false);
|
||||
@HeaderComment({
|
||||
"聊天的格式,注意 “%1$s” 和 “%2$s” 不可缺少。",
|
||||
"- %1$s -> 玩家名", "- %2$s -> 聊天内容"
|
||||
})
|
||||
public static ConfigValue<String> FORMAT = ConfiguredValue.of(String.class, "<%1$s> %2$s");
|
||||
public static final ConfigValue<String> FORMAT = ConfiguredValue.of(String.class, "<%1$s> %2$s");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@HeaderComment({"前缀GUI界面设定"})
|
||||
public static class GUI {
|
||||
public static class GUI extends ConfigurationRoot {
|
||||
|
||||
@HeaderComment("GUI的标题")
|
||||
public static final ConfigValue<String> TITLE = ConfiguredValue.of(String.class, "&f&l我的前缀 &8| 列表");
|
||||
|
||||
@HeaderComment("GUI中的按钮")
|
||||
public static final class ITEMS {
|
||||
@HeaderComment("GUI中的基本按钮物品")
|
||||
public static final class BOTTOMS extends ConfigurationRoot {
|
||||
|
||||
@HeaderComment("前往下一页的物品 (只有存在下一页时才会显示)")
|
||||
public static final ConfiguredItem NEXT_PAGE = ConfiguredItem.create()
|
||||
@@ -116,24 +112,20 @@ 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) -> GUIItemReader.readFrom(v))
|
||||
.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({"相关的声音,留空则不播放声音", "格式为 【声音名:音量:音调】 或 【声音名:音量】 或 【声音名】"})
|
||||
public static final class SOUNDS {
|
||||
public static final class SOUNDS extends ConfigurationRoot {
|
||||
|
||||
public static final ConfiguredSound GUI_OPEN = ConfiguredSound.of("BLOCK_NOTE_BLOCK_PLING", 0.5F, 0.8F);
|
||||
public static final ConfiguredSound GUI_CLICK = ConfiguredSound.of("UI_BUTTON_CLICK");
|
||||
@@ -143,7 +135,7 @@ public class PluginConfig extends ConfigurationRoot {
|
||||
}
|
||||
|
||||
@HeaderComment({"默认前缀配置"})
|
||||
public static final class DEFAULT_PREFIX {
|
||||
public static final class DEFAULT_PREFIX extends ConfigurationRoot {
|
||||
|
||||
@HeaderComment("默认前缀的显示名称,用于在消息提示中显示。")
|
||||
public static final ConfigValue<String> NAME = ConfiguredValue.of(String.class, "默认前缀");
|
||||
@@ -154,8 +146,13 @@ public class PluginConfig extends ConfigurationRoot {
|
||||
@HeaderComment({"默认前缀的内容,即用于显示的实际前缀"})
|
||||
public static final ConfigValue<String> CONTENT = ConfiguredValue.of(String.class, "&r");
|
||||
|
||||
@HeaderComment({"选择默认前缀时执行的操作"})
|
||||
public static final ConfiguredList<String> ACTIONS = ConfiguredList.builderOf(String.class).fromString()
|
||||
.defaults("[CONSOLE] " + "say %player_name% 选择了默认前缀")
|
||||
.build();
|
||||
|
||||
@HeaderComment({"默认前缀的显示物品"})
|
||||
public static final class ITEM {
|
||||
public static final class ITEM extends ConfigurationRoot {
|
||||
|
||||
@HeaderComment({"当未选择默认前缀时显示的物品"})
|
||||
public static final ConfiguredItem NOT_USING = ConfiguredItem.create()
|
||||
@@ -0,0 +1,94 @@
|
||||
package cc.carm.plugin.userprefix.conf;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||
import cc.carm.lib.configuration.core.annotation.HeaderComment;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList;
|
||||
|
||||
public class PluginMessages extends ConfigurationRoot {
|
||||
|
||||
public static final class COMMAND_USAGE extends ConfigurationRoot {
|
||||
|
||||
public static final ConfiguredMessageList<String> CONSOLE = ConfiguredMessageList.asStrings().defaults(
|
||||
"&f请输入 &b/prefix <玩家ID> &f为指定玩家打开前缀GUI。"
|
||||
).build();
|
||||
|
||||
public static final ConfiguredMessageList<String> ADMIN = ConfiguredMessageList.asStrings().defaults(
|
||||
"&3&l用户前缀系统 &f帮助",
|
||||
"&8# &f/upa list",
|
||||
"&8- &7查看当前前缀列表。",
|
||||
"&8# &f/upa set &b<玩家ID> &b<前缀ID>",
|
||||
"&8- &7为玩家设定指定前缀。",
|
||||
"&8- &7&o注意:玩家必须拥有指定前缀的权限。",
|
||||
"&8# &f/upa reload",
|
||||
"&8- &7重载前缀配置。"
|
||||
).build();
|
||||
|
||||
public static final ConfiguredMessageList<String> NO_PERM = ConfiguredMessageList.asStrings()
|
||||
.defaults("&c&l抱歉!&f但您没有权限使用该指令。")
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public static final ConfiguredMessageList<String> NOT_ONLINE = ConfiguredMessageList.asStrings()
|
||||
.defaults("&7玩家 &b%(player) &7并不在线。")
|
||||
.params("player").build();
|
||||
|
||||
public static final ConfiguredMessageList<String> SELECTED = ConfiguredMessageList.asStrings()
|
||||
.defaults("&7您选择了 &f%(name) &7作为当前显示的前缀。")
|
||||
.params("name").build();
|
||||
|
||||
public static final ConfiguredMessageList<String> EXPIRED = ConfiguredMessageList.asStrings()
|
||||
.defaults(
|
||||
"&7您先前使用的前缀 &f%(oldName) &7已到期。",
|
||||
"&7现在已为您重新调整为 &f%(newName) &7。"
|
||||
).params("oldName", "newName").build();
|
||||
|
||||
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 final ConfiguredMessageList<String> SUCCESS = ConfiguredMessageList.asStrings()
|
||||
.defaults("&a&l重载完成!&7耗时 &f%(time)ms&7,共加载了 &b%(count) &7个前缀。")
|
||||
.params("time", "count").build();
|
||||
|
||||
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 final ConfiguredMessageList<String> SUCCESS = ConfiguredMessageList.asStrings()
|
||||
.defaults("&a&l设置成功!&7成功设定玩家 &b%(player) &f的前缀为 &r%(prefix) &f。")
|
||||
.params("player", "prefix").build();
|
||||
|
||||
public static final ConfiguredMessageList<String> PREFIX_NOT_FOUND = ConfiguredMessageList.asStrings()
|
||||
.defaults("&c&l无法设置!&7不存在ID为 &b%(prefix) &7的前缀。")
|
||||
.params("prefix").build();
|
||||
|
||||
public static final ConfiguredMessageList<String> NO_PERM = ConfiguredMessageList.asStrings()
|
||||
.defaults("&c&l无法设置!&7玩家 &b%(player) &7并没有前缀 &r%(prefix) &7的前缀。")
|
||||
.params("player", "prefix")
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@HeaderComment("管理员使用的 “/upa list” 指令的格式")
|
||||
public static final class LIST extends ConfigurationRoot {
|
||||
|
||||
public static final ConfiguredMessageList<String> HEADER = ConfiguredMessageList.asStrings()
|
||||
.defaults("&3&l用户前缀系统 &f前缀列表").build();
|
||||
|
||||
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)"
|
||||
).params("weight", "identifier", "name", "permission", "content", "sender_name").build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
+29
-20
@@ -1,22 +1,19 @@
|
||||
package cc.carm.plugin.userprefix.configuration.prefix;
|
||||
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.configuration.file.FileConfiguration;
|
||||
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;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
public class PrefixConfig {
|
||||
|
||||
|
||||
private @Nullable File dataFile;
|
||||
private @Nullable FileConfiguration configuration;
|
||||
|
||||
protected final @NotNull String identifier;
|
||||
|
||||
protected final @NotNull String name;
|
||||
@@ -26,20 +23,24 @@ public class PrefixConfig {
|
||||
|
||||
protected final @Nullable String permission;
|
||||
|
||||
protected final @NotNull ItemConfig itemHasPermission;
|
||||
protected final @Nullable ItemConfig itemNoPermission;
|
||||
protected final @Nullable ItemConfig itemWhenUsing;
|
||||
protected final @NotNull List<GUIActionConfiguration> actions;
|
||||
|
||||
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 ItemConfig itemHasPermission,
|
||||
@Nullable ItemConfig itemWhenUsing,
|
||||
@Nullable ItemConfig itemNoPermission) {
|
||||
@NotNull List<GUIActionConfiguration> actions,
|
||||
@NotNull ItemStack itemHasPermission,
|
||||
@Nullable ItemStack itemWhenUsing,
|
||||
@Nullable ItemStack itemNoPermission) {
|
||||
this.identifier = identifier;
|
||||
this.name = name;
|
||||
this.content = content;
|
||||
this.weight = weight;
|
||||
this.permission = permission;
|
||||
this.actions = actions;
|
||||
this.itemHasPermission = itemHasPermission;
|
||||
this.itemNoPermission = itemNoPermission;
|
||||
this.itemWhenUsing = itemWhenUsing;
|
||||
@@ -71,27 +72,35 @@ 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 getItemHasPermission(player);
|
||||
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;
|
||||
}
|
||||
|
||||
public void executeActions(@NotNull Player player) {
|
||||
this.actions.forEach(action -> action.executeAction(player));
|
||||
}
|
||||
|
||||
public boolean isVisible(Player player) {
|
||||
return this.itemWhenUsing != null || checkPermission(player);
|
||||
return this.itemNoPermission != null || checkPermission(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1,67 +0,0 @@
|
||||
package cc.carm.plugin.userprefix.configuration;
|
||||
|
||||
import cc.carm.lib.configuration.core.ConfigurationRoot;
|
||||
import cc.carm.lib.configuration.core.annotation.HeaderComment;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.value.ConfiguredMessageList;
|
||||
|
||||
public class PluginMessages extends ConfigurationRoot {
|
||||
|
||||
public static final class COMMAND_USAGE {
|
||||
|
||||
public static ConfiguredMessageList<String> CONSOLE = ConfiguredMessageList.asStrings().defaults(
|
||||
"&f请输入 &b/prefix <玩家ID> &f为指定玩家打开前缀GUI。"
|
||||
).build();
|
||||
|
||||
public static ConfiguredMessageList<String> ADMIN = ConfiguredMessageList.asStrings().defaults(
|
||||
"&3&l用户前缀系统 &f帮助",
|
||||
"&8# &f/upa list",
|
||||
"&8- &7查看当前前缀列表。",
|
||||
"&8# &f/upa reload",
|
||||
"&8- &7重载前缀配置。"
|
||||
).build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static ConfiguredMessageList<String> SELECTED = ConfiguredMessageList.asStrings()
|
||||
.defaults("&7您选择了 &f%(name) &7作为当前显示的前缀。")
|
||||
.params("name").build();
|
||||
|
||||
public static 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()
|
||||
.defaults("&7您先前使用的前缀已被移除,现在已为您重新调整为 &f%(newName) &7。")
|
||||
.params("newName").build();
|
||||
|
||||
public static final class RELOAD {
|
||||
|
||||
public static 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()
|
||||
.defaults("&c&l重载出错!&7错误提示为 &8“&r%(error)&8”。")
|
||||
.params("error").build();
|
||||
}
|
||||
|
||||
|
||||
@HeaderComment("管理员使用的 “/upa list” 指令的格式")
|
||||
public static final class LIST {
|
||||
|
||||
public static ConfiguredMessageList<String> HEADER = ConfiguredMessageList.asStrings()
|
||||
.defaults("&3&l用户前缀系统 &f前缀列表").build();
|
||||
|
||||
public static ConfiguredMessageList<String> VALUE = ConfiguredMessageList.asStrings().defaults(
|
||||
"&8#%(weight) &f%(identifier)",
|
||||
"&8- &7显示名 &r%(name) &7权限 &r%(permission)",
|
||||
"&8- &7内容示例&r %(content) %(sender_name)"
|
||||
).params("weight", "identifier", "name", "permission", "content", "sender_name").build();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package cc.carm.plugin.userprefix.configuration.reader;
|
||||
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationWrapper;
|
||||
import cc.carm.lib.easyplugin.gui.configuration.GUIActionConfiguration;
|
||||
import cc.carm.lib.easyplugin.gui.configuration.GUIItemConfiguration;
|
||||
import org.bukkit.Material;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class GUIItemReader {
|
||||
|
||||
public static @Nullable GUIItemConfiguration readFrom(@Nullable ConfigurationWrapper section) {
|
||||
if (section == null) return null;
|
||||
String material = Optional.ofNullable(section.getString("type")).orElse("STONE");
|
||||
Material type = Optional.ofNullable(Material.matchMaterial(material)).orElse(Material.STONE);
|
||||
int data = section.getInt("data", 0);
|
||||
int amount = section.getInt("amount", 1);
|
||||
String name = section.getString("name");
|
||||
List<String> lore = section.getStringList("lore");
|
||||
|
||||
List<Integer> slots = section.getIntegerList("slots");
|
||||
int slot = section.getInt("slot", 0);
|
||||
|
||||
List<String> actionsString = section.getStringList("actions");
|
||||
List<GUIActionConfiguration> actions = new ArrayList<>();
|
||||
for (String actionString : actionsString) {
|
||||
GUIActionConfiguration action = GUIActionConfiguration.deserialize(actionString);
|
||||
if (action == null) continue;
|
||||
actions.add(action);
|
||||
}
|
||||
|
||||
return new GUIItemConfiguration(
|
||||
type, amount, data, name, lore, actions,
|
||||
slots.size() > 0 ? slots : Collections.singletonList(slot)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package cc.carm.plugin.userprefix.event;
|
||||
|
||||
import cc.carm.plugin.userprefix.Main;
|
||||
import cc.carm.plugin.userprefix.configuration.prefix.PrefixConfig;
|
||||
import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package cc.carm.plugin.userprefix.event;
|
||||
|
||||
import cc.carm.plugin.userprefix.Main;
|
||||
import cc.carm.plugin.userprefix.configuration.prefix.PrefixConfig;
|
||||
import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -1,89 +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.configuration.prefix.PrefixConfig;
|
||||
import me.clip.placeholderapi.expansion.PlaceholderExpansion;
|
||||
import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig;
|
||||
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_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)
|
||||
);
|
||||
|
||||
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 UserPrefixExpansion(@NotNull Main plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@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";
|
||||
public String onErrorParams(@Nullable OfflinePlayer player) {
|
||||
return "参数不足";
|
||||
}
|
||||
|
||||
@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 "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 "参数错误";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ package cc.carm.plugin.userprefix.listener;
|
||||
|
||||
import cc.carm.lib.easyplugin.utils.MessageUtils;
|
||||
import cc.carm.plugin.userprefix.Main;
|
||||
import cc.carm.plugin.userprefix.configuration.PluginConfig;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import cc.carm.plugin.userprefix.conf.PluginConfig;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
@@ -20,8 +19,8 @@ public class ChatListener implements Listener {
|
||||
try {
|
||||
event.setFormat(MessageUtils.setPlaceholders(event.getPlayer(), format));
|
||||
} catch (Exception exception) {
|
||||
Main.serve("请检查配置文件中聊天相关是否配置正确。");
|
||||
Main.serve("Please check the chat configuration.");
|
||||
Main.severe("请检查配置文件中聊天相关是否配置正确。");
|
||||
Main.severe("Please check the chat configuration.");
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
package cc.carm.plugin.userprefix.listener.processor;
|
||||
package cc.carm.plugin.userprefix.listener;
|
||||
|
||||
import cc.carm.plugin.userprefix.Main;
|
||||
import cc.carm.plugin.userprefix.UserPrefixAPI;
|
||||
@@ -7,7 +7,7 @@ import net.luckperms.api.event.user.UserDataRecalculateEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class UserNodeUpdateProcessor {
|
||||
public class UserPermListener {
|
||||
|
||||
public static void process(UserDataRecalculateEvent event) {
|
||||
Player player = Bukkit.getPlayer(event.getUser().getUniqueId());
|
||||
@@ -3,8 +3,8 @@ package cc.carm.plugin.userprefix.manager;
|
||||
import cc.carm.lib.configuration.core.source.ConfigurationProvider;
|
||||
import cc.carm.lib.easyplugin.utils.JarResourceUtils;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.MineConfiguration;
|
||||
import cc.carm.plugin.userprefix.configuration.PluginConfig;
|
||||
import cc.carm.plugin.userprefix.configuration.PluginMessages;
|
||||
import cc.carm.plugin.userprefix.conf.PluginConfig;
|
||||
import cc.carm.plugin.userprefix.conf.PluginMessages;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -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.mineconfiguration.bukkit.data.ItemConfig;
|
||||
import cc.carm.lib.mineconfiguration.bukkit.source.CraftSectionWrapper;
|
||||
import cc.carm.lib.easyplugin.gui.configuration.GUIActionConfiguration;
|
||||
import cc.carm.lib.easyplugin.utils.ItemStackFactory;
|
||||
import cc.carm.plugin.userprefix.Main;
|
||||
import cc.carm.plugin.userprefix.configuration.PluginConfig;
|
||||
import cc.carm.plugin.userprefix.configuration.prefix.PrefixConfig;
|
||||
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;
|
||||
@@ -41,9 +43,9 @@ public class PrefixManager {
|
||||
|
||||
String[] filesList = prefixDataFolder.list();
|
||||
if (filesList == null || filesList.length < 1) {
|
||||
Main.serve("配置文件夹中暂无任何前缀配置问,请检查。");
|
||||
Main.serve("There's no configured prefix.");
|
||||
Main.serve("Path: " + prefixDataFolder.getAbsolutePath());
|
||||
Main.severe("配置文件夹中暂无任何前缀配置问,请检查。");
|
||||
Main.severe("There's no configured prefix.");
|
||||
Main.severe("Path: " + prefixDataFolder.getAbsolutePath());
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -57,12 +59,12 @@ public class PrefixManager {
|
||||
if (files.size() > 0) {
|
||||
for (File file : files) {
|
||||
try {
|
||||
PrefixConfig prefix = adPrefix(file);
|
||||
PrefixConfig prefix = addPrefix(file);
|
||||
Main.debugging("完成前缀加载 " + prefix.getIdentifier() + " : " + prefix.getName());
|
||||
loaded.put(prefix.getIdentifier(), prefix);
|
||||
} catch (Exception ex) {
|
||||
Main.serve("在加载前缀 " + file.getAbsolutePath() + " 时出错,请检查配置!");
|
||||
Main.serve("Error occurred when loading prefix #" + file.getAbsolutePath() + " !");
|
||||
Main.severe("在加载前缀 " + file.getAbsolutePath() + " 时出错,请检查配置!");
|
||||
Main.severe("Error occurred when loading prefix #" + file.getAbsolutePath() + " !");
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -78,9 +80,9 @@ public class PrefixManager {
|
||||
PluginConfig.DEFAULT_PREFIX.CONTENT.getNotNull(),
|
||||
PluginConfig.DEFAULT_PREFIX.WEIGHT.getNotNull(),
|
||||
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());
|
||||
}
|
||||
@@ -122,34 +124,43 @@ public class PrefixManager {
|
||||
}
|
||||
}
|
||||
|
||||
public static @NotNull PrefixConfig adPrefix(@NotNull File file) throws Exception {
|
||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
|
||||
String identifier = configuration.getString("identifier");
|
||||
if (identifier == null) throw new Exception("配置文件 " + file.getAbsolutePath() + " 中没有配置前缀的唯一标识。");
|
||||
public static @NotNull PrefixConfig addPrefix(@NotNull File file) throws Exception {
|
||||
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"),
|
||||
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(CraftSectionWrapper.of(section));
|
||||
else return XItemStack.deserialize(section);
|
||||
}
|
||||
|
||||
protected static List<GUIActionConfiguration> readActions(@NotNull List<String> strings) {
|
||||
return strings.stream().map(GUIActionConfiguration::deserialize).filter(Objects::nonNull).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package cc.carm.plugin.userprefix.manager;
|
||||
import cc.carm.lib.easyplugin.gui.GUI;
|
||||
import cc.carm.plugin.userprefix.Main;
|
||||
import cc.carm.plugin.userprefix.UserPrefixAPI;
|
||||
import cc.carm.plugin.userprefix.configuration.PluginConfig;
|
||||
import cc.carm.plugin.userprefix.configuration.PluginMessages;
|
||||
import cc.carm.plugin.userprefix.configuration.prefix.PrefixConfig;
|
||||
import cc.carm.plugin.userprefix.conf.PluginConfig;
|
||||
import cc.carm.plugin.userprefix.conf.PluginMessages;
|
||||
import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig;
|
||||
import cc.carm.plugin.userprefix.event.UserPrefixChangeEvent;
|
||||
import cc.carm.plugin.userprefix.event.UserPrefixExpireEvent;
|
||||
import cc.carm.plugin.userprefix.hooker.UserNameTag;
|
||||
@@ -131,19 +131,17 @@ 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) -> {
|
||||
if (after != null) {
|
||||
setPrefix(player, after, updateView);
|
||||
}
|
||||
if (after != null) setPrefix(player, after, updateView);
|
||||
checkingPlayers.remove(player.getUniqueId());
|
||||
});
|
||||
|
||||
@@ -183,6 +181,7 @@ public class UserManager {
|
||||
*/
|
||||
public void setPrefix(Player player, PrefixConfig prefix, boolean updateView) {
|
||||
setPrefixData(player, prefix.getIdentifier());
|
||||
prefix.executeActions(player);
|
||||
if (updateView) updatePrefixView(player, false);
|
||||
}
|
||||
|
||||
@@ -210,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();
|
||||
}
|
||||
|
||||
@@ -4,15 +4,17 @@ import cc.carm.lib.easyplugin.gui.GUIItem;
|
||||
import cc.carm.lib.easyplugin.gui.GUIType;
|
||||
import cc.carm.lib.easyplugin.gui.paged.AutoPagedGUI;
|
||||
import cc.carm.plugin.userprefix.UserPrefixAPI;
|
||||
import cc.carm.plugin.userprefix.configuration.PluginConfig;
|
||||
import cc.carm.plugin.userprefix.configuration.PluginMessages;
|
||||
import cc.carm.plugin.userprefix.configuration.prefix.PrefixConfig;
|
||||
import cc.carm.plugin.userprefix.conf.PluginConfig;
|
||||
import cc.carm.plugin.userprefix.conf.PluginMessages;
|
||||
import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig;
|
||||
import cc.carm.plugin.userprefix.event.UserPrefixChangeEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
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 {
|
||||
|
||||
@@ -27,7 +29,7 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
||||
setPreviousPageSlot(18);
|
||||
setNextPageSlot(26);
|
||||
|
||||
loadBackButton();
|
||||
loadExtraIcons();
|
||||
loadItems();
|
||||
}
|
||||
|
||||
@@ -35,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() {
|
||||
@@ -48,18 +50,28 @@ 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)) {
|
||||
|
||||
@Override
|
||||
public void onClick(ClickType type) {
|
||||
public void onClick(Player clicker, ClickType type) {
|
||||
player.closeInventory();
|
||||
//再次检查,防止打开GUI后、选择前的时间段内权限消失
|
||||
if (prefix.checkPermission(player)) {
|
||||
UserPrefixAPI.getUserManager().setPrefix(player, prefix, true);
|
||||
|
||||
// 发送消息与提示
|
||||
PluginConfig.SOUNDS.PREFIX_CHANGE.playTo(player);
|
||||
PluginMessages.SELECTED.send(player, prefix.getName());
|
||||
|
||||
UserPrefixChangeEvent.call(player, usingPrefix, prefix, config -> {
|
||||
if (config == null) return;
|
||||
UserPrefixAPI.getUserManager().setPrefix(player, config, true);
|
||||
});
|
||||
|
||||
} else {
|
||||
PluginConfig.SOUNDS.GUI_CLICK.playTo(player);
|
||||
}
|
||||
@@ -68,7 +80,7 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
||||
} else {
|
||||
addItem(new GUIItem(prefix.getItemNoPermission(player)) {
|
||||
@Override
|
||||
public void onClick(ClickType type) {
|
||||
public void onClick(Player clicker, ClickType type) {
|
||||
PluginConfig.SOUNDS.GUI_CLICK.playTo(player);
|
||||
}
|
||||
});
|
||||
|
||||
+10
-3
@@ -22,11 +22,18 @@ weight: 1
|
||||
# (because it is impossible to display items without permission at all)
|
||||
permission: "yc.vip"
|
||||
|
||||
# Actions when select [Unnecessary]
|
||||
# Please check https://github.com/CarmJos/UserPrefix/tree/master/.documentation/ACTIONS.md
|
||||
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:
|
||||
- ""
|
||||
@@ -36,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 it’s selected
|
||||
@@ -48,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!"
|
||||
@@ -22,13 +22,21 @@ weight: 1
|
||||
# 如果没有就是人人都能用,也代表不用配置“itemNoPermission”了(因为压根不可能显示没权限时候的物品)
|
||||
permission: "yc.pro"
|
||||
|
||||
# 选择这个前缀时执行的操作 [非必须]
|
||||
# 用于在玩家选择/取消选择前缀时执行相应动作,以便于实现一些特殊的功能。
|
||||
# 具体操作类型详见介绍,前缀操作不支持限定点击类型。
|
||||
# https://github.com/CarmJos/UserPrefix/tree/master/.documentation/ACTIONS.md
|
||||
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会员专属称号"
|
||||
@@ -41,7 +49,7 @@ item:
|
||||
# 正在使用时显示的物品 [非必需]
|
||||
# 当用户正在使用时会显示这个物品,不配置即自动加载“itemHasPermission”
|
||||
using:
|
||||
type: DIAMOND
|
||||
material: DIAMOND
|
||||
name: "&b&lPro &b会员前缀"
|
||||
flags:
|
||||
- HIDE_ENCHANTS # 隐藏附魔显示
|
||||
@@ -58,7 +66,7 @@ item:
|
||||
# 没有权限时显示的物品 [非必需]
|
||||
# 如果没有权限就会显示这个item。如果不配置该物品,则玩家没有使用权限时不会显示在GUI里面。
|
||||
no-perm:
|
||||
type: INK_SACK
|
||||
material: INK_SACK
|
||||
data: 8
|
||||
name: "&b&lPro+ &b会员前缀 &c(未拥有)"
|
||||
lore:
|
||||
@@ -68,4 +76,4 @@ item:
|
||||
- "&f您将获得多种特权与更好的游戏体验。"
|
||||
- "&f您可以输入 &b/vip &f指令查看详细特权!"
|
||||
- ""
|
||||
- "&e✯ 加入Pro+会员以使用该前缀!"
|
||||
- "&e✯ 加入Pro+会员以使用该前缀!"
|
||||
|
||||
Reference in New Issue
Block a user