Prefixes and Color code problems when using getDisplayName();

Discussion in 'Plugin Development' started by Jessy1237, Jan 14, 2012.

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


    Ok so i have tryed to fix my problem but here it is. My plugin RTest once you get the word correct it asks vault to find an economy plugin then after that it trys to give the player a reward in money but one problem if the person has a prefix or a color coded name that all gets sent to the economy plugin and it gives off an error because it can't find the account.

    Here is the class the code is flawless except the prefix and Color code problem
    package com.Jessy1237.RTest;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.permission.Permission;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerListener;
    public class RTestPlayerListener extends PlayerListener{
        static String message = "";
        static int EorD = 0;
        static int seconds = 0;
        public static RTest plugin;
        public static Economy econ;
        public Permission perms;
        public RTestPlayerListener(RTest instance){
            plugin = instance;
        public static void enable(){
            EorD = 1;
        public static void disable(){
            EorD = 0;
        public void onPlayerChat(PlayerChatEvent event){
            perms = plugin.perms;
            econ = RTest.econ;
            Player player = event.getPlayer();
            String name = player.getDisplayName();
            if(perms.playerHas(player, "RTest.Member") || perms.playerHas(player, "RTest.Admin")){
                Player players[] = plugin.getServer().getOnlinePlayers();
                if((event.getMessage()).equals((loadRnum.dNum1))  && EorD == 1){
                    econ.depositPlayer(name, RTest.reward());
                    for(int i = 0; i <players.length; i++)
                        players[i].sendMessage((new StringBuilder()).append(plugin.getColour(RTest.ChatColor())).append("The Winner is: " + name + ".").append(message).toString());
          "[RTest] Displaying Winner to Players...");
                    if((RTest.b) == 1){
                        RTest.b = 0;
                if((event.getMessage()).equals((loadRnum.dNum1)) && EorD == 1){
                    player.sendMessage(plugin.getColour(RTest.ChatColor()) + "You don't have permission to win a Reaction Test");
                    player.sendMessage(plugin.getColour(RTest.ChatColor()) + "Congratulations Though for Getting it right!");
                    if(EorD == 1){
                        player.sendMessage(plugin.getColour(RTest.ChatColor()) + "You don't have permission to win a Reaction Test");
    The actual line that gives off the account error is "econ.deopsitPlayer(name, RTest.reward());"

    Pls reply back soon
  2. Offline


    First, if you have only 2 integer-states, why don't you use a boolean then? (->EorD)
    And try to use player.getName() instead of player.getDisplayName().
  3. Offline


    Ok thanks so much i tried player.getName(); before but it didn't work but then i looked at the error and iConomy couldn't read its db so i deleted it and had a fresh db and it worked and about the EorD, that was when i had only started java but now i am a lot better than before and i can't be bothered changing it.
  4. Offline


    You should always go back and fix the mistakes you have made, its the mark of a good developer.
Thread Status:
Not open for further replies.

Share This Page