commands icon indicating copy to clipboard operation
commands copied to clipboard

Main command permission is null if i set a permission on a subcommand

Open DevJoey opened this issue 2 years ago • 4 comments

Hello, i have this command here!

`@CommandAlias("hide") @CommandPermission("core.command.hide") public class HideCommand extends BaseCommand {

private final ProxySockeCore plugin;

public HideCommand(ProxySockeCore plugin) {
    this.plugin = plugin;
}

@Default
public void onDefault(Player player){
    if(plugin.getPlayerDataManager().isNotLoaded(player)){
        player.sendMessage("§cDeine Daten wurden noch nicht geladen!");
        return;
    }
    PlayerDataHolder holder = plugin.getPlayerDataManager().get(player);
    if(holder.isHidden()){
        //Vanish deaktivieren
        holder.setHidden(false);
        player.removeMetadata("vanished", plugin);
        for(Player online : plugin.getServer().getOnlinePlayers()){
            if(online == player) continue;
            online.showPlayer(plugin, player);
        }
        player.sendMessage("§aDu bist nun wieder für alle Spieler sichtbar!");
    }else{
        //Vanish aktivieren
        holder.setHidden(true);
        player.setMetadata("vanished", new FixedMetadataValue(plugin, true));
        for(Player online : plugin.getServer().getOnlinePlayers()){
            if(online == player) continue;
            if(!online.hasPermission("core.command.hide.see")) online.hidePlayer(plugin, player);
        }
        HideUtils.removeTarget(player);
        player.sendMessage("§aDu bist nun für alle Spieler unsichtbar!");
    }
}

@Subcommand("info")
public void onInfo(Player player){
    if(plugin.getPlayerDataManager().isNotLoaded(player)){
        player.sendMessage("§cDeine Daten wurden noch nicht geladen!");
        return;
    }
    if(plugin.getPlayerDataManager().get(player).isHidden()){
        player.sendMessage("§aDu bist nicht für Spieler sichtbar!");
        return;
    }
    player.sendMessage("§cDu bist für alle Spieler sichtbar!");
}

@Subcommand("list")
@CommandPermission("core.command.hide.list")
public void onList(Player player){
    List<String> vanished = new ArrayList<>();
    for(Player p : plugin.getServer().getOnlinePlayers()){
        if(p.hasMetadata("vanished")) vanished.add(p.getName());
    }
    player.sendMessage(String.format("§fVersteckt (%d): §e%s", vanished.size(), String.join(", ", vanished)));
}

@CatchUnknown
public void onUnknown(Player player){
    player.sendMessage("§c» §7Unterbefehle für: §e§o'/hide'\n"
            + " §8▪ §f/hide info\n"
            + " §8▪ §f/hide list");
}

}`

I use this code to get the permission of a command

Command command = plugin.getServer().getCommandMap().getCommand("ignore");

Now if i call command.getPermission() it return null, but it must return "core.command.hide"

On all other commands i have made it works well

The error occurs, if i add a subcommand with a permission!

To Test:

  1. Make a normal command without SubCommands (a @Default method) and a permission set

  2. Use this code on Paper: Command command = plugin.getServer().getCommandMap().getCommand("nameofthecommand");

  3. Call command.getPermission() you will see the permission

  4. Now add a subcommand with @SubCommand("test") and @CommandPermission("test.test");

  5. Call command.getPermission() another time, and you will see that it returns null

It would be nice if this gets fixed because it destroys my system!

Thanks

DevJoey avatar Oct 28 '22 15:10 DevJoey

Im not able to set a permission for the maincommand itself. Why?

DevJoey avatar Oct 28 '22 15:10 DevJoey

The fundamental issue is that you are trying to use the Bukkit api to get information about the ACF command system.

Perhaps you could try CommandManager#getRootCommand https://github.com/aikar/commands/blob/master/core/src/main/java/co/aikar/commands/CommandManager.java#L326

chickeneer avatar Nov 06 '22 15:11 chickeneer

I must use the BukkitAPI, because i want filter non acf Commands too. And the RootCommand do not provide me any method to get his "RootCommandPermission" because is it not even possible to set one. ACF allows executing a rootcommands subcommand, if you have a subcommands permission. That is the reason why acf dont gives the root a permission if a subcommand has a permission . If the rootcmd had a permission set, executing a subcommand would require to have the rootcommand-permission as well. Beacuse of that, an extra @RootCommandPermission annotation would be very nice.

DevJoey avatar Nov 06 '22 22:11 DevJoey

The big issue here: It's possible to create multiple classes with the same root command. I already explained it in discord:

@CommandPermission("root.one")
@CommandAlias("bla")
public class OneCommand extends BaseCommand { ... }

@CommandPermission("root.two")
@CommandAlias("bla")
public class TwoCommand extends BaseCommand { ... }

Both classes have the same root command but different command permissions. Introduzing a new annotation doesn't solve that issue.

You can use CommandManager#getRootCommand, parse it to a RootCommand from Bukkit (BukkitRootCommand from ACF extends Command from Bukkit) and use Command#setCommandPermission by yourself.

Adding a getter or overloading the getter in BukkitCommandManager could be helpful here. I don't see a better solution for that.

Joo200 avatar Nov 06 '22 22:11 Joo200