Kicking all players

Discussion in 'Plugin Development' started by alan1099, Feb 8, 2014.

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

    alan1099

    I need help getting all players and kicking them like /kickall (message) and then it kicks all of the players from the server. THANKS!
     
  2. Bukkit.KickAll(); I believe. Don't count on it ;)
     
  3. Offline

    PatoTheBest

    Code:java
    1. for (Player player : Bukkit.getOnlinePlayers()){
    2. player.kickPlayer("You have been kicked form the server.");
    3. }
     
  4. Offline

    Jugglernaught

    alan1099 Connor2weirdness
    A better way to do it would be with a for() statement along with the kick statement. The one that Connor2weirdness said does not exist. I will model what I mean below:

    Code:java
    1. for(Player p : Bukkit.getServer().getOnlinePlayers()) {
    2. String name = p.getName();
    3. Bukkit.getServer().getPlayer(name).kickPlayer("//This is your kick message");
     
  5. Offline

    thomasb454

    Code:java
    1. for (Player player : Bukkit.getOnlinePlayers()) {
    2. player.kickPlayer("Kicked");
    3. }
    4.  
    5.  
     
  6. Offline

    PatoTheBest

    Why are you converting a Player into a string and then into a player?
     
    MayoDwarf likes this.
  7. Offline

    xTigerRebornx

    PatoTheBest Thats what I was wondering, too.... He already has the Player, why is he getting it again? XD
     
    MayoDwarf likes this.
  8. Offline

    Gater12

  9. Offline

    Harmings

    alan1099
    Code:java
    1. public void kickAll(String[] args) {
    2. StringBuilder sb = new StringBuilder();
    3. for (int i = 0; i < args.length; i++) {
    4. sb.append(args[i]).append(" ");
    5. }
    6. String msg = sb.toString();
    7. for (Player players : Bukkit.getServer().getOnlinePlayers()) {
    8. players.kickPlayer(msg);
    9. }
    10. }[/i]

    Usage: kickAll(args);
     
  10. Offline

    HungerCraftNL

    By all your methodes do you getting kicked by yourself too, I made this so you don't kick yourself, only the others. It's untested.
    PHP:
    public void kick(Player pString[] message){
      if(
    p.isOnline()){
        for(
    Player online Bukkit.getOnlinePlayers()){
          
    ArrayList<String= new ArrayList<String>();
          
    o.remove(p.getName());
          for(
    String on o){
            
    StringBuilder sb = new StringBuilder;
            for(
    int i 0args.lengthi++){
              
    sb.append(args[i]).append(" ");
            }
            
    String message sb.toString();
            
    String msg message.replaceAll("(&([a-f0-9]))""\u00A7$2");
            
    Player op Bukkit.getServer().getPlayer(msg);
            
    op.kickPlayer(message);
          }
        }
      }
    }
     
  11. Offline

    xMrPoi

    Harmings what's all the
    Code:java
    1. [I] [/I]
    stuff?
     
  12. Offline

    Harmings

    xMrPoi
    No clue lol
    I edited the post, it's fixed
     
  13. Offline

    xMrPoi

    HungerCraftNL you could just do this
    Code:java
    1. for(Player player:Bukkit.getOnlinePlayers()){
    2. if(player.getName().equals(sender.getName()) continue;
    3. player.kickPlayer("Kicked from server");
    4. }
    Also, you're using "p" which you have not defined in that method so it would return an error.
     
    Harmings likes this.
  14. Offline

    Harmings

    HungerCraftNL
    Or you can just check:
    if (!online.getName().equals(sender.getName()))
     
  15. Offline

    HungerCraftNL

    xMrPoi
    Yes, I forgot to define 'p' in my code.
     
  16. Offline

    xMrPoi

    HungerCraftNL Are you sure that would even work? You're making a new String ArrayList every time it continues through to a new player. You're also removing p from he ArrayList without checking if it contains p.
     
  17. Offline

    Gater12

    xMrPoi That's XenForo being dumb.
     
  18. Offline

    HungerCraftNL

    xMrPoi
    I haven't tested it, but the CommandSender is always online, except it's the console.
     
  19. Offline

    xMrPoi

Thread Status:
Not open for further replies.

Share This Page