How do I kick a player when an admin issues a command?

Discussion in 'Plugin Development' started by sammyg7241, Jan 25, 2015.

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

    sammyg7241

    Hello, I am making a plugin to kick, ban players. I need help with how I can kick/ban a player when an admin runs a command. For example /dmkick Bob, how can I kick Bob from the server?


    Thanks!
     
  2. Offline

    Ambamore2000

    I think there's a Bukkit.kickPlayer method and a banPlayer method, not too sure.
     
  3. Offline

    mkezar

    Could you show us your code @sammyg7241? To do it, you have your command event, and your player Variable (/dmkick player). Then you add permissions And set the permissions to the admin.
     
  4. Offline

    Ambamore2000

    I don't see why you need to see his code? Doesn't seem like he started it.
     
  5. Offline

    mkezar

    Well it helps to see what he started because we can see where he needs to fix (if he does)

    Lol derp. You were asking what method you would use! Lol derp! Let me check.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  6. Offline

    teej107

    Have you tried looking in the Bukkit documentation? The actions you are looking for can be done in one method.
     
  7. Offline

    sammyg7241

    @mkezar Here is my main class file so far

    Code:
    package me.sammyg7241.dm;
    
    import java.util.logging.Level;
    import java.util.logging.Logger;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Doorman extends JavaPlugin{
       
       
        public static Doorman instance;
        public final static Logger log = Logger.getLogger("Minecraft");
       
       
        public void OnEnable(){
            this.log("Doorman has been enabled!", Level.INFO);
        }
       
        public void OnDisable(){
            this.log("Doorman has been disabled!", Level.INFO);
        }
       
        public void log(String s, Level l){
            Doorman.log.log(l, "[Doorman]" + s);
        }
       
       
       
    
    }
    
     
  8. Offline

    FameForAim

    Code:
               
      public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    if(sender instanceof Player){
        Player p = (Player)sender;
        if(cmd.equals("dmkick")) {
                  if(args.length == 1){
                Player target = Bukkit.getServer().getPlayer(args[0]);
          
                target.kickPlayer("Reason");
    return true;
    }
    return false;
    }
    
     
    Last edited: Jan 25, 2015
  9. Offline

    Regablith

  10. Offline

    InfamousSheep

    If it's an admin command, check if the player has the required permission using
    player.hasPermission("perm")
    Or, alternatively you can check if they're an operator with player.isOp()
     
  11. Offline

    567legodude

    @sammyg7241 Like some people said before.
    For your command just use player.kickPlayer("message") or something like that.
    And there should also be a player.setBanned(true)
    Try those and see how they do for you.
     
Thread Status:
Not open for further replies.

Share This Page