From d2b64044e2fe4d068903019e062110e604799d7b Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 03:40:47 -0600 Subject: [PATCH] Added checking to make sure that the next character after a ^ is color code. --- vminecraftChat.java | 24 +++++++++++++++++------- vminecraftCommands.java | 9 ++++----- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index 21bbbde6c..70fdddb0c 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -225,7 +225,7 @@ public class vminecraftChat { color = Colors.White; break; default: - color = Colors.White; + color = null; break; } return color; @@ -381,14 +381,24 @@ public class vminecraftChat { //Loop through looking for a color code for(int x = 0; x< msg.length(); x++) { + //If the char is a ^ if(msg.charAt(x)=='^' && x != msg.length() - 1) { - //Set the most recent color to the new color - recentColor = vminecraftChat.colorChange(msg.charAt(x+1)); - temp += recentColor; - x++; - } - else{ + //If the following character is a color code + if(vminecraftChat.colorChange(msg.charAt(x+1)) != null) + { + //Set the most recent color to the new color + recentColor = vminecraftChat.colorChange(msg.charAt(x+1)); + //Add the color + temp += recentColor; + //Skip these chars + x++; + //Otherwise ignore it. + } else { + temp += msg.charAt(x); + } + //Insert the character + } else { temp += msg.charAt(x); } } diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 8aeda9fbc..b6484d766 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -61,13 +61,12 @@ public class vminecraftCommands{ if(vminecraftSettings.getInstance().cmdHeal()) { //If a target wasn't specified, heal the user. - if (args == null){ - if (player.getHealth() < 20){ - vminecraftChat.gmsg("Your health is restored"); - } + if (args.length < 1){ + player.setHealth(20); + player.sendMessage("Your health is restored"); //If a target was specified, try to find them and then heal them //Otherwise report the error - } else if (args != null){ + } else if (args.length > 0){ Player playerTarget = etc.getServer().matchPlayer(args[0]); if (playerTarget != null){