Nickname plugin

Discussion in 'Plugin Development' started by Teh_Matt_GR, Jan 6, 2018.

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

    Teh_Matt_GR

    Hi guys I starter some days ago making a nickname plugin. Everything was ok but when I tested to use the nick it didn't work for the chat and the nametag!
    Only on tablist worked and I tried to fix it but I couldn't. Can you help me?
    Code:
                                if(player.hasPermission("evolution.nick") || player.isOp()) {
                                    player.setDisplayName(args[0].replace("&", "§"));
                                    player.setDisplayName(args[1].replace("&", "§"));
                                    player.setPlayerListName(args[1].replace("&", "§"));
                                    Main.getMain().setNick(player, args[1]);
                                    player.sendMessage(prefix + ChatColor.GREEN + "You updated you nick to " + ChatColor.GOLD + ChatColor.translateAlternateColorCodes('&', args[1]));
                                }
                            }else if(args.length == 3){
                                if(player.hasPermission("evolution.nick.other") || player.isOp()){
                                    Player c = Bukkit.getPlayer(args[2]);
                                    if(c != null){
                                        c.setDisplayName(args[1].replace("&", "§") + ChatColor.RESET);
                                        c.setPlayerListName(args[1].replace("&", "§"));
                                        Main.getMain().setNick(c, args[1]);
                                        c.sendMessage(prefix + ChatColor.GOLD + player.getName() + ChatColor.GREEN + " setted your nickname to " + ChatColor.AQUA + args[1] + ChatColor.GREEN + "!");
                                        player.sendMessage(prefix + ChatColor.GREEN + "You have changed " + ChatColor.RED + c.getName() + "'s" + ChatColor.GOLD + " nick to " + ChatColor.translateAlternateColorCodes('&', args[1]));
                                    }else{
                                        player.sendMessage(prefix + ChatColor.RED + "Cannot find player " + args[2] + "!");
                                    }
                                }
                            }
                        }
    


    It has more but these work fine!
    can you help me how to add nickname for chat and for nametag?
     
    Last edited by a moderator: Jan 6, 2018
  2. Offline

    AyWuzzUp

    Not sure if this is the best way, but what if you were to store the player's nickname within a configuration file and then when they speak check if they have a nickname if so when they talk replace their name with their custom nickname? I do not have much experience with nick names but that might work for what you are trying. Also other things I would like to mention is the way you go about your way of setting these nicknames -

    First of all why are you setting the person's display as argument zero and then after you set their display name to argument one?
    That simply makes player.setDisplayName(args[0].replace("&", "§")); useless!
    Code:
    player.setDisplayName(args[0].replace("&", "§"));
    player.setDisplayName(args[1].replace("&", "§"));
    

    Also organisation is very well a needed within your plugin, why not make one simple method for a simple nickname change -
    Code:
    public void nicknamePlayer(Player player, String nick) {
    
        String nickname = ChatColor.translateAlternateColorCodes('&', nick);
        player.setDisplayName(nickname);
        player.setPlayerListName(nickname);
        player.sendMessage(ChatColor.GREEN + "Your nickname has been changed to " + nickname);
    
        //Store nickname within a configuration
        //When the player talks retrieve their nickname if it's valid
          and then replace their name when they talk with the actual nickname
    }
    

    Also for changing a player’s name above their head it’s possible but correct me if I am wrong @timtower it’s not very well supported ? However I did run into this, this nay be of help to what you’re trying to do - https://bukkit.org/threads/change-player-name-tags-once-again.444702/
     
    Last edited: Jan 9, 2018
  3. Offline

    Teh_Matt_GR

    if ill do this it wont save the nicknames!
     
  4. Offline

    AyWuzzUp

    Well of course it doesn't, I am not going to make your plugin for you. If you are having issues with these simple tasks (such as making a nickname method, storing data within a configuration, and replacing a player's name when they speak) I would suggest having a good knowledge of Java and Bukkit before attempting to code.
     
    Last edited: Jan 9, 2018
Thread Status:
Not open for further replies.

Share This Page