&k Nickname spasm thingy..

Discussion in 'Plugin Development' started by kreashenz, Mar 28, 2013.

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

    kreashenz

    I don't know what to say in the title.. But yeah, when I use /nick and i put JUST &k, it will change my WHOLE name, and message, to ChatColor.MAGIC thingy.. How do I make it so only the NAME, and not the whole message would be turned to &k?
     
  2. Offline

    Minecrell

    Reset the formats after the name with &r or ChatColor.RESET.
     
  3. Offline

    kreashenz

    Minecrell
    This is my chat event, so I would just add ChatColor.RESET to the end of the 5th line?
    Code:
    @EventHandler
    public void AsyncChat(AsyncPlayerChatEvent e)
    {
    if (e.getPlayer().isOp() || e.getPlayer().hasPermission("mcrp.chat.color"))
    e.setMessage(ChatFormat.ColourUtils.format(e.getMessage() + ChatColor.RESET));
    else
    e.getMessage().replace("&", "&");
    }
    }
     
  4. Offline

    Minecrell

    kreashenz
    You have to use it there where you want to stop the "magic" format. So I think behind the name. But you have to set the colors after it again.
     
  5. Offline

    kreashenz

    Minecrell I posted the wrong file.. I think I should of posted the Nickname one, not the chat one.. So anyway, here
    Code:
    package me.kreashenz.minecraftrp.Commands;
     
    import me.kreashenz.minecraftrp.MCRP;
    import me.kreashenz.minecraftrp.Utilities.ChatFormat.ColourUtils;
    import me.kreashenz.minecraftrp.Utilities.Functions;
    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class Nickname
    implements CommandExecutor
    {
        public MCRP plugin;
     
        public Nickname(MCRP plugin)
        {
            this.plugin = plugin;
        }
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("nick")) {
                if ((sender instanceof Player)) {
                    if (sender.hasPermission("mcrp.nick")) {
                        Player p = (Player)sender;
                        if (args.length == 0)
                        {
                            try {
                                sender.sendMessage(Functions.getPrefix() + "§cUsage : §f/nick <player> <new nick>");
                            } catch (ArrayIndexOutOfBoundsException array) {
                                sender.sendMessage(Functions.getPrefix() + "§cUsage : §f/nick <player> <new nick>");
                            }
                        } else if (args.length == 1) {
                            String newNick = args[0];
                            p.setDisplayName(ColourUtils.format(newNick));
                            sender.sendMessage("§eYour new nickname is : " + ColourUtils.format(newNick));
                        }
                        else if (args.length == 2) {
                            Player target = Bukkit.getPlayer(args[0]);
                            String newNick = args[1];
                            if (sender.hasPermission("mcrp.nick.other")) {
                                if (target == null) {
                                    sender.sendMessage(Functions.getPrefix() + "§cTarget player either not found or offline!");
                                } else {
                                    target.setDisplayName(ColourUtils.format(newNick));
                                    sender.sendMessage("§eYour new nickname is : " + ColourUtils.format(newNick));
                                }
                            } else sender.sendMessage(Functions.getPrefix() + "§cYou don't have permission to change anothers nickname."); 
                        }
                    } else sender.sendMessage(Functions.noPerm());
                } else sender.sendMessage("§cYou must be a player to use this command.");
            }
            return true;
        }
    }
     
  6. Offline

    Minecrell

    Hmm, I think setting ChatColor.RESET before e.getMessage() should fix the problem but I'm not sure.
     
  7. Offline

    kreashenz

    Minecrell Nahp, no work.. I don't know, I might just keep screwing with it till I find it. Thanks anyway.
     
  8. Offline

    Minecrell

    You could try adding a RESET at the end of the display name.
     
  9. Offline

    kreashenz

    Minecrell Nah, that didn't work, I already tried.. I am looking for other things now, I will try get someone else to fix it, or at least attempt :D
     
  10. Offline

    AquaBladeMC

    I can't even type &k. It says: Error: Nicknames need to be alphanumeric.
     
  11. Offline

    Drkmaster83

    Instead of e.getMessage(), create a new String variable and set that to ChatColor.RESET + e.getMessage(). Then, anytime you desire to use e.getMessage(), replace it with that variable.

    You must have added an extra character instead of just "&k." You probably typed "&&k" by mistake.
     
Thread Status:
Not open for further replies.

Share This Page