Solved How to remove all player's nicknames?

Discussion in 'Plugin Development' started by MegaNarwhal, Nov 30, 2012.

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

    MegaNarwhal

    I'm writing a small plugin to remove people's nicknames (I got tired of the many Notches and Honeydews on my server), but I can't seem to find a way to remove offline players' nicknames. How would I go about doing this? This is what I currently have, but it only works on online players.

    Code:
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
                if(cmd.getName().equalsIgnoreCase("removenicks")){
                    sender.sendMessage("Removing everyones nicknames.");
                    for(Player on : this.getServer().getOnlinePlayers()) {
                      this.getServer().dispatchCommand(this.getServer().getConsoleSender(), "nick " + on.getName() + " off");
                      }
                    return true;
                    }
                return false;
            }
    Does Essentials completely control display names, or can they be modified by Bukkit? Help is appreciated :) And please go easy on me, I don't really know much about coding in Java, or using the Bukkit API. I just felt like making a plugin to speed up this process and make sure there aren't any nicknames left on my server.
     
  2. Offline

    gomeow

    You could try this:
    Code:
    Bukkit.getOfflinePlayer(args[0]).setDisplayName(Bukkit.getOfflinePlayer(args[0]).getName());
     
  3. Offline

    MegaNarwhal

    That just sets their display name to their username. Will that still count as a nickname or will it remove the nickname completely?
     
  4. Offline

    gomeow

    It will appear as though it is gone
     
  5. Offline

    MegaNarwhal

    But it won't actually be removed? On my server, there is a * before people's names if they have a nickname. Will this appear for everyone if I use the code you suggested? Also, should I use getPlayer instead of getOfflinePlayer to remove all nicknames?
     
  6. Offline

    gomeow

    That star is from another plugin. If you do my method, it won't have a star unless you actually add it to my code
     
  7. Offline

    MegaNarwhal

    Oh... so the star is actually prefixed to the display name itself, not just added in front of it if they have a nickname set? My goal is to have the display name reset to whatever it would be for the person when they first join the server. Sorry for asking so many questions, I just want to get this right the first time and not have everyone on my server spazz out if I screw up :p
     
  8. Offline

    gomeow

    Yes, the star is from that. For example, my old server I would prefix a ~ before their name. And don't worry, it's Friday, I am on a car ride and bored (I'm not driving... :))
     
  9. Offline

    MegaNarwhal

    Hah, I was about to say that coding and driving is dangerous :rolleyes: All right, here's the code now. Tell me if I'm missing anything:
    Code:
            public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
                if(cmd.getName().equalsIgnoreCase("removenicks")){
                    sender.sendMessage("Removing everyone's nicknames.");
                    //for(Player on : this.getServer().getOnlinePlayers()) {
                    //this.getServer().dispatchCommand(this.getServer().getConsoleSender(), "nick " + on.getName() + " off");
            Bukkit.getPlayer(args[0]).setDisplayName(Bukkit.getPlayer(args[0]).getName());
                    return true;
                    }
                return false;
                }
    Thanks for all the help!
     
  10. Offline

    gomeow

    You should un comment the for loop
     
  11. Offline

    MegaNarwhal

    How do I get all players with this.getServer()? Right now it only gets online players.

    EDIT: Oh, never mind :rolleyes: Ok, is this right?
    Code:
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("removenicks")){
                sender.sendMessage("Removing everyone's nicknames.");
                for(OfflinePlayer p : this.getServer().getOfflinePlayers()) {
                //this.getServer().dispatchCommand(this.getServer().getConsoleSender(), "nick " + on.getName() + " off");
        Bukkit.getPlayer(args[0]).setDisplayName(Bukkit.getPlayer(args[0]).getName());
                return true;
                }
            }
            return false;
            }
    EDIT: Nope... I'm not sure what to do with the for loop because the variable isn't used.
     
  12. Offline

    gomeow

    I don't think it's possible. You would need to store a list of connected players somewhere like a yml
     
  13. Offline

    MegaNarwhal

    Using getOfflinePlayers just gets every player that has ever connected to the server, right? I just don't know what to do with the variable in the for loop. Do I need to put it anywhere?
     
  14. Offline

    jwnordquist

    Hm.. i dont know how to do it, but there is a folder in the world file that has everyones player data file <playername>.dat you could get all the names from there
     
  15. Offline

    MegaNarwhal

    I know that, but thousands of people have been on my server. getOfflinePlayers returns an array of all usernames, but I don't know how to take that and batch-change the display names of people.
     
  16. Offline

    jwnordquist

    hmm... take a look at the API's for essentials, (assuming your using it) because there is a yml file for every person on the server, and that includes there full name and nickname in the same file
     
  17. Offline

    MegaNarwhal

    I use Essentials, but I don't think that it can change display names for offline players. My concern now is that because Essentials stores nicknames in the player files, it might end up not letting me change the display names, or not showing them when I change them. Every plugin I try to make always turns out to be more complicated than I had planned [skeleton]
     
  18. Offline

    jwnordquist

    hmm... i wouldn't make it as a plugin, but as an external application that you can run to go threw all the yml files and remove there nicknames. after that, remove the nickname permission from your permissions
     
  19. Offline

    MegaNarwhal

    I could easily run a regex, but I'd rather not open all of those files and I want to get a better understanding of Java.
     
  20. Offline

    jwnordquist

    ah, thats understandable. so do you want to completely stop the nicknames, or blacklist names?
     
  21. Offline

    NinjaW0lf

    Code:java
    1.  
    2. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    3. if(label.equalsIgnoreCase("removenicks")){
    4. for(OfflinePlayer p : bukkit.getServer().getOfflinePlayers()) {
    5. sender.sendMessage("Removing everyone's nicknames.");
    6. p.getPlayer().setDisplayName(p.getPlayer().getName());
    7. }
    8. return true;
    9. }
    10. return false;
    11. }
    12.  
    13.  


    That should work.
     
  22. Offline

    gomeow

    Have you read the whole thread? We already went over that and we are working with offline players, not online players...
     
  23. Offline

    NinjaW0lf

    yea, fixed that., edited. i copied the code he had in op instead of his last post and just fixed it, wasnt thinking bout it.
     
  24. Offline

    MegaNarwhal

  25. Offline

    NinjaW0lf

    NP. ive been working with for loops and gettingall online players.
     
  26. Offline

    Stuartie_h_94

    Did you ever release this? I would really like something like this :)
     
  27. Offline

    bm11111

    I really need this plugin.
     
  28. Offline

    wumpyc

    Sorry for bumping, but I need a way to clear all nicknames from players aswell.

    Nevermind. /nick ** off did the trick.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
Thread Status:
Not open for further replies.

Share This Page