Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DevJoey opened this issue Oct 28, 2022 · 4 comments
Open

Comments

@DevJoey
Copy link

DevJoey commented Oct 28, 2022

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
Copy link
Author

DevJoey commented Oct 28, 2022

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

@chickeneer
Copy link
Collaborator

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

@DevJoey
Copy link
Author

DevJoey commented Nov 6, 2022

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.

@Joo200
Copy link
Contributor

Joo200 commented Nov 6, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants