diff --git a/vminecraftChat.java b/vminecraftChat.java index dddbbd7e9..a1f7b039f 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -71,34 +71,22 @@ public class vminecraftChat { int length = 0; for(int x = 0; x\"*()".indexOf(str.charAt(x)) != -1) - { length+=5; - } else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1) - { length+=6; - } else if("@~".indexOf(str.charAt(x)) != -1) - { length+=7; - } else if(str.charAt(x)==' ') - { length+=4; - } } return length; } @@ -107,9 +95,9 @@ public class vminecraftChat { public static String rainbow(String msg){ String temp = ""; //The array of colors to use - String[] rainbow = new String[] {Colors.Red, Colors.Rose, - Colors.Yellow, Colors.Green, Colors.Blue, - Colors.LightPurple, Colors.Purple}; + String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Gold, + Colors.Yellow, Colors.LightGreen, Colors.Green, Colors.Blue, + Colors.Navy, Colors.DarkPurple, Colors.Purple, Colors.LightPurple}; int counter=0; //Loop through the message applying the colors for(int x=0; x "; - if(vminecraftSettings.getInstance().quakeColors() && message.length()>2) { + if(vminecraftSettings.getInstance().quakeColors()) { //Log the chat log.log(Level.INFO, "<"+player.getName()+"> "+message); diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 46acf3cfb..62ab55308 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -12,6 +12,9 @@ import java.util.logging.Logger; public class vminecraftCommands{ //Log output protected static final Logger log = Logger.getLogger("Minecraft"); + static final int EXIT_FAIL = 0, + EXIT_SUCCESS = 1, + EXIT_CONTINUE = 2; //The list of commands for vminecraft public static commandList cl = new commandList(); @@ -35,8 +38,12 @@ public class vminecraftCommands{ cl.register("/slay", "slay", "Kill target player"); cl.register("/ezmodo", "invuln", "Toggle invulnerability"); cl.register("/ezlist", "ezlist", "List invulnerable players"); + cl.register("/heal", "heal", "heal yourself or other players"); cl.register("/suicide", "suicide", "kill yourself... you loser"); + + cl.register("/modify", "modifySplit"); + cl.registerAlias("/playerlist", "/who"); cl.registerAlias("/suicide", "/wrists"); } @@ -84,11 +91,10 @@ public class vminecraftCommands{ //Input: Player player: The player using the command // String[] args: The arguments for the command. Should be a // player name - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Teleports the user to another player //===================================================================== - public static boolean teleport(Player player, String[] args) + public static int teleport(Player player, String[] args) { //Get if the command is enabled if(vminecraftSettings.getInstance().cmdTp()) @@ -123,20 +129,19 @@ public class vminecraftCommands{ //Otherwise inform the user that the player doesn't exist } } - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: masstp (/masstp) //Input: Player player: The player using the command // String[] args: Should be empty or is ignored - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Teleports all players to the user //===================================================================== - public static boolean masstp(Player player, String[] args) + public static int masstp(Player player, String[] args) { //If the command is enabled if(vminecraftSettings.getInstance().cmdMasstp()) { @@ -149,9 +154,9 @@ public class vminecraftCommands{ //Inform the user that the command has executed successfully player.sendMessage(Colors.Blue+"Summoning successful."); - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== @@ -159,11 +164,10 @@ public class vminecraftCommands{ //Input: Player player: The player using the command // String[] args: The arguments for the command. Should be a // player name - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Teleports the user to another player //===================================================================== - public static boolean tphere(Player player, String[] args) + public static int tphere(Player player, String[] args) { //Check if the command is enabled. if (vminecraftSettings.getInstance().cmdTphere()) { @@ -189,34 +193,32 @@ public class vminecraftCommands{ playerTarget.teleportTo(player); } } - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: reload (/reload) //Input: Player player: The player using the command // String[] args: Ignored - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Reloads the settings for vminecraft //===================================================================== - public static boolean reload(Player player, String[] args) + public static int reload(Player player, String[] args) { vminecraftSettings.getInstance().loadSettings(); - return true; + return EXIT_SUCCESS; } //===================================================================== //Function: rules (/rules) //Input: Player player: The player using the command // String[] args: Ignored - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Lists the rules //===================================================================== - public static boolean rules(Player player, String[] args) + public static int rules(Player player, String[] args) { //If the rules exist if(vminecraftSettings.getInstance().cmdRules() @@ -226,20 +228,19 @@ public class vminecraftCommands{ if(str.isEmpty()) player.sendMessage(Colors.Blue+str); } - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: fabulous (/fabulous) //Input: Player player: The player using the command // String[] args: The message to apply the effect to - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Makes the text rainbow colored //===================================================================== - public static boolean fabulous(Player player, String[] args) + public static int fabulous(Player player, String[] args) { //If the command is enabled if(vminecraftSettings.getInstance().cmdFabulous()) { @@ -248,7 +249,7 @@ public class vminecraftCommands{ String playerName = Colors.White + "<" + vminecraftChat.nameColor(player) + Colors.White +"> "; //Make sure a message has been specified - if (args.length < 1) {return false;} + if (args.length < 1) {return EXIT_FAIL;} String str = " "; //Merge the message again @@ -264,27 +265,26 @@ public class vminecraftCommands{ for(String msg: message) { if (msg.contains(playerName)) - vminecraftChat.gmsg( - vminecraftChat.rainbow( - msg.substring(playerName.length() - 1))); + vminecraftChat.gmsg( playerName + + vminecraftChat.rainbow( + msg.substring(playerName.length()))); else - vminecraftChat.gmsg(msg); + vminecraftChat.gmsg(vminecraftChat.rainbow(msg)); } - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: whois (/whois) //Input: Player player: The player using the command // String[] args: The player to find info on - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Displays information about the player specified //===================================================================== - public static boolean whois(Player player, String[] args) + public static int whois(Player player, String[] args) { //If the command is enabled if (vminecraftSettings.getInstance().cmdWhoIs()) { @@ -324,20 +324,19 @@ public class vminecraftCommands{ player.sendMessage(Colors.Rose+"Player not found."); } } - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_SUCCESS; } //===================================================================== //Function: who (/who) //Input: Player player: The player using the command // String[] args: Ignored - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Displays the connected players //===================================================================== - public static boolean who(Player player, String[] args) + public static int who(Player player, String[] args) { //If the command is enabled if (vminecraftSettings.getInstance().cmdWho()) { @@ -368,20 +367,19 @@ public class vminecraftCommands{ for(String msg: tempOut) player.sendMessage( msg ); - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: say (/say) //Input: Player player: The player using the command // String[] args: The message to apply the effect to - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Announces the message to all players //===================================================================== - public static boolean say(Player player, String[] args) + public static int say(Player player, String[] args) { //If the command is enabled if (vminecraftSettings.getInstance().cmdSay()) { @@ -391,20 +389,19 @@ public class vminecraftCommands{ } //Display the message globally vminecraftChat.gmsg(Colors.Yellow + etc.combineSplit(0, args, " ")); - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: slay (/slay) //Input: Player player: The player using the command // String[] args: The target for the command - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Kill the target player //===================================================================== - public static boolean slay(Player player, String[] args) + public static int slay(Player player, String[] args) { //Check if the command is enabled if(vminecraftSettings.getInstance().cmdEzModo()) { @@ -412,29 +409,30 @@ public class vminecraftCommands{ Player playerTarget = etc.getServer().matchPlayer(args[0]); //If the player doesn't exist don't run if(playerTarget == null) - return false; + return EXIT_FAIL; //If the player isn't invulnerable kill them if (!vminecraftSettings.getInstance().isEzModo(playerTarget.getName())) { playerTarget.setHealth(0); - vminecraftChat.gmsg(player.getColor() + player.getName() + Colors.LightBlue + " has slain " + playerTarget.getColor() + playerTarget.getName()); + vminecraftChat.gmsg(vminecraftChat.nameColor(player) + + Colors.LightBlue + " has slain " + + vminecraftChat.nameColor(playerTarget)); //Otherwise output error to the user } else { player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha"); } - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: invuln (/ezmodo) //Input: Player player: The player using the command // String[] args: The target for the command - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Kill the target player //===================================================================== - public static boolean invuln(Player player, String[] args) + public static int invuln(Player player, String[] args) { //If the command is enabled if (vminecraftSettings.getInstance().cmdEzModo()) { @@ -451,29 +449,56 @@ public class vminecraftCommands{ vminecraftSettings.getInstance().addEzModo(player.getName()); player.setHealth(vminecraftSettings.getInstance().ezModoHealth()); } - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: ezlist (/ezlist) //Input: Player player: The player using the command // String[] args: Ignored - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: List all invulnerable players //===================================================================== - public static boolean ezlist(Player player, String[] args) + public static int ezlist(Player player, String[] args) { //If the feature is enabled list the players if(vminecraftSettings.getInstance().cmdEzModo()) { player.sendMessage("Ezmodo: " + vminecraftSettings.getInstance().ezModoList()); - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; + } + + //===================================================================== + //Function: modifySplit (/modify) + //Input: Player player: The player using the command + // String[] args: Player, Command, Arguments + //Output: int: Exit Code + //Use: List all invulnerable players + //===================================================================== + public static int modifySplit(Player player, String[] args) + { + //Exploit fix for people giving themselves commands + if(args[1].equals("commands")) + return EXIT_FAIL; + else if (args[1].equals("tag")) + playerTag(player, args); + return EXIT_CONTINUE; + } + + //===================================================================== + //Function: playerTag (/modify player tag *) + //Input: Player player: The player using the command + // String[] args: Player, Command, Arguments + //Output: int: Exit Code + //Use: List all invulnerable players + //===================================================================== + public static int playerTag(Player player, String[] args) + { + return EXIT_SUCCESS; } - //Disable using /modify to add commands (need to make a boolean settings for this) @@ -603,6 +628,9 @@ log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" class commandList { command[] commands; protected static final Logger log = Logger.getLogger("Minecraft"); + static final int EXIT_FAIL = 0, + EXIT_SUCCESS = 1, + EXIT_CONTINUE = 2; //===================================================================== //Function: commandList @@ -738,10 +766,10 @@ class commandList { //Output: boolean: If the command was called successfully //Use: Attempts to call a command //===================================================================== - public boolean call(String name, Player player, String[] arg){ + public int call(String name, Player player, String[] arg){ //Make sure the user has access to the command if(!player.canUseCommand(name)) { - return false; + return EXIT_FAIL; } //Search for the command for(command cmd : commands) @@ -756,13 +784,13 @@ class commandList { log.log(Level.SEVERE, "Exception while running command", e); } catch (IllegalArgumentException e) { log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e); - return false; + return EXIT_FAIL; } } } //Something went wrong - return false; + return EXIT_FAIL; } //===================================================================== @@ -801,14 +829,14 @@ class commandList { //Output: boolean: If the command was called successfully //Use: Attempts to call the command //===================================================================== - boolean call(Player player, String[] arg) + int call(Player player, String[] arg) { Method m; try { m = vminecraftCommands.class.getMethod(function, Player.class, String[].class); m.setAccessible(true); - return (Boolean) m.invoke(null, player, arg); + return (Integer) m.invoke(null, player, arg); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { @@ -820,7 +848,7 @@ class commandList { } catch (InvocationTargetException e) { e.printStackTrace(); } - return true; + return 1; } } @@ -867,7 +895,7 @@ class commandList { //Output: boolean: If the command was called successfully //Use: Attempts to call the command //===================================================================== - boolean call(Player player, String[] arg) + int call(Player player, String[] arg) { if(args != null) { String[] temp = new String[args.length]; @@ -902,12 +930,7 @@ class commandList { player.command(reference + " " + etc.combineSplit(0, temp, " ")); } else player.command(reference); - - /*if(temp != null) - etc.getServer().useConsoleCommand(reference + " " + etc.combineSplit(0, temp, " "), player); - else - etc.getServer().useConsoleCommand(reference, player);*/ - return true; + return EXIT_SUCCESS; } } } \ No newline at end of file diff --git a/vminecraftListener.java b/vminecraftListener.java index 7bc1081a6..319ebc8e9 100644 --- a/vminecraftListener.java +++ b/vminecraftListener.java @@ -54,17 +54,18 @@ public class vminecraftListener extends PluginListener { //===================================================================== public boolean onCommand(Player player, String[] split) { - //Explot fix on /modify - if(split[0].equals("/modify") && split[2].equals("commands")) { - return false; - } - //Copy the arguments into their own array. String[] args = new String[split.length - 1]; System.arraycopy(split, 1, args, 0, args.length); //Return the results of the command - return vminecraftCommands.cl.call(split[0], player, args); + int exitCode = vminecraftCommands.cl.call(split[0], player, args); + if(exitCode == 0) + return false; + else if(exitCode == 1) + return true; + else + return false; } diff --git a/vminecraftSettings.java b/vminecraftSettings.java index 4d764cede..8397526a4 100644 --- a/vminecraftSettings.java +++ b/vminecraftSettings.java @@ -2,7 +2,6 @@ import java.io.*; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.Random; //===================================================================== //Class: vminecraftSettings //Use: Controls the settings for vminecraft