Solved How would I do this?

Discussion in 'Plugin Development' started by xxCoderForLifexx, Jan 30, 2013.

Thread Status:
Not open for further replies.
  1. I need to make a message to the sender when they do the command like
    Code:
    "That Needs to be a Player"
    Code:java
    1. if(cmd.getName().equalsIgnoreCase("remove")){
    2. if(sender instanceof Player){
    3. Player player = (Player) sender;
    4. if(player.hasPermission("player.remove")){
    5. Player target = sender.getServer().getPlayer(args[0]);
    6. target.remove();
    7. target.kickPlayer(ChatColor.GREEN + "Removed by " + ChatColor.AQUA + "RemovePlayer " + ChatColor.GREEN + "Have A Nice Day " + ChatColor.RED + target.getName());
    8. target.isBanned();
    9. target.setBanned(true);
    10. target.sendMessage(args[0] + "Removed from the server");
    11.  
    12. }
    13. }
    14. }else{
    15.  
    16. }
    17. /*Player target = sender.getServer().getPlayer(args[0]);*/
    18.  
    19. return true;
    20. }
     
  2. Offline

    Frazz86

    Try this
    Code:
    if(target != null)
    {
    //stuff to do if player exists
    }
    else
    {
    //stuff to do if player doesn't exist
    player.sendMessage(ChatColor.RED + "That player does not exist, please try again!");
    }
    
     
  3. Offline

    ZeusAllMighty11

    Code:
     target.remove();
     target.kickPlayer(ChatColor.GREEN + "Removed by " + ChatColor.AQUA + "RemovePlayer " + ChatColor.GREEN + "Have A Nice Day " + ChatColor.RED + target.getName());
     target.isBanned();
     target.setBanned(true);
     target.sendMessage(args[0] + "Removed from the server");
    
    What is .remove() o.o

    Ok, you kicked the player...

    Why did you do a random check isBanned then do nothing?

    kk you set banned...

    You sent them a message when they will be banned offline? NPE?
     
    stickeric and stuntguy3000 like this.
  4. It a plugin a guy wants me to make to like just remove the player from ever being on the server so that's why the ban and .remove
     
  5. Offline

    ZeusAllMighty11


    isBanned() doesn't do anything but return a boolean... ?
     
  6. Offline

    caseif

    Correct me if I'm wrong, but doesn't the vanilla ban command automatically remove the player from the server? Additionally, as ZeusAllMighty11 said, your last line will always throw an NPE. You'll want to use Bukkit.broadcast(message) instead.
     
  7. Well I do not know if it does or not but I just put it in there in case
    and I will correct the code it is mostly in testing right now so..
     
  8. Offline

    ZeusAllMighty11

    Easiest ban code IMO:

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
        if(cmd.getName().equalsIgnoreCase("zban")){
            if(args.length >= 1){
                Player target = Bukkit.getServer().getPlayer(args[0]);
                target.setBanned(true);
                target.kickPlayer(); // ? is this necessary i forget, but I thoughts so
                Bukkit.broadcastMessage(ChatColor.YELLOW + sender.getName() + ChatColor.RED + " Laid the ban hammer on " + ChatColor.YELLOW + target.getName());
            }
        }
    }
    
     
Thread Status:
Not open for further replies.

Share This Page