Fixed /who (Again. I seem to break it a lot!) and tweaked the line length function a little.

This commit is contained in:
cerevisiae 2010-11-30 00:25:16 -06:00
parent 724db6eab4
commit 7ae44da043
4 changed files with 120 additions and 101 deletions

View File

@ -71,35 +71,23 @@ public class vminecraftChat {
int length = 0; int length = 0;
for(int x = 0; x<str.length(); x++) for(int x = 0; x<str.length(); x++)
{ {
if("i;,.:|!".indexOf(str.charAt(x)) != -1) if(str.charAt(x) == '§')
{ x++;
else if("i;,.:|!".indexOf(str.charAt(x)) != -1)
length+=2; length+=2;
}
else if("l'".indexOf(str.charAt(x)) != -1) else if("l'".indexOf(str.charAt(x)) != -1)
{
length+=3; length+=3;
}
else if("tI[]".indexOf(str.charAt(x)) != -1) else if("tI[]".indexOf(str.charAt(x)) != -1)
{
length+=4; length+=4;
}
else if("kf{}<>\"*()".indexOf(str.charAt(x)) != -1) else if("kf{}<>\"*()".indexOf(str.charAt(x)) != -1)
{
length+=5; length+=5;
}
else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1) else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1)
{
length+=6; length+=6;
}
else if("@~".indexOf(str.charAt(x)) != -1) else if("@~".indexOf(str.charAt(x)) != -1)
{
length+=7; length+=7;
}
else if(str.charAt(x)==' ') else if(str.charAt(x)==' ')
{
length+=4; length+=4;
} }
}
return length; return length;
} }
@ -128,9 +116,22 @@ public class vminecraftChat {
//Use: Returns the colored name; //Use: Returns the colored name;
//===================================================================== //=====================================================================
public static String nameColor(Player player){ public static String nameColor(Player player){
//Get the prefix
String[] playerPrefix = new String[]{player.getPrefix()}; String[] playerPrefix = new String[]{player.getPrefix()};
return applyColors(playerPrefix)[0].substring(3)
+ player.getColor().substring(0,2) + player.getName(); //Add the name
String output = player.getName();
//Add the color if there is one
if(player.getColor() != null && player.getColor() != "")
output = player.getColor().substring(0,2) + output;
//Add the prefix if there is one
if(playerPrefix[0] != null && playerPrefix[0] != "")
output = applyColors(playerPrefix)[0].substring(3) + output;
//Return the name
return output;
} }
//===================================================================== //=====================================================================

View File

@ -12,6 +12,9 @@ import java.util.logging.Logger;
public class vminecraftCommands{ public class vminecraftCommands{
//Log output //Log output
protected static final Logger log = Logger.getLogger("Minecraft"); 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 //The list of commands for vminecraft
public static commandList cl = new commandList(); public static commandList cl = new commandList();
@ -35,6 +38,7 @@ public class vminecraftCommands{
cl.register("/slay", "slay", "Kill target player"); cl.register("/slay", "slay", "Kill target player");
cl.register("/ezmodo", "invuln", "Toggle invulnerability"); cl.register("/ezmodo", "invuln", "Toggle invulnerability");
cl.register("/ezlist", "ezlist", "List invulnerable players"); cl.register("/ezlist", "ezlist", "List invulnerable players");
cl.register("/modify", "modifySplit");
cl.registerAlias("/playerlist", "/who"); cl.registerAlias("/playerlist", "/who");
} }
@ -44,11 +48,10 @@ public class vminecraftCommands{
//Input: Player player: The player using the command //Input: Player player: The player using the command
// String[] args: The arguments for the command. Should be a // String[] args: The arguments for the command. Should be a
// player name // player name
//Output: boolean: If the user has access to the command //Output: int: Exit Code
// and it is enabled
//Use: Teleports the user to another player //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 //Get if the command is enabled
if(vminecraftSettings.getInstance().cmdTp()) if(vminecraftSettings.getInstance().cmdTp())
@ -83,20 +86,19 @@ public class vminecraftCommands{
//Otherwise inform the user that the player doesn't exist //Otherwise inform the user that the player doesn't exist
} }
} }
return true; return EXIT_SUCCESS;
} }
return false; return EXIT_FAIL;
} }
//===================================================================== //=====================================================================
//Function: masstp (/masstp) //Function: masstp (/masstp)
//Input: Player player: The player using the command //Input: Player player: The player using the command
// String[] args: Should be empty or is ignored // String[] args: Should be empty or is ignored
//Output: boolean: If the user has access to the command //Output: int: Exit Code
// and it is enabled
//Use: Teleports all players to the user //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 the command is enabled
if(vminecraftSettings.getInstance().cmdMasstp()) { if(vminecraftSettings.getInstance().cmdMasstp()) {
@ -109,9 +111,9 @@ public class vminecraftCommands{
//Inform the user that the command has executed successfully //Inform the user that the command has executed successfully
player.sendMessage(Colors.Blue+"Summoning successful."); player.sendMessage(Colors.Blue+"Summoning successful.");
return true; return EXIT_SUCCESS;
} }
return false; return EXIT_FAIL;
} }
//===================================================================== //=====================================================================
@ -119,11 +121,10 @@ public class vminecraftCommands{
//Input: Player player: The player using the command //Input: Player player: The player using the command
// String[] args: The arguments for the command. Should be a // String[] args: The arguments for the command. Should be a
// player name // player name
//Output: boolean: If the user has access to the command //Output: int: Exit Code
// and it is enabled
//Use: Teleports the user to another player //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. //Check if the command is enabled.
if (vminecraftSettings.getInstance().cmdTphere()) { if (vminecraftSettings.getInstance().cmdTphere()) {
@ -149,34 +150,32 @@ public class vminecraftCommands{
playerTarget.teleportTo(player); playerTarget.teleportTo(player);
} }
} }
return true; return EXIT_SUCCESS;
} }
return false; return EXIT_FAIL;
} }
//===================================================================== //=====================================================================
//Function: reload (/reload) //Function: reload (/reload)
//Input: Player player: The player using the command //Input: Player player: The player using the command
// String[] args: Ignored // String[] args: Ignored
//Output: boolean: If the user has access to the command //Output: int: Exit Code
// and it is enabled
//Use: Reloads the settings for vminecraft //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(); vminecraftSettings.getInstance().loadSettings();
return true; return EXIT_SUCCESS;
} }
//===================================================================== //=====================================================================
//Function: rules (/rules) //Function: rules (/rules)
//Input: Player player: The player using the command //Input: Player player: The player using the command
// String[] args: Ignored // String[] args: Ignored
//Output: boolean: If the user has access to the command //Output: int: Exit Code
// and it is enabled
//Use: Lists the rules //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 the rules exist
if(vminecraftSettings.getInstance().cmdRules() if(vminecraftSettings.getInstance().cmdRules()
@ -186,20 +185,19 @@ public class vminecraftCommands{
if(str.isEmpty()) if(str.isEmpty())
player.sendMessage(Colors.Blue+str); player.sendMessage(Colors.Blue+str);
} }
return true; return EXIT_SUCCESS;
} }
return false; return EXIT_FAIL;
} }
//===================================================================== //=====================================================================
//Function: fabulous (/fabulous) //Function: fabulous (/fabulous)
//Input: Player player: The player using the command //Input: Player player: The player using the command
// String[] args: The message to apply the effect to // String[] args: The message to apply the effect to
//Output: boolean: If the user has access to the command //Output: int: Exit Code
// and it is enabled
//Use: Makes the text rainbow colored //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 the command is enabled
if(vminecraftSettings.getInstance().cmdFabulous()) { if(vminecraftSettings.getInstance().cmdFabulous()) {
@ -208,7 +206,7 @@ public class vminecraftCommands{
String playerName = Colors.White + "<" String playerName = Colors.White + "<"
+ vminecraftChat.nameColor(player) + Colors.White +"> "; + vminecraftChat.nameColor(player) + Colors.White +"> ";
//Make sure a message has been specified //Make sure a message has been specified
if (args.length < 1) {return false;} if (args.length < 1) {return EXIT_FAIL;}
String str = " "; String str = " ";
//Merge the message again //Merge the message again
@ -228,23 +226,22 @@ public class vminecraftCommands{
+ vminecraftChat.rainbow( + vminecraftChat.rainbow(
msg.substring(playerName.length() - 1))); msg.substring(playerName.length() - 1)));
else else
vminecraftChat.gmsg(msg); vminecraftChat.gmsg(vminecraftChat.rainbow(msg));
} }
return true; return EXIT_SUCCESS;
} }
return false; return EXIT_FAIL;
} }
//===================================================================== //=====================================================================
//Function: whois (/whois) //Function: whois (/whois)
//Input: Player player: The player using the command //Input: Player player: The player using the command
// String[] args: The player to find info on // String[] args: The player to find info on
//Output: boolean: If the user has access to the command //Output: int: Exit Code
// and it is enabled
//Use: Displays information about the player specified //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 the command is enabled
if (vminecraftSettings.getInstance().cmdWhoIs()) { if (vminecraftSettings.getInstance().cmdWhoIs()) {
@ -284,20 +281,19 @@ public class vminecraftCommands{
player.sendMessage(Colors.Rose+"Player not found."); player.sendMessage(Colors.Rose+"Player not found.");
} }
} }
return true; return EXIT_SUCCESS;
} }
return false; return EXIT_SUCCESS;
} }
//===================================================================== //=====================================================================
//Function: who (/who) //Function: who (/who)
//Input: Player player: The player using the command //Input: Player player: The player using the command
// String[] args: Ignored // String[] args: Ignored
//Output: boolean: If the user has access to the command //Output: int: Exit Code
// and it is enabled
//Use: Displays the connected players //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 the command is enabled
if (vminecraftSettings.getInstance().cmdWho()) { if (vminecraftSettings.getInstance().cmdWho()) {
@ -328,20 +324,19 @@ public class vminecraftCommands{
for(String msg: tempOut) for(String msg: tempOut)
player.sendMessage( msg ); player.sendMessage( msg );
return true; return EXIT_SUCCESS;
} }
return false; return EXIT_FAIL;
} }
//===================================================================== //=====================================================================
//Function: say (/say) //Function: say (/say)
//Input: Player player: The player using the command //Input: Player player: The player using the command
// String[] args: The message to apply the effect to // String[] args: The message to apply the effect to
//Output: boolean: If the user has access to the command //Output: int: Exit Code
// and it is enabled
//Use: Announces the message to all players //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 the command is enabled
if (vminecraftSettings.getInstance().cmdSay()) { if (vminecraftSettings.getInstance().cmdSay()) {
@ -351,20 +346,19 @@ public class vminecraftCommands{
} }
//Display the message globally //Display the message globally
vminecraftChat.gmsg(Colors.Yellow + etc.combineSplit(0, args, " ")); vminecraftChat.gmsg(Colors.Yellow + etc.combineSplit(0, args, " "));
return true; return EXIT_SUCCESS;
} }
return false; return EXIT_FAIL;
} }
//===================================================================== //=====================================================================
//Function: slay (/slay) //Function: slay (/slay)
//Input: Player player: The player using the command //Input: Player player: The player using the command
// String[] args: The target for the command // String[] args: The target for the command
//Output: boolean: If the user has access to the command //Output: int: Exit Code
// and it is enabled
//Use: Kill the target player //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 //Check if the command is enabled
if(vminecraftSettings.getInstance().cmdEzModo()) { if(vminecraftSettings.getInstance().cmdEzModo()) {
@ -372,7 +366,7 @@ public class vminecraftCommands{
Player playerTarget = etc.getServer().matchPlayer(args[0]); Player playerTarget = etc.getServer().matchPlayer(args[0]);
//If the player doesn't exist don't run //If the player doesn't exist don't run
if(playerTarget == null) if(playerTarget == null)
return false; return EXIT_SUCCESS;
//If the player isn't invulnerable kill them //If the player isn't invulnerable kill them
if (!vminecraftSettings.getInstance().isEzModo(playerTarget.getName())) { if (!vminecraftSettings.getInstance().isEzModo(playerTarget.getName())) {
playerTarget.setHealth(0); playerTarget.setHealth(0);
@ -381,20 +375,19 @@ public class vminecraftCommands{
} else { } else {
player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha"); player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha");
} }
return true; return EXIT_FAIL;
} }
return false; return EXIT_SUCCESS;
} }
//===================================================================== //=====================================================================
//Function: invuln (/ezmodo) //Function: invuln (/ezmodo)
//Input: Player player: The player using the command //Input: Player player: The player using the command
// String[] args: The target for the command // String[] args: The target for the command
//Output: boolean: If the user has access to the command //Output: int: Exit Code
// and it is enabled
//Use: Kill the target player //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 the command is enabled
if (vminecraftSettings.getInstance().cmdEzModo()) { if (vminecraftSettings.getInstance().cmdEzModo()) {
@ -411,29 +404,56 @@ public class vminecraftCommands{
vminecraftSettings.getInstance().addEzModo(player.getName()); vminecraftSettings.getInstance().addEzModo(player.getName());
player.setHealth(vminecraftSettings.getInstance().ezModoHealth()); player.setHealth(vminecraftSettings.getInstance().ezModoHealth());
} }
return true; return EXIT_SUCCESS;
} }
return false; return EXIT_FAIL;
} }
//===================================================================== //=====================================================================
//Function: ezlist (/ezlist) //Function: ezlist (/ezlist)
//Input: Player player: The player using the command //Input: Player player: The player using the command
// String[] args: Ignored // String[] args: Ignored
//Output: boolean: If the user has access to the command //Output: int: Exit Code
// and it is enabled
//Use: List all invulnerable players //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 the feature is enabled list the players
if(vminecraftSettings.getInstance().cmdEzModo()) { if(vminecraftSettings.getInstance().cmdEzModo()) {
player.sendMessage("Ezmodo: " + vminecraftSettings.getInstance().ezModoList()); 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) //Disable using /modify to add commands (need to make a boolean settings for this)
@ -563,6 +583,9 @@ log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+"
class commandList { class commandList {
command[] commands; command[] commands;
protected static final Logger log = Logger.getLogger("Minecraft"); protected static final Logger log = Logger.getLogger("Minecraft");
static final int EXIT_FAIL = 0,
EXIT_SUCCESS = 1,
EXIT_CONTINUE = 2;
//===================================================================== //=====================================================================
//Function: commandList //Function: commandList
@ -698,10 +721,10 @@ class commandList {
//Output: boolean: If the command was called successfully //Output: boolean: If the command was called successfully
//Use: Attempts to call a command //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 //Make sure the user has access to the command
if(!player.canUseCommand(name)) { if(!player.canUseCommand(name)) {
return false; return EXIT_FAIL;
} }
//Search for the command //Search for the command
for(command cmd : commands) for(command cmd : commands)
@ -716,13 +739,13 @@ class commandList {
log.log(Level.SEVERE, "Exception while running command", e); log.log(Level.SEVERE, "Exception while running command", e);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e); log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e);
return false; return EXIT_FAIL;
} }
} }
} }
//Something went wrong //Something went wrong
return false; return EXIT_FAIL;
} }
//===================================================================== //=====================================================================
@ -761,14 +784,14 @@ class commandList {
//Output: boolean: If the command was called successfully //Output: boolean: If the command was called successfully
//Use: Attempts to call the command //Use: Attempts to call the command
//===================================================================== //=====================================================================
boolean call(Player player, String[] arg) int call(Player player, String[] arg)
{ {
Method m; Method m;
try { try {
m = vminecraftCommands.class.getMethod(function, Player.class, String[].class); m = vminecraftCommands.class.getMethod(function, Player.class, String[].class);
m.setAccessible(true); m.setAccessible(true);
return (Boolean) m.invoke(null, player, arg); return (Integer) m.invoke(null, player, arg);
} catch (SecurityException e) { } catch (SecurityException e) {
e.printStackTrace(); e.printStackTrace();
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
@ -780,7 +803,7 @@ class commandList {
} catch (InvocationTargetException e) { } catch (InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
} }
return true; return 1;
} }
} }
@ -827,7 +850,7 @@ class commandList {
//Output: boolean: If the command was called successfully //Output: boolean: If the command was called successfully
//Use: Attempts to call the command //Use: Attempts to call the command
//===================================================================== //=====================================================================
boolean call(Player player, String[] arg) int call(Player player, String[] arg)
{ {
if(args != null) { if(args != null) {
String[] temp = new String[args.length]; String[] temp = new String[args.length];
@ -862,12 +885,7 @@ class commandList {
player.command(reference + " " + etc.combineSplit(0, temp, " ")); player.command(reference + " " + etc.combineSplit(0, temp, " "));
} else } else
player.command(reference); player.command(reference);
return EXIT_SUCCESS;
/*if(temp != null)
etc.getServer().useConsoleCommand(reference + " " + etc.combineSplit(0, temp, " "), player);
else
etc.getServer().useConsoleCommand(reference, player);*/
return true;
} }
} }
} }

View File

@ -54,17 +54,18 @@ public class vminecraftListener extends PluginListener {
//===================================================================== //=====================================================================
public boolean onCommand(Player player, String[] split) { 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. //Copy the arguments into their own array.
String[] args = new String[split.length - 1]; String[] args = new String[split.length - 1];
System.arraycopy(split, 1, args, 0, args.length); System.arraycopy(split, 1, args, 0, args.length);
//Return the results of the command //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;
} }

View File

@ -2,7 +2,6 @@ import java.io.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.Random;
//===================================================================== //=====================================================================
//Class: vminecraftSettings //Class: vminecraftSettings
//Use: Controls the settings for vminecraft //Use: Controls the settings for vminecraft