From 42b8bd8ee1d6f76b4f04ccaa42115cf4a1d5704e Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 02:29:50 -0600 Subject: [PATCH] Attempting to fix /heal --- vminecraftChat.java | 29 ++++++++++++----- vminecraftCommands.java | 72 +++++++++++++++++++++++++---------------- 2 files changed, 65 insertions(+), 36 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index a1f7b039f..21bbbde6c 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -67,8 +67,16 @@ public class vminecraftChat { return tempout; } + //===================================================================== + //Function: msgLength + //Input: String str: The string to find the length of + //Output: int: The length on the screen of a string + //Use: Finds the length on the screen of a string. Ignores colors. + //===================================================================== private static int msgLength(String str){ int length = 0; + //Loop through all the characters, skipping any color characters + //and their following color codes for(int x = 0; x " + message); return true; } @@ -270,7 +283,7 @@ public class vminecraftChat { public static boolean quote(Player player, String message) { //Format the name - String playerName = Colors.White + "<" + nameColor(player) + String playerName = Colors.White + "<" + getName(player) + Colors.White + "> "; if(vminecraftSettings.getInstance().greentext()) { //Log the chat @@ -298,7 +311,7 @@ public class vminecraftChat { { //Format the name String playerName = Colors.White + "<" - + nameColor(player) + Colors.White +"> "; + + getName(player) + Colors.White +"> "; if (vminecraftSettings.getInstance().FFF()) { log.log(Level.INFO, "<"+player.getName()+"> "+message); @@ -324,7 +337,7 @@ public class vminecraftChat { { //Format the name String playerName = Colors.White + "<" - + nameColor(player) + Colors.White +"> "; + + getName(player) + Colors.White +"> "; if(vminecraftSettings.getInstance().quakeColors()) { //Log the chat diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 3b8aba357..8aeda9fbc 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -48,44 +48,60 @@ public class vminecraftCommands{ cl.registerAlias("/wrists", "/suicide"); } - //Heal + //===================================================================== + //Function: heal (/heal) + //Input: Player player: The player using the command + // String[] args: The arguments for the command. Should be a + // player name or blank + //Output: int: Exit Code + //Use: Heals yourself or a specified player. + //===================================================================== public static int heal(Player player, String[] args) { if(vminecraftSettings.getInstance().cmdHeal()) { - if (args[1] == null){ - if (player.getHealth() < 20){ - vminecraftChat.gmsg("Your health is restored"); - return EXIT_SUCCESS; - } - else if (args[1] != null){ - Player playerTarget = etc.getServer().matchPlayer(args[1]); - if (playerTarget != null){ - playerTarget.setHealth(20); - vminecraftChat.gmsg(Colors.Blue + "You have healed " + playerTarget.getColor() + playerTarget.getName()); - vminecraftChat.gmsg(Colors.Blue + "You have been healed by " + player.getColor() + player.getName()); - return EXIT_SUCCESS; - } - else if (playerTarget == null){ - vminecraftChat.gmsg(Colors.Rose + "Couldn't find that player"); - return EXIT_FAIL; - } - - } + //If a target wasn't specified, heal the user. + if (args == null){ + if (player.getHealth() < 20){ + vminecraftChat.gmsg("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){ + Player playerTarget = etc.getServer().matchPlayer(args[0]); + + if (playerTarget != null){ + playerTarget.setHealth(20); + player.sendMessage(Colors.Blue + "You have healed " + vminecraftChat.getName(playerTarget)); + playerTarget.sendMessage(Colors.Blue + "You have been healed by " + vminecraftChat.getName(player)); + } + else if (playerTarget == null){ + vminecraftChat.gmsg(Colors.Rose + "Couldn't find that player"); + } } + return EXIT_SUCCESS; } return EXIT_FAIL; - } - //Suicide + } + + //===================================================================== + //Function: suicide (/suicide, /wrists) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: int: Exit Code + //Use: Kills yourself + //===================================================================== public static int suicide(Player player, String[] args) { if(vminecraftSettings.getInstance().cmdSuicide()) { + //Set your health to 0. Not much to it. player.setHealth(0); return EXIT_SUCCESS; } return EXIT_FAIL; } + //===================================================================== //Function: teleport (/tp) //Input: Player player: The player using the command @@ -247,7 +263,7 @@ public class vminecraftCommands{ //Format the name String playerName = Colors.White + "<" - + vminecraftChat.nameColor(player) + Colors.White +"> "; + + vminecraftChat.getName(player) + Colors.White +"> "; //Make sure a message has been specified if (args.length < 1) {return EXIT_FAIL;} String str = " "; @@ -306,7 +322,7 @@ public class vminecraftCommands{ //Displaying the information player.sendMessage(Colors.Blue + "Whois results for " + - vminecraftChat.nameColor(playerTarget)); + vminecraftChat.getName(playerTarget)); //Group for(String group: playerTarget.getGroups()) player.sendMessage(Colors.Blue + "Groups: " + group); @@ -347,9 +363,9 @@ public class vminecraftCommands{ { if(p != null){ if(count == 0) - tempList += vminecraftChat.nameColor(p); + tempList += vminecraftChat.getName(p); else - tempList += Colors.White + ", " + vminecraftChat.nameColor(p); + tempList += Colors.White + ", " + vminecraftChat.getName(p); count++; } } @@ -413,9 +429,9 @@ public class vminecraftCommands{ //If the player isn't invulnerable kill them if (!vminecraftSettings.getInstance().isEzModo(playerTarget.getName())) { playerTarget.setHealth(0); - vminecraftChat.gmsg(vminecraftChat.nameColor(player) + vminecraftChat.gmsg(vminecraftChat.getName(player) + Colors.LightBlue + " has slain " - + vminecraftChat.nameColor(playerTarget)); + + vminecraftChat.getName(playerTarget)); //Otherwise output error to the user } else { player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha");