SpongePowered / SpongeForge

A Forge mod that implements SpongeAPI
http://www.spongepowered.org/
MIT License
1.14k stars 306 forks source link

testPermission never called - CommandCallable #282

Closed WhippyCleric closed 9 years ago

WhippyCleric commented 9 years ago

Currently the testPermission method of commands implement command callable never seems to be called. Setting this to return true or false seems to have no effect

Lunaphied commented 9 years ago

Can you post the code you're testing with?

WhippyCleric commented 9 years ago

I basically just created a command and validated I could call it normally in game. Setting the return of has permission to either true or false does nothing. Example of my command class:

public class SpawnCommand implements CommandCallable{

        @Inject
    Logger logger;

    @Override
    public Optional<Text> getHelp(CommandSource arg0) {
        // TODO Auto-generated method stub
        return null;
    }
    @Override
    public Optional<Text> getShortDescription(CommandSource arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public Text getUsage(CommandSource arg0) {
        return Texts.builder("/spawn").color(TextColors.GOLD).build();
    }

    @Override
    public Optional<CommandResult> process(CommandSource sender, String args)
            throws CommandException {
        if(sender instanceof Player){
            Player player = (Player) sender;
            NoWorldLocation spawn = CommandConfiguration.getSpawn();
            if(spawn!=null){
                player.setLocation(new Location(player.getWorld(), spawn.getX(), spawn.getY(), spawn.getZ()));
            }else{
                player.sendMessage(Texts.builder("No spawn has been set on this server! Use /setSpawn to set a spawn.").color(TextColors.RED).build());
            }
        }else{
            logger.warn("Spawn called by non player entity");
        }
        return null;
    }

    @Override
    public List<String> getSuggestions(CommandSource arg0, String arg1)
            throws CommandException {
        return Collections.emptyList();
    }

    @Override
    public boolean testPermission(CommandSource sender) {
        return false;
    }

}

I have registered the command in the plugin the normal way. I was looking into trying to code a generic permissions plugin however the API doc seems not to be written for this now. I could do permissions myself at the level of the command, calling if(testPermission(sender)){} in the process method but obviously this does not extend to other plugins. Maybe I am just misunderstanding the correct usage of this method?

Zidane commented 9 years ago

@zml2008

Please check into this.

zml2008 commented 9 years ago

Read the javadocs, you're supposed to call testPermission yourself.