Prevent bukkit from showing no permissions msg?

Discussion in 'Plugin Development' started by TopGear93, Jun 14, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    TopGear93

    In a current project of mine i have made a bukkit command go off when a player does an action how can i prevent the "No you cannot do that. if you believe this is an error let the Adminstrator know" not go off?
     
  2. Offline

    ZeusAllMighty11

    Edit: Irrelevant Message
     
  3. Offline

    TopGear93

    Ok, want proof? I made a whitelisting command that allows players to whitelist themselves only. Not others. Currently im testing my plugin and when i use /wl it throws the no permissions msg plus my messages. I need to find a way to stop bukkit from throwing that no permissions msg.


    Code:
    package us.topgear93.trialplay.commands;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    import us.topgear93.trialplay.TrialPlay;
    
    public class wl implements CommandExecutor{
        public TrialPlay plugin;
        public wl(TrialPlay plugin){
            this.plugin = plugin;
        }
        @Override
        public boolean onCommand(final CommandSender sender, Command cmd, String label, String[] args) {
            Player player = null;
            if (sender instanceof Player) {
                player = (Player) sender;
                if(label.equalsIgnoreCase("wl")){
                    //                        if (TrialPlay.permission.has(sender, "TrialPlay.self.whitelist") || sender.isOp()){
                    if(player.isWhitelisted()){
                        player.sendMessage(ChatColor.DARK_BLUE + "[" + ChatColor.WHITE + plugin.getConfig().getString("TrialPlay.title") + ChatColor.DARK_BLUE + "]-" + ChatColor.WHITE + plugin.getConfig().getString("TrialPlay.wl.already"));
                        return false;
                    }
                    player.performCommand("whitelist add " + sender.getName());
                    player.sendMessage(ChatColor.DARK_BLUE + "[" + ChatColor.WHITE + plugin.getConfig().getString("TrialPlay.title") + ChatColor.DARK_BLUE + "]-" + ChatColor.GOLD + sender.getName() + ChatColor.WHITE + plugin.getConfig().getString("TrialPlay.wl.added1"));
                    player.sendMessage(ChatColor.DARK_BLUE + "[" + ChatColor.WHITE + plugin.getConfig().getString("TrialPlay.title") + ChatColor.DARK_BLUE + "]-" + ChatColor.WHITE + plugin.getConfig().getString("TrialPlay.wl.added2"));
                    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
                        @Override
                        public void run() {
                            ((Player) sender).kickPlayer(plugin.getConfig().getString("TrialPlay.timer.kickmsg"));                                    
                        }
                    }, plugin.getConfig().getLong("TrialPlay.timer.wl"));
                    return true;
                }else{
                    player.sendMessage(ChatColor.DARK_BLUE + "[" + ChatColor.WHITE + plugin.getConfig().getString("TrialPlay.title") + ChatColor.DARK_BLUE + "]-" + ChatColor.DARK_RED + plugin.getConfig().getString("TrialPlay.noperm.wl"));
                    return false;
                }
            }
            return false;
        }
    }
     
  4. Offline

    LartTyler

    Have you added your command to the plugin.yml file?
     
  5. Offline

    TopGear93

    yep

    Code:
    name: TrialPlay
    main: us.topgear93.trialplay.TrialPlay
    version: 0.0.1
    depend: [Vault]
    commands:
      tp:
          description: version check and config reload
      wl:
          description: whitelist
      trial:
          description: player trial cmd
     
  6. Offline

    LartTyler

    AH! I assume you're displaying the no permission message yourself? With the line:
    Code:
    player.sendMessage(ChatColor.DARK_BLUE + "[" + ChatColor.WHITE + plugin.getConfig().getString("TrialPlay.title") + ChatColor.DARK_BLUE + "]-" + ChatColor.DARK_RED + plugin.getConfig().getString("TrialPlay.noperm.wl"));
    
    Am I right? If so, change your return statement immediately after that to return true. Anytime you return false, Bukkit will display the No perms message, regardless of what your plugin did before the method returned.
     
  7. Offline

    TopGear93

    the no permissions msg in the config equals "TrialPlay.noperm.wl", "No permissions to whitelist yourself!".

    im getting this though.

    [​IMG]
     
  8. Offline

    LartTyler

    Perhaps it's caused by your attempt to force the player to execute the default whitelist command? If they're not Op, they won't be able to use it, and you'll get that error. If you wanna run it without giving the player Op status, use this:

    Code:Java
    1.  
    2. Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "whitelist add " + sender.getName());
    3.  


    That will execute the command as if it was run from the default console.
     
    TopGear93 likes this.
  9. Offline

    TopGear93

    wow didn't realize there was a shortcut like that. thanks for the help. I did a quick hack job to fix my small problem with temporarily adding the permissions to use the whitelist and then remove it. Your idea is much simpler and safer.
     
  10. Offline

    LartTyler

    Glad to hear I could help :)
     
    TopGear93 likes this.
Thread Status:
Not open for further replies.

Share This Page