From 82e32d73953096bbfe890329b85a371ed75e1b75 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 5 Jan 2011 08:20:42 -0800 Subject: [PATCH] Changed file names to be shorter --- vChat.java | 685 ++++++++++++++ vCom.java | 2303 +++++++++++++++++++++++++++++++++++++++++++++++ vConfig.java | 300 ++++++ vListener.java | 187 ++++ vMinecraft.java | 8 +- vUsers.java | 633 +++++++++++++ vmc.java | 38 + 7 files changed, 4150 insertions(+), 4 deletions(-) create mode 100644 vChat.java create mode 100644 vCom.java create mode 100644 vConfig.java create mode 100644 vListener.java create mode 100644 vUsers.java create mode 100644 vmc.java diff --git a/vChat.java b/vChat.java new file mode 100644 index 000000000..4532e4087 --- /dev/null +++ b/vChat.java @@ -0,0 +1,685 @@ +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; + +//===================================================================== +//Class: vMinecraftChat +//Use: Encapsulates all chat commands added by this mod +//Author: nossr50, TrapAlice, cerevisiae +//===================================================================== +public class vChat { + protected static final Logger log = Logger.getLogger("Minecraft"); + protected static final int lineLength = 312; + //The array of colors to use + protected static final String[] rainbow = new String[] { + Colors.Red, + Colors.Rose, + Colors.Gold, + Colors.Yellow, + Colors.LightGreen, + Colors.Green, + Colors.LightBlue, + Colors.Blue, + Colors.Navy, + Colors.DarkPurple, + Colors.Purple, + Colors.LightPurple}; + protected static final String[] xmas = new String[] { + Colors.Red, + Colors.Red, + Colors.White, + Colors.White, + Colors.Green, + Colors.Green, + }; + + //===================================================================== + //Function: gmsg + //Input: Player sender: The player sending the message + // String msg: The message to be broadcast to all players + //Output: None + //Use: Outputs a message to everybody + //===================================================================== + public static void gmsg(Player sender, String msg){ + if(sender != null && sender.isMuted()) + sender.sendMessage(Colors.Red + "You have been muted."); + + for (Player receiver : etc.getServer().getPlayerList()) { + + if (receiver == null) return; + + if(vUsers.getProfile(receiver) == null) return; + + //Check if the person has the sender ignored + if(sender != null) + if(vUsers.getProfile(receiver).isIgnored(sender)) + return; + + String[] message = applyColors(wordWrap(msg)); + for(String out : message) + receiver.sendMessage(out); + } + } + + //===================================================================== + //Function: gmsg + //Input: String msg: The message to be broadcast to all players + //Output: None + //Use: Outputs a message to everybody + //===================================================================== + public static void gmsg(String msg){gmsg(null, msg);} + + //===================================================================== + //Function: sendMessage + //Input: Player sender: The player sending the message + // Player receiver: The player receiving the message + // String msg: The message to be broadcast to all players + //Output: None + //Use: Outputs a message to everybody + //===================================================================== + public static void sendMessage(Player sender, Player receiver, String msg){ + if(sender != null && sender.isMuted()) + sender.sendMessage(Colors.Red + "You have been muted."); + + //Check if the receiver has the sender ignored + if(vUsers.getProfile(receiver) == null) + return; + + if(sender != null) + if(vUsers.getProfile(receiver).isIgnored(sender)) + { + sendMessage(sender, sender, Colors.Rose + receiver.getName() + + " has you on their ignore list."); + return; + } + + String[] message = applyColors(wordWrap(msg)); + for(String out : message) + receiver.sendMessage(out); + //Tell them if they are + } + + //===================================================================== + //Function: sendMessage + //Input: Player receiver: The player receiving the message + // String msg: The message to be broadcast to all players + //Output: None + //Use: Outputs a message to everybody + //===================================================================== + public static void sendMessage(Player receiver, String msg) + { + sendMessage(null, receiver, msg); + } + + //===================================================================== + //Function: wordWrap + //Input: String msg: The message to be wrapped + //Output: String[]: The array of substrings + //Use: Cuts the message apart into whole words short enough to fit + // on one line + //===================================================================== + public static String[] wordWrap(String msg){ + //Split each word apart + ArrayList split = new ArrayList(); + for(String in : msg.split(" ")) + split.add(in); + + //Create an arraylist for the output + ArrayList out = new ArrayList(); + //While i is less than the length of the array of words + while(!split.isEmpty()){ + int len = 0; + + //Create an arraylist to hold individual words + ArrayList words = new ArrayList(); + + //Loop through the words finding their length and increasing + //j, the end point for the sub string + while(!split.isEmpty() && split.get(0) != null && len <= lineLength) + { + int wordLength = msgLength(split.get(0)) + 4; + + //If a word is too long for a line + if(wordLength > lineLength) + { + String[] tempArray = wordCut(len, split.remove(0)); + words.add(tempArray[0]); + split.add(tempArray[1]); + } + + //If the word is not too long to fit + len += wordLength; + if( len < lineLength) + words.add(split.remove(0)); + } + //Merge them and add them to the output array. + out.add( etc.combineSplit(0, + words.toArray(new String[words.size()]), " ") + " " ); + } + //Convert to an array and return + return out.toArray(new String[out.size()]); + } + + //===================================================================== + //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. + //===================================================================== + public 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 0) + length += len; + else + x++; + x++; + } + if(x > str.length()) + x = str.length(); + //Add the substring to the output after cutting it + output[0] = str.substring(0, x); + //Add the last of the string to the output. + output[1] = str.substring(x); + return output; + } + + //===================================================================== + //Function: charLength + //Input: char x: The character to find the length of. + //Output: int: The length of the character + //Use: Finds the visual length of the character on the screen. + //===================================================================== + private static int charLength(char x) + { + if("i.:,;|!".indexOf(x) != -1) + return 2; + else if("l'".indexOf(x) != -1) + return 3; + else if("tI[]".indexOf(x) != -1) + return 4; + else if("fk{}<>\"*()".indexOf(x) != -1) + return 5; + else if("abcdeghjmnopqrsuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ1234567890\\/#?$%-=_+&^".indexOf(x) != -1) + return 6; + else if("@~".indexOf(x) != -1) + return 7; + else if(x==' ') + return 4; + else + return -1; + } + + //===================================================================== + //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 = ""; + int counter=0; + //Loop through the message applying the colors + for(int x=0; x " + message); + return true; + } + return false; + } + public static boolean partyChat(Player player, String message){ + if(vUsers.getProfile(player).inParty()){ + String partychat = Colors.Green + "(" + getName(player) + Colors.Green + ") "; + for (Player p: etc.getServer().getPlayerList()){ + if (p != null){ + if (vUsers.getProfile(p).inParty() && (vUsers.getProfile(p).getParty().equals(vUsers.getProfile(player).getParty()))){ + sendMessage(player, p, partychat + Colors.Green + message); + } + } + } + return true; + } + return false; + } + + //===================================================================== + //Function: quote + //Input: Player player: The player talking + // String message: The message to apply the effect to + //Output: boolean: If this feature is enabled + //Use: Displays a message as a quote + //===================================================================== + public static boolean quote(Player player, String message) + { + //Format the name + String playerName = Colors.White + "<" + getName(player) + + Colors.White + "> "; + if(vConfig.getInstance().greentext()) { + //Log the chat + log.log(Level.INFO, "<"+player.getName()+"> " + message); + + //Output the message + gmsg(player, playerName + Colors.LightGreen + message); + return true; + } + return false; + } + + //===================================================================== + //Function: rage + //Input: Player player: The player talking + // String message: The message to apply the effect to + //Output: boolean: If this feature is enabled + //Use: Displays a message in red + //===================================================================== + public static boolean rage(Player player, String message) + { + //Format the name + String playerName = Colors.White + "<" + + getName(player) + Colors.White +"> "; + if (vConfig.getInstance().FFF()) { + log.log(Level.INFO, "<"+player.getName()+"> "+message); + + //Output the message + gmsg(player, playerName + Colors.Red + message); + return true; + } + return false; + } + + //===================================================================== + //Function: quakeColors + //Input: Player player: The player talking + // String message: The message to apply the effect to + //Output: boolean: If this feature is enabled + //Use: Displays a message in red + //===================================================================== + public static boolean quakeColors(Player player, String message) + { + //Format the name + String playerName = Colors.White + "<" + + getName(player) + Colors.White +"> "; + if(vConfig.getInstance().quakeColors()) { + + String color = vUsers.getProfile(player).getColor(); + //Log the chat + log.log(Level.INFO, "<"+player.getName()+"> " + message); + + //Output the message + gmsg(player, playerName + color + message); + + //Loop through the string finding the color codes and inserting them + return true; + } + return false; + } + + //===================================================================== + //Function: emote + //Input: Player player: The player talking + // String message: The message to apply the effect to + //Output: boolean: If this feature is enabled + //Use: /me but with our custom colors applied + //===================================================================== + public static boolean emote(Player player, String message) + { + gmsg(player, "* " + getName(player) + " " + Colors.White + message); + return true; + } + + + //===================================================================== + //Function: applyColors + //Input: String[] message: The lines to be colored + //Output: String[]: The lines, but colorful + //Use: Colors each line + //===================================================================== + public static String[] applyColors(String[] message) + { + if(message != null && message[0] != null && !message[0].isEmpty()){ + //The color to start the line with + String recentColor = Colors.White; + + //Go through each line + int counter = 0; + int i = 0; + boolean taste = false; + boolean xmasparty = false; + + for(String msg: message) + { + //Start the line with the most recent color + String temp = ""; + if(!recentColor.equals("^r") && recentColor != null) + temp += recentColor; + + //Loop through looking for a color code + for(int x = 0; x< msg.length(); x++) + { + //If the char is a ^ or � + if(taste || msg.charAt(x) == '^' + || msg.charAt(x) == Colors.Red.charAt(0)) + { + if(x != msg.length() - 1) + { + //If the following character is a color code + if(vChat.colorChange(msg.charAt(x+1)) != null) + { + //Set the most recent color to the new color + recentColor = vChat.colorChange(msg.charAt(x+1)); + + //If the color specified is rainbow + if(taste || recentColor.equals("^r")) + { + //Skip the quake code for rainbow + if(recentColor.equals("^r")) + { + x += 2; + } + + //Taste keeps it going with rainbow if there + //are more lines + taste = true; + //Loop through the message applying the colors + while(x < msg.length() && msg.charAt(x) != '^' + && msg.charAt(x) != Colors.Red.charAt(0)) + { + temp += rainbow[i] + msg.charAt(x); + + if(msg.charAt(x) != ' ') i++; + if(i == rainbow.length) i = 0; + x++; + } + + //If it reached another color instead of the end + if(x < msg.length() && msg.charAt(x) == '^' + || x < msg.length() + && msg.charAt(x) == Colors.Red.charAt(0) ) + { + taste = false; + i = 0; + x--; + } + } + if(xmasparty || recentColor.equals("^x")) + { + //Skip the quake code for xmas + if(recentColor.equals("^x")) + { + x += 2; + } + + //Taste keeps it going with xmas if there + //are more lines + xmasparty = true; + //Loop through the message applying the colors + while(x < msg.length() && msg.charAt(x) != '^' + && msg.charAt(x) != Colors.Red.charAt(0)) + { + temp += xmas[i] + msg.charAt(x); + + if(msg.charAt(x) != ' ') i++; + if(i == xmas.length) i = 0; + x++; + } + + //If it reached another color instead of the end + if(x < msg.length() && msg.charAt(x) == '^' + || x < msg.length() + && msg.charAt(x) == Colors.Red.charAt(0) ) + { + xmasparty = false; + i = 0; + x--; + } + } + else + + { + //Add the color + temp += recentColor; + //Skip these chars + x++; + } + + //Otherwise ignore it. + } else { + temp += msg.charAt(x); + } + //Insert the character + } else { + temp += msg.charAt(x); + } + } else { + temp += msg.charAt(x); + } + } + //Replace the message with the colorful message + message[counter] = temp; + counter++; + } + } + return message; + } +} \ No newline at end of file diff --git a/vCom.java b/vCom.java new file mode 100644 index 000000000..edb336fc4 --- /dev/null +++ b/vCom.java @@ -0,0 +1,2303 @@ +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.HashMap; +import java.util.List; + +//===================================================================== +//Class: vMinecraftCommands +//Use: Encapsulates all commands added by this mod +//Author: nos, trapalice, cerevisiae +//===================================================================== + +//===================================================================== +//Class: commandList +//Use: The list of commands that will be checked for +//Author: cerevisiae +//===================================================================== +public class vCom{ +private static HashMap hidden = new HashMap(); + + //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(); + + //===================================================================== + //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. + + //register: Registers a function for use with a command + //String: The command that will be used + //String: The name of the function that will be called when + // the command is used + //String(Optional): The help menu description + + //Administrative + cl.register("/prefix", "prefix", "Set your name color and prefix"); + cl.register("/rprefix", "removeTag", "Remove your name color and prefix"); + cl.register("/nick", "nickName", "Set your display name"); + cl.register("/rnick", "removeNick", "Reset your display name to your account name"); + cl.register("/suffix", "suffix", "Set your suffix"); + cl.register("/rsuffix", "removeSuffix", "Remove your suffix"); + cl.register("/vminecraft", "vminecrafthelp"); + cl.register("/reload", "reload"); + cl.register("/whois", "whois", "/whois [user]"); + cl.register("/say", "say"); + cl.register("/a", "adminChatToggle", "Toggle admin chat for every message"); + cl.register("/rules", "rules", "Displays the rules"); + cl.register("/who", "who"); + cl.register("/promote", "promote", "Promote a player one rank"); + cl.register("/demote", "demote", "Demote a player one rank"); + cl.register("/hide", "hide", "Turn invisible"); + cl.register("/silent", "silent", "Turn off global messages for yourself"); + + //Party + cl.register("/party", "party"); + cl.register("/pquit", "partyquit"); + cl.register("/p", "partychat"); + + //Movement + cl.register("/freeze", "freeze"); + cl.register("/tp", "teleport"); + cl.register("/tphere", "tphere"); + cl.register("/tpback", "tpback"); + cl.register("/masstp", "masstp", "Teleports those with lower permissions to you"); + cl.register("/myspawn", "myspawn"); + + //Health + 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("/slay", "slay", "Kill target player"); + + //Social + cl.register("/colors", "colors", "Set your default chat color: /colors "); + cl.register("/me", "me"); + cl.register("/fabulous", "fabulous", "makes text SUUUPER"); + cl.register("/msg", "message", "Send a message to a player /msg [Player] [Message]"); + cl.register("/reply", "reply", "Reply to a player /reply [Message], Alias: /r"); + cl.register("/ignore", "addIgnored", "Adds a user to your ignore list"); + cl.register("/unignore", "removeIgnored", "Removes a user from your ignore list"); + cl.register("/ignorelist", "ignoreList", "Lists the players you have ignored"); + + //registerAlias: Runs the second command when the first command is called + //String: The command that this will be called by + //String: The message that will be called when the first is entered + // Can be modified with %# to have it insert a player + // argument into that position. + // EX: Aliased command is + // cl.registerAlias("/test", "/i %0 100") + // Player uses /test wood + // The %0 will be replaced with wood for this instance + // and Player will be given 100 wood. + cl.registerAlias("/playerlist", "/who"); + cl.registerAlias("/vhelp", "/vminecraft"); + cl.registerAlias("/r", "/reply"); + cl.registerAlias("/t", "/msg"); + cl.registerAlias("/tell", "/msg"); + cl.registerAlias("/wrists", "/suicide"); + cl.registerAlias("/kill", "/suicide"); + cl.registerAlias("/ci", "/clearinventory"); + + //registerMessage: Displays a message whenever a command is used + //String: The command it will run on + //String: What will be displayed + // %p is the player calling the command + // %# is the argument number of the command. + // %#p is an argument number that will be required to be + // an online player + //String: The color the message will be + //int: The number of arguments required for the message to appear + //boolean: If the message should only display for admins + cl.registerMessage("/kick", "%p has kicked %0p", Colors.Blue, 1, false); + cl.registerMessage("/ban", "%p has banned %0p", Colors.Blue, 1, false); + cl.registerMessage("/ipban", "%p has IP banned %0p", Colors.Blue, 1, false); + cl.registerMessage("/time", "Time change thanks to %p", Colors.Blue, 1, true); + } + //===================================================================== + //Function: vminecrafthelp (/vhelp or /vminecraft) + //Input: Player player: The player using the command + //Output: int: Exit Code + //Use: Displays the current status of most vMinecraft settings + // and provides some useful tips. + //===================================================================== + public static int vminecrafthelp(Player player, String[] args){ + vChat.sendMessage(player, player, Colors.Yellow + + "Chat Settings"); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Admin Chat: " + vConfig.getInstance() + .adminchat()); + vChat.sendMessage(player, player, Colors.DarkPurple + + "FFF turns red: " + vConfig.getInstance() + .FFF()); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Greentext After >: " + vConfig.getInstance() + .greentext()); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Quake Color Script: " + vConfig.getInstance() + .quakeColors()); + vChat.sendMessage(player, player, Colors.Yellow + + "Enabled Commands are TRUE, disabled are FALSE"); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Command /ezmodo: " + vConfig.getInstance() + .cmdEzModo()); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Command /fabulous: " + vConfig.getInstance() + .cmdFabulous()); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Command /rules: " + vConfig.getInstance() + .cmdRules()); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Command /heal: " + vConfig.getInstance() + .cmdHeal()); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Command /masstp: " + vConfig.getInstance() + .cmdMasstp()); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Command /say: " + vConfig.getInstance() + .cmdSay()); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Command /suicide: " + vConfig.getInstance() + .cmdSuicide()); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Command /whois: " + vConfig.getInstance() + .cmdWhoIs()); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Command /tp won't work on higher ranked players: " + + vConfig.getInstance().cmdTp()); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Command /tphere won't work on higher ranked players: " + + vConfig.getInstance().cmdTphere()); + vChat.sendMessage(player, player, Colors.Yellow + + "Other Settings"); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Command /who: " + vConfig.getInstance() + .cmdWho()); + vChat.sendMessage(player, player, Colors.DarkPurple + + "COLORED PLAYER LIST IS DEPENDENT ON /who BEING TRUE!"); + vChat.sendMessage(player, player, Colors.DarkPurple + + "Global Messages: " + vConfig.getInstance() + .globalmessages()); + return EXIT_SUCCESS; + } + public void onDisconnect(Player player){ + if(hidden.containsKey(player.getName())) + hidden.remove(player.getName()); + if(vConfig.getInstance().isEzModo(player.getName())) + vConfig.getInstance().removeEzModo(player.getName()); + } + + public void run() + { + for (Player InvisiblePlayer : hidden.values()) + { + for (Player p : etc.getServer().getPlayerList()) + { + if (vmc.getDistance(InvisiblePlayer, p) <= vConfig.range && p.getUser() != InvisiblePlayer.getUser()) + { + p.getUser().a.b(new dv(InvisiblePlayer.getUser().g)); + } + } + } + } + public static int silent(Player player, String[] args){ + if(player.canUseCommand("/silent")){ + if(!vUsers.getProfile(player).isSilent()){ + vUsers.getProfile(player).setSilent(); + player.sendMessage(Colors.DarkPurple + "You are now silent... shh"); + return EXIT_SUCCESS; + } + if(vUsers.getProfile(player).isSilent()){ + vUsers.getProfile(player).disableSilent(); + player.sendMessage(Colors.DarkPurple + "You are no longer silent"); + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + return EXIT_FAIL; + } + //Will make a player disappear or reappear + //Big thanks to the Vanish Plugins author: nodren + public static int hide(Player player, String[] args){ + if (player.canUseCommand("/hide")){ + if(hidden.get(player.getName()) != null) { + hidden.remove(player.getName()); + player.sendMessage(Colors.DarkPurple + "You are no longer invisible"); + hidden.remove(player.getName()); + updateInvisibleForAll(); + vmc.sendNotInvisible(player); + log.log(Level.INFO, player.getName() + " reappeared"); + player.sendMessage(Colors.Rose + "You have reappeared!"); + return EXIT_SUCCESS; + } + hidden.put(player.getName(), player); + player.sendMessage(Colors.DarkPurple + "You are now invisible"); + vmc.sendInvisible(player); + log.log(Level.INFO, player.getName() + " went invisible"); + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + public static void updateInvisibleForAll() + { + List playerList = etc.getServer().getPlayerList(); + for (Player InvisiblePlayer : hidden.values()) + { + for (Player p : playerList) + { + if (vmc.getDistance(InvisiblePlayer, p) <= vConfig.range && p.getUser() != InvisiblePlayer.getUser()) + { + p.getUser().a.b(new dv(InvisiblePlayer.getUser().g)); + } + } + } + } + public static int partychat(Player player, String[] args){ + if (args.length < 1) { + player.sendMessage(Colors.Rose + "Usage is /p [Message]"); + return EXIT_SUCCESS; + } + if(vUsers.getProfile(player).inParty()){ + String str = etc.combineSplit(0, args, " "); + vChat.partyChat(player, str); + return EXIT_SUCCESS; + } else{ + return EXIT_FAIL; + } + } + public static int party(Player player, String[] args){ + if(vUsers.getProfile(player).inParty()){ + player.sendMessage(Colors.Red + "You are already in a party, use /pquit to leave it"); + return EXIT_SUCCESS; + } + if(args[0] != null) { + vUsers.getProfile(player).setParty(args[0]); + player.sendMessage(Colors.DarkPurple + "Party set to " + args[0]); + return EXIT_SUCCESS; + } else { + player.sendMessage(Colors.Red + "Correct usage is /party [partyname]"); + return EXIT_SUCCESS; + } + } + public static int partyquit(Player player, String[] args){ + if(vUsers.getProfile(player).inParty()){ + vUsers.getProfile(player).removeParty(); + player.sendMessage(Colors.LightGreen + "Party successfully removed"); + return EXIT_SUCCESS; + } else { + player.sendMessage(Colors.Red + "You are not in a party"); + return EXIT_SUCCESS; + } + } + public static int tpback(Player player, String[] args){ + if(player.canUseCommand("/tpback")){ + String tpxyz = vUsers.getProfile(player).getTpxyz(); + String tpxyz2[] = tpxyz.split(","); + double x = Double.parseDouble(tpxyz2[0]); + double y = Double.parseDouble(tpxyz2[1]); + double z = Double.parseDouble(tpxyz2[2]); + player.teleportTo(x, y, z, 0, 0); + String cx = Double.toString(etc.getServer().getSpawnLocation().x); + String cy = Double.toString(etc.getServer().getSpawnLocation().y); + String cz = Double.toString(etc.getServer().getSpawnLocation().z); + String cxyz = cx + "," + cy + "," + cz; + vUsers.getProfile(player).setTpback(cxyz); + player.sendMessage(Colors.Rose + "/tpback data reset to spawn"); + return EXIT_SUCCESS; + } + return EXIT_SUCCESS; + } + //===================================================================== + //Function: myspawn (/myspawn) + //Input: Player player: The player using the command + //Output: int: Exit Code + //Use: Returns a player to their home but with penalties + //===================================================================== + public static int myspawn(Player player, String[] args){ + if(player.canUseCommand("/myspawn") && vConfig.getInstance().playerspawn()) + { + player.sendMessage(Colors.DarkPurple + "Returned to myspawn"); + player.sendMessage(Colors.Red + "Penalty: Inventory Cleared"); + player.setHealth(20); + Warp home = null; + home = etc.getDataSource().getHome(player.getName()); + player.teleportTo(home.Location); + Inventory inv = player.getInventory(); + inv.clearContents(); + inv.update(); + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + //===================================================================== + //Function: prefix (/prefix) + //Input: Player player: The player using the command + // String[] args: The name of the player + //Output: int: Exit Code + //Use: Freezes a player in place + //===================================================================== + public static int freeze(Player player, String[] args){ + if(player.canUseCommand("/freeze") && vConfig.getInstance().freeze()){ + if (args.length < 1){ + vChat.gmsg(Colors.Rose + "Usage is /freeze [Player]"); + return EXIT_SUCCESS; + } + Player other = etc.getServer().matchPlayer(args[0]); + if (other == null) + { + vChat.gmsg(Colors.Rose + "The player you specified could not be found"); + return EXIT_SUCCESS; + } + if(player != other && other.hasControlOver(player)){ + vChat.gmsg(Colors.Rose + "The player you specified has a higher rank than you"); + return EXIT_SUCCESS; + } + if(vConfig.getInstance().isFrozen(other.getName())){ + vConfig.getInstance().removeFrozen(other.getName()); + vChat.gmsg(player.getName() + Colors.Blue + " has unfrozen " + other.getName()); + return EXIT_SUCCESS; + } else { + vConfig.getInstance().addFrozen(other.getName()); + vChat.gmsg(player.getName() + Colors.Blue + " has frozen " + other.getName()); + return EXIT_SUCCESS; + } + } + return EXIT_SUCCESS; + } + //===================================================================== + //Function: prefix (/prefix) + //Input: Player player: The player using the command + // String[] args: The color and the prefix + //Output: int: Exit Code + //Use: Changes your name color and prefix + //===================================================================== + public static int prefix(Player player, String[] args){ + + //if the player can prefix others + if(player.canUseCommand("/prefixother") && vConfig.getInstance().prefix()){ + + //Check if there are enough arguments + if(args.length < 2){ + vChat.sendMessage(player, player, Colors.Rose + "Usage is /prefix [Player] [Color Code] "); + player.sendMessage(Colors.DarkPurple + "Example: /prefix " + player.getName() + " e ^0[^a<3^0]"); + vChat.sendMessage(player, player, Colors.DarkPurple + "This would produce a name like... " + Colors.Black + "[" + Colors.LightGreen + "<3" + Colors.Black + "]" + Colors.Yellow + player.getName()); + return EXIT_SUCCESS; + } + + //Check if the player exists + Player other = etc.getServer().matchPlayer(args[0]); + if(other == null) + { + vChat.sendMessage(player, player, Colors.Rose + + "The player you specified could not be found"); + return EXIT_SUCCESS; + } + + //Check if they are a higher rank than the other person + if(player != other && other.hasControlOver(player)) + { + vChat.sendMessage(player, player, Colors.Rose + + "The player you specified is a higher rank than you."); + return EXIT_SUCCESS; + } + + + //Check if the prefix is too long + if(vChat.msgLength(args[1]) > 60) + { + vChat.sendMessage(player, player, Colors.Rose + + "The prefix you entered was too long."); + return EXIT_SUCCESS; + } + if(args.length >= 2 && args[0] != null) + { + other.setPrefix(args[1]); + player.sendMessage(Colors.Rose + "Name color changed"); + FlatFileSource ffs = new FlatFileSource(); + ffs.modifyPlayer(other); + } + + if(args.length >= 3 && args[1] != null) + { + vUsers.players.findProfile(other).setTag(args[2]); + player.sendMessage(Colors.LightGreen + "Prefix changed"); + } + return EXIT_SUCCESS; + } + //If the player can set their prefix + if(!player.canUseCommand("/prefix")&& vConfig.getInstance().prefix()){ + return EXIT_FAIL; + } + + //Check if there are enough arguments + if(args.length < 1){ + vChat.sendMessage(player, player, Colors.Rose + "Usage is /prefix [Color Code] "); + player.sendMessage(Colors.DarkPurple + "Example: /prefix e ^0[^a<3^0]"); + vChat.sendMessage(player, player, Colors.DarkPurple + "This would produce a name like... " + Colors.Black + "[" + Colors.LightGreen + "<3" + Colors.Black + "]" + Colors.Yellow + player.getName()); + return EXIT_SUCCESS; + } + //Name color + if(args.length >= 1 && args[0] != null){ + player.setPrefix(args[0]); + player.sendMessage(Colors.Rose + "Name color changed"); + } + //Prefix + if(args.length >= 2 && args[1] != null){ + //Check if the prefix is too long + if(vChat.msgLength(args[1]) > 60) + { + vChat.sendMessage(player, player, Colors.Rose + + "The prefix you entered was too long."); + return EXIT_SUCCESS; + } + vUsers.players.findProfile(player).setTag(args[1]); + player.sendMessage(Colors.LightGreen + "Prefix changed"); + } + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: removeTag (/rprefix) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: int: Exit Code + //Use: Removes your prefix + //===================================================================== + public static int removeTag(Player player, String[] args){ + + //if the player can suffix others + if(player.canUseCommand("/prefixother")&& vConfig.getInstance().prefix()){ + if(args.length < 1){ + vChat.sendMessage(player, player, Colors.Rose + + "Usage is /rprefix [Player]"); + return EXIT_SUCCESS; + } + + //Check if the player exists + Player other = etc.getServer().matchPlayer(args[0]); + if(other == null) + { + vChat.sendMessage(player, player, Colors.Rose + + "The player you specified could not be found"); + return EXIT_SUCCESS; + } + + //Check if they are a higher rank than the other person + if(player != other && other.hasControlOver(player)) + { + vChat.sendMessage(player, player, Colors.Rose + + "The player you specified is a higher rank than you."); + return EXIT_SUCCESS; + } + + vUsers.getProfile(other).setTag(""); + player.sendMessage(Colors.LightGreen + "Prefix Removed"); + + return EXIT_SUCCESS; + } + + //Check if the player can set their own prefix. + if(!player.canUseCommand("/prefix")&& vConfig.getInstance().prefix()){ + return EXIT_FAIL; + } + if(args.length < 1){ + vChat.sendMessage(player, player, Colors.Rose + + "Usage is /rprefix"); + return EXIT_SUCCESS; + } + vUsers.getProfile(player).setTag(""); + player.sendMessage(Colors.LightGreen + "Prefix Removed"); + + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: nickName (/nick) + //Input: Player player: The player using the command + // String[] args: The color and the prefix + //Output: int: Exit Code + //Use: Changes your name + //===================================================================== + public static int nickName(Player player, String[] args){ + + //if the player can nickname others + if(player.canUseCommand("/nickother") && vConfig.getInstance().nick()){ + if(args.length < 2){ + vChat.sendMessage(player, player, Colors.Rose + + "Usage is /nick [Player] [Name]"); + return EXIT_SUCCESS; + } + + //Check if the nickname is too long + if(vChat.msgLength(args[1]) > 85) + { + vChat.sendMessage(player, player, Colors.Rose + + "The nick you entered was too long."); + return EXIT_SUCCESS; + } + + //Check if the player exists + Player other = etc.getServer().matchPlayer(args[0]); + if(other == null) + { + vChat.sendMessage(player, player, Colors.Rose + + "The player you specified could not be found"); + return EXIT_SUCCESS; + } + + //Check if they are a higher rank than the other person + if(player != other && other.hasControlOver(player)) + { + vChat.sendMessage(player, player, Colors.Rose + + "The player you specified is a higher rank than you."); + return EXIT_SUCCESS; + } + + vUsers.getProfile(other).setNick(args[1]); + player.sendMessage(Colors.LightGreen + "Nickname Set"); + + return EXIT_SUCCESS; + } + + //Make sure they can nickname themselves + if(!player.canUseCommand("/nick")){ + return EXIT_FAIL; + } + + //Check if the nickname is too long + if(vChat.msgLength(args[1]) > 85) + { + vChat.sendMessage(player, player, Colors.Rose + + "The nick you entered was too long."); + return EXIT_SUCCESS; + } + + if(args.length < 1){ + vChat.sendMessage(player, player, Colors.Rose + + "Usage is /nick [Name]"); + return EXIT_SUCCESS; + } + vUsers.getProfile(player).setNick(args[0]); + player.sendMessage(Colors.LightGreen + "Nickname Set"); + + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: removeNick (/rnick) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: int: Exit Code + //Use: Removes your nick + //===================================================================== + public static int removeNick(Player player, String[] args){ + + //if the player can nick others + if(player.canUseCommand("/nickother")&& vConfig.getInstance().nick()){ + if(args.length < 1){ + vChat.sendMessage(player, player, Colors.Rose + + "Usage is /rnick [Player]"); + return EXIT_SUCCESS; + } + + //Check if the player exists + Player other = etc.getServer().matchPlayer(args[0]); + if(other == null) + { + vChat.sendMessage(player, player, Colors.Rose + + "The player you specified could not be found"); + return EXIT_SUCCESS; + } + + //Check if they are a higher rank than the other person + if(player != other && other.hasControlOver(player)) + { + vChat.sendMessage(player, player, Colors.Rose + + "The player you specified is a higher rank than you."); + return EXIT_SUCCESS; + } + + vUsers.getProfile(other).setNick(""); + player.sendMessage(Colors.LightGreen + "Nickname Removed"); + + return EXIT_SUCCESS; + } + + //Check if the player can set their own nick. + if(!player.canUseCommand("/nick")&& vConfig.getInstance().nick()){ + return EXIT_FAIL; + } + if(args.length < 1){ + vChat.sendMessage(player, player, Colors.Rose + + "Usage is /rnick"); + return EXIT_SUCCESS; + } + vUsers.getProfile(player).setNick(""); + player.sendMessage(Colors.LightGreen + "Nickname Removed"); + + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: suffix (/suffix) + //Input: Player player: The player using the command + // String[] args: The color and the suffix + //Output: int: Exit Code + //Use: Changes your suffix + //===================================================================== + public static int suffix(Player player, String[] args){ + + //if the player can suffix others + if(player.canUseCommand("/suffixother")&& vConfig.getInstance().suffix()){ + if(args.length < 2){ + vChat.sendMessage(player, player, Colors.Rose + + "Usage is /suffix [Player] [Name]"); + return EXIT_SUCCESS; + } + + //Check if the suffix is too long + if(vChat.msgLength(args[1]) > 60) + { + vChat.sendMessage(player, player, Colors.Rose + + "The suffix you entered was too long."); + return EXIT_SUCCESS; + } + + //Check if the player exists + Player other = etc.getServer().matchPlayer(args[0]); + if(other == null) + { + vChat.sendMessage(player, player, Colors.Rose + + "The player you specified could not be found"); + return EXIT_SUCCESS; + } + + //Check if they are a higher rank than the other person + if(player != other && other.hasControlOver(player)) + { + vChat.sendMessage(player, player, Colors.Rose + + "The player you specified is a higher rank than you."); + return EXIT_SUCCESS; + } + vUsers.getProfile(other).setSuffix(args[1]); + player.sendMessage(Colors.LightGreen + "Suffix Set"); + + return EXIT_SUCCESS; + } + + //Check if the player can set their own suffix. + if(!player.canUseCommand("/suffix")&& vConfig.getInstance().suffix()){ + return EXIT_FAIL; + } + if(args.length < 1){ + vChat.sendMessage(player, player, Colors.Rose + + "Usage is /suffix [Suffix]"); + return EXIT_SUCCESS; + } + + //Check if the suffix is too long + if(vChat.msgLength(args[1]) > 60) + { + vChat.sendMessage(player, player, Colors.Rose + + "The suffix you entered was too long."); + return EXIT_SUCCESS; + } + vUsers.getProfile(player).setSuffix(args[0]); + player.sendMessage(Colors.LightGreen + "Suffix Set"); + + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: removeSuffix (/rsuffix) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: int: Exit Code + //Use: Removes your suffix + //===================================================================== + public static int removeSuffix(Player player, String[] args){ + + //if the player can suffix others + if(player.canUseCommand("/suffixother")&& vConfig.getInstance().suffix()){ + if(args.length < 1){ + vChat.sendMessage(player, player, Colors.Rose + + "Usage is /rsuffix [Player]"); + return EXIT_SUCCESS; + } + + //Check if the player exists + Player other = etc.getServer().matchPlayer(args[0]); + if(other == null) + { + vChat.sendMessage(player, player, Colors.Rose + + "The player you specified could not be found"); + return EXIT_SUCCESS; + } + + //Check if they are a higher rank than the other person + if(player != other && other.hasControlOver(player)) + { + vChat.sendMessage(player, player, Colors.Rose + + "The player you specified is a higher rank than you."); + return EXIT_SUCCESS; + } + vUsers.getProfile(other).setSuffix(""); + player.sendMessage(Colors.LightGreen + "Suffix Removed"); + + return EXIT_SUCCESS; + } + + //Check if the player can set their own suffix. + if(!player.canUseCommand("/suffix")&& vConfig.getInstance().suffix()){ + return EXIT_FAIL; + } + if(args.length < 1){ + vChat.sendMessage(player, player, Colors.Rose + + "Usage is /rsuffix"); + return EXIT_SUCCESS; + } + vUsers.getProfile(player).setSuffix(""); + player.sendMessage(Colors.LightGreen + "Suffix Removed"); + + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: colors (/colors) + //Input: Player player: The player using the command + //Output: int: Exit Code + //Use: Displays a list of all colors and color codes + //===================================================================== + public static int colors(Player player, String[] args){ + if(args.length > 0&& vConfig.getInstance().colors()) + { + vUsers.getProfile(player).setColor(args[0]); + vChat.sendMessage(player, player, "^" + args[0].charAt(0) + + "Default chat color set."); + } else { + player.sendMessage(Colors.Rose + "You use these color codes like in quake or MW2."); + player.sendMessage(Colors.Rose + "^4 would make text " + Colors.Red + + "red" + Colors.Rose + ", ^a would make it " + Colors.LightGreen + + "light green" + Colors.Rose + "."); + vChat.sendMessage(player, player, + Colors.Black + "0" + + Colors.Navy + "1" + + Colors.Green + "2" + + Colors.Blue + "3" + + Colors.Red + "4" + + Colors.Purple + "5" + + Colors.Gold + "6" + + Colors.LightGray + "7" + + Colors.Gray + "8" + + Colors.DarkPurple + "9" + + Colors.LightGreen + "A" + + Colors.LightBlue + "B" + + Colors.Rose + "C" + + Colors.LightPurple + "D" + + Colors.Yellow + "E" + + Colors.White + "F" + + "^r" + "[R]ainbow"); + } + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: me (/me) + //Input: Player player: The player using the command + // String[] args: Will contain the message the player sends + //Output: int: Exit Code + //Use: The player uses this to emote, but now its colorful. + //===================================================================== + public static int me(Player player, String[] args) + { + String str = etc.combineSplit(0, args, " "); + if (args.length < 1) return EXIT_FAIL; + vChat.emote(player, str); + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: message (/msg, /w, /whisper) + //Input: Player player: The player using the command + // String[] args: Will contain the target player name and + // message the player sends + //Output: int: Exit Code + //Use: Send a message to a player + //===================================================================== + public static int message(Player player, String[] args) + { + + //Make sure a player is specified + if (args.length < 2) { + vChat.sendMessage(player, player, Colors.Rose + + "Usage is /msg [player] [message]"); + return EXIT_SUCCESS; + } + + //Make sure the player exists + Player toPlayer = etc.getServer().matchPlayer(args[0]); + if (toPlayer == null || args.length < 1) { + vChat.sendMessage(player, player, Colors.Rose + + "No player by the name of " + args[0] + " could be found."); + return EXIT_SUCCESS; + } + + String msg = etc.combineSplit(1, args, " "); + //Send the message to the targeted player and the sender + vChat.sendMessage(player, toPlayer, + Colors.LightGreen + "[From:" + vChat.getName(player) + + Colors.LightGreen + "] " + msg); + vChat.sendMessage(player, player, + Colors.LightGreen + "[To:" + vChat.getName(toPlayer) + + Colors.LightGreen + "] " + msg); + //Set the last massager for each player + vUsers.getProfile(player).setMessage(toPlayer); + vUsers.getProfile(toPlayer).setMessage(player); + + //Display the message to the log + log.log(Level.INFO, player.getName() + " whispered to " + toPlayer.getName() + + ": " + msg); + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: reply (/r, /reply) + //Input: Player player: The player using the command + // String[] args: Will contain the message the player sends + //Output: int: Exit Code + //Use: Send a message to a player + //===================================================================== + public static int reply(Player player, String[] args) + { + //If the profile exists for the player + if(vUsers.getProfile(player) == null ) { + vChat.sendMessage(player, player, + Colors.Rose + "The person you last message has logged off"); + return EXIT_SUCCESS; + } + + //Make sure a message is specified + if (args.length < 1) { + vChat.sendMessage(player, player, + Colors.Rose + "Usage is /reply [Message]"); + return EXIT_SUCCESS; + } + + //Make sure the player they're talking to is online + Player toPlayer = vUsers.getProfile(player).getMessage(); + if (toPlayer == null) { + vChat.sendMessage(player, player, + Colors.Rose + "The person you last message has logged off"); + return EXIT_SUCCESS; + } + + String msg = etc.combineSplit(0, args, " "); + + //Send the message to the targeted player and the sender + vChat.sendMessage(player, toPlayer, + Colors.LightGreen + "[From:" + vChat.getName(player) + + Colors.LightGreen + "] " + msg); + vChat.sendMessage(player, player, + Colors.LightGreen + "[To:" + vChat.getName(toPlayer) + + Colors.LightGreen + "] " + msg); + + //Set the last messager for each player + vUsers.getProfile(player).setMessage(toPlayer); + vUsers.getProfile(toPlayer).setMessage(player); + + //Display the message to the log + log.log(Level.INFO, player.getName() + " whispered to " + toPlayer.getName() + + ": " + msg); + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: addIgnored (/ignore) + //Input: Player player: The player using the command + // String[] args: The name of the player to ignore + //Output: int: Exit Code + //Use: Adds a player to the ignore list + //===================================================================== + public static int addIgnored(Player player, String[] args) + { + //Make sure the player gave you a user to ignore + if(args.length < 1 && vConfig.getInstance().ignore()) + { + vChat.sendMessage(player, player, + Colors.Rose + "Usage: /ignore [Player]"); + return EXIT_SUCCESS; + } + + //Find the player and make sure they exist + Player ignore = etc.getServer().matchPlayer(args[0]); + if(ignore == null&& vConfig.getInstance().ignore()) + { + vChat.sendMessage(player, player, Colors.Rose + + "The person you tried to ignore is not logged in."); + return EXIT_SUCCESS; + } + + if(!player.hasControlOver(ignore)&& vConfig.getInstance().ignore()) + { + vChat.sendMessage(player, player, Colors.Rose + + "You can't ignore someone a higher rank than you."); + return EXIT_SUCCESS; + } + + //Don't let the player ignore themselves + if(ignore.getName().equalsIgnoreCase(player.getName())) + { + vChat.sendMessage(player, player, + Colors.Rose + "You cannot ignore yourself"); + return EXIT_SUCCESS; + } + + //Attempt to ignore the player and report accordingly + if(vUsers.getProfile(player).addIgnore(ignore)) + vChat.sendMessage(player, player, Colors.Rose + + ignore.getName() + " has been successfuly ignored."); + else + vChat.sendMessage(player, player, Colors.Rose + + "You are already ignoring " + ignore.getName()); + + + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: removeIgnored (/unignore) + //Input: Player player: The player using the command + // String[] args: The name of the player to stop ignoring + //Output: int: Exit Code + //Use: Removes a player from the ignore list + //===================================================================== + public static int removeIgnored(Player player, String[] args) + { + //Make sure the player gave you a user to ignore + if(args.length < 1&& vConfig.getInstance().ignore()) + { + vChat.sendMessage(player, player, + Colors.Rose + "Usage: /unignore [Player]"); + return EXIT_SUCCESS; + } + + //Find the player and make sure they exist + Player ignore = etc.getServer().matchPlayer(args[0]); + if(ignore == null&& vConfig.getInstance().ignore()) + { + vChat.sendMessage(player, player, + Colors.Rose + "The person you tried to unignore is not logged in."); + return EXIT_SUCCESS; + } + + //Attempt to ignore the player and report accordingly + if(vUsers.getProfile(player).removeIgnore(ignore)) + vChat.sendMessage(player, player, + Colors.Rose + ignore.getName()+ " has been successfuly " + + "unignored."); + else + vChat.sendMessage(player, player, + Colors.Rose + "You are not currently ignoring " + ignore.getName()); + + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: ignoreList (/ignorelist) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: int: Exit Code + //Use: Lists the player you have ignored + //===================================================================== + public static int ignoreList(Player player, String[] args) + { + if (vConfig.getInstance().ignore()){ + //Get the ignore list + String[] list = vUsers.getProfile(player).listIgnore(); + + //Find the last page number + int lastPage = (int)list.length / 5; + if((int)list.length % 5 > 0) + lastPage++; + + //Find the page number the player wants displayed + int page = 0; + if(args.length > 0 && Integer.valueOf(args[0]) > 0 + && Integer.valueOf(args[0]) <= lastPage) + page = Integer.valueOf(args[0]) - 1; + + //Display the header + vChat.sendMessage(player, player, + Colors.Rose + "Ignore List [" + page + "/" + + lastPage + "]"); + + //Display up to 5 people + for(int i = 0; i < 5 && i + (page * 5) < list.length; i++) + vChat.sendMessage(player, player, + Colors.Rose + list[i+ (page * 5)]); + + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + + //===================================================================== + //Function: adminChatToggle (/a) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: int: Exit Code + //Use: Toggles the player into admin chat. Every message they + // send will be piped to admin chat. + //===================================================================== + public static int adminChatToggle(Player player, String[] args) + { + //Make sure the user has access to the command + if(!player.canUseCommand("/a")) return EXIT_FAIL; + + if(!vConfig.getInstance().adminChatToggle()) return EXIT_FAIL; + + //If the player is already toggled for admin chat, remove them + if (vConfig.getInstance().isAdminToggled(player.getName())) { + player.sendMessage(Colors.Red + "Admin Chat Toggle = off"); + vConfig.getInstance().removeAdminToggled(player.getName()); + //Otherwise include them + } else { + player.sendMessage(Colors.Blue + "Admin Chat Toggled on"); + vConfig.getInstance().addAdminToggled(player.getName()); + } + return EXIT_SUCCESS; + } + //===================================================================== + //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) + { + //Make sure the user has access to the command + if(!player.canUseCommand("/heal")) return EXIT_FAIL; + + if(!vConfig.getInstance().cmdHeal()) return EXIT_FAIL; + + //If a target wasn't specified, heal the user. + if (args.length < 1){ + player.setHealth(20); + player.sendMessage("Your health is restored"); + return EXIT_SUCCESS; + } + + //If a target was specified, try to find them and then heal them + //Otherwise report the error + Player playerTarget = etc.getServer().matchPlayer(args[0]); + if (playerTarget == null){ + player.sendMessage(Colors.Rose + + "Couldn't find that player"); + return EXIT_SUCCESS; + } + + playerTarget.setHealth(20); + player.sendMessage(Colors.Blue + "You have healed " + + vChat.getName(playerTarget)); + playerTarget.sendMessage(Colors.Blue + + "You have been healed by " + + vChat.getName(player)); + return EXIT_SUCCESS; + } + + //===================================================================== + //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) + { + //Make sure the user has access to the command + if(!player.canUseCommand("/suicide")) return EXIT_FAIL; + + if(!vConfig.getInstance().cmdSuicide()) return EXIT_FAIL; + + //Set your health to 0. Not much to it. + player.setHealth(0); + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: teleport (/tp) + //Input: Player player: The player using the command + // String[] args: The arguments for the command. Should be a + // player name + //Output: int: Exit Code + //Use: Teleports the user to another player + //===================================================================== + public static int teleport(Player player, String[] args) + { + //Make sure the user has access to the command + if(!player.canUseCommand("/tp")) return EXIT_FAIL; + //Get if the command is enabled + if(!vConfig.getInstance().cmdTp())return EXIT_FAIL; + + //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]"); + return EXIT_SUCCESS; + } + + //Find the player by name + Player playerTarget = etc.getServer().matchPlayer(args[0]); + + //Target player isn't found + if(playerTarget == null) + player.sendMessage(Colors.Rose + "Can't find user " + + args[0] + "."); + //If it's you, return witty message + else if (player.getName().equalsIgnoreCase(args[0])) + 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 + else { + //Storing their previous location for tpback + double x = player.getLocation().x; + double y = player.getLocation().y; + double z = player.getLocation().z; + String x2 = Double.toString(x); + String y2 = Double.toString(y); + String z2 = Double.toString(z); + String xyz = x2+","+y2+","+z2; + vUsers.getProfile(player).setTpback(xyz); + if(player.canUseCommand("/tpback")){ + player.sendMessage(Colors.DarkPurple + "Your previous location has been stored"); + player.sendMessage(Colors.DarkPurple + "Use /tpback to return"); + } + if(!vUsers.getProfile(player).isSilent()){ + vChat.gmsg( player, vChat.getName(player) + + Colors.LightBlue + " has teleported to " + + vChat.getName(playerTarget)); + } + log.log(Level.INFO, player.getName() + " teleported to " + + playerTarget.getName()); + + player.teleportTo(playerTarget); + + } + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: masstp (/masstp) + //Input: Player player: The player using the command + // String[] args: Should be empty or is ignored + //Output: int: Exit Code + //Use: Teleports all players to the user + //===================================================================== + public static int masstp(Player player, String[] args) + { + //Make sure the user has access to the command + if(!player.canUseCommand("/masstp")) return EXIT_FAIL; + + //If the command is enabled + if(!vConfig.getInstance().cmdMasstp())return EXIT_FAIL; + + //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."); + + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: tphere (/tphere) + //Input: Player player: The player using the command + // String[] args: The arguments for the command. Should be a + // player name + //Output: int: Exit Code + //Use: Teleports the user to another player + //===================================================================== + public static int tphere(Player player, String[] args) + { + //Make sure the user has access to the command + if(!player.canUseCommand("/tphere")) return EXIT_FAIL; + + //Check if the command is enabled. + if (!vConfig.getInstance().cmdTphere())return EXIT_FAIL; + + //Make sure a player is specified + if (args.length < 1) { + player.sendMessage(Colors.Rose + "Correct usage" + + " is: /tphere [player]"); + return EXIT_SUCCESS; + } + + //Get the player by name + Player playerTarget = etc.getServer().matchPlayer(args[0]); + + //If the target doesn't exist + if(playerTarget == null) + player.sendMessage(Colors.Rose + "Can't find user " + + args[0] + "."); + //If the player has a higher rank than the user, return error + else if (!player.hasControlOver(playerTarget)) + player.sendMessage(Colors.Red + "That player has higher" + + " permissions than you."); + //If the user teleports themselves, mock them + else if (player.getName().equalsIgnoreCase(args[0])) + player.sendMessage(Colors.Rose + "Wow look at that! You" + + " teleported yourself to yourself!"); + //If the target exists, teleport them to the user + else { + log.log(Level.INFO, player.getName() + " teleported " + + playerTarget.getName() + " to their self."); + playerTarget.teleportTo(player); + double x = player.getLocation().x; + double y = player.getLocation().y; + double z = player.getLocation().z; + String x2 = Double.toString(x); + String y2 = Double.toString(y); + String z2 = Double.toString(z); + String xyz = x2+","+y2+","+z2; + vUsers.getProfile(playerTarget).setTpback(xyz); + if(playerTarget.canUseCommand("/tpback")) + { + playerTarget.sendMessage(Colors.DarkPurple + "Your previous location has been stored"); + playerTarget.sendMessage(Colors.DarkPurple + "Use /tpback to return"); + } + } + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: reload (/reload) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: int: Exit Code + //Use: Reloads the settings for vMinecraft + //===================================================================== + public static int reload(Player player, String[] args) + { + //Make sure the user has access to the command + if(!player.canUseCommand("/reload")) return EXIT_FAIL; + + vConfig.getInstance().loadSettings(); + return EXIT_FAIL; + } + + //===================================================================== + //Function: rules (/rules) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: int: Exit Code + //Use: Lists the rules + //===================================================================== + public static int rules(Player player, String[] args) + { + //If the rules exist + if(!vConfig.getInstance().cmdRules() + && vConfig.getInstance().getRules().length > 0 + && !vConfig.getInstance().getRules()[0].isEmpty()) { + return EXIT_FAIL; + } + + //Apply QuakeCode Colors to the rules + String[] rules = vChat.applyColors( + vConfig.getInstance().getRules()); + //Display them + for (String str : rules ) { + if(!str.isEmpty()) + player.sendMessage(Colors.Blue + str); + else + player.sendMessage(Colors.Blue + + "!!!The Rules Have Not Been Set!!!"); + } + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: fabulous (/fabulous) + //Input: Player player: The player using the command + // String[] args: The message to apply the effect to + //Output: int: Exit Code + //Use: Makes the text rainbow colored + //===================================================================== + public static int fabulous(Player player, String[] args) + { + //If the command is enabled + if(!vConfig.getInstance().cmdFabulous()) return EXIT_FAIL; + + //Make sure a message has been specified + if (args.length < 1) { + player.sendMessage(Colors.Rose + "Usage /fabulous [Message]"); + return EXIT_SUCCESS; + } + + //Format the name + String playerName = Colors.White + "<" + + vChat.getName(player) + Colors.White +"> "; + + //Merge the message again + String str = etc.combineSplit(0, args, " "); + + //Output for server + log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\""); + + //Prepend the player name and cut into lines. + vChat.gmsg(player, playerName + vChat.rainbow(str)); + + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: whois (/whois) + //Input: Player player: The player using the command + // String[] args: The player to find info on + //Output: int: Exit Code + //Use: Displays information about the player specified + //===================================================================== + public static int whois(Player player, String[] args) + { + //Make sure the user has access to the command + if(!player.canUseCommand("/whois")) return EXIT_FAIL; + + //If the command is enabled + if (!vConfig.getInstance().cmdWhoIs()) return EXIT_FAIL; + + //If a player is specified + if (args.length < 1) + { + player.sendMessage(Colors.Rose + "Usage is /whois [player]"); + return EXIT_SUCCESS; + } + + //Get the player by name + Player playerTarget = etc.getServer().matchPlayer(args[0]); + + //If the player exists + if (playerTarget == null){ + player.sendMessage(Colors.Rose+"Player not found."); + return EXIT_SUCCESS; + } + + //Displaying the information + player.sendMessage(Colors.Blue + "Whois results for " + + vChat.getName(playerTarget)); + //Group + for(String group: playerTarget.getGroups()) + player.sendMessage(Colors.Blue + "Groups: " + group); + + //Only let admins see this info + if(player.isAdmin()) + { + //Admin + player.sendMessage(Colors.Blue+"Admin: " + + String.valueOf(playerTarget.isAdmin())); + //IP + player.sendMessage(Colors.Blue+"IP: " + playerTarget.getIP()); + //Restrictions + player.sendMessage(Colors.Blue+"Can ignore restrictions: " + + String.valueOf(playerTarget.canIgnoreRestrictions())); + } + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: who (/who) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: int: Exit Code + //Use: Displays the connected players + //===================================================================== + public static int who(Player player, String[] args) + { + //If the command is enabled + if (!vConfig.getInstance().cmdWho()) return EXIT_FAIL; + + //Loop through all players counting them and adding to the list + int count=0; + String tempList = ""; + for( Player p : etc.getServer().getPlayerList()) + { + if(p != null){ + if(count == 0) + tempList += vChat.getName(p); + else + tempList += Colors.White + ", " + vChat.getName(p); + count++; + } + } + //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 + vChat.sendMessage(player, player, Colors.Rose + "Player List (" + + count + "/" + maxPlayers +"): " + tempList); + + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: say (/say) + //Input: Player player: The player using the command + // String[] args: The message to apply the effect to + //Output: int: Exit Code + //Use: Announces the message to all players + //===================================================================== + public static int say(Player player, String[] args) + { + //Make sure the user has access to the command + if(!player.canUseCommand("/say")) return EXIT_FAIL; + + //Check if the command is enabled + if (!vConfig.getInstance().cmdSay()) return EXIT_FAIL; + + //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 + vChat.gmsg(player, Colors.Yellow + + etc.combineSplit(0, args, " ")); + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: slay (/slay) + //Input: Player player: The player using the command + // String[] args: The target for the command + //Output: int: Exit Code + //Use: Kill the target player + //===================================================================== + public static int slay(Player player, String[] args) + { + //Make sure the user has access to the command + if(!player.canUseCommand("/slay")) return EXIT_FAIL; + + //Check if the command is enabled + if(!vConfig.getInstance().cmdEzModo()) return EXIT_FAIL; + + //Get the player by name + Player playerTarget = etc.getServer().matchPlayer(args[0]); + + //If the player doesn't exist don't run + if(playerTarget == null) + { + player.sendMessage(Colors.Rose + "Usage is /slay [Player]"); + return EXIT_SUCCESS; + } + + //If the player isn't invulnerable kill them + if (vConfig.getInstance() + .isEzModo(playerTarget.getName())) { + player.sendMessage(Colors.Rose + "That player is currently in" + + " ezmodo! Hahahaha"); + } + + playerTarget.setHealth(0); + if(!vUsers.getProfile(player).isSilent()){ + vChat.gmsg(player, vChat.getName(player) + + Colors.LightBlue + " has slain " + + vChat.getName(playerTarget)); + } + //Otherwise output error to the user + + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: invuln (/ezmodo) + //Input: Player player: The player using the command + // String[] args: The target for the command + //Output: int: Exit Code + //Use: Kill the target player + //===================================================================== + public static int invuln(Player player, String[] args) + { + //Make sure the user has access to the command + if(!player.canUseCommand("/ezmodo")) return EXIT_FAIL; + + //If the command is enabled + if (!vConfig.getInstance().cmdEzModo()) return EXIT_FAIL; + + //If the player is already invulnerable, turn ezmodo off. + if (vConfig.getInstance().isEzModo(player.getName())) { + player.sendMessage(Colors.Red + "ezmodo = off"); + vConfig.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**"); + vConfig.getInstance().addEzModo(player.getName()); + } + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: ezlist (/ezlist) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: int: Exit Code + //Use: List all invulnerable players + //===================================================================== + public static int ezlist(Player player, String[] args) + { + //Make sure the user has access to the command + if(!player.canUseCommand("/ezmodo")) return EXIT_FAIL; + //If the feature is enabled list the players + if(!vConfig.getInstance().cmdEzModo()) return EXIT_FAIL; + + player.sendMessage("Ezmodo: " + vConfig.getInstance().ezModoList()); + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: modify (/modify) + //Input: Player player: The player using the command + // String[] args: Player, Command, Arguments + //Output: int: Exit Code + //Use: Display help for modifying features of players + //===================================================================== + /* + public static int modify(Player player, String[] args) + { + if(player.canUseCommand("/prefixother")) + vChat.sendMessage(player, player, "/prefix [Player]" + + " [Color] (Tag) - Set a players prefix and tag."); + else if(player.canUseCommand("/prefix")) + vChat.sendMessage(player, player, "/prefix [Color]" + + " (Tag) - Set your prefix and tag."); + + if(player.canUseCommand("/nickother")) + vChat.sendMessage(player, player, "/nick [Player]" + + " [Nickname] - Set a players nickname."); + else if(player.canUseCommand("/nick")) + vChat.sendMessage(player, player, "/nick [Nick]" + + " - Set your nickname."); + + if(player.canUseCommand("/suffixother")) + vChat.sendMessage(player, player, "/suffix [Player]" + + " [Suffix] - Set a players suffix."); + else if(player.canUseCommand("/suffix")) + vChat.sendMessage(player, player, "/suffix [Suffix]" + + " - Set your suffix."); + + if(player.canUseCommand("/suffixother")) + vChat.sendMessage(player, player, "/suffix [Player]" + + " [Suffix] - Set a players suffix."); + else if(player.canUseCommand("/suffix")) + vChat.sendMessage(player, player, "/suffix [Suffix]" + + " - Set your suffix."); + + if(player.canUseCommand("/vranks")) + { + vChat.sendMessage(player, player, "/promote [Player]" + + " - Promotes a player one rank"); + vChat.sendMessage(player, player, "/demote [Player]" + + " - Demotes a player one rank"); + } + return EXIT_SUCCESS; + } + + * + */ + //===================================================================== + //Function: promote (/promote) + //Input: Player player: The player using the command + // String[] args: Player to promote + //Output: int: Exit Code + //Use: Attempt to promote a player one rank + //===================================================================== + public static int promote(Player player, String[] args) + { + //Check if they can promote + if(!player.canUseCommand("/promote")) return EXIT_FAIL; + + //Check if they specified a player + if(args.length < 1) + { + vChat.sendMessage(player, Colors.Rose + "Usage: /promote [Player] (Rank)"); + return EXIT_SUCCESS; + } + + //Try to find the player + Player target = etc.getServer().matchPlayer(args[0]); + if(target == null) + { + vChat.sendMessage(player, Colors.Rose + "The player specified could not be found"); + return EXIT_SUCCESS; + } + + //Get the list of ranks + String[] ranks = vConfig.getInstance().getRanks(); + + //Find the targets current rank number + String[] tarGroups = target.getGroups(); + int tarRank = 0, + tarPos = 0; + boolean leave = false; + for(String rank : ranks) + { + for(String group : tarGroups) + { + if(rank.equalsIgnoreCase(group)) + { + leave = true; + break; + } + else + tarPos++; + } + if(leave) + break; + tarRank++; + tarPos = 0; + } + if(!leave) + { + tarRank = 0; + tarPos = 0; + if(tarGroups != null) + { + String[] tempGroups = new String[tarGroups.length + 1]; + System.arraycopy(tarGroups, 0, tempGroups, 1, tarGroups.length); + tarGroups = tempGroups; + } else + tarGroups = new String[1]; + } + + leave = false; + //Get the player's rank + String[] myGroups = player.getGroups(); + int myRank = 0; + + for(String rank : ranks) + { + for(String group : myGroups) + if(rank.equalsIgnoreCase(group)) + { + + leave = true; + break; + } + if(leave) + break; + myRank++; + } + if(!leave) + myRank = 0; + + //Make sure they're not promoting to their rank or higher + if(myRank <= tarRank + 1) + { + vChat.sendMessage(player, Colors.Rose + "You cannot promote someone to" + + " your rank or higher."); + return EXIT_SUCCESS; + } + + tarGroups[tarPos] = ranks[tarRank + 1]; + target.setGroups(tarGroups); + + //Make sure the player is in the files + FlatFileSource ffs = new FlatFileSource(); + if(!ffs.doesPlayerExist(target.getName())) + { + vChat.sendMessage(player, Colors.Rose + "Adding player."); + ffs.addPlayer(target); + } + else + { + ffs.modifyPlayer(target); + } + + vChat.sendMessage(player, Colors.Rose + target.getName() + + " has been promoted to " + ranks[tarRank + 1] + "."); + vChat.sendMessage(target, Colors.Rose + "You have been promoted to " + + ranks[tarRank + 1] + "."); + + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: demote (/demote) + //Input: Player player: The player using the command + // String[] args: Player to promote + //Output: int: Exit Code + //Use: Attempt to promote a player one rank + //===================================================================== + public static int demote(Player player, String[] args) + { + //Check if they can demote + if(!player.canUseCommand("/demote")) return EXIT_FAIL; + + //Check if they specified a player + if(args.length < 1) + { + vChat.sendMessage(player, Colors.Rose + "Usage: /demote [Player] (Rank)"); + return EXIT_SUCCESS; + } + + //Try to find the player + Player target = etc.getServer().matchPlayer(args[0]); + if(target == null) + { + vChat.sendMessage(player, Colors.Rose + "The player specified could not be found"); + return EXIT_SUCCESS; + } + + //Get the list of ranks + String[] ranks = vConfig.getInstance().getRanks(); + + //Find the targets current rank number + String[] tarGroups = target.getGroups(); + int tarRank = 0, + tarPos = 0; + boolean leave = false; + for(String rank : ranks) + { + for(String group : tarGroups) + { + if(rank.equalsIgnoreCase(group)) + { + leave = true; + break; + } + else + tarPos++; + } + if(leave) + break; + tarRank++; + tarPos = 0; + } + if(!leave) + { + tarRank = 0; + tarPos = 0; + if(tarGroups != null) + { + String[] tempGroups = new String[tarGroups.length + 1]; + System.arraycopy(tarGroups, 0, tempGroups, 1, tarGroups.length); + tarGroups = tempGroups; + } else + tarGroups = new String[1]; + } + + leave = false; + //Get the player's rank + String[] myGroups = player.getGroups(); + int myRank = 0; + + for(String rank : ranks) + { + for(String group : myGroups) + if(rank.equalsIgnoreCase(group)) + { + leave = true; + break; + } + if(leave) + break; + myRank++; + } + if(!leave) + { + myRank = 0; + } + + //Make sure they're not demoting to their rank or higher + if(myRank <= tarRank) + { + vChat.sendMessage(player, Colors.Rose + "You cannot demote someone who is" + + " your rank or higher."); + return EXIT_SUCCESS; + } + + if(tarRank - 1 < 0) + { + vChat.sendMessage(player, Colors.Rose + target.getName() + " is already the" + + " lowest rank."); + return EXIT_SUCCESS; + + } + + tarGroups[tarPos] = ranks[tarRank - 1]; + target.setGroups(tarGroups); + + //Make sure the player is in the files + FlatFileSource ffs = new FlatFileSource(); + if(!ffs.doesPlayerExist(target.getName())) + { + vChat.sendMessage(player, Colors.Rose + "Adding player."); + ffs.addPlayer(target); + } + else + { + ffs.modifyPlayer(target); + } + + vChat.sendMessage(player, Colors.Rose + target.getName() + + " has been demoted to " + ranks[tarRank - 1] + "."); + vChat.sendMessage(target, Colors.Rose + "You have been demoted to " + + ranks[tarRank - 1] + "."); + + return EXIT_SUCCESS; + } +} +class commandList { + ArrayList commands; + protected static final Logger log = Logger.getLogger("Minecraft"); + static final int EXIT_FAIL = 0, + EXIT_SUCCESS = 1, + EXIT_CONTINUE = 2; + + //===================================================================== + //Function: commandList + //Input: None + //Output: None + //Use: Initialize the array of commands + //===================================================================== + public commandList(){ + commands = new ArrayList(); + } + + //===================================================================== + //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) + { + //Check to make sure the command doesn't already exist + for(command temp : commands) + if(temp.getName().equalsIgnoreCase(name)) + return false; + + //Add the new function to the list + commands.add(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) + { + //Check to make sure the command doesn't already exist + for(command temp : commands) + if(temp.getName().equalsIgnoreCase(name)) + return false; + + //Add the new function to the list + commands.add(new commandRef(name, com)); + + //exit successfully + return true; + } + + //===================================================================== + //Function: registerMessage + //Input: String name: The name of the command + // String msg: The message to be displayed + // boolean admin: If the message is displayed to admins only + //Output: boolean: Whether the command was input successfully or not + //Use: Registers a command to the command list for checking later + //===================================================================== + public boolean registerMessage(String name, String msg, String clr, int args, boolean admin) + { + //Check to make sure the command doesn't already exist + for(command temp : commands) + if(temp.getName().equalsIgnoreCase(name)) + return false; + + //Add the new function to the list + commands.add(new commandAnnounce(name, msg, clr, args, admin)); + + //exit successfully + return true; + } + + //===================================================================== + //Function: call + //Input: String name: The name of the command to be run + // Player player: The player calling the command + // String[] arg: The arguments being input for the command + //Output: boolean: If the command was called successfully + //Use: Attempts to call a command + //===================================================================== + public int call(String name, Player player, String[] arg){ + //Search for the command + for(command cmd : commands) + { + //When found + if(cmd.getName().equalsIgnoreCase(name)) + { + try { + //Call the command and return results + return cmd.call(player, arg); + } catch (SecurityException e) { + log.log(Level.SEVERE, "Exception while running command", e); + } catch (IllegalArgumentException e) { + log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e); + return EXIT_FAIL; + } + } + } + + //Something went wrong + return EXIT_FAIL; + } + + //===================================================================== + //Function: toString + //Input: None + //Output: String: A string representation of the aliases in the list + //Use: Displays all the aliases in thel ist + //===================================================================== + public String toString() + { + String temp = ""; + int i = 0; + for(command comm : commands) + { + temp += comm.toString(); + if(i < commands.size() - 1) + temp +=","; + } + return temp; + } + + + + //===================================================================== + //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 + //===================================================================== + public String getName(){return commandName;} + + + //===================================================================== + //Function: call + //Input: String[] arg: The arguments for the command + //Output: boolean: If the command was called successfully + //Use: Attempts to call the command + //===================================================================== + int call(Player player, String[] arg) + { + + Method m; + try { + m = vCom.class.getMethod(function, Player.class, String[].class); + m.setAccessible(true); + return (Integer) m.invoke(null, player, arg); + } 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(); + } + return 1; + } + + //===================================================================== + //Function: toString + //Input: None + //Output: String: null + //Use: Returns null + //===================================================================== + public String toString() { return null; } + } + + //===================================================================== + //Class: commandRef + //Use: A command referencing another command + //Author: cerevisiae + //===================================================================== + private class commandRef extends command + { + private String reference; + private String[] args; + + //===================================================================== + //Function: command + //Input: String name: The command name + // String com: The command to run + //Output: None + //Use: Initialize the command + //===================================================================== + public commandRef(String name, String com){ + super(name, ""); + + //Get the reference name + String[]temp = com.split(" "); + reference = temp[0]; + + //Get the arguments + args = new String[temp.length - 1]; + System.arraycopy(temp, 1, args, 0, temp.length - 1); + } + + + //===================================================================== + //Function: call + //Input: String[] arg: The arguments for the command + //Output: boolean: If the command was called successfully + //Use: Attempts to call the command + //===================================================================== + int call(Player player, String[] arg) + { + String[] temp = new String[0]; + int lastSet = 0, + argCount = 0; + + //If there are args set with the function + if(args != null && args.length > 0) { + temp = new String[args.length]; + System.arraycopy(args, 0, temp, 0, args.length); + //Insert the arguments into the pre-set arguments + for(String argument : temp) + { + if(argument.startsWith("%") && argument.length() > 1) + { + int argNum = Integer.parseInt(argument.substring(1)); + if( argNum < arg.length ) + { + temp[lastSet] = arg[argNum]; + argCount++; + } + } + lastSet++; + } + } + + //If there are args being input + if(arg.length > 0) { + //Append the rest of the arguments to the argument array + if(lastSet < temp.length + arg.length - argCount) + { + String[] temp2 = new String[temp.length + arg.length - argCount]; + System.arraycopy(temp, 0, temp2, 0, temp.length); + System.arraycopy(arg, argCount, temp2, + temp.length, arg.length - argCount); + temp = temp2; + } + + log.log(Level.INFO, reference + " " + etc.combineSplit(0, temp, " ")); + //Call the referenced command + player.command(reference + " " + etc.combineSplit(0, temp, " ")); + } else + player.command(reference); + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: toString + //Input: None + //Output: String: A string representation of this command. + // command@referencedcommand arg1 arg2 argn + //Use: Returns the string representation of the alias + //===================================================================== + public String toString() + { + String temp = getName(); + temp += '@'; + temp += reference; + temp += etc.combineSplit(0, args, " "); + return temp; + } + } + + //===================================================================== + //Class: commandAnnounce + //Use: Announces when a command is used + //Author: cerevisiae + //===================================================================== + private class commandAnnounce extends command + { + private String message; + private boolean admin; + private int minArgs; + private String color; + + //===================================================================== + //Function: commandAnnounce + //Input: String name: The command name + // String msg: The message to announce + //Output: None + //Use: Initialize the command + //===================================================================== + public commandAnnounce(String name, String msg, String clr, int args, boolean admn){ + super(name, ""); + message = msg; + admin = admn; + minArgs = args; + color = clr; + } + + + //===================================================================== + //Function: call + //Input: String[] arg: The arguments for the command + //Output: boolean: If the command was called successfully + //Use: Attempts to call the command + //===================================================================== + int call(Player player, String[] arg) + { + //Make sure the player can use the command first + if(!player.canUseCommand(super.commandName)) return EXIT_FAIL; + + //Make sure the command is long enough to fire + if(minArgs < arg.length) + return EXIT_FAIL; + + if(vConfig.getInstance().globalmessages()) + { + //Split up the message + String[] temp = message.split(" "); + + //Insert the arguments into the message + int i = 0; + for(String argument : temp) + { + if(argument.startsWith("%") && argument.length() > 1) + { + char position = argument.charAt(1); + //Replace %p with the player name + if(position == 'p') + temp[i] = vChat.getName(player) + color; + else if( Character.isDigit(position) && Character.getNumericValue(position) < arg.length ) + { + //If the argument is specified to be a player insert it if the + //player is found or exit if they aren't + if(argument.length() > 2 && argument.charAt(2) == 'p') + { + Player targetName = etc.getServer().matchPlayer(arg[Character.getNumericValue(position)]); + if(targetName != null) + temp[i] = vChat.getName(targetName) + color; + else + return EXIT_FAIL; + } + //Replace %# with the argument at position # + else + temp[i] = arg[Character.getNumericValue(position)]; + } + } + i++; + } + message = etc.combineSplit(0, temp, " "); + + //If it's an admin message only + if(admin) + { + for (Player p: etc.getServer().getPlayerList()) { + //If p is not null + if (p != null) { + //And if p is an admin or has access to adminchat send message + if (p.isAdmin()) { + vChat.sendMessage(player, p, color + message); + } + } + } + } else + vChat.gmsg(player, message); + } + return EXIT_FAIL; + } + + //===================================================================== + //Function: toString + //Input: None + //Output: String: null + //Use: Returns null + //===================================================================== + public String toString() { return null; } + } +} \ No newline at end of file diff --git a/vConfig.java b/vConfig.java new file mode 100644 index 000000000..548d7ff3a --- /dev/null +++ b/vConfig.java @@ -0,0 +1,300 @@ +import java.io.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.logging.Level; +import java.util.logging.Logger; +//===================================================================== +//Class: vminecraftSettings +//Use: Controls the settings for vminecraft +//Author: nossr50, TrapAlice, cerevisiae +//===================================================================== +public class vConfig { + //private final static Object syncLock = new Object(); + protected static final Logger log = Logger.getLogger("Minecraft"); + private static volatile vConfig instance; + static int range; + + + //The feature settings + static boolean toggle = true, + adminChat = false, + greentext = false, + FFF = false, + quakeColors = false, + prefix = false, + suffix = false, + ignore = false, + colors = false, + nick = false, + playerspawn = false, + freeze = false, + lavaspread = false, + colorsrequirepermission = false, + cmdFabulous = false, + cmdPromote = false, + cmdDemote = false, + cmdWhoIs = false, + cmdRules = false, + cmdMasstp = false, + cmdTp = false, + cmdTphere = false, + globalmessages = false, + cmdSay = false, + cmdWho = false, + stopFire = false, + cmdHeal = false, + cmdSuicide = false, + cmdAdminToggle = false, + cmdEzModo = false; + //An array of players currently in ezmodo + static ArrayList ezModo = new ArrayList(); + //An array of players currently frozen + static ArrayList frozenplayers = new ArrayList(); + //An array of players currently toggled for admin chat + static ArrayList adminChatList = new ArrayList(); + //An array of blocks that won't catch on fire + static public ArrayList fireblockan; + + + private PropertiesFile properties; + String file = "vminecraft.properties"; + public String rules[] = new String[0]; + public static String deathMessages[] = new String[0]; + public static String ranks[] = new String[0]; + + + //===================================================================== + //Function: loadSettings + //Input: None + //Output: None + //Use: Loads the settings from the properties + //===================================================================== + public void loadSettings() + { + File theDir = new File("vminecraft.properties"); + if(!theDir.exists()){ + String location = "vminecraft.properties"; + properties = new PropertiesFile("vminecraft.properties"); + FileWriter writer = null; + try { + writer = new FileWriter(location); + writer.write("#This plugin is modular\r\n"); + writer.write("#Turn any features you don't want to false and they won't be running\r\n"); + writer.write("#If you edit this file and save it, then use /reload it will reload the settings\r\n"); + writer.write("#Chat Options\r\n"); + writer.write("#Allows the use of color codes following ^ symbol\r\n"); + writer.write("ColoredChat=true\r\n"); + writer.write("#Require per player permission for quakecolors\r\n"); + writer.write("colorsrequirepermissions=false\r\n"); + writer.write("#use /coloruse to give players permission if this is enabled\r\n"); + writer.write("#Text following a > will be colored green to mimic quoting of popular internet message boards\r\n"); + writer.write("QuotesAreGreen=true\r\n"); + writer.write("#Turns any chat message starting with FFF automagically blood red\r\n"); + writer.write("FFF=true\r\n"); + writer.write("\r\n"); + writer.write("#Admin Settings\r\n"); + writer.write("#Enables or disables players spawning to their home location\r\n"); + writer.write("playerspawn=true\r\n"); + writer.write("#Enables or disables the admin only chat\r\n"); + writer.write("adminchat=true\r\n"); + writer.write("#Lets non admins use admin chat if they have the /adminchat command permission\r\n"); + writer.write("/adminchat=true\r\n"); + writer.write("#Enables overriding of regular /tp and /tphere to make it so you can only teleport to players with lower permissions, and only bring players of lower permissions to you\r\n"); + writer.write("/tp=true\r\n"); + writer.write("/tphere=true\r\n"); + writer.write("#Mass Tp uses the same concept, anyone with this command only brings those with lower permissions to themselves\r\n"); + writer.write("/masstp=true\r\n"); + writer.write("\r\n"); + writer.write("#Server Settings\r\n"); + writer.write("#Enables or Disables the following commands, give groups/users permissions to use these commands for them to work\r\n"); + writer.write("/fabulous=true\r\n"); + writer.write("/prefix=true\r\n"); + writer.write("/freeze=true\r\n"); + writer.write("/suffix=true\r\n"); + writer.write("/ignore=true\r\n"); + writer.write("/colors=true\r\n"); + writer.write("/whois=true\r\n"); + writer.write("/nick=true\r\n"); + writer.write("/who=true\r\n"); + writer.write("/promote=true\r\n"); + writer.write("/demote=true\r\n"); + writer.write("/say=true\r\n"); + writer.write("/rules=true\r\n"); + writer.write("/suicide=true\r\n"); + writer.write("/ezmodo=true\r\n"); + writer.write("#Global Messages\r\n"); + writer.write("#Enable or Disable sending announcements about sensitive commands to the entire server\r\n"); + writer.write("globalmessages=true\r\n"); + writer.write("#Adding player names to this list will have them start off in ezmodo\r\n"); + writer.write("ezModo=\r\n"); + writer.write("#Stop fire from spreading\r\n"); + writer.write("stopFire=false\r\n"); + writer.write("#Stop lava from spreading fire"); + writer.write("lavaspread=false"); + writer.write("#Blocks disabled from fire"); + writer.write("fireblocks="); + writer.write("\r\n"); + writer.write("#Organize your player ranks from lowest to highest.\r\n"); + writer.write("ranks=\r\n"); + writer.write("#Write the rules to be shown when /rules is used here, it works just like the MOTD does\r\n"); + writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n"); + writer.write("#The Random Death messages, seperate them by comma. All death messages start with the player name and a space.\r\n"); + writer.write("deathMessages=is no more,died horribly,went peacefully\r\n"); + writer.write("hiddendistance=1024"); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while creating " + location, e); + } finally { + try { + if (writer != null) { + writer.close(); + } + } catch (IOException e) { + log.log(Level.SEVERE, "Exception while closing writer for " + location, e); + } + } + + } else { + properties = new PropertiesFile("vminecraft.properties"); + try { + properties.load(); + } catch (IOException e) { + log.log(Level.SEVERE, "Exception while loading vminecraft.properties", e); + } + } + + try { + adminChat = properties.getBoolean("adminchat",true); + playerspawn = properties.getBoolean("playerspawn",true); + greentext = properties.getBoolean("QuotesAreGreen",true); + FFF = properties.getBoolean("FFF",true); + quakeColors = properties.getBoolean("ColoredChat",true); + colorsrequirepermission = properties.getBoolean("colorsrequirepermission",true); + prefix = properties.getBoolean("prefix",true); + suffix = properties.getBoolean("suffix",true); + ignore = properties.getBoolean("ignore",true); + colors = properties.getBoolean("colors",true); + nick = properties.getBoolean("nick",true); + freeze = properties.getBoolean("/freeze",true); + cmdFabulous = properties.getBoolean("/fabulous",true); + cmdPromote = properties.getBoolean("/promote",true); + cmdDemote = properties.getBoolean("/demote",true); + cmdWhoIs = properties.getBoolean("/whois",true); + cmdWho = properties.getBoolean("/who",true); + cmdRules = properties.getBoolean("/rules",true); + cmdTp = properties.getBoolean("/tp",true); + cmdMasstp = properties.getBoolean("/masstp",true); + cmdTphere = properties.getBoolean("/tphere",true); + cmdSuicide = properties.getBoolean("/suicide", true); + cmdHeal = properties.getBoolean("/heal",true); + cmdAdminToggle = properties.getBoolean("/adminchat", true); + globalmessages = properties.getBoolean("globalmessages",true); + cmdSay = properties.getBoolean("/say",true); + cmdEzModo = properties.getBoolean("/ezmodo",true); + stopFire = properties.getBoolean("stopFire",true); + lavaspread = properties.getBoolean("lavaspread",true); + rules = properties.getString("rules", "").split("@"); + deathMessages = properties.getString("deathmessages", "").split(","); + String[] tempEz = properties.getString("ezModo").split(","); + String[] fireblocks = properties.getString("fireblocks").split(","); + fireblockan = new ArrayList(); + for(String str : fireblocks) + { + if(!str.isEmpty()) + fireblockan.add(Integer.parseInt(str)); + } + ezModo = new ArrayList(); + ezModo.addAll(Arrays.asList(tempEz)); + ranks = properties.getString("ranks").split(","); + range = properties.getInt("hiddendistance",1024); + log.log(Level.INFO, "vminecraft plugin successfully loaded"); + } + catch (Exception e) + { + log.log(Level.SEVERE, "vminecraft Error: ERROR LOADING PROPERTIES FILE {0}", e); + } + } + + //===================================================================== + //Function: adminchat, greentext, FFF, quakeColors, cmdFabulous, + // cmdPromote, cmdDemote, cmdWhoIs, cmdTp, cmdTphere, cmdSay + // cmdRules, globalmessages, cmdMasstp, cmdEzModo + //Input: None + //Output: Boolan: If the feature is enabled + //Use: Returns if the feature is enabled + //===================================================================== + public boolean adminchat() {return adminChat;} + public boolean adminChatToggle() {return cmdAdminToggle;} + public boolean greentext() {return greentext;} + public boolean FFF() {return FFF;} + public boolean quakeColors() {return quakeColors;} + public boolean prefix() {return prefix;} + public boolean suffix() {return suffix;} + public boolean ignore() {return ignore;} + public boolean colors() {return colors;} + public boolean nick() {return nick;} + public boolean playerspawn() {return playerspawn;} + public boolean colorsreq() {return colorsrequirepermission;} + public boolean freeze() {return freeze;} + public boolean cmdFabulous() {return cmdFabulous;} + public boolean cmdPromote() {return cmdPromote;} + public boolean cmdDemote() {return cmdDemote;} + public boolean cmdWhoIs() {return cmdWhoIs;} + public boolean cmdTp() {return cmdTp;} + public boolean cmdTphere() {return cmdTphere;} + public boolean cmdSay() {return cmdSay;} + public boolean cmdRules() {return cmdRules;} + public boolean globalmessages() {return globalmessages;} + public boolean cmdMasstp() {return cmdMasstp;} + public boolean cmdWho() {return cmdWho;} + public boolean stopFire() {return stopFire;} + public boolean lavaSpread() {return lavaspread;} + public boolean cmdSuicide() {return cmdSuicide;} + public boolean cmdHeal() {return cmdHeal;} + public ArrayList getFireBlockIds() {return fireblockan;} + public String[] getRanks() {return ranks;} + + //EzModo methods + public boolean cmdEzModo() {return cmdEzModo;} + public boolean isEzModo(String playerName) {return ezModo.contains(playerName);} + public boolean isFrozen(String playerName) {return frozenplayers.contains(playerName);} + public boolean isAdminToggled(String playerName) {return adminChatList.contains(playerName);} + public void removeEzModo(String playerName) {ezModo.remove(ezModo.indexOf(playerName));} + public void removeAdminToggled(String playerName) {adminChatList.remove(adminChatList.indexOf(playerName));} + public void addEzModo(String playerName) {ezModo.add(playerName);} + public void addAdminToggled(String playerName) {adminChatList.add(playerName);} + public void addFrozen(String playerName) {frozenplayers.add(playerName);} + public void removeFrozen (String playerName) {frozenplayers.remove(frozenplayers.indexOf(playerName));} + public String ezModoList() {return ezModo.toString();} + + //Random death message method + public static String randomDeathMsg() { + if (deathMessages == null) { + return "died"; + } + return deathMessages[ (int) (Math.random() * deathMessages.length)]; + } + + //===================================================================== + //Function: getInstance + //Input: None + //Output: vminecraftSettings: The instance of the settings + //Use: Returns the instance of the settings + //===================================================================== + public static vConfig getInstance() { + if (instance == null) { + instance = new vConfig(); + } + return instance; + } + + //===================================================================== + //Function: getRules + //Input: None + //Output: String[]: The list of rules + //Use: Gets the array containing the rules + //===================================================================== + public String[] getRules() { + return rules; + } + +} \ No newline at end of file diff --git a/vListener.java b/vListener.java new file mode 100644 index 000000000..9c2cd88bd --- /dev/null +++ b/vListener.java @@ -0,0 +1,187 @@ +import java.util.logging.Level; +import java.util.logging.Logger; +//===================================================================== +//Class: vMinecraftListener +//Use: The listener to catch incoming chat and commands +//Author: nossr50, TrapAlice, cerevisiae +//===================================================================== +public class vListener extends PluginListener { + protected static final Logger log = Logger.getLogger("Minecraft"); + + //===================================================================== + //Function: disable + //Input: None + //Output: None + //Use: Disables vMinecraft, but why would you want to do that? ;) + //===================================================================== + public void disable() { + log.log(Level.INFO, "vMinecraft disabled"); + } + public void onPlayerMove(Player player, Location from, Location to) { + if(vConfig.getInstance().isFrozen(player.getName())){ + player.teleportTo(from); + } + vCom.updateInvisibleForAll(); + } + + //===================================================================== + //Function: onChat + //Input: Player player: The player calling the command + // String message: The message to color + //Output: boolean: If the user has access to the command + // and it is enabled + //Use: Checks for quote, rage, and colors + //===================================================================== + + public boolean onChat(Player player, String message){ + + //Quote (Greentext) + if (message.startsWith("@") || + vConfig.getInstance().isAdminToggled(player.getName())) + return vChat.adminChat(player, message); + + else if (message.startsWith(">")) + return vChat.quote(player, message); + + //Rage (FFF) + else if (message.startsWith("FFF")) + return vChat.rage(player, message); + + //Send through quakeColors otherwise + else + return vChat.quakeColors(player, message); + } + + //===================================================================== + //Function: onCommand + //Input: Player player: The player calling the command + // String[] split: The arguments + //Output: boolean: If the user has access to the command + // and it is enabled + //Use: Checks for exploits and runs the commands + //===================================================================== + public boolean onCommand(Player player, String[] split) { + + //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 + int exitCode = vCom.cl.call(split[0], player, args); + if(exitCode == 0) + return false; + else if(exitCode == 1) + return true; + else + return false; + + } + + //===================================================================== + //Function: onHealthChange + //Input: Player player: The player calling the command + // int oldValue: The old health value; + // int newValue: The new health value + //Output: boolean: If the user has access to the command + // and it is enabled + //Use: Checks for exploits and runs the commands + //===================================================================== + public boolean onHealthChange(Player player,int oldValue,int newValue){ + + //Sets a player as dead + if (player.getHealth() < 1){ + vUsers.getProfile(player).isDead(true); + } + if (player.getHealth() > 1 && vUsers.getProfile(player).isDead()){ + if(vConfig.getInstance().playerspawn()) + { + Warp home = null; + if (etc.getDataSource().getHome(player.getName()) != null){ + home = etc.getDataSource().getHome(player.getName()); + player.teleportTo(home.Location); + player.sendMessage(Colors.DarkPurple + "Return here with /myspawn"); + player.sendMessage(Colors.DarkPurple + "The penalty for returning is the loss of inventory"); + } + if(player.canUseCommand("/sethome")) + player.sendMessage(Colors.DarkPurple + "Set your own spawn with /sethome"); + } + vUsers.getProfile(player).isDead(false); + if(!vUsers.getProfile(player).isSilent()) + vChat.gmsg(Colors.Gray + player.getName() + " " + vConfig.randomDeathMsg()); + } + return false; + } + + public void onLogin(Player player){ + vChat.sendMessage(player, player, Colors.Rose + "There are currently " + etc.getServer().getPlayerList().size() + " players online."); + vUsers.addUser(player); + } + + public void onDisconnect(Player player){ + vUsers.removeUser(player); + } + + public boolean onIgnite(Block block, Player player) { + + if(vConfig.getInstance().stopFire()){ + //There are 3 ways fire can spread + //1 = lava, 2 = lighter, 3 = spread (other fire blocks) + //Stop lava from spreading + if(block.getStatus() == 1 && vConfig.getInstance().lavaSpread()){ + return true; + } + //Stop fire from spreading fire + if (block.getStatus() == 3 && vConfig.getInstance().stopFire()){ + return true; + } + //Checking to see if any of the blocks fire is trying to spread to is on the "fireblockan" list + if (block.getStatus() == 3){ + int x, + y, + z, + g; + x = block.getX(); + y = block.getY(); + z = block.getZ(); + //Finding out the blockid of the current blocks fire is trying to spread to + int blockid = etc.getServer().getBlockIdAt(x, y, z); + //Check to see the blockid doesn't match anything on the list + for(x = 0; x >= vConfig.fireblockan.size(); x++){ + if (vConfig.fireblockan.get(x) == blockid){ + return true; + } + } + + } + //Stop players without permission from being able to set fires + if(block.getStatus() == 2 && !player.canUseCommand("/flint")){ + return true; + } + } + return false; + } + + public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { + //Invincibility for EzModo players + if(defender.isPlayer()){ + Player dplayer = defender.getPlayer(); + if(vConfig.getInstance().isEzModo(dplayer.getName())){ + return true; + } + if(attacker != null && attacker.isPlayer()){ + Player aplayer = attacker.getPlayer(); + if(vUsers.getProfile(dplayer).inParty()){ + if(vmc.inSameParty(aplayer, dplayer)){ + return true; + } else{ + return false; + } + } + else { + return false; + } + } + } + return false; + } +} diff --git a/vMinecraft.java b/vMinecraft.java index c4376659e..ab1770907 100644 --- a/vMinecraft.java +++ b/vMinecraft.java @@ -6,13 +6,13 @@ import java.util.logging.Logger; //Author: nossr50, TrapAlice, cerevisiae //===================================================================== public class vMinecraft extends Plugin { - static final vMinecraftListener listener = new vMinecraftListener(); + static final vListener listener = new vListener(); protected static final Logger log = Logger.getLogger("Minecraft"); public void enable() { - vMinecraftSettings.getInstance().loadSettings(); - vMinecraftUsers.getInstance().loadUsers(); - vMinecraftCommands.loadCommands(); + vConfig.getInstance().loadSettings(); + vUsers.getInstance().loadUsers(); + vCom.loadCommands(); } public void disable() { diff --git a/vUsers.java b/vUsers.java new file mode 100644 index 000000000..a9f33cbf5 --- /dev/null +++ b/vUsers.java @@ -0,0 +1,633 @@ +import java.io.*; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; + + +//===================================================================== +//Class: PlayerList +//Use: Encapsulates the player list +//Author: cerevisiae +//===================================================================== +public class vUsers { + private static volatile vUsers instance; + protected static final Logger log = Logger.getLogger("Minecraft"); + private PropertiesFile properties; + String location = "vminecraft.users"; + + public static PlayerList players = new PlayerList(); + + + public void loadUsers(){ + File theDir = new File(location); + if(!theDir.exists()){ + properties = new PropertiesFile(location); + FileWriter writer = null; + try { + writer = new FileWriter(location); + writer.write("#Storage place for user information\r\n"); + writer.write("#username:nickname:suffix:tag:ignore,list,names:alias,commands,here\r\n"); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while creating " + location, e); + } finally { + try { + if (writer != null) { + writer.close(); + } + } catch (IOException e) { + log.log(Level.SEVERE, "Exception while closing writer for " + location, e); + } + } + + } else { + properties = new PropertiesFile(location); + try { + properties.load(); + } catch (IOException e) { + log.log(Level.SEVERE, "Exception while loading " + location, e); + } + } + } + + //===================================================================== + //Function: addUser + //Input: Player player: The player to create a profile for + //Output: none + //Use: Loads the profile for the specified player + //===================================================================== + public static void addUser(Player player){ + players.addPlayer(player); + } + + //===================================================================== + //Function: removeUser + //Input: Player player: The player to stop following + //Output: none + //Use: Creates the player profile + //===================================================================== + public static void removeUser(Player player){ + players.removePlayer(player); + } + + //===================================================================== + //Function: getProfile + //Input: Player player: The player to find the profile for + //Output: PlayerList.PlayerProfile: The profile + //Use: Gets the player profile + //===================================================================== + public static PlayerList.PlayerProfile getProfile(Player player){ + return players.findProfile(player); + } + + public static vUsers getInstance() { + if (instance == null) { + instance = new vUsers(); + } + return instance; + } + public static void getRow(){ + + } +} +class PlayerList +{ + protected static final Logger log = Logger.getLogger("Minecraft"); + ArrayList players; + + //===================================================================== + //Function: PlayerList + //Input: Player player: The player to create a profile object for + //Output: none + //Use: Initializes the ArrayList + //===================================================================== + public PlayerList() { players = new ArrayList(); } + + //===================================================================== + //Function: addPlayer + //Input: Player player: The player to add + //Output: None + //Use: Add a profile of the specified player + //===================================================================== + public void addPlayer(Player player) + { + players.add(new PlayerProfile(player)); + } + + //===================================================================== + //Function: removePlayer + //Input: Player player: The player to remove + //Output: None + //Use: Remove the profile of the specified player + //===================================================================== + public void removePlayer(Player player) + { + players.remove(findProfile(player)); + } + + //===================================================================== + //Function: findProfile + //Input: Player player: The player to find's profile + //Output: PlayerProfile: The profile of the specified player + //Use: Get the profile for the specified player + //===================================================================== + public PlayerProfile findProfile(Player player) + { + for(PlayerProfile ply : players) + { + if(ply.isPlayer(player)) + return ply; + } + return null; + } + + //===================================================================== + //Class: PlayerProfile + //Use: Encapsulates all commands for player options + //Author: cerevisiae + //===================================================================== + class PlayerProfile + { + protected final Logger log = Logger.getLogger("Minecraft"); + private String playerName, + lastMessage, + nickName, + tag, + suffix, + party, + tpxyz; + + private boolean dead, + silent; + + char defaultColor; + + String location = "vminecraft.users"; + + private ArrayList ignoreList; + private commandList aliasList; + + static final int EXIT_FAIL = 0, + EXIT_SUCCESS = 1, + EXIT_CONTINUE = 2; + + //===================================================================== + //Function: PlayerProfile + //Input: Player player: The player to create a profile object for + //Output: none + //Use: Loads settings for the player or creates them if they don't + // exist. + //===================================================================== + public PlayerProfile(Player player) + { + //Declare things + playerName = player.getName(); + tag = new String(); + nickName = new String(); + suffix = new String(); + tpxyz = new String(); + party = new String(); + party = null; + defaultColor = 'f'; + ignoreList = new ArrayList(); + aliasList = new commandList(); + dead = false; + + //Try to load the player and if they aren't found, append them + if(!load()) + addPlayer(); + } + + public boolean load() + { + try { + //Open the user file + FileReader file = new FileReader(location); + BufferedReader in = new BufferedReader(file); + String line = ""; + while((line = in.readLine()) != null) + { + //Find if the line contains the player we want. + String[] character = line.split(":"); + if(!character[0].equals(playerName)){continue;} + + //Get the tag + if(character.length > 1) + tag = character[1]; + //Get the nickname + if(character.length > 2) + nickName = character[2]; + //Get the suffix + if(character.length > 3) + suffix = character[3]; + //Get the color + if(character.length > 4) + defaultColor = character[4].charAt(0); + //Ignore previously ignored players + if(character.length > 5) + { + String[] ignores = character[5].split(","); + if(ignores.length > 0) + { + for(String ignore : ignores) + ignoreList.add(ignore); + } + } + //Register the aliases + if(character.length > 6) + { + String[] allAliases = character[6].split(","); + if(allAliases.length > 0) + { + for(String singleAlias : allAliases) + { + String[] parts = singleAlias.split("@"); + if(parts.length > 1) + { + aliasList.registerAlias(parts[0], parts[1]); + } + } + } + } + //XYZ TP Back value + //Not sure if declaring a double this way will work or not + if(character.length > 7) + { + tpxyz = character[7]; + } + in.close(); + return true; + } + in.close(); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while reading " + + location + " (Are you sure you formatted it correctly?)", e); + } + return false; + } + + //===================================================================== + // Function: save + // Input: none + // Output: None + // Use: Writes current values of PlayerProfile to disk + // Call this function to save current values + //===================================================================== + public void save() + { + try { + //Open the file + FileReader file = new FileReader(location); + BufferedReader in = new BufferedReader(file); + StringBuilder writer = new StringBuilder(); + String line = ""; + + //While not at the end of the file + while((line = in.readLine()) != null) + { + //Read the line in and copy it to the output it's not the player + //we want to edit + if(!line.split(":")[0].equalsIgnoreCase(playerName)) + { + writer.append(line).append("\r\n"); + + //Otherwise write the new player information + } else { + writer.append(playerName + ":"); + writer.append(tag + ":"); + writer.append(nickName + ":"); + writer.append(suffix + ":"); + writer.append(defaultColor + ":"); + + int i = 0; + for(String ignore : ignoreList) + { + writer.append(ignore); + if(i < ignoreList.size() - 1) + writer.append(","); + } + writer.append(":"); + writer.append(aliasList.toString()); + writer.append(tpxyz.toString()); + writer.append("\r\n"); + } + } + in.close(); + + + //Write the new file + FileWriter out = new FileWriter(location); + out.write(writer.toString()); + out.close(); + + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e); + } + } + + public void addPlayer() + { + try { + //Open the file to write the player + FileWriter file = new FileWriter(location, true); + BufferedWriter out = new BufferedWriter(file); + + //Add the player to the end + out.append(playerName + ":"); + out.append(tag + ":"); + out.append(nickName + ":"); + out.append(suffix + ":"); + out.append(defaultColor + ":"); + + + int i = 0; + for(String ignore : ignoreList) + { + out.append(ignore); + if(i < ignoreList.size() - 1) + out.append(","); + } + out.append(":"); + out.append(tpxyz + ":"); + + out.append(aliasList.toString()); + out.newLine(); + out.close(); + + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e); + } + } + + //===================================================================== + //Function: isPlayer + //Input: None + //Output: Player: The player this profile belongs to + //Use: Finds if this profile belongs to a specified player + //===================================================================== + public boolean isPlayer(Player player) + { + return player.getName().equals(playerName); + } + + //===================================================================== + //Function: isIgnored + //Input: Player player: Checks if a player is ignored + //Output: boolean: If they're ignored + //Use: Finds if the specified player is in the ignore list + //===================================================================== + public boolean isIgnored(Player player){ + return ignoreList.contains(player.getName()); + } + + //===================================================================== + //Function: addIgnore + //Input: Player name: The player to ignore + //Output: boolean: If the player was successfully ignored + //Use: Ignores a player. + //===================================================================== + public boolean addIgnore(Player name) + { + if(!ignoreList.contains(name)) + { + ignoreList.add(name.getName()); + save(); + return true; + } + return false; + } + + //===================================================================== + //Function: removeIgnore + //Input: Player name: The player to unignore + //Output: boolean: If the player was successfully unignored + //Use: Stops ignoring a player. + //===================================================================== + public boolean removeIgnore(Player name) + { + if(ignoreList.contains(name.getName())) + { + ignoreList.remove(name.getName()); + save(); + return true; + } + return false; + } + + //===================================================================== + //Function: removeIgnore + //Input: Player name: The player to unignore + //Output: boolean: If the player was successfully unignored + //Use: Stops ignoring a player. + //===================================================================== + public String[] listIgnore() + { + return ignoreList.toArray(new String[ignoreList.size()]); + } + + //===================================================================== + //Function: addAlias + //Input: String command: The command to try to call + // String[] args: The arguments for the command + //Output: None + //Use: Adds a command + //===================================================================== + public void addAlias(String name, String callCommand) + { + aliasList.registerAlias(name, callCommand); + save(); + } + + //===================================================================== + //Function: callAlias + //Input: String command: The command to try to call + // Player player: Checks if a player is ignored + // String[] args: The arguments for the command + //Output: int: Exit code + //Use: Attempts to call a command + //===================================================================== + public int callAlias(String command, Player player, String[] args) + { + try + { + //Attemt to call the function + return aliasList.call(command, player, args); + } + catch (Throwable e) + { + //The function wasn't found, returns fail + return EXIT_FAIL; + } + } + + //===================================================================== + //Function: setTag + //Input: String newTag: The tag to set for the player + //Output: None + //Use: Sets a player tag + //===================================================================== + public void setTag(String newTag) + { + tag = newTag; + save(); + } + //===================================================================== + //Function: setTpback + //Input: None + //Output: None + //Use: Sets a player's tpback xyz coordinates + //===================================================================== + public void setTpback(String newtpback) + { + tpxyz = newtpback; + save(); + } + //===================================================================== + //Function: getTpxyz + //Input: None + //Output: Double: The player's tpback x coords + //Use: Gets the x value of tpback + //===================================================================== + public String getTpxyz() + { + return tpxyz; + } + //Function: getTag + //Input: None + //Output: String: The player tag + //Use: Gets a player tag + //===================================================================== + public String getTag() { return tag; } + + //===================================================================== + //Function: setNick + //Input: String newTag: The nickname to set for the player + //Output: None + //Use: Sets a player nickname + //===================================================================== + public void setNick(String newNick) + { + nickName = newNick; + save(); + } + + public void setSilent(){ + silent = true; + } + public void disableSilent(){ + silent = false; + } + public boolean isSilent(){ + return silent; + } + //Store the player's party + public void setParty(String newParty) + { + party = newParty; + save(); + } + //Retrieve the player's party + public String getParty() {return party;} + //Remove party + public void removeParty() { + party = null; + save(); + } + //Retrieve whether or not the player is in a party + public boolean inParty() { + if(party != null){ + return true; + } else { + return false; + } + } + + //===================================================================== + //Function: getNick + //Input: None + //Output: String: The player nickname + //Use: Gets a player nickname + //===================================================================== + public String getNick() { return nickName; } + + //===================================================================== + //Function: setSuffix + //Input: String newTag: The suffix to set for the player + //Output: None + //Use: Sets a player suffix + //===================================================================== + public void setSuffix(String newSuffix) + { + suffix = newSuffix; + save(); + } + + //===================================================================== + //Function: getSuffix + //Input: None + //Output: String: The player suffix + //Use: Gets a player suffix + //===================================================================== + public String getSuffix() { return suffix; } + + //===================================================================== + //Function: setColor + //Input: String newTag: The color to set for the player + //Output: None + //Use: Sets a player color + //===================================================================== + public void setColor(String newColor) + { + defaultColor = newColor.charAt(0); + save(); + } + + //===================================================================== + //Function: getColor + //Input: None + //Output: String: The player color + //Use: Gets a player color + //===================================================================== + public String getColor() {return vChat.colorChange(defaultColor);} + + //===================================================================== + //Function: setMessage + //Input: String newName: The name of the player they last messaged + // or recieved a message from. + //Output: None + //Use: Sets a player tag + //===================================================================== + public void setMessage(Player newName){ lastMessage = newName.getName(); } + + //===================================================================== + //Function: getMessage + //Input: None + //Output: String: The player name + //Use: Gets the name of the player they last messaged or recieved + // a message from. + //===================================================================== + public Player getMessage() + { + if(lastMessage != null) + return etc.getServer().matchPlayer(lastMessage); + return null; + } + + //===================================================================== + //Function: isDead + //Input: None + //Output: boolean: If the player is dead or not + //Use: Gets the player is dead or not. + //===================================================================== + public boolean isDead() {return dead;} + + //===================================================================== + //Function: isDead + //Input: boolean isded: if the player is dead or not. + //Output: None + //Use: Sets if the player is dead or not + //===================================================================== + public void isDead(boolean isded){dead = isded;} + } +} + + diff --git a/vmc.java b/vmc.java new file mode 100644 index 000000000..453a1ad84 --- /dev/null +++ b/vmc.java @@ -0,0 +1,38 @@ +public class vmc { + + //Check if two players are in the same party + public static boolean inSameParty(Player playera, Player playerb){ + if(vUsers.getProfile(playera).getParty().equals(vUsers.getProfile(playerb).getParty())){ + return true; + } else { + return false; + } + } + //Get the distance between two players + public static double getDistance(Player player1, Player player2) + { + return Math.sqrt(Math.pow(player1.getX() - player2.getX(), 2) + Math.pow(player1.getY() - player2.getY(), 2) + + Math.pow(player1.getZ() - player2.getZ(), 2)); + } + //Send the "invisibility" toggle to players near the hidden player + public static void sendInvisible(Player player){ + for (Player p : etc.getServer().getPlayerList()) + { + if (vmc.getDistance(player, p) <= vConfig.range && p.getUser() != player.getUser()) + { + p.getUser().a.b(new dv(player.getUser().g)); + } + } + } + //Send "visibility" toggle to invisible players turning them back to normal + public static void sendNotInvisible(Player player){ + for (Player p : etc.getServer().getPlayerList()) + { + if (vmc.getDistance(player, p) < vConfig.range && p.getUser() != player.getUser()) + { + p.getUser().a.b(new d(player.getUser())); + } + } + } + +}