Player List help

Discussion in 'Plugin Development' started by GoogleMaps, Dec 12, 2015.

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

    GoogleMaps

    So I have this code, it works and all but for some reason it sends part of the message twice I don't know why.
    Code:
    
    @Override
    
    publicboolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    
    if(label.equalsIgnoreCase("staff"))
    
    {
    
    Player p = (Player) sender;
    
    
    
    
    
    StringBuilder str = new StringBuilder();
    
    
    
    for(Player ps : Bukkit.getOnlinePlayers()){
    
    
    
    if(str.length() > 0){
    
    
    
    str.append(", ");
    
    
    
    }
    
    
    
    if(p.hasPermission("googlemaps.join.istaff")|| p.isOp()) {
    
    
    
    str.append(ps.getDisplayName() + " §7");
    
    
    
    
    
    p.sendMessage("§6---------- §bOnline Staff " + str.toString() + "§6---------- ");
    
    
    
    
    
    }else{
    
    p.sendMessage(ChatColor.RED + "No permission... :(");
    
    }
    
    
    
    
    
    
    
    
    
    }}
    
    returnfalse;
    
    
    
    }
    
    
     
  2. Offline

    Lightspeed

    Please show us what it sends you to help.
     
  3. Offline

    MOMOTHEREAL

    I believe you should replace:
    Code:
    if(p.hasPermission("googlemaps.join.istaff") || p.isOp()) {
    with:
    Code:
    if(ps.hasPermission("googlemaps.join.istaff") || ps.isOp()) {
     
    Zombie_Striker likes this.
  4. Don't use labal
    You don't need to check the command
    Do as @MOMOTHEREAL said
    You can clean the for statement up quite a bit.
     
    MOMOTHEREAL likes this.
  5. Offline

    Lightspeed

    If he has 1 command in the yml and 1 in javaplugin code . . . You don't need to check the command?
    I never knew this but, now it makes since I think.
    **I never mess with command in java plugin :p**
     
  6. Offline

    MOMOTHEREAL

    @Lightspeed
    //Offtopic
    onCommand(...) will only fire when the command is registered as part of the current plugin.
     
  7. Offline

    GoogleMaps

    Code:
    name: GoogleJoin
    version: 1.0
    main: com.GoogleMaps.Join.Main
    author: GoogleMaps
    description: eZ Plugin
    commands:
       staff:
         description: Set yourself on fire.
       uuid:
         description: List how many times you have died 
    The plugin.yml is not working now? :/
     
  8. Offline

    Lightspeed

    What do you mean?
     
  9. Offline

    MOMOTHEREAL

    @GoogleMaps
    Please provide more details, such as a stacktrace from your console (and the code related to it), so we can assist you further.
     
  10. Offline

    GoogleMaps

    There's no erros but it still sends parts of he messages twice
     
  11. Offline

    Lightspeed

    @GoogleMaps Give us a screenshot of chat so we can figure out why.
     
  12. Offline

    Gorbit99

    //Offtopic
    Googlemaps, like I already said, you should change your package name to something like me.googlemaps, or even change your username. You don't own googlemaps.com, and it's not like: "Hey, nobody owns it, I might as well use it"
     
  13. Offline

    GoogleMaps

    [​IMG]
    That is what happened when I typed the command
    It sends my name twice?
    Also that hacked client in the left corner was testing some anti-cheat
     
  14. Offline

    mcdorli

    It probably does like
    message1: admin1
    message2: admin1, admin2
    message3: admin1, admin2, admin3
    ....
    You sedn the message each time you add a name to it.
    Edit: I inserted your code in IntelliJ to check out with tabs, and yes,

    Some things:

    You blind cast the player to sender, especially if you don't need it
    Use ChatColor.COLORNAME
    Follow java naming conventions
    Use cmd.getName()....

    What your code currently does:
    for each player, You append his name to the stringbuilder, then you send the string to the current commandsender. Then you repeat this for every player
     
    Last edited: Dec 18, 2015
  15. Offline

    GoogleMaps

    How would I fix this
     
  16. Offline

    mcdorli

    remove the p.sendMessage, and put it outside the for loop
     
Thread Status:
Not open for further replies.

Share This Page