Weird thing I don't understand - changing text on signs

Discussion in 'Plugin Development' started by Rprrr, Jan 14, 2013.

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

    Rprrr

    Hi,

    I'm trying to change the colour of text on a sign after it's written. My code:
    Code:
        @EventHandler
        public void onSignChange(SignChangeEvent e){
            if (e.getPlayer().hasPermission("zs.sign.create")){
                String[] txt = e.getLines();
                if (txt[3] !=null){
                    if (txt[3].equals("[Buy]")){                 
                        if (txt[0] !=null){                     
                                char[] chars = txt[0].toCharArray();                             
                                int nr = chars[1];
                                for (int i = 0; i < chars.length; i++){
                                    Bukkit.broadcastMessage(i + " = " + chars[i]);
                                }
                                e.setLine(0, ChatColor.GRAY + "[" + ChatColor.GOLD + nr + ChatColor.GRAY + "]");
                                e.setLine(3, ChatColor.GRAY + "[" + ChatColor.GOLD + "Buy" + ChatColor.GRAY + "]");
                                e.getBlock().getState().update();
                        }
                    }
                }
            }
        }
    So yeah, most of this works. The only problem: on the first line.. it puts [49] (with colours), while it should be [1] (if 1 was entered). I tried printing out the values of chars[], but it simply gives me 0 = [, 1 = 1 and 2 = ].. so why does it put '[49]' on the sign, then? :l

    Anyone knows why this is happening?
     
  2. Offline

    fireblast709

    you convert a char to int. 1 is the 49th ASCII character
     
Thread Status:
Not open for further replies.

Share This Page