mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-12-25 18:49:00 +01:00
Don't send 1.13 tab completions to players without access to any LP commands (#1310)
This commit is contained in:
parent
90246afd03
commit
e07f8c0fbe
@ -12,7 +12,7 @@ repositories {
|
||||
dependencies {
|
||||
compile project(':common')
|
||||
|
||||
compileOnly 'org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT'
|
||||
compileOnly 'org.spigotmc:spigot-api:1.13.2-R0.1-SNAPSHOT'
|
||||
compileOnly 'me.lucko:commodore:1.0'
|
||||
compileOnly('net.milkbowl.vault:VaultAPI:1.6') {
|
||||
exclude(module: 'bukkit')
|
||||
|
@ -40,8 +40,13 @@ import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import me.lucko.commodore.Commodore;
|
||||
import me.lucko.commodore.CommodoreProvider;
|
||||
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
|
||||
import me.lucko.luckperms.common.sender.Sender;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerCommandSendEvent;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStream;
|
||||
@ -53,6 +58,7 @@ import java.util.zip.GZIPInputStream;
|
||||
public class LuckPermsBrigadier {
|
||||
|
||||
public static void register(LPBukkitPlugin plugin, Command pluginCommand) throws Exception {
|
||||
// register completions with commodore
|
||||
Commodore commodore = CommodoreProvider.getCommodore(plugin.getBootstrap());
|
||||
try (InputStream is = plugin.getBootstrap().getResourceStream("luckperms-brigadier.json.gz")) {
|
||||
if (is == null) {
|
||||
@ -65,6 +71,30 @@ public class LuckPermsBrigadier {
|
||||
commodore.register(pluginCommand, command);
|
||||
}
|
||||
}
|
||||
|
||||
// add event listener to prevent completions from being send to players without permission
|
||||
// to use any LP commands.
|
||||
PluginManager pluginManager = plugin.getBootstrap().getServer().getPluginManager();
|
||||
pluginManager.registerEvents(new PermissionListener(plugin, pluginCommand), plugin.getBootstrap());
|
||||
}
|
||||
|
||||
private static final class PermissionListener implements Listener {
|
||||
private final LPBukkitPlugin plugin;
|
||||
private final Command pluginCommand;
|
||||
|
||||
private PermissionListener(LPBukkitPlugin plugin, Command pluginCommand) {
|
||||
this.plugin = plugin;
|
||||
this.pluginCommand = pluginCommand;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCommandSend(PlayerCommandSendEvent e) {
|
||||
Sender playerAsSender = this.plugin.getSenderFactory().wrap(e.getPlayer());
|
||||
if (!this.plugin.getCommandManager().hasPermissionForAny(playerAsSender)) {
|
||||
e.getCommands().remove(this.pluginCommand.getLabel());
|
||||
e.getCommands().removeAll(this.pluginCommand.getAliases());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ArgumentBuilder deserialize(JsonObject data) {
|
||||
|
@ -156,6 +156,10 @@ public class CommandManager {
|
||||
}, executor);
|
||||
}
|
||||
|
||||
public boolean hasPermissionForAny(Sender sender) {
|
||||
return this.mainCommands.stream().anyMatch(c -> c.shouldDisplay() && c.isAuthorized(sender));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private CommandResult execute(Sender sender, String label, List<String> args) {
|
||||
List<String> arguments = new ArrayList<>(args);
|
||||
@ -164,8 +168,9 @@ public class CommandManager {
|
||||
// Handle no arguments
|
||||
if (arguments.isEmpty() || (arguments.size() == 1 && arguments.get(0).trim().isEmpty())) {
|
||||
MessageUtils.sendPluginMessage(sender, "&2Running &bLuckPerms v" + this.plugin.getBootstrap().getVersion() + "&2.");
|
||||
if (this.mainCommands.stream().anyMatch(c -> c.shouldDisplay() && c.isAuthorized(sender))) {
|
||||
if (hasPermissionForAny(sender)) {
|
||||
Message.VIEW_AVAILABLE_COMMANDS_PROMPT.send(sender, label);
|
||||
return CommandResult.SUCCESS;
|
||||
} else {
|
||||
Collection<? extends Group> groups = this.plugin.getGroupManager().getAll().values();
|
||||
if (groups.size() <= 1 && groups.stream().allMatch(g -> g.getOwnNodes().isEmpty())) {
|
||||
@ -173,8 +178,8 @@ public class CommandManager {
|
||||
} else {
|
||||
Message.NO_PERMISSION_FOR_SUBCOMMANDS.send(sender);
|
||||
}
|
||||
return CommandResult.NO_PERMISSION;
|
||||
}
|
||||
return CommandResult.INVALID_ARGS;
|
||||
}
|
||||
|
||||
// Look for the main command.
|
||||
|
Loading…
Reference in New Issue
Block a user