mirror of
https://github.com/CarmJos/UserPrefix.git
synced 2026-07-17 01:11:23 +08:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 762d366b59 | |||
| 8e775a7b15 | |||
| 74c3964883 | |||
| dfe072b1fd | |||
| 3b2eaf2519 | |||
| 75ee308174 | |||
| bed1651027 | |||
| 7dde64e699 | |||
| 9b88142676 | |||
| e0cfd87ac6 | |||
| fd764fa348 | |||
| 480cebd16a | |||
| 6cd25cf94a | |||
| 72071492b3 | |||
| b334c3476e | |||
| c94ed28b98 | |||
| 72aa4e3a82 |
@@ -38,7 +38,7 @@ jobs:
|
|||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v6
|
uses: actions/checkout@v7
|
||||||
|
|
||||||
# Initializes the CodeQL tools for scanning.
|
# Initializes the CodeQL tools for scanning.
|
||||||
- name: Initialize CodeQL
|
- name: Initialize CodeQL
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v7
|
||||||
- name: "Set up JDK"
|
- name: "Set up JDK"
|
||||||
uses: actions/setup-java@v5
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
@@ -102,6 +102,8 @@ jobs:
|
|||||||
spigot
|
spigot
|
||||||
paper
|
paper
|
||||||
purpur
|
purpur
|
||||||
|
folia
|
||||||
|
bukkit
|
||||||
game-versions: |
|
game-versions: |
|
||||||
>=1.8 <=1.21.8
|
>=1.8 <=1.21.8
|
||||||
game-version-filter: releases
|
game-version-filter: releases
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v7
|
||||||
- name: "Set up JDK"
|
- name: "Set up JDK"
|
||||||
uses: actions/setup-java@v5
|
uses: actions/setup-java@v5
|
||||||
with:
|
with:
|
||||||
@@ -37,7 +37,7 @@ jobs:
|
|||||||
cp -vrf asset/*.jar artifacts
|
cp -vrf asset/*.jar artifacts
|
||||||
|
|
||||||
- name: "Upload artifact"
|
- name: "Upload artifact"
|
||||||
uses: actions/upload-artifact@v6
|
uses: actions/upload-artifact@v7
|
||||||
with:
|
with:
|
||||||
name: Artifact
|
name: Artifact
|
||||||
path: artifacts
|
path: artifacts
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
|
|
||||||
<groupId>cc.carm.plugin</groupId>
|
<groupId>cc.carm.plugin</groupId>
|
||||||
<artifactId>userprefix</artifactId>
|
<artifactId>userprefix</artifactId>
|
||||||
<version>3.3.1</version>
|
<version>3.4.0</version>
|
||||||
|
|
||||||
<name>UserPrefix</name>
|
<name>UserPrefix</name>
|
||||||
<description>轻便、高效、实时的用户前缀系统。</description>
|
<description>轻便、高效、实时的用户前缀系统。</description>
|
||||||
@@ -173,7 +173,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.cryptomorin</groupId>
|
<groupId>com.github.cryptomorin</groupId>
|
||||||
<artifactId>XSeries</artifactId>
|
<artifactId>XSeries</artifactId>
|
||||||
<version>13.6.0</version>
|
<version>13.8.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
@@ -195,7 +195,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>me.clip</groupId>
|
<groupId>me.clip</groupId>
|
||||||
<artifactId>placeholderapi</artifactId>
|
<artifactId>placeholderapi</artifactId>
|
||||||
<version>2.11.7</version>
|
<version>2.12.3</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -209,14 +209,14 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.bstats</groupId>
|
<groupId>org.bstats</groupId>
|
||||||
<artifactId>bstats-bukkit</artifactId>
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
<version>3.1.0</version>
|
<version>3.2.1</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains</groupId>
|
<groupId>org.jetbrains</groupId>
|
||||||
<artifactId>annotations</artifactId>
|
<artifactId>annotations</artifactId>
|
||||||
<version>26.0.2-1</version>
|
<version>26.1.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
@@ -256,7 +256,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.14.1</version>
|
<version>3.15.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>${project.jdk.version}</source>
|
<source>${project.jdk.version}</source>
|
||||||
<target>${project.jdk.version}</target>
|
<target>${project.jdk.version}</target>
|
||||||
@@ -285,7 +285,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-shade-plugin</artifactId>
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
<version>3.6.1</version>
|
<version>3.6.2</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
@@ -337,8 +337,6 @@
|
|||||||
<links>
|
<links>
|
||||||
<link>https://javadoc.io/doc/org.jetbrains/annotations/</link>
|
<link>https://javadoc.io/doc/org.jetbrains/annotations/</link>
|
||||||
<link>https://hub.spigotmc.org/javadocs/bukkit/</link>
|
<link>https://hub.spigotmc.org/javadocs/bukkit/</link>
|
||||||
<link>https://carmjos.github.io/EasyPlugin/</link>
|
|
||||||
<link>https://carmjos.github.io/MineConfiguration/</link>
|
|
||||||
</links>
|
</links>
|
||||||
<detectJavaApiLink>true</detectJavaApiLink>
|
<detectJavaApiLink>true</detectJavaApiLink>
|
||||||
<encoding>UTF-8</encoding>
|
<encoding>UTF-8</encoding>
|
||||||
@@ -358,7 +356,7 @@
|
|||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.5.4</version>
|
<version>3.5.6</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<useSystemClassLoader>false</useSystemClassLoader>
|
<useSystemClassLoader>false</useSystemClassLoader>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@@ -1,33 +1,81 @@
|
|||||||
package cc.carm.plugin.userprefix.command;
|
package cc.carm.plugin.userprefix.command;
|
||||||
|
|
||||||
|
import cc.carm.plugin.userprefix.UserPrefixAPI;
|
||||||
import cc.carm.plugin.userprefix.conf.PluginMessages;
|
import cc.carm.plugin.userprefix.conf.PluginMessages;
|
||||||
|
import cc.carm.plugin.userprefix.manager.PrefixManager;
|
||||||
import cc.carm.plugin.userprefix.ui.PrefixSelectGUI;
|
import cc.carm.plugin.userprefix.ui.PrefixSelectGUI;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.Command;
|
import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabCompleter;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
public class UserCommand implements CommandExecutor {
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
public class UserCommand implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
|
||||||
if (sender instanceof Player) {
|
if (sender instanceof Player) {
|
||||||
PrefixSelectGUI.open((Player) sender);
|
Player player = (Player) sender;
|
||||||
|
String group = strings.length > 0 ? strings[0] : null;
|
||||||
|
PrefixSelectGUI.open(player, group);
|
||||||
} else {
|
} else {
|
||||||
if (strings.length != 1) {
|
if (strings.length < 1) {
|
||||||
PluginMessages.COMMAND_USAGE.CONSOLE.sendTo(sender);
|
PluginMessages.COMMAND_USAGE.CONSOLE.sendTo(sender);
|
||||||
} else {
|
} else {
|
||||||
Player player = Bukkit.getPlayer(strings[0]);
|
Player player = Bukkit.getPlayer(strings[0]);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
PrefixSelectGUI.open(player);
|
String group = strings.length > 1 ? strings[1] : null;
|
||||||
|
PrefixSelectGUI.open(player, group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] strings) {
|
||||||
|
List<String> completions = new ArrayList<>();
|
||||||
|
|
||||||
|
if (sender instanceof Player) {
|
||||||
|
if (strings.length == 1) {
|
||||||
|
// 补全 group 名称
|
||||||
|
Set<String> groups = UserPrefixAPI.getPrefixManager().getGroups();
|
||||||
|
String input = strings[0].toLowerCase();
|
||||||
|
completions.addAll(groups.stream()
|
||||||
|
.filter(g -> g.toLowerCase().startsWith(input))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 控制台
|
||||||
|
if (strings.length == 1) {
|
||||||
|
// 补全在线玩家名
|
||||||
|
String input = strings[0].toLowerCase();
|
||||||
|
completions.addAll(Bukkit.getOnlinePlayers().stream()
|
||||||
|
.map(Player::getName)
|
||||||
|
.filter(name -> name.toLowerCase().startsWith(input))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
} else if (strings.length == 2) {
|
||||||
|
// 补全 group 名称
|
||||||
|
Set<String> groups = UserPrefixAPI.getPrefixManager().getGroups();
|
||||||
|
String input = strings[1].toLowerCase();
|
||||||
|
completions.addAll(groups.stream()
|
||||||
|
.filter(g -> g.toLowerCase().startsWith(input))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return completions;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -35,6 +35,8 @@ public class PrefixConfig {
|
|||||||
|
|
||||||
protected final @Nullable String permission;
|
protected final @Nullable String permission;
|
||||||
|
|
||||||
|
protected final @Nullable String group;
|
||||||
|
|
||||||
protected final @NotNull List<GUIActionConfiguration> actions;
|
protected final @NotNull List<GUIActionConfiguration> actions;
|
||||||
|
|
||||||
protected final @NotNull ItemStack itemHasPermission;
|
protected final @NotNull ItemStack itemHasPermission;
|
||||||
@@ -76,6 +78,21 @@ public class PrefixConfig {
|
|||||||
@NotNull ItemStack itemHasPermission,
|
@NotNull ItemStack itemHasPermission,
|
||||||
@Nullable ItemStack itemWhenUsing,
|
@Nullable ItemStack itemWhenUsing,
|
||||||
@Nullable ItemStack itemNoPermission) {
|
@Nullable ItemStack itemNoPermission) {
|
||||||
|
this(
|
||||||
|
identifier, name, description,
|
||||||
|
content, period, weight, permission, null, actions,
|
||||||
|
itemHasPermission, itemWhenUsing, itemNoPermission
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrefixConfig(@NotNull String identifier,
|
||||||
|
@NotNull String name, @NotNull List<String> description,
|
||||||
|
@NotNull List<String> content, long period,
|
||||||
|
int weight, @Nullable String permission, @Nullable String group,
|
||||||
|
@NotNull List<GUIActionConfiguration> actions,
|
||||||
|
@NotNull ItemStack itemHasPermission,
|
||||||
|
@Nullable ItemStack itemWhenUsing,
|
||||||
|
@Nullable ItemStack itemNoPermission) {
|
||||||
this.identifier = identifier;
|
this.identifier = identifier;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
@@ -83,6 +100,7 @@ public class PrefixConfig {
|
|||||||
this.period = period;
|
this.period = period;
|
||||||
this.weight = weight;
|
this.weight = weight;
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
|
this.group = group;
|
||||||
this.actions = actions;
|
this.actions = actions;
|
||||||
this.itemHasPermission = itemHasPermission;
|
this.itemHasPermission = itemHasPermission;
|
||||||
this.itemNoPermission = itemNoPermission;
|
this.itemNoPermission = itemNoPermission;
|
||||||
@@ -104,6 +122,11 @@ public class PrefixConfig {
|
|||||||
return ColorParser.parse(description);
|
return ColorParser.parse(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getGroup() {
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public String getContent(CommandSender viewer) {
|
public String getContent(CommandSender viewer) {
|
||||||
if (content.isEmpty()) return "?";
|
if (content.isEmpty()) return "?";
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ public class PrefixManager {
|
|||||||
protected @NotNull Map<String, PrefixConfig> prefixes = new HashMap<>();
|
protected @NotNull Map<String, PrefixConfig> prefixes = new HashMap<>();
|
||||||
protected PrefixConfig defaultPrefix;
|
protected PrefixConfig defaultPrefix;
|
||||||
|
|
||||||
|
|
||||||
public int loadPrefixes() {
|
public int loadPrefixes() {
|
||||||
loadDefaultPrefix();
|
loadDefaultPrefix();
|
||||||
loadConfiguredPrefixes();
|
loadConfiguredPrefixes();
|
||||||
@@ -38,25 +39,21 @@ public class PrefixManager {
|
|||||||
|
|
||||||
File prefixDataFolder = getStorageFolder();
|
File prefixDataFolder = getStorageFolder();
|
||||||
if (!prefixDataFolder.isDirectory() || !prefixDataFolder.exists()) {
|
if (!prefixDataFolder.isDirectory() || !prefixDataFolder.exists()) {
|
||||||
prefixDataFolder.mkdir();
|
prefixDataFolder.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] filesList = prefixDataFolder.list();
|
List<File> files = new ArrayList<>();
|
||||||
if (filesList == null || filesList.length < 1) {
|
collectYamlFiles(prefixDataFolder, files);
|
||||||
|
|
||||||
|
if (files.isEmpty()) {
|
||||||
Main.severe("配置文件夹中暂无任何前缀配置问,请检查。");
|
Main.severe("配置文件夹中暂无任何前缀配置问,请检查。");
|
||||||
Main.severe("There's no configured prefix.");
|
Main.severe("There's no configured prefix.");
|
||||||
Main.severe("Path: " + prefixDataFolder.getAbsolutePath());
|
Main.severe("Path: " + prefixDataFolder.getAbsolutePath());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<File> files = Arrays.stream(filesList)
|
|
||||||
.map(s -> new File(prefixDataFolder, s))
|
|
||||||
.filter(File::isFile)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
HashMap<String, PrefixConfig> loaded = new HashMap<>();
|
HashMap<String, PrefixConfig> loaded = new HashMap<>();
|
||||||
|
|
||||||
if (files.size() > 0) {
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
try {
|
try {
|
||||||
PrefixConfig prefix = addPrefix(file);
|
PrefixConfig prefix = addPrefix(file);
|
||||||
@@ -68,11 +65,39 @@ public class PrefixManager {
|
|||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this.prefixes = loaded;
|
this.prefixes = loaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 递归收集文件夹下的所有YAML文件
|
||||||
|
*
|
||||||
|
* @param folder 目标文件夹
|
||||||
|
* @param files 文件列表
|
||||||
|
*/
|
||||||
|
private void collectYamlFiles(@NotNull File folder, @NotNull List<File> files) {
|
||||||
|
File[] children = folder.listFiles();
|
||||||
|
if (children == null) return;
|
||||||
|
for (File child : children) {
|
||||||
|
if (child.isDirectory()) {
|
||||||
|
collectYamlFiles(child, files);
|
||||||
|
} else if (child.isFile() && isYamlFile(child)) {
|
||||||
|
files.add(child);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断文件是否为YAML文件
|
||||||
|
*
|
||||||
|
* @param file 文件
|
||||||
|
* @return 如果是.yml或.yaml文件返回true
|
||||||
|
*/
|
||||||
|
private boolean isYamlFile(@NotNull File file) {
|
||||||
|
String name = file.getName().toLowerCase();
|
||||||
|
return name.endsWith(".yml") || name.endsWith(".yaml");
|
||||||
|
}
|
||||||
|
|
||||||
public void loadDefaultPrefix() {
|
public void loadDefaultPrefix() {
|
||||||
this.defaultPrefix = new PrefixConfig(
|
this.defaultPrefix = new PrefixConfig(
|
||||||
"default",
|
"default",
|
||||||
@@ -96,6 +121,36 @@ public class PrefixManager {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据group获取可见的前缀列表
|
||||||
|
*
|
||||||
|
* @param player 玩家
|
||||||
|
* @param group 分组名称,为null时返回所有前缀
|
||||||
|
* @return 过滤后的前缀列表
|
||||||
|
*/
|
||||||
|
public List<PrefixConfig> getVisiblePrefix(Player player, @Nullable String group) {
|
||||||
|
if (group == null || group.isEmpty()) {
|
||||||
|
return getVisiblePrefix(player);
|
||||||
|
}
|
||||||
|
return getPrefixes().values().stream()
|
||||||
|
.filter(c -> c.isVisible(player))
|
||||||
|
.filter(c -> group.equalsIgnoreCase(c.getGroup()))
|
||||||
|
.sorted(Comparator.comparingInt(PrefixConfig::getWeight))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取所有已配置的group列表
|
||||||
|
*
|
||||||
|
* @return group名称集合
|
||||||
|
*/
|
||||||
|
public Set<String> getGroups() {
|
||||||
|
return getPrefixes().values().stream()
|
||||||
|
.map(PrefixConfig::getGroup)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public PrefixConfig getDefaultPrefix() {
|
public PrefixConfig getDefaultPrefix() {
|
||||||
return defaultPrefix;
|
return defaultPrefix;
|
||||||
@@ -152,6 +207,7 @@ public class PrefixManager {
|
|||||||
conf.getLong("period", -1L),
|
conf.getLong("period", -1L),
|
||||||
conf.getInt("weight", 1),
|
conf.getInt("weight", 1),
|
||||||
conf.getString("permission"),
|
conf.getString("permission"),
|
||||||
|
conf.getString("group"),
|
||||||
readActions(conf.getStringList("actions")),
|
readActions(conf.getStringList("actions")),
|
||||||
readItem(
|
readItem(
|
||||||
conf.getConfigurationSection("item.has-perm"),
|
conf.getConfigurationSection("item.has-perm"),
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import cc.carm.plugin.userprefix.conf.prefix.PrefixConfig;
|
|||||||
import cc.carm.plugin.userprefix.event.UserPrefixChangeEvent;
|
import cc.carm.plugin.userprefix.event.UserPrefixChangeEvent;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.inventory.ClickType;
|
import org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@@ -21,10 +22,16 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
|||||||
public static HashSet<Player> openingUsers = new HashSet<>();
|
public static HashSet<Player> openingUsers = new HashSet<>();
|
||||||
|
|
||||||
protected final Player player;
|
protected final Player player;
|
||||||
|
protected final @Nullable String group;
|
||||||
|
|
||||||
public PrefixSelectGUI(Player player) {
|
public PrefixSelectGUI(Player player) {
|
||||||
|
this(player, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PrefixSelectGUI(Player player, @Nullable String group) {
|
||||||
super(GUIType.SIX_BY_NINE, PluginConfig.GUI.TITLE.get(), 10, 43);
|
super(GUIType.SIX_BY_NINE, PluginConfig.GUI.TITLE.get(), 10, 43);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
|
this.group = group;
|
||||||
|
|
||||||
setPreviousPageSlot(18);
|
setPreviousPageSlot(18);
|
||||||
setNextPageSlot(26);
|
setNextPageSlot(26);
|
||||||
@@ -37,6 +44,11 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
|||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getGroup() {
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
|
||||||
public void loadExtraIcons() {
|
public void loadExtraIcons() {
|
||||||
PluginConfig.GUI.ITEMS.getNotNull().getItems().values().forEach(v -> v.setupItems(player, this));
|
PluginConfig.GUI.ITEMS.getNotNull().getItems().values().forEach(v -> v.setupItems(player, this));
|
||||||
}
|
}
|
||||||
@@ -44,7 +56,7 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
|||||||
public void loadItems() {
|
public void loadItems() {
|
||||||
List<PrefixConfig> prefixList = new ArrayList<>();
|
List<PrefixConfig> prefixList = new ArrayList<>();
|
||||||
prefixList.add(UserPrefixAPI.getPrefixManager().getDefaultPrefix());
|
prefixList.add(UserPrefixAPI.getPrefixManager().getDefaultPrefix());
|
||||||
prefixList.addAll(UserPrefixAPI.getPrefixManager().getVisiblePrefix(player)); //只需要读取看得见的
|
prefixList.addAll(UserPrefixAPI.getPrefixManager().getVisiblePrefix(player, group));
|
||||||
|
|
||||||
PrefixConfig usingPrefix = UserPrefixAPI.getUserManager().getPrefix(getPlayer());
|
PrefixConfig usingPrefix = UserPrefixAPI.getUserManager().getPrefix(getPlayer());
|
||||||
|
|
||||||
@@ -60,10 +72,7 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(Player clicker, ClickType type) {
|
public void onClick(Player clicker, ClickType type) {
|
||||||
player.closeInventory();
|
player.closeInventory();
|
||||||
//再次检查,防止打开GUI后、选择前的时间段内权限消失
|
|
||||||
if (prefix.checkPermission(player)) {
|
if (prefix.checkPermission(player)) {
|
||||||
|
|
||||||
// 发送消息与提示
|
|
||||||
PluginConfig.SOUNDS.PREFIX_CHANGE.playTo(player);
|
PluginConfig.SOUNDS.PREFIX_CHANGE.playTo(player);
|
||||||
PluginMessages.SELECTED.sendTo(player, prefix.getName());
|
PluginMessages.SELECTED.sendTo(player, prefix.getName());
|
||||||
|
|
||||||
@@ -86,8 +95,6 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -107,11 +114,12 @@ public class PrefixSelectGUI extends AutoPagedGUI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void open(Player player) {
|
public static void open(Player player) {
|
||||||
// player.closeInventory(); // 防止冲突
|
open(player, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void open(Player player, @Nullable String group) {
|
||||||
PluginConfig.SOUNDS.GUI_OPEN.playTo(player);
|
PluginConfig.SOUNDS.GUI_OPEN.playTo(player);
|
||||||
new PrefixSelectGUI(player).openGUI(player);
|
new PrefixSelectGUI(player, group).openGUI(player);
|
||||||
openingUsers.add(player);
|
openingUsers.add(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ period: -1
|
|||||||
# At TabList : the larger is displayed at the top
|
# At TabList : the larger is displayed at the top
|
||||||
weight: 1
|
weight: 1
|
||||||
|
|
||||||
|
# Group [Unnecessary]
|
||||||
|
# Used to group prefixes, players can use /prefix <group> to view prefixes in the corresponding group
|
||||||
|
# If not configured, it means the prefix is not in any group
|
||||||
|
group: vip
|
||||||
|
|
||||||
# Permission [Unnecessary]
|
# Permission [Unnecessary]
|
||||||
# If there is no permission for detection, everyone can use it,
|
# If there is no permission for detection, everyone can use it,
|
||||||
# which means there is no need to configure "itemNoPermission"
|
# which means there is no need to configure "itemNoPermission"
|
||||||
|
|||||||
@@ -23,6 +23,11 @@ period: -1
|
|||||||
# En TabList : el más grande se muestra en la parte superior
|
# En TabList : el más grande se muestra en la parte superior
|
||||||
weight: 1
|
weight: 1
|
||||||
|
|
||||||
|
# Grupo [Innecesario]
|
||||||
|
# Se utiliza para agrupar prefijos, los jugadores pueden usar /prefix <group> para ver prefijos en el grupo correspondiente
|
||||||
|
# Si no se configura, significa que el prefijo no está en ningún grupo
|
||||||
|
group: vip
|
||||||
|
|
||||||
# Permisos [Innecesario]
|
# Permisos [Innecesario]
|
||||||
# Si no hay permiso para la detección, todo el mundo puede utilizarlo,
|
# Si no hay permiso para la detección, todo el mundo puede utilizarlo,
|
||||||
# lo que significa que no es necesario configurar "itemNoPermission"
|
# lo que significa que no es necesario configurar "itemNoPermission"
|
||||||
|
|||||||
@@ -25,6 +25,11 @@ period: -1
|
|||||||
# 在TabList中,显示顺序可以在 config.yml 中自定义
|
# 在TabList中,显示顺序可以在 config.yml 中自定义
|
||||||
weight: 1
|
weight: 1
|
||||||
|
|
||||||
|
# 分组 [非必须]
|
||||||
|
# 用于将前缀分组,玩家可以通过 /prefix <group> 查看对应分组的前缀
|
||||||
|
# 若不配置则代表不在任何分组中
|
||||||
|
group: vip
|
||||||
|
|
||||||
|
|
||||||
# 检测的权限 [非必须]
|
# 检测的权限 [非必须]
|
||||||
# 如果没有就是人人都能用,也代表不用配置“itemNoPermission”了(因为压根不可能显示没权限时候的物品)
|
# 如果没有就是人人都能用,也代表不用配置“itemNoPermission”了(因为压根不可能显示没权限时候的物品)
|
||||||
|
|||||||
Reference in New Issue
Block a user