mirror of
https://github.com/CarmJos/UserPrefix.git
synced 2026-07-16 00:41:08 +08:00
feat(prefix): add group support for prefix selection and tab completion
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
@@ -1,15 +1,24 @@
|
|||||||
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
|
||||||
@@ -32,5 +41,41 @@ public class UserCommand implements CommandExecutor {
|
|||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -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();
|
||||||
|
|||||||
@@ -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