2010-11-28 08:10:14 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Class: vminecraftCommands
|
|
|
|
//Use: Encapsulates all commands added by this mod
|
|
|
|
//Author: nos, trapalice, cerevisiae
|
|
|
|
//=====================================================================
|
|
|
|
public class vminecraftCommands{
|
|
|
|
//Log output
|
|
|
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
2010-11-30 07:25:16 +01:00
|
|
|
static final int EXIT_FAIL = 0,
|
|
|
|
EXIT_SUCCESS = 1,
|
|
|
|
EXIT_CONTINUE = 2;
|
2010-11-28 08:10:14 +01:00
|
|
|
|
|
|
|
//The list of commands for vminecraft
|
|
|
|
public static commandList cl = new commandList();
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: loadCommands
|
|
|
|
//Input: None
|
|
|
|
//Output: None
|
|
|
|
//Use: Imports all the commands into the command list
|
|
|
|
//=====================================================================
|
|
|
|
public static void loadCommands(){
|
|
|
|
//If we had commands we would add them here.
|
|
|
|
cl.register("/tp", "teleport");
|
|
|
|
cl.register("/masstp", "masstp", "Teleports those with lower permissions to you");
|
|
|
|
cl.register("/reload", "reload");
|
|
|
|
cl.register("/rules", "rules", "Displays the rules");
|
|
|
|
cl.register("/fabulous", "fabulous", "makes text SUUUPER");
|
|
|
|
cl.register("/whois", "whois", "/whois [user]");
|
2010-11-28 08:17:52 +01:00
|
|
|
cl.register("/who", "who");
|
2010-11-28 08:10:14 +01:00
|
|
|
cl.register("/say", "say");
|
|
|
|
cl.register("/slay", "slay", "Kill target player");
|
|
|
|
cl.register("/ezmodo", "invuln", "Toggle invulnerability");
|
|
|
|
cl.register("/ezlist", "ezlist", "List invulnerable players");
|
2010-11-30 08:32:01 +01:00
|
|
|
|
2010-11-30 07:58:27 +01:00
|
|
|
cl.register("/heal", "heal", "heal yourself or other players");
|
|
|
|
cl.register("/suicide", "suicide", "kill yourself... you loser");
|
2010-11-30 08:32:01 +01:00
|
|
|
|
2010-11-30 07:25:16 +01:00
|
|
|
cl.register("/modify", "modifySplit");
|
2010-11-30 08:32:01 +01:00
|
|
|
|
2010-11-29 02:30:34 +01:00
|
|
|
cl.registerAlias("/playerlist", "/who");
|
2010-11-30 08:40:31 +01:00
|
|
|
cl.registerAlias("/wrists", "/suicide");
|
2010-11-30 07:58:27 +01:00
|
|
|
}
|
|
|
|
|
2010-11-30 09:29:50 +01:00
|
|
|
//=====================================================================
|
|
|
|
//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.
|
|
|
|
//=====================================================================
|
2010-11-30 08:40:31 +01:00
|
|
|
public static int heal(Player player, String[] args)
|
2010-11-30 07:58:27 +01:00
|
|
|
{
|
2010-11-30 08:40:31 +01:00
|
|
|
if(vminecraftSettings.getInstance().cmdHeal())
|
2010-11-30 07:58:27 +01:00
|
|
|
{
|
2010-11-30 09:29:50 +01:00
|
|
|
//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");
|
|
|
|
}
|
2010-11-30 07:58:27 +01:00
|
|
|
}
|
2010-11-30 09:29:50 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-30 07:58:27 +01:00
|
|
|
}
|
2010-11-30 08:40:31 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-30 09:29:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: suicide (/suicide, /wrists)
|
|
|
|
//Input: Player player: The player using the command
|
|
|
|
// String[] args: Ignored
|
|
|
|
//Output: int: Exit Code
|
|
|
|
//Use: Kills yourself
|
|
|
|
//=====================================================================
|
2010-11-30 08:40:31 +01:00
|
|
|
public static int suicide(Player player, String[] args)
|
2010-11-30 07:58:27 +01:00
|
|
|
{
|
2010-11-30 08:40:31 +01:00
|
|
|
if(vminecraftSettings.getInstance().cmdSuicide())
|
2010-11-30 07:58:27 +01:00
|
|
|
{
|
2010-11-30 09:29:50 +01:00
|
|
|
//Set your health to 0. Not much to it.
|
2010-11-30 07:58:27 +01:00
|
|
|
player.setHealth(0);
|
2010-11-30 08:40:31 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-30 07:58:27 +01:00
|
|
|
}
|
2010-11-30 08:40:31 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 09:29:50 +01:00
|
|
|
|
2010-11-28 08:10:14 +01:00
|
|
|
//=====================================================================
|
|
|
|
//Function: teleport (/tp)
|
|
|
|
//Input: Player player: The player using the command
|
|
|
|
// String[] args: The arguments for the command. Should be a
|
|
|
|
// player name
|
2010-11-30 07:25:16 +01:00
|
|
|
//Output: int: Exit Code
|
2010-11-28 08:10:14 +01:00
|
|
|
//Use: Teleports the user to another player
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
public static int teleport(Player player, String[] args)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
|
|
|
//Get if the command is enabled
|
|
|
|
if(vminecraftSettings.getInstance().cmdTp())
|
|
|
|
{
|
|
|
|
//Make sure a player has been specified and return an error if not
|
|
|
|
if (args.length < 1) {
|
|
|
|
player.sendMessage(Colors.Rose + "Correct usage is: /tp [player]");
|
|
|
|
} else {
|
|
|
|
|
|
|
|
//Find the player by name
|
|
|
|
Player playerTarget = etc.getServer().matchPlayer(args[0]);
|
2010-11-29 00:43:42 +01:00
|
|
|
|
|
|
|
//Target player isn't found
|
|
|
|
if(playerTarget == null)
|
|
|
|
player.sendMessage(Colors.Rose + "Can't find user "
|
|
|
|
+ args[0] + ".");
|
2010-11-28 08:10:14 +01:00
|
|
|
//If it's you, return witty message
|
2010-11-29 00:43:42 +01:00
|
|
|
else if (player.getName().equalsIgnoreCase(args[0]))
|
2010-11-28 08:10:14 +01:00
|
|
|
player.sendMessage(Colors.Rose + "You're already here!");
|
|
|
|
|
|
|
|
//If the player is higher rank than you, inform the user
|
|
|
|
else if (!player.hasControlOver(playerTarget))
|
|
|
|
player.sendMessage(Colors.Red +
|
|
|
|
"That player has higher permissions than you.");
|
|
|
|
|
|
|
|
//If the player exists transport the user to the player
|
2010-11-29 00:43:42 +01:00
|
|
|
else {
|
2010-11-28 08:10:14 +01:00
|
|
|
log.log(Level.INFO, player.getName() + " teleported to " +
|
|
|
|
playerTarget.getName());
|
|
|
|
player.teleportTo(playerTarget);
|
|
|
|
|
|
|
|
//Otherwise inform the user that the player doesn't exist
|
|
|
|
}
|
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: masstp (/masstp)
|
|
|
|
//Input: Player player: The player using the command
|
|
|
|
// String[] args: Should be empty or is ignored
|
2010-11-30 07:25:16 +01:00
|
|
|
//Output: int: Exit Code
|
2010-11-28 08:10:14 +01:00
|
|
|
//Use: Teleports all players to the user
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
public static int masstp(Player player, String[] args)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
|
|
|
//If the command is enabled
|
|
|
|
if(vminecraftSettings.getInstance().cmdMasstp()) {
|
|
|
|
//Go through all players and move them to the user
|
|
|
|
for (Player p : etc.getServer().getPlayerList()) {
|
|
|
|
if (!p.hasControlOver(player)) {
|
|
|
|
p.teleportTo(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Inform the user that the command has executed successfully
|
|
|
|
player.sendMessage(Colors.Blue+"Summoning successful.");
|
|
|
|
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: tphere (/tphere)
|
|
|
|
//Input: Player player: The player using the command
|
|
|
|
// String[] args: The arguments for the command. Should be a
|
|
|
|
// player name
|
2010-11-30 07:25:16 +01:00
|
|
|
//Output: int: Exit Code
|
2010-11-28 08:10:14 +01:00
|
|
|
//Use: Teleports the user to another player
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
public static int tphere(Player player, String[] args)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
|
|
|
//Check if the command is enabled.
|
|
|
|
if (vminecraftSettings.getInstance().cmdTphere()) {
|
|
|
|
//Make sure a player is specified
|
|
|
|
if (args.length < 1) {
|
|
|
|
player.sendMessage(Colors.Rose + "Correct usage is: /tphere [player]");
|
|
|
|
} else {
|
|
|
|
//Get the player by name
|
|
|
|
Player playerTarget = etc.getServer().matchPlayer(args[0]);
|
2010-11-29 00:43:42 +01:00
|
|
|
|
|
|
|
//If the target doesn't exist
|
|
|
|
if(playerTarget == null)
|
|
|
|
player.sendMessage(Colors.Rose + "Can't find user " + args[0] + ".");
|
2010-11-28 08:10:14 +01:00
|
|
|
//If the player has a higher rank than the user, return error
|
2010-11-29 00:43:42 +01:00
|
|
|
else if (!player.hasControlOver(playerTarget))
|
2010-11-28 08:10:14 +01:00
|
|
|
player.sendMessage(Colors.Red + "That player has higher permissions than you.");
|
|
|
|
//If the user teleports themselves, mock them
|
2010-11-29 00:43:42 +01:00
|
|
|
else if (player.getName().equalsIgnoreCase(args[0]))
|
2010-11-28 08:10:14 +01:00
|
|
|
player.sendMessage(Colors.Rose + "Wow look at that! You teleported yourself to yourself!");
|
|
|
|
//If the target exists, teleport them to the user
|
2010-11-29 00:43:42 +01:00
|
|
|
else {
|
2010-11-28 08:10:14 +01:00
|
|
|
log.log(Level.INFO, player.getName() + " teleported " + player.getName() + " to their self.");
|
|
|
|
playerTarget.teleportTo(player);
|
|
|
|
}
|
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: reload (/reload)
|
|
|
|
//Input: Player player: The player using the command
|
|
|
|
// String[] args: Ignored
|
2010-11-30 07:25:16 +01:00
|
|
|
//Output: int: Exit Code
|
2010-11-28 08:10:14 +01:00
|
|
|
//Use: Reloads the settings for vminecraft
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
public static int reload(Player player, String[] args)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
2010-11-29 02:30:34 +01:00
|
|
|
vminecraftSettings.getInstance().loadSettings();
|
2010-11-30 09:31:04 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: rules (/rules)
|
|
|
|
//Input: Player player: The player using the command
|
|
|
|
// String[] args: Ignored
|
2010-11-30 07:25:16 +01:00
|
|
|
//Output: int: Exit Code
|
2010-11-28 08:10:14 +01:00
|
|
|
//Use: Lists the rules
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
public static int rules(Player player, String[] args)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
|
|
|
//If the rules exist
|
2010-11-30 02:13:16 +01:00
|
|
|
if(vminecraftSettings.getInstance().cmdRules()
|
|
|
|
&& vminecraftSettings.getInstance().getRules().length != 0) {
|
2010-11-28 08:10:14 +01:00
|
|
|
//Display them
|
|
|
|
for (String str : vminecraftSettings.getInstance().getRules()) {
|
2010-11-30 02:13:16 +01:00
|
|
|
if(str.isEmpty())
|
2010-11-29 00:43:42 +01:00
|
|
|
player.sendMessage(Colors.Blue+str);
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: fabulous (/fabulous)
|
|
|
|
//Input: Player player: The player using the command
|
|
|
|
// String[] args: The message to apply the effect to
|
2010-11-30 07:25:16 +01:00
|
|
|
//Output: int: Exit Code
|
2010-11-28 08:10:14 +01:00
|
|
|
//Use: Makes the text rainbow colored
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
public static int fabulous(Player player, String[] args)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
|
|
|
//If the command is enabled
|
|
|
|
if(vminecraftSettings.getInstance().cmdFabulous()) {
|
2010-11-30 04:00:03 +01:00
|
|
|
|
|
|
|
//Format the name
|
|
|
|
String playerName = Colors.White + "<"
|
2010-11-30 09:29:50 +01:00
|
|
|
+ vminecraftChat.getName(player) + Colors.White +"> ";
|
2010-11-28 08:10:14 +01:00
|
|
|
//Make sure a message has been specified
|
2010-11-30 07:25:16 +01:00
|
|
|
if (args.length < 1) {return EXIT_FAIL;}
|
2010-11-30 02:13:16 +01:00
|
|
|
String str = " ";
|
2010-11-30 04:00:03 +01:00
|
|
|
|
2010-11-28 08:10:14 +01:00
|
|
|
//Merge the message again
|
2010-11-30 04:00:03 +01:00
|
|
|
str = etc.combineSplit(0, args, " ");
|
|
|
|
|
2010-11-29 00:43:42 +01:00
|
|
|
//Output for server
|
|
|
|
log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\"");
|
2010-11-30 04:00:03 +01:00
|
|
|
|
|
|
|
//Prepend the player name and cut into lines.
|
2010-11-30 02:13:16 +01:00
|
|
|
String[] message = vminecraftChat.wordWrap(playerName + str);
|
2010-11-29 00:43:42 +01:00
|
|
|
|
2010-11-30 04:00:03 +01:00
|
|
|
//Output the message
|
|
|
|
for(String msg: message)
|
|
|
|
{
|
|
|
|
if (msg.contains(playerName))
|
2010-11-30 06:02:23 +01:00
|
|
|
vminecraftChat.gmsg( playerName
|
|
|
|
+ vminecraftChat.rainbow(
|
2010-11-30 07:32:18 +01:00
|
|
|
msg.substring(playerName.length())));
|
2010-11-30 04:00:03 +01:00
|
|
|
else
|
2010-11-30 07:25:16 +01:00
|
|
|
vminecraftChat.gmsg(vminecraftChat.rainbow(msg));
|
2010-11-30 04:00:03 +01:00
|
|
|
}
|
2010-11-29 00:43:42 +01:00
|
|
|
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: whois (/whois)
|
|
|
|
//Input: Player player: The player using the command
|
|
|
|
// String[] args: The player to find info on
|
2010-11-30 07:25:16 +01:00
|
|
|
//Output: int: Exit Code
|
2010-11-28 08:10:14 +01:00
|
|
|
//Use: Displays information about the player specified
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
public static int whois(Player player, String[] args)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
|
|
|
//If the command is enabled
|
|
|
|
if (vminecraftSettings.getInstance().cmdWhoIs()) {
|
|
|
|
//If a player is specified
|
2010-11-29 00:43:42 +01:00
|
|
|
if (args.length < 1)
|
2010-11-28 08:10:14 +01:00
|
|
|
player.sendMessage(Colors.Rose + "Usage is /whois [player]");
|
2010-11-29 00:43:42 +01:00
|
|
|
else {
|
|
|
|
//Get the player by name
|
|
|
|
Player playerTarget = null;
|
|
|
|
for( Player p : etc.getServer().getPlayerList())
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
2010-11-29 00:43:42 +01:00
|
|
|
if (p.getName().equalsIgnoreCase(args[0]))
|
|
|
|
{
|
|
|
|
playerTarget = p;
|
|
|
|
}
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-29 00:43:42 +01:00
|
|
|
//If the player exists
|
|
|
|
if (playerTarget != null){
|
2010-11-28 08:10:14 +01:00
|
|
|
|
2010-11-29 00:43:42 +01:00
|
|
|
//Displaying the information
|
|
|
|
player.sendMessage(Colors.Blue + "Whois results for " +
|
2010-11-30 09:29:50 +01:00
|
|
|
vminecraftChat.getName(playerTarget));
|
2010-11-29 00:43:42 +01:00
|
|
|
//Group
|
2010-11-29 10:05:53 +01:00
|
|
|
for(String group: playerTarget.getGroups())
|
|
|
|
player.sendMessage(Colors.Blue + "Groups: " + group);
|
2010-11-29 00:43:42 +01:00
|
|
|
//Admin
|
|
|
|
player.sendMessage(Colors.Blue+"Admin: " +
|
2010-11-30 03:51:30 +01:00
|
|
|
String.valueOf(playerTarget.isAdmin()));
|
2010-11-29 00:43:42 +01:00
|
|
|
//IP
|
|
|
|
player.sendMessage(Colors.Blue+"IP: " + playerTarget.getIP());
|
|
|
|
//Restrictions
|
|
|
|
player.sendMessage(Colors.Blue+"Can ignore restrictions: " +
|
|
|
|
String.valueOf(playerTarget.canIgnoreRestrictions()));
|
2010-11-28 08:10:14 +01:00
|
|
|
|
2010-11-29 00:43:42 +01:00
|
|
|
//Give the user an error if the player doesn't exist
|
|
|
|
} else {
|
|
|
|
player.sendMessage(Colors.Rose+"Player not found.");
|
|
|
|
}
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: who (/who)
|
|
|
|
//Input: Player player: The player using the command
|
|
|
|
// String[] args: Ignored
|
2010-11-30 07:25:16 +01:00
|
|
|
//Output: int: Exit Code
|
2010-11-28 08:10:14 +01:00
|
|
|
//Use: Displays the connected players
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
public static int who(Player player, String[] args)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
|
|
|
//If the command is enabled
|
|
|
|
if (vminecraftSettings.getInstance().cmdWho()) {
|
|
|
|
//Loop through all players counting them and adding to the list
|
|
|
|
int count=0;
|
|
|
|
String tempList = "";
|
|
|
|
for( Player p : etc.getServer().getPlayerList())
|
|
|
|
{
|
2010-11-29 00:43:42 +01:00
|
|
|
if(p != null){
|
|
|
|
if(count == 0)
|
2010-11-30 09:29:50 +01:00
|
|
|
tempList += vminecraftChat.getName(p);
|
2010-11-29 00:43:42 +01:00
|
|
|
else
|
2010-11-30 09:29:50 +01:00
|
|
|
tempList += Colors.White + ", " + vminecraftChat.getName(p);
|
2010-11-29 00:43:42 +01:00
|
|
|
count++;
|
|
|
|
}
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
//Get the max players from the config
|
|
|
|
PropertiesFile server = new PropertiesFile("server.properties");
|
|
|
|
try {
|
|
|
|
server.load();
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
int maxPlayers = server.getInt("max-players");
|
|
|
|
//Output the player list
|
2010-11-29 00:43:42 +01:00
|
|
|
String[] tempOut = vminecraftChat.wordWrap(Colors.Rose + "Player List ("
|
|
|
|
+ count + "/" + maxPlayers +"): " + tempList);
|
|
|
|
for(String msg: tempOut)
|
|
|
|
player.sendMessage( msg );
|
2010-11-28 08:10:14 +01:00
|
|
|
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: say (/say)
|
|
|
|
//Input: Player player: The player using the command
|
|
|
|
// String[] args: The message to apply the effect to
|
2010-11-30 07:25:16 +01:00
|
|
|
//Output: int: Exit Code
|
2010-11-28 08:10:14 +01:00
|
|
|
//Use: Announces the message to all players
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
public static int say(Player player, String[] args)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
|
|
|
//If the command is enabled
|
|
|
|
if (vminecraftSettings.getInstance().cmdSay()) {
|
|
|
|
//Make sure a message is supplied or output an error
|
|
|
|
if (args.length < 1) {
|
|
|
|
player.sendMessage(Colors.Rose + "Usage is /say [message]");
|
|
|
|
}
|
|
|
|
//Display the message globally
|
|
|
|
vminecraftChat.gmsg(Colors.Yellow + etc.combineSplit(0, args, " "));
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: slay (/slay)
|
|
|
|
//Input: Player player: The player using the command
|
|
|
|
// String[] args: The target for the command
|
2010-11-30 07:25:16 +01:00
|
|
|
//Output: int: Exit Code
|
2010-11-28 08:10:14 +01:00
|
|
|
//Use: Kill the target player
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
public static int slay(Player player, String[] args)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
|
|
|
//Check if the command is enabled
|
|
|
|
if(vminecraftSettings.getInstance().cmdEzModo()) {
|
|
|
|
//Get the player by name
|
|
|
|
Player playerTarget = etc.getServer().matchPlayer(args[0]);
|
2010-11-29 00:43:42 +01:00
|
|
|
//If the player doesn't exist don't run
|
|
|
|
if(playerTarget == null)
|
2010-11-30 07:39:32 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
//If the player isn't invulnerable kill them
|
2010-11-29 00:43:42 +01:00
|
|
|
if (!vminecraftSettings.getInstance().isEzModo(playerTarget.getName())) {
|
2010-11-28 08:10:14 +01:00
|
|
|
playerTarget.setHealth(0);
|
2010-11-30 09:29:50 +01:00
|
|
|
vminecraftChat.gmsg(vminecraftChat.getName(player)
|
2010-11-30 07:39:32 +01:00
|
|
|
+ Colors.LightBlue + " has slain "
|
2010-11-30 09:29:50 +01:00
|
|
|
+ vminecraftChat.getName(playerTarget));
|
2010-11-28 08:10:14 +01:00
|
|
|
//Otherwise output error to the user
|
|
|
|
} else {
|
|
|
|
player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha");
|
|
|
|
}
|
2010-11-30 07:39:32 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 07:39:32 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: invuln (/ezmodo)
|
|
|
|
//Input: Player player: The player using the command
|
|
|
|
// String[] args: The target for the command
|
2010-11-30 07:25:16 +01:00
|
|
|
//Output: int: Exit Code
|
2010-11-28 08:10:14 +01:00
|
|
|
//Use: Kill the target player
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
public static int invuln(Player player, String[] args)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
|
|
|
//If the command is enabled
|
|
|
|
if (vminecraftSettings.getInstance().cmdEzModo()) {
|
|
|
|
//If the player is already invulnerable, turn ezmodo off.
|
|
|
|
if (vminecraftSettings.getInstance().isEzModo(player.getName())) {
|
|
|
|
player.sendMessage(Colors.Red + "ezmodo = off");
|
|
|
|
vminecraftSettings.getInstance().removeEzModo(player.getName());
|
|
|
|
//Otherwise make them invulnerable
|
|
|
|
} else {
|
|
|
|
player.sendMessage(Colors.LightBlue + "eh- maji? ezmodo!?");
|
|
|
|
player.sendMessage(Colors.Rose + "kimo-i");
|
|
|
|
player.sendMessage(Colors.LightBlue + "Easy Mode ga yurusareru no wa shougakusei made dayo ne");
|
|
|
|
player.sendMessage(Colors.Red + "**Laughter**");
|
|
|
|
vminecraftSettings.getInstance().addEzModo(player.getName());
|
|
|
|
player.setHealth(vminecraftSettings.getInstance().ezModoHealth());
|
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: ezlist (/ezlist)
|
|
|
|
//Input: Player player: The player using the command
|
|
|
|
// String[] args: Ignored
|
2010-11-30 07:25:16 +01:00
|
|
|
//Output: int: Exit Code
|
2010-11-28 08:10:14 +01:00
|
|
|
//Use: List all invulnerable players
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
public static int ezlist(Player player, String[] args)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
|
|
|
//If the feature is enabled list the players
|
|
|
|
if(vminecraftSettings.getInstance().cmdEzModo()) {
|
|
|
|
player.sendMessage("Ezmodo: " + vminecraftSettings.getInstance().ezModoList());
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
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;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Disable using /modify to add commands (need to make a boolean settings for this)
|
|
|
|
|
|
|
|
//ezlist
|
|
|
|
//ezmodo
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
//Promote
|
|
|
|
if (vminecraftSettings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote")) {
|
|
|
|
if(split.length != 2)
|
|
|
|
{
|
|
|
|
player.sendMessage(Colors.Rose + "Usage is /promote [Player]");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Player playerTarget = null;
|
|
|
|
if(split.length==2){
|
|
|
|
for( Player p : etc.getServer().getPlayerList())
|
|
|
|
{
|
|
|
|
if (p.getName().equalsIgnoreCase(split[1]))
|
|
|
|
{
|
|
|
|
playerTarget = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( playerTarget!=null)
|
|
|
|
{
|
|
|
|
String playerTargetGroup[] = playerTarget.getGroups();
|
|
|
|
String playerGroup[] = player.getGroups();
|
|
|
|
player.sendMessage("Debug data:");
|
|
|
|
player.sendMessage("PlayerTarget: "+playerTargetGroup[0]);
|
|
|
|
player.sendMessage("Player: "+playerGroup[0]);
|
|
|
|
if(playerTargetGroup[0].equals("admins"))
|
|
|
|
{
|
|
|
|
player.sendMessage(Colors.Rose + "You can not promote " + split[1] + " any higher.");
|
|
|
|
}
|
|
|
|
if(playerTargetGroup[0].equals("mods") && (playerGroup[0].equals("owner")))
|
|
|
|
{
|
|
|
|
playerTarget.setGroups(ranks.Admins);
|
|
|
|
etc.getInstance().getDataSource().modifyPlayer(playerTarget);
|
|
|
|
String message = Colors.Yellow + split[1] + " was promoted to" + Colors.Rose + " Admin";
|
|
|
|
other.gmsg(message);
|
|
|
|
}
|
|
|
|
else if (playerTargetGroup[0].equals("trusted") && (playerGroup[0].equals("admins") || playerGroup[0].equals("owner")))
|
|
|
|
{
|
|
|
|
playerTarget.setGroups(ranks.Mods);
|
|
|
|
playerTargetGroup[0]="Mods";
|
|
|
|
etc.getInstance().getDataSource().modifyPlayer(playerTarget);
|
|
|
|
String message = Colors.Yellow + split[1] + " was promoted to" + Colors.DarkPurple + " Mod";
|
|
|
|
other.gmsg(message);
|
|
|
|
}
|
|
|
|
else if (playerTargetGroup[0].equals("default") && (playerGroup[0].equals("mods") || playerGroup[0].equals("admins") || player.isInGroup("owner")))
|
|
|
|
{
|
|
|
|
playerTarget.setGroups(ranks.Trusted);
|
|
|
|
etc.getInstance().getDataSource().modifyPlayer(playerTarget);
|
|
|
|
String message = Colors.Yellow + split[1] + " was promoted to" + Colors.LightGreen + " Trusted";
|
|
|
|
other.gmsg(message);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
player.sendMessage(Colors.Rose + "Player not found");
|
|
|
|
}
|
|
|
|
log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Demote
|
|
|
|
if (vminecraftSettings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote"))
|
|
|
|
{
|
|
|
|
if(split.length != 2)
|
|
|
|
{
|
|
|
|
player.sendMessage(Colors.Rose + "Usage is /demote [Player]");
|
|
|
|
}
|
|
|
|
|
|
|
|
Player playerTarget = null;
|
|
|
|
|
|
|
|
for( Player p : etc.getServer().getPlayerList())
|
|
|
|
{
|
|
|
|
if (p.getName().equalsIgnoreCase(split[1]))
|
|
|
|
{
|
|
|
|
playerTarget = p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( playerTarget!=null)
|
|
|
|
{
|
|
|
|
if(playerTarget.isInGroup("admins") && (player.isInGroup("superadmins")))
|
|
|
|
{
|
|
|
|
playerTarget.setGroups(ranks.Mods);
|
|
|
|
etc.getInstance().getDataSource().modifyPlayer(playerTarget);
|
|
|
|
String message = Colors.Yellow + split[1] + " was demoted to" + Colors.DarkPurple + " Mod";
|
|
|
|
other.gmsg(message);
|
|
|
|
}
|
|
|
|
if(playerTarget.isInGroup("mods") && (player.isInGroup("admins") || player.isInGroup("superadmins")))
|
|
|
|
{
|
|
|
|
playerTarget.setGroups(ranks.Trusted);
|
|
|
|
etc.getInstance().getDataSource().modifyPlayer(playerTarget);
|
|
|
|
String message = Colors.Yellow + split[1] + " was demoted to" + Colors.LightGreen + " Trusted";
|
|
|
|
other.gmsg(message);
|
|
|
|
}
|
|
|
|
else if (playerTarget.isInGroup("trusted") && (player.isInGroup("mods") || player.isInGroup("superadmins") || player.isInGroup("admins")))
|
|
|
|
{
|
|
|
|
playerTarget.setGroups(ranks.Def);
|
|
|
|
etc.getInstance().getDataSource().modifyPlayer(playerTarget);
|
|
|
|
String message = Colors.Yellow + split[1] + " was demoted to" + Colors.White + " Default";
|
|
|
|
other.gmsg(message);
|
|
|
|
}
|
|
|
|
else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins")))
|
|
|
|
{
|
|
|
|
player.sendMessage(Colors.Rose + "You can not demote " + split[1] + " any lower.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
player.sendMessage(Colors.Rose + "Player not found");
|
|
|
|
}
|
|
|
|
log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" ");
|
|
|
|
return true;
|
|
|
|
}*/
|
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Class: commandList
|
|
|
|
//Use: The list of commands that will be checked for
|
|
|
|
//Author: cerevisiae
|
|
|
|
//=====================================================================
|
|
|
|
class commandList {
|
|
|
|
command[] commands;
|
|
|
|
protected static final Logger log = Logger.getLogger("Minecraft");
|
2010-11-30 07:25:16 +01:00
|
|
|
static final int EXIT_FAIL = 0,
|
|
|
|
EXIT_SUCCESS = 1,
|
|
|
|
EXIT_CONTINUE = 2;
|
2010-11-28 08:10:14 +01:00
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: commandList
|
|
|
|
//Input: None
|
|
|
|
//Output: None
|
|
|
|
//Use: Initialize the array of commands
|
|
|
|
//=====================================================================
|
|
|
|
public commandList(){
|
|
|
|
commands = new command[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: register
|
|
|
|
//Input: String name: The name of the command
|
|
|
|
// String func: The function to be called
|
|
|
|
//Output: boolean: Whether the command was input successfully or not
|
|
|
|
//Use: Registers a command to the command list for checking later
|
|
|
|
//=====================================================================
|
|
|
|
public boolean register(String name, String func){
|
|
|
|
|
|
|
|
//If the command list isn't empty
|
|
|
|
if(commands.length > 0)
|
|
|
|
{
|
|
|
|
//Check to make sure the command doesn't already exist
|
|
|
|
for(int i = 0; i < commands.length; i++)
|
|
|
|
if(commands[i].getName().equalsIgnoreCase(name))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
//Create a new temp array
|
|
|
|
command[] temp = new command[commands.length + 1];
|
|
|
|
//Copy the old command list over
|
|
|
|
System.arraycopy(commands, 0, temp, 0, commands.length);
|
|
|
|
//Set commands to equal the new array
|
|
|
|
commands = temp;
|
|
|
|
} else {
|
|
|
|
commands = new command[1];
|
|
|
|
}
|
|
|
|
|
|
|
|
//Add the new function to the list
|
|
|
|
commands[commands.length - 1] = new command(name, func);
|
|
|
|
|
|
|
|
//exit successfully
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: register
|
|
|
|
//Input: String name: The name of the command
|
|
|
|
// String func: The function to be called
|
|
|
|
// String info: The information for the command to put in help
|
|
|
|
//Output: boolean: Whether the command was input successfully or not
|
|
|
|
//Use: Registers a command to the command list for checking later
|
|
|
|
//=====================================================================
|
|
|
|
public boolean register(String name, String func, String info){
|
|
|
|
//Add to the /help list
|
|
|
|
etc.getInstance().addCommand(name, info);
|
|
|
|
|
|
|
|
//Finish registering
|
|
|
|
return register(name, func);
|
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: register
|
|
|
|
//Input: String name: The name of the command
|
|
|
|
// String func: The function to be called
|
|
|
|
//Output: boolean: Whether the command was input successfully or not
|
|
|
|
//Use: Registers a command to the command list for checking later
|
|
|
|
//=====================================================================
|
|
|
|
public boolean registerAlias(String name, String com, String[] args){
|
|
|
|
|
|
|
|
//If the command list isn't empty
|
|
|
|
if(commands.length > 0)
|
|
|
|
{
|
2010-11-29 02:30:34 +01:00
|
|
|
//Check to make sure the command doesn't already exist
|
|
|
|
for(int i = 0; i < commands.length; i++)
|
|
|
|
if(commands[i].getName().equalsIgnoreCase(name))
|
|
|
|
return false;
|
|
|
|
|
2010-11-28 08:10:14 +01:00
|
|
|
//Create a new temp array
|
2010-11-29 02:30:34 +01:00
|
|
|
command[] temp = new command[commands.length + 1];
|
2010-11-28 08:10:14 +01:00
|
|
|
//Copy the old command list over
|
|
|
|
System.arraycopy(commands, 0, temp, 0, commands.length);
|
|
|
|
//Set commands to equal the new array
|
|
|
|
commands = temp;
|
2010-11-29 02:30:34 +01:00
|
|
|
} else {
|
|
|
|
commands = new command[1];
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
2010-11-29 02:30:34 +01:00
|
|
|
|
|
|
|
//Add the new function to the list
|
|
|
|
commands[commands.length - 1] = new commandRef(name, com, args);
|
2010-11-28 08:10:14 +01:00
|
|
|
|
2010-11-29 02:30:34 +01:00
|
|
|
//exit successfully
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: register
|
|
|
|
//Input: String name: The name of the command
|
|
|
|
// String func: The function to be called
|
|
|
|
//Output: boolean: Whether the command was input successfully or not
|
|
|
|
//Use: Registers a command to the command list for checking later
|
|
|
|
//=====================================================================
|
|
|
|
public boolean registerAlias(String name, String com){
|
2010-11-28 08:10:14 +01:00
|
|
|
|
2010-11-29 02:30:34 +01:00
|
|
|
//If the command list isn't empty
|
|
|
|
if(commands.length > 0)
|
|
|
|
{
|
|
|
|
//Check to make sure the command doesn't already exist
|
|
|
|
for(int i = 0; i < commands.length; i++)
|
|
|
|
if(commands[i].getName().equalsIgnoreCase(name))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
//Create a new temp array
|
|
|
|
command[] temp = new command[commands.length + 1];
|
|
|
|
//Copy the old command list over
|
|
|
|
System.arraycopy(commands, 0, temp, 0, commands.length);
|
|
|
|
//Set commands to equal the new array
|
|
|
|
commands = temp;
|
|
|
|
} else {
|
|
|
|
commands = new command[1];
|
|
|
|
}
|
2010-11-28 08:10:14 +01:00
|
|
|
|
|
|
|
//Add the new function to the list
|
2010-11-29 02:30:34 +01:00
|
|
|
commands[commands.length - 1] = new commandRef(name, com);
|
2010-11-28 08:10:14 +01:00
|
|
|
|
|
|
|
//exit successfully
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: call
|
|
|
|
//Input: String name: The name of the command to be run
|
|
|
|
//Output: boolean: If the command was called successfully
|
|
|
|
//Use: Attempts to call a command
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
public int call(String name, Player player, String[] arg){
|
2010-11-28 08:10:14 +01:00
|
|
|
//Make sure the user has access to the command
|
|
|
|
if(!player.canUseCommand(name)) {
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
//Search for the command
|
2010-11-29 02:30:34 +01:00
|
|
|
for(command cmd : commands)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
|
|
|
//When found
|
2010-11-29 02:30:34 +01:00
|
|
|
if(cmd.getName().equalsIgnoreCase(name))
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
//Call the command and return results
|
2010-11-29 02:30:34 +01:00
|
|
|
return cmd.call(player, arg);
|
2010-11-28 08:10:14 +01:00
|
|
|
} catch (SecurityException e) {
|
|
|
|
log.log(Level.SEVERE, "Exception while running command", e);
|
|
|
|
} catch (IllegalArgumentException e) {
|
2010-11-29 02:30:34 +01:00
|
|
|
log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e);
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Something went wrong
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_FAIL;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Class: command
|
|
|
|
//Use: The specific command
|
|
|
|
//Author: cerevisiae
|
|
|
|
//=====================================================================
|
|
|
|
private class command{
|
|
|
|
private String commandName;
|
|
|
|
private String function;
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: command
|
|
|
|
//Input: None
|
|
|
|
//Output: None
|
|
|
|
//Use: Initialize the command
|
|
|
|
//=====================================================================
|
|
|
|
public command(String name, String func){
|
|
|
|
commandName = name;
|
|
|
|
function = func;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: getName
|
|
|
|
//Input: None
|
|
|
|
//Output: String: The command name
|
|
|
|
//Use: Returns the command name
|
|
|
|
//=====================================================================
|
2010-11-29 02:30:34 +01:00
|
|
|
public String getName(){return commandName;}
|
2010-11-28 08:10:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: call
|
|
|
|
//Input: String[] arg: The arguments for the command
|
|
|
|
//Output: boolean: If the command was called successfully
|
|
|
|
//Use: Attempts to call the command
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
int call(Player player, String[] arg)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
2010-11-29 02:30:34 +01:00
|
|
|
|
|
|
|
Method m;
|
|
|
|
try {
|
|
|
|
m = vminecraftCommands.class.getMethod(function, Player.class, String[].class);
|
|
|
|
m.setAccessible(true);
|
2010-11-30 07:25:16 +01:00
|
|
|
return (Integer) m.invoke(null, player, arg);
|
2010-11-29 02:30:34 +01:00
|
|
|
} catch (SecurityException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalArgumentException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
2010-11-30 07:25:16 +01:00
|
|
|
return 1;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Class: commandRef
|
|
|
|
//Use: A command referencing another command
|
|
|
|
//Author: cerevisiae
|
|
|
|
//=====================================================================
|
|
|
|
private class commandRef extends command{
|
|
|
|
private String reference;
|
|
|
|
private String[] args;
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: command
|
2010-11-29 02:30:34 +01:00
|
|
|
//Input: String name: The command name
|
|
|
|
// String com: The command to run
|
|
|
|
// String[] arg: the arguments to apply
|
2010-11-28 08:10:14 +01:00
|
|
|
//Output: None
|
|
|
|
//Use: Initialize the command
|
|
|
|
//=====================================================================
|
|
|
|
public commandRef(String name, String com, String[] arg){
|
|
|
|
super(name, "");
|
|
|
|
reference = com;
|
|
|
|
args = arg;
|
|
|
|
}
|
|
|
|
|
|
|
|
//=====================================================================
|
2010-11-29 02:30:34 +01:00
|
|
|
//Function: command
|
|
|
|
//Input: String name: The command name
|
|
|
|
// String com: The command to run
|
|
|
|
//Output: None
|
|
|
|
//Use: Initialize the command
|
2010-11-28 08:10:14 +01:00
|
|
|
//=====================================================================
|
2010-11-29 02:30:34 +01:00
|
|
|
public commandRef(String name, String com){
|
|
|
|
super(name, "");
|
|
|
|
reference = com;
|
|
|
|
args = null;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//=====================================================================
|
|
|
|
//Function: call
|
|
|
|
//Input: String[] arg: The arguments for the command
|
|
|
|
//Output: boolean: If the command was called successfully
|
|
|
|
//Use: Attempts to call the command
|
|
|
|
//=====================================================================
|
2010-11-30 07:25:16 +01:00
|
|
|
int call(Player player, String[] arg)
|
2010-11-28 08:10:14 +01:00
|
|
|
{
|
2010-11-29 04:04:59 +01:00
|
|
|
if(args != null) {
|
|
|
|
String[] temp = new String[args.length];
|
|
|
|
System.arraycopy(args, 0, temp, 0, args.length);
|
2010-11-29 02:30:34 +01:00
|
|
|
//Insert the arguments into the pre-set arguments
|
2010-11-29 04:04:59 +01:00
|
|
|
int lastSet = 0,
|
|
|
|
argCount = 0;
|
|
|
|
for(String argument : temp)
|
|
|
|
{
|
|
|
|
if(argument.startsWith("%"))
|
|
|
|
{
|
|
|
|
int argNum = Integer.parseInt(argument.substring(1));
|
|
|
|
if( argNum < arg.length )
|
|
|
|
{
|
|
|
|
temp[lastSet] = arg[argNum];
|
|
|
|
argCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
lastSet++;
|
|
|
|
}
|
2010-11-29 02:30:34 +01:00
|
|
|
//Append the rest of the arguments to the argument array
|
2010-11-29 04:04:59 +01:00
|
|
|
if(lastSet < temp.length + arg.length - argCount)
|
2010-11-29 02:30:34 +01:00
|
|
|
{
|
2010-11-29 04:04:59 +01:00
|
|
|
String[] temp2 = new String[temp.length + arg.length - argCount];
|
2010-11-29 02:30:34 +01:00
|
|
|
System.arraycopy(temp, 0, temp2, 0, temp.length);
|
2010-11-29 04:04:59 +01:00
|
|
|
System.arraycopy(arg, argCount, temp2,
|
|
|
|
temp.length, arg.length - argCount);
|
|
|
|
temp = temp2;
|
2010-11-29 02:30:34 +01:00
|
|
|
}
|
2010-11-29 04:04:59 +01:00
|
|
|
|
2010-11-28 08:10:14 +01:00
|
|
|
//Call the referenced command
|
2010-11-29 02:30:34 +01:00
|
|
|
player.command(reference + " " + etc.combineSplit(0, temp, " "));
|
2010-11-29 04:04:59 +01:00
|
|
|
} else
|
2010-11-29 02:30:34 +01:00
|
|
|
player.command(reference);
|
2010-11-30 07:25:16 +01:00
|
|
|
return EXIT_SUCCESS;
|
2010-11-28 08:10:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|