浏览代码

Merge branch 'master' of github.com:nossr50/vminecraft-plugin

nossr50 14 年之前
父节点
当前提交
15b92cde5c
共有 2 个文件被更改,包括 65 次插入36 次删除
  1. 21 8
      vminecraftChat.java
  2. 44 28
      vminecraftCommands.java

+ 21 - 8
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<str.length(); x++)
 		{
 			if(str.charAt(x) == '§')
@@ -90,8 +98,13 @@ public class vminecraftChat {
 		}
 		return length;
     }
-    
 
+	//=====================================================================
+	//Function:	rainbow
+	//Input:	String msg: The string to colorify
+	//Output:	String: The rainbowed result
+	//Use:		Rainbowifies a string;
+	//=====================================================================
     public static String rainbow(String msg){
     	String temp = "";
     	//The array of colors to use
@@ -110,12 +123,12 @@ public class vminecraftChat {
 		return temp;
     }
 	//=====================================================================
-	//Function:	nameColor
+	//Function:	getName
 	//Input:	Player player: The player to get name as color
 	//Output:	String: The name colored 
 	//Use:		Returns the colored name;
 	//=====================================================================
-    public static String nameColor(Player player){
+    public static String getName(Player player){
     	
     	//Get the prefix
     	String[] playerPrefix = new String[]{player.getPrefix()};
@@ -231,7 +244,7 @@ public class vminecraftChat {
 		if(player.isAdmin() || player.canUseCommand("/adminchat"))
 		{
 			//Special formatting for adminchat {Username}
-	        String adminchat = Colors.DarkPurple + "{" + nameColor(player)
+	        String adminchat = Colors.DarkPurple + "{" + getName(player)
 	        +  Colors.DarkPurple +"}" + Colors.White + " ";
 	        
 	        String[] msg = wordWrap(adminchat + message.substring(1, message.length()));
@@ -253,7 +266,7 @@ public class vminecraftChat {
 			}
 
 		    //So you can read adminchat from the server console
-			log.log(Level.INFO, "@" + "<" + nameColor(player)
+			log.log(Level.INFO, "@" + "<" + getName(player)
 					+  Colors.White +"> " + 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

+ 44 - 28
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");