From 3c316c1cca1035c3bd3c2941d02e57d22f9f5f1b Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sat, 27 Nov 2010 04:35:23 -0800 Subject: [PATCH 01/82] Added a simple death detection and global message when a player dies. Signed-off-by: nossr50 --- settings.java | 6 +++- vminecraftListener.java | 68 ++++++++++++++++++++++++++++++++--------- vminecraftPlugin.java | 15 +++++++-- 3 files changed, 71 insertions(+), 18 deletions(-) diff --git a/settings.java b/settings.java index 3bd99a48d..be2adad89 100644 --- a/settings.java +++ b/settings.java @@ -21,11 +21,12 @@ public class settings { private boolean cmdTphere = false; private boolean globalmessages = false; private boolean cmdSay = false; + private boolean cmdEzModo = false; private PropertiesFile properties; String file = "vminecraft.properties"; public String rules[] = null; - public void loadSettings() + public void loadSettings() throws IOException { File theDir = new File("vminecraft.properties"); if(!theDir.exists()) @@ -52,6 +53,7 @@ public class settings { writer.write("globalmessages=true\r\n"); writer.write("FFF=true\r\n"); writer.write("adminchat=true\r\n"); + writer.write("cmdEzModo=true\r\n"); writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n"); } catch (Exception e) { log.log(Level.SEVERE, "Exception while creating " + location, e); @@ -86,6 +88,7 @@ public class settings { cmdTphere = properties.getBoolean("cmdTphere",true); globalmessages = properties.getBoolean("globalmessages",true); cmdSay = properties.getBoolean("cmdSay",true); + cmdEzModo = properties.getBoolean("cmdEzModo",true); rules = properties.getString("rules", "").split("@"); log.log(Level.INFO, "vminecraft plugin successfully loaded"); @@ -110,6 +113,7 @@ public class settings { public boolean cmdRules() {return cmdRules;} public boolean globalmessages() {return globalmessages;} public boolean cmdMasstp() {return cmdMasstp;} + public boolean cmdEzModo() {return cmdEzModo;} public static settings getInstance() { if (instance == null) { diff --git a/vminecraftListener.java b/vminecraftListener.java index f1dc12b58..ec5aa8f52 100644 --- a/vminecraftListener.java +++ b/vminecraftListener.java @@ -1,25 +1,36 @@ //Vminecraft plugin by nossr50 & TrapAlice +import java.io.IOException; +import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; public class vminecraftListener extends PluginListener { protected static final Logger log = Logger.getLogger("Minecraft"); - public void disable() { - log.log(Level.INFO, "vminecraft disabled"); - } + private ArrayList ezmodo = new ArrayList(); //An array of players currently in ezmodo - public void enable() { + public void enable() throws IOException { settings.getInstance().loadSettings(); //Load the settings files + if (etc.getInstance().isHealthEnabled()){ + etc.getInstance().addCommand("/ezmodo", "Toggle invulnerability"); + } log.log(Level.INFO, "vminecraft enabled"); } - public void onPlayerMove () { - if (ezmodo.contains(player.getName())){ - if (player.getHealth() < 30) - { - player.setHealth(30); - } - } + public void disable() { + log.log(Level.INFO, "vminecraft disabled"); + if (etc.getInstance().isHealthEnabled()) { + etc.getInstance().removeCommand("/ezmodo"); + } + } + + public boolean onHealthChange(Player player,int oldValue,int newValue){ + if (player.getHealth() != 30 && ezmodo.contains(player.getName())) { + player.setHealth(30); + } + else if (settings.getInstance().globalmessages() && player.getHealth() < 1) { + other.gmsg(Colors.Gray + player.getName() + " is no more"); + } + return false; } public boolean onChat(Player player, String message){ String temp2 = "<" + player.getColor() + player.getName() + Colors.White +"> "; //Copies the formatting of id.java @@ -101,11 +112,34 @@ import java.util.logging.Logger; } player.sendMessage(Colors.Blue+"Summoning successful."); } - //ezmodo - if (split[0].equals("/ezmodo")) { + //Disable using /modify to add commands (need to make a boolean settings for this) + if(split[0].equals("/modify") && split[2].equals("commands")) { + return true; + } + //ezlist + if(settings.getInstance().cmdEzModo() && split[0].equals("/ezlist")) { + player.sendMessage("Ezmodo: " + ezmodo); + return true; + } + //slay + if(settings.getInstance().cmdEzModo() && split[0].equals("/slay")) { + Player playerTarget = etc.getServer().matchPlayer(split[1]); + if (!ezmodo.contains(playerTarget.getName())) { + playerTarget.setHealth(0); + other.gmsg(player.getColor() + player.getName() + Colors.LightBlue + " has slain " + playerTarget.getColor() + playerTarget.getName()); + return true; + } + else { + player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha"); + return true; + } + } + //ezmodo + if (settings.getInstance().cmdEzModo() && split[0].equals("/ezmodo")) { if (ezmodo.contains(player.getName())) { player.sendMessage(Colors.Red + "ezmodo = off"); ezmodo.remove(ezmodo.indexOf(player.getName())); + return true; } else { player.sendMessage(Colors.LightBlue + "eh- maji? ezmodo!?"); player.sendMessage(Colors.Rose + "kimo-i"); @@ -113,8 +147,8 @@ import java.util.logging.Logger; player.sendMessage(Colors.Red + "**Laughter**"); ezmodo.add(player.getName()); player.setHealth(30); + return true; } - return true; } //Replacement for /tp if(settings.getInstance().cmdTp() && split[0].equalsIgnoreCase("/tp")) { @@ -198,7 +232,11 @@ import java.util.logging.Logger; } //Should only reload vminecraft settings if the player is able to use /reload if(split[0].equalsIgnoreCase("/reload") && player.canUseCommand("/reload")) { - settings.getInstance().loadSettings(); + try { + settings.getInstance().loadSettings(); + } catch (IOException ex) { + Logger.getLogger(vminecraftListener.class.getName()).log(Level.SEVERE, null, ex); + } return false; } //Rules diff --git a/vminecraftPlugin.java b/vminecraftPlugin.java index adfe72a6d..855d49bc3 100644 --- a/vminecraftPlugin.java +++ b/vminecraftPlugin.java @@ -1,3 +1,8 @@ + +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; + /** * vminecraft Plugin * @author Robert, TrapAlice @@ -5,14 +10,17 @@ //This is how we setup the listener public class vminecraftPlugin extends Plugin { static final vminecraftListener listener = new vminecraftListener(); - public void enable() { //If we had commands we would add them here. etc.getInstance().addCommand("/masstp", "Teleports those with lower permissions to you"); etc.getInstance().addCommand("/rules", "Displays the rules"); etc.getInstance().addCommand("/fabulous", "makes text SUUUPER"); etc.getInstance().addCommand("/whois", "/whois [user]"); - settings.getInstance().loadSettings(); //Hopefully this will make the plugin load right away + try { + settings.getInstance().loadSettings(); //Hopefully this will make the plugin load right away + } catch (IOException ex) { + Logger.getLogger(vminecraftPlugin.class.getName()).log(Level.SEVERE, null, ex); + } } public void disable() { @@ -23,5 +31,8 @@ public class vminecraftPlugin extends Plugin { //Here we add the hook we're going to use. In this case it's the arm swing event. etc.getLoader().addListener(PluginLoader.Hook.CHAT, listener, this, PluginListener.Priority.MEDIUM); etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH); + if(etc.getInstance().isHealthEnabled()){ + etc.getLoader().addListener(PluginLoader.Hook.HEALTH_CHANGE, listener, this, PluginListener.Priority.MEDIUM); + } } } From 96ed2b100bf0606020a6f512371b317fee5e4db5 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 28 Nov 2010 01:10:14 -0600 Subject: [PATCH 02/82] Reorganized a lot of code. Added tons of comments. Change how commands are added. Encapsulated commands into their own functions. Modified some commands. Recoded others. Added personalized /who that shows name colors. --- vminecraftAnnouncements.java | 53 +++ vminecraftChat.java | 281 ++++++++++++ vminecraftCommands.java | 819 +++++++++++++++++++++++++++++++++++ vminecraftListener.java | 519 ++++------------------ vminecraftPlugin.java | 36 +- vminecraftSettings.java | 190 ++++++++ 6 files changed, 1436 insertions(+), 462 deletions(-) create mode 100644 vminecraftAnnouncements.java create mode 100644 vminecraftChat.java create mode 100644 vminecraftCommands.java create mode 100644 vminecraftSettings.java diff --git a/vminecraftAnnouncements.java b/vminecraftAnnouncements.java new file mode 100644 index 000000000..8f7f14700 --- /dev/null +++ b/vminecraftAnnouncements.java @@ -0,0 +1,53 @@ +//===================================================================== +//Class: vMinecraftAnnouncements +//Use: Encapsulates all announcements broadcast when commands are +// run +//Author: nossr50, TrapAlice, cerevisiae +//===================================================================== +public class vminecraftAnnouncements { + + //===================================================================== + //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 if /kick, /ban, /ipban, and /time are run and + // displays a global message + //===================================================================== + public boolean onCommand(Player player, String[] split) { + if(!player.canUseCommand(split[0])) { + return false; + } + //Only run if the global message feature is enabled + if(vminecraftSettings.getInstance().globalmessages()) + { + //Global messages that should only parse when a command can be successful + if(split[0].equalsIgnoreCase("/kick")) { + Player playerTarget = etc.getServer().matchPlayer(split[1]); + if (playerTarget != null && !playerTarget.hasControlOver(player)) { + vminecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has kicked "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); + } + } + if(split[0].equalsIgnoreCase("/ban")) { + Player playerTarget = etc.getServer().matchPlayer(split[1]); + if (playerTarget != null && !playerTarget.hasControlOver(player)) { + vminecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); + } + } + if(split[0].equalsIgnoreCase("/ipban")) { + Player playerTarget = etc.getServer().matchPlayer(split[1]); + if (playerTarget != null && !playerTarget.hasControlOver(player)) { + vminecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has IP banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); + } + } + if(split[0].equalsIgnoreCase("/time")) { + if (split.length <= 2) { + vminecraftChat.gmsg(Colors.Blue+"Time changes thanks to "+player.getColor()+player.getName()); + } + } + } + + return true; + } +} diff --git a/vminecraftChat.java b/vminecraftChat.java new file mode 100644 index 000000000..b62365350 --- /dev/null +++ b/vminecraftChat.java @@ -0,0 +1,281 @@ +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 vminecraftChat { + protected static final Logger log = Logger.getLogger("Minecraft"); + + //===================================================================== + //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){ + for (Player p : etc.getServer().getPlayerList()) { + if (p != null) { + p.sendMessage(msg); + } + } + } + + //===================================================================== + //Function: nameColor + //Input: Player player: The player to get name as color + //Output: String: The name colored + //Use: Returns the colored name; + //===================================================================== + public static String nameColor(Player player){ + return player.getColor() + player.getName(); + } + + //===================================================================== + //Function: colorChange + //Input: char colour: The color code to find the color for + //Output: String: The color that the code identified + //Use: Finds a color giving a color code + //===================================================================== + public static String colorChange(char colour) + { + String color = ""; + switch(colour) + { + case '0': + color = Colors.Black; + break; + case '1': + color = Colors.Navy; + break; + case '2': + color = Colors.Green; + break; + case '3': + color = Colors.Blue; + break; + case '4': + color = Colors.Red; + break; + case '5': + color = Colors.Purple; + break; + case '6': + color = Colors.Gold; + break; + case '7': + color = Colors.LightGray; + break; + case '8': + color = Colors.Gray; + break; + case '9': + color = Colors.DarkPurple; + break; + case 'a': + color = Colors.LightGreen; + break; + case 'b': + color = Colors.LightBlue; + break; + case 'c': + color = Colors.Rose; + break; + case 'd': + color = Colors.LightPurple; + break; + case 'e': + color = Colors.Yellow; + break; + case 'f': + color = Colors.White; + break; + case 'A': + color = Colors.LightGreen; + break; + case 'B': + color = Colors.LightBlue; + break; + case 'C': + color = Colors.Rose; + break; + case 'D': + color = Colors.LightPurple; + break; + case 'E': + color = Colors.Yellow; + break; + case 'F': + color = Colors.White; + break; + default: + color = Colors.White; + break; + } + return color; + } + + //===================================================================== + //Function: lengthCheck + //Input: String str: The message to make sure isn't too long + //Output: boolean: If the message is too long + //Use: Check if a message is too long + //===================================================================== + public static boolean lengthCheck(String str) + { + int length = 0; + for(int x = 0; x\"*()".indexOf(str.charAt(x)) != -1) + { + length+=5; + } + else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1) + { + length+=6; + } + else if("@~".indexOf(str.charAt(x)) != -1) + { + length+=7; + } + else if(str.charAt(x)==' ') + { + length+=4; + } + } + if(length<=316) + { + return true; + } else { return false; } + + } + + //===================================================================== + //Function: adminChat + //Input: Player player: The player talking + // String message: The message to apply the effect to + //Output: boolean: If this feature is enabled + //Use: Sends messages only to admins + //===================================================================== + public static boolean adminChat(Player player, String message){ + + //Check if the player can use this feature + if(player.isAdmin() || player.canUseCommand("/adminchat")) + { + //Special formatting for adminchat {Username} + String adminchat = Colors.DarkPurple + "{" + player.getColor() + + player.getName() + Colors.DarkPurple +"}" + Colors.White + " "; + + //Get the player from the playerlist to send the message to. + 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 + if (p.isAdmin() || (p.canUseCommand("/adminchat"))) { + + //Send them the message + p.sendMessage(adminchat + + message.substring(1, message.length())); + } + } + } + + //So you can read adminchat from the server console + log.log(Level.INFO, "@" + "<" + nameColor(player) + + Colors.White +"> " + 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 = "<" + nameColor(player) + Colors.White +"> "; + if(vminecraftSettings.getInstance().greentext()) { + //Log the chat + log.log(Level.INFO, "<"+player.getName()+"> "+message); + //Output the message + gmsg(playerName + Colors.LightGreen + message); + } + 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 = "<" + nameColor(player) + Colors.White +"> "; + if (vminecraftSettings.getInstance().FFF()) { + log.log(Level.INFO, "<"+player.getName()+"> "+message); + gmsg(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 = "<" + nameColor(player) + Colors.White +"> "; + if(vminecraftSettings.getInstance().quakeColors()&&message.length()>2 && vminecraftChat.lengthCheck(playerName + message)) { + + //Loop through the string finding the color codes and inserting them + String temp = ""; + for(int x = 0; x< message.length(); x++) + { + if(message.charAt(x)=='^' && x != message.length() - 1) + { + temp += vminecraftChat.colorChange(message.charAt(x+1)); + x++; + } + else{ + temp+=message.charAt(x); + } + } + //Log the chat + log.log(Level.INFO, "<"+player.getName()+"> "+message); + + //Broadcast the message + gmsg(playerName + temp + " "); + return true; + } + return false; + } +} diff --git a/vminecraftCommands.java b/vminecraftCommands.java new file mode 100644 index 000000000..f3412bb87 --- /dev/null +++ b/vminecraftCommands.java @@ -0,0 +1,819 @@ +import java.awt.Color; +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; + +//===================================================================== +//Class: vminecraftCommands +//Use: Encapsulates all commands added by this mod +//Author: nos, trapalice, cerevisiae +//===================================================================== +public class vminecraftCommands{ + //Log output + protected static final Logger log = Logger.getLogger("Minecraft"); + + //The list of commands for vminecraft + public static commandList cl = new commandList(); + + //===================================================================== + //Function: loadCommands + //Input: None + //Output: None + //Use: Imports all the commands into the command list + //===================================================================== + public static void loadCommands(){ + //If we had commands we would add them here. + cl.register("/tp", "teleport"); + cl.register("/masstp", "masstp", "Teleports those with lower permissions to you"); + cl.register("/reload", "reload"); + cl.register("/rules", "rules", "Displays the rules"); + cl.register("/fabulous", "fabulous", "makes text SUUUPER"); + cl.register("/whois", "whois", "/whois [user]"); + cl.register("/say", "say"); + cl.register("/slay", "slay", "Kill target player"); + cl.register("/ezmodo", "invuln", "Toggle invulnerability"); + cl.register("/ezlist", "ezlist", "List invulnerable players"); + } + + + //===================================================================== + //Function: teleport (/tp) + //Input: Player player: The player using the command + // String[] args: The arguments for the command. Should be a + // player name + //Output: boolean: If the user has access to the command + // and it is enabled + //Use: Teleports the user to another player + //===================================================================== + public static boolean teleport(Player player, String[] args) + { + //Get if the command is enabled + if(vminecraftSettings.getInstance().cmdTp()) + { + //Make sure a player has been specified and return an error if not + if (args.length < 1) { + player.sendMessage(Colors.Rose + "Correct usage is: /tp [player]"); + } else { + + //Find the player by name + Player playerTarget = etc.getServer().matchPlayer(args[0]); + + //If it's you, return witty message + 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 if (playerTarget != null) { + log.log(Level.INFO, player.getName() + " teleported to " + + playerTarget.getName()); + player.teleportTo(playerTarget); + + //Otherwise inform the user that the player doesn't exist + } else { + player.sendMessage(Colors.Rose + "Can't find user " + + args[0] + "."); + } + } + return true; + } + return false; + } + + //===================================================================== + //Function: masstp (/masstp) + //Input: Player player: The player using the command + // String[] args: Should be empty or is ignored + //Output: boolean: If the user has access to the command + // and it is enabled + //Use: Teleports all players to the user + //===================================================================== + public static boolean masstp(Player player, String[] args) + { + //If the command is enabled + if(vminecraftSettings.getInstance().cmdMasstp()) { + //Go through all players and move them to the user + for (Player p : etc.getServer().getPlayerList()) { + if (!p.hasControlOver(player)) { + p.teleportTo(player); + } + } + //Inform the user that the command has executed successfully + player.sendMessage(Colors.Blue+"Summoning successful."); + + return true; + } + return false; + } + + //===================================================================== + //Function: tphere (/tphere) + //Input: Player player: The player using the command + // String[] args: The arguments for the command. Should be a + // player name + //Output: boolean: If the user has access to the command + // and it is enabled + //Use: Teleports the user to another player + //===================================================================== + public static boolean tphere(Player player, String[] args) + { + //Check if the command is enabled. + if (vminecraftSettings.getInstance().cmdTphere()) { + //Make sure a player is specified + if (args.length < 1) { + player.sendMessage(Colors.Rose + "Correct usage is: /tphere [player]"); + } else { + //Get the player by name + Player playerTarget = etc.getServer().matchPlayer(args[0]); + //If the player has a higher rank than the user, return error + 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 if (playerTarget != null) { + log.log(Level.INFO, player.getName() + " teleported " + player.getName() + " to their self."); + playerTarget.teleportTo(player); + //Otherwise inform the user that the target doens't exist. + } else { + player.sendMessage(Colors.Rose + "Can't find user " + args[0] + "."); + } + } + return true; + } + return false; + } + + //===================================================================== + //Function: reload (/reload) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: boolean: If the user has access to the command + // and it is enabled + //Use: Reloads the settings for vminecraft + //===================================================================== + public static boolean reload(Player player, String[] args) + { + //Should only reload vminecraft settings if the player is able to use /reload + try { + vminecraftSettings.getInstance().loadSettings(); + } catch (IOException e) { + log.log(Level.SEVERE, "Exception while loading settings", e); + } + return true; + } + + //===================================================================== + //Function: rules (/rules) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: boolean: If the user has access to the command + // and it is enabled + //Use: Lists the rules + //===================================================================== + public static boolean rules(Player player, String[] args) + { + //If the rules exist + if(vminecraftSettings.getInstance().cmdRules()) { + //Display them + for (String str : vminecraftSettings.getInstance().getRules()) { + player.sendMessage(Colors.Blue+str); + } + return true; + } + return false; + } + + //===================================================================== + //Function: fabulous (/fabulous) + //Input: Player player: The player using the command + // String[] args: The message to apply the effect to + //Output: boolean: If the user has access to the command + // and it is enabled + //Use: Makes the text rainbow colored + //===================================================================== + public static boolean fabulous(Player player, String[] args) + { + //If the command is enabled + if(vminecraftSettings.getInstance().cmdFabulous()) { + //Make sure a message has been specified + if (args.length < 1) {return false;} + String str = "", + temp = ""; + //Merge the message again + str = etc.combineSplit(0, args, " "); + String playerName = "<" + player.getName() + "> "; + String temp2 = playerName + str; + //The array of colors to use + String[] rainbow = new String[] {Colors.Red, Colors.Rose, + Colors.Yellow, Colors.Green, Colors.Blue, + Colors.LightPurple, Colors.Purple}; + int counter=0; + //If the message isn't too long + if(vminecraftChat.lengthCheck(temp2)) + { + //Output for server + log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\""); + + //Loop through the message applying the colors + for(int x=0; x 0) + { + //Check to make sure the command doesn't already exist + for(int i = 0; i < commands.length; i++) + if(commands[i].getName().equalsIgnoreCase(name)) + return false; + + //Create a new temp array + command[] temp = new command[commands.length + 1]; + //Copy the old command list over + System.arraycopy(commands, 0, temp, 0, commands.length); + //Set commands to equal the new array + commands = temp; + } else { + commands = new command[1]; + } + + //Add the new function to the list + commands[commands.length - 1] = new command(name, func); + + //exit successfully + return true; + } + + //===================================================================== + //Function: register + //Input: String name: The name of the command + // String func: The function to be called + // String info: The information for the command to put in help + //Output: boolean: Whether the command was input successfully or not + //Use: Registers a command to the command list for checking later + //===================================================================== + public boolean register(String name, String func, String info){ + //Add to the /help list + etc.getInstance().addCommand(name, info); + + //Finish registering + return register(name, func); + } + + //===================================================================== + //Function: register + //Input: String name: The name of the command + // String func: The function to be called + //Output: boolean: Whether the command was input successfully or not + //Use: Registers a command to the command list for checking later + //===================================================================== + public boolean registerAlias(String name, String com, String[] args){ + + //Check to make sure the alias doesn't already exist + for(int i = 0; i < commands.length; i++) + //The alias already exists + if(commands[i].getName().equalsIgnoreCase(name)) + return false; + + //If the command list isn't empty + if(commands.length > 0) + { + //Create a new temp array + command[] temp = new command[commands.length]; + //Copy the old command list over + System.arraycopy(commands, 0, temp, 0, commands.length); + //Set commands to equal the new array + commands = temp; + } + + + + //Add the new function to the list + commands[commands.length] = new commandRef(name, com, args); + + //exit successfully + return true; + } + + //===================================================================== + //Function: call + //Input: String name: The name of the command to be run + //Output: boolean: If the command was called successfully + //Use: Attempts to call a command + //===================================================================== + public boolean call(String name, Player player, String[] arg){ + //Make sure the user has access to the command + if(!player.canUseCommand(name)) { + return false; + } + //Search for the command + for(int i = 0; i < commands.length; i++) + { + //When found + if(commands[i].getName().equalsIgnoreCase(name)) + { + try { + //Call the command and return results + return commands[i].call(player, arg); + } catch (SecurityException e) { + log.log(Level.SEVERE, "Exception while running command", e); + } catch (IllegalArgumentException e) { + log.log(Level.SEVERE, "Exception while running command", e); + } + } + } + + //Something went wrong + return false; + } + + //===================================================================== + //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 + //===================================================================== + public boolean call(Player player, String[] arg) + { + try { + Method m = vminecraftCommands.class.getMethod(function, Player.class, String[].class); + m.setAccessible(true); + return (Boolean) m.invoke(null, player, arg); + + } catch (SecurityException e) { + log.log(Level.SEVERE, "Exception while running command", e); + } catch (NoSuchMethodException e) { + log.log(Level.SEVERE, "Exception while running command", e); + } catch (IllegalArgumentException e) { + log.log(Level.SEVERE, "Exception while running command", e); + } catch (IllegalAccessException e) { + log.log(Level.SEVERE, "Exception while running command", e); + } catch (InvocationTargetException e) { + log.log(Level.SEVERE, "Exception while running command", e); + } + return true; + } + } + + //===================================================================== + //Class: commandRef + //Use: A command referencing another command + //Author: cerevisiae + //===================================================================== + private class commandRef extends command{ + private String commandName; + private String reference; + private String[] args; + + //===================================================================== + //Function: command + //Input: None + //Output: None + //Use: Initialize the command + //===================================================================== + public commandRef(String name, String com, String[] arg){ + super(name, ""); + reference = com; + args = arg; + } + + //===================================================================== + //Function: call + //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 + //===================================================================== + public boolean call(String[] arg) + { + + //Insert the arguments into the pre-set arguments + String[] temp = args; + int lastSet = -1; + for(int i = 0; i < temp.length; i++) + if(temp[i].startsWith("%")) + temp[i] = arg[lastSet = Integer.parseInt(temp[i].substring(1))]; + + //Append the rest of the arguments to the argument array + if(lastSet + 1 < arg.length) + { + String[] temp2 = new String[temp.length + arg.length - lastSet]; + System.arraycopy(temp, 0, temp2, 0, temp.length); + System.arraycopy(arg, lastSet + 1, temp2, + temp.length, arg.length - lastSet); + } + + //Call the referenced command + //TODO STILL TO BE WRITTEN + return true; + } + } +} \ No newline at end of file diff --git a/vminecraftListener.java b/vminecraftListener.java index ec5aa8f52..5a0578f56 100644 --- a/vminecraftListener.java +++ b/vminecraftListener.java @@ -1,456 +1,89 @@ -//Vminecraft plugin by nossr50 & TrapAlice -import java.io.IOException; -import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; - - public class vminecraftListener extends PluginListener { - protected static final Logger log = Logger.getLogger("Minecraft"); - - private ArrayList ezmodo = new ArrayList(); //An array of players currently in ezmodo - - public void enable() throws IOException { - settings.getInstance().loadSettings(); //Load the settings files - if (etc.getInstance().isHealthEnabled()){ - etc.getInstance().addCommand("/ezmodo", "Toggle invulnerability"); - } - log.log(Level.INFO, "vminecraft enabled"); - } - public void disable() { - log.log(Level.INFO, "vminecraft disabled"); - if (etc.getInstance().isHealthEnabled()) { - etc.getInstance().removeCommand("/ezmodo"); - } - } - - public boolean onHealthChange(Player player,int oldValue,int newValue){ - if (player.getHealth() != 30 && ezmodo.contains(player.getName())) { - player.setHealth(30); - } - else if (settings.getInstance().globalmessages() && player.getHealth() < 1) { - other.gmsg(Colors.Gray + player.getName() + " is no more"); - } - return false; +//===================================================================== +//Class: vminecraftListener +//Use: The listener to catch incoming chat and commands +//Author: nossr50, TrapAlice, cerevisiae +//===================================================================== +public class vminecraftListener 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"); } + + //===================================================================== + //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){ - String temp2 = "<" + player.getColor() + player.getName() + Colors.White +"> "; //Copies the formatting of id.java - String adminchat = Colors.DarkPurple + "{" + player.getColor() + player.getName() + Colors.DarkPurple +"}" + Colors.White + " "; //Special formatting for adminchat - String message2 = ""; //Used for greentext and FFF - String check = temp2+message; //Calculates how long your message will be including your name in the equation, this prevents minecraft clients from crashing when a color code is inserted after a linebreak - if (settings.getInstance().adminchat()&&message.startsWith("@") && (player.isAdmin() || player.canUseCommand("/adminchat"))) { - for (Player p : etc.getServer().getPlayerList()) { - String blaa = ""; - if (p != null) { - if (p.isAdmin() || (p.canUseCommand("/adminchat"))) { - for ( int x = 1; x< message.length(); x++) { - blaa+=message.charAt(x); - } - if (p.isAdmin() || (p.canUseCommand("/adminchat"))){ - if (p != null) { - p.sendMessage(adminchat+blaa); - } - } - } - } - } - log.log(Level.INFO, "@"+temp2+message); //So you can read adminchat from the server console - return true; - } - //Greentext - if (settings.getInstance().greentext()&&message.startsWith(">")) { - log.log(Level.INFO, "<"+player.getName()+"> "+message); - message = Colors.LightGreen + message; - message2 = temp2 + message; - other.gmsg(message2); - return true; - } - //FFF - if (settings.getInstance().FFF()&&message.startsWith("FFF")) { - log.log(Level.INFO, "<"+player.getName()+"> "+message); - message = Colors.Red + message; - message2 = temp2 + message; - other.gmsg(message2); - return true; - } - //QuakeColors - if(settings.getInstance().quakeColors()&&message.length()>2 && other.lengthCheck(check)) { - String temp = ""; - for(int x = 0; x< message.length(); x++) - { - if(message.charAt(x)=='^'&&x!=message.length()-1) - { - temp+=other.colorChange(message.charAt(x+1)); - x+=1; - } - else{ - temp+=message.charAt(x); - } - } - log.log(Level.INFO, "<"+player.getName()+"> "+message); - message = temp2 + temp + " "; - for (Player p : etc.getServer().getPlayerList()) { - if (p != null) { - other.gmsg(message); - return true; - } - } - } - return false; + //Quote (Greentext) + if (message.startsWith(">")) + vminecraftChat.quote(player, message); + + //Rage (FFF) + else if (message.startsWith("FFF")) + vminecraftChat.rage(player, message); + + //Send through quakeColors otherwise + else + vminecraftChat.quakeColors(player, message); + + return false; } + + //===================================================================== + //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) { - public boolean onCommand(Player player, String[] split) { - if(!player.canUseCommand(split[0])) { - return false; - } - if(settings.getInstance().cmdMasstp() && split[0].equalsIgnoreCase("/masstp")) { - for (Player p : etc.getServer().getPlayerList()) { - if (!p.hasControlOver(player)) { - p.teleportTo(player); - } - - } - player.sendMessage(Colors.Blue+"Summoning successful."); - } - //Disable using /modify to add commands (need to make a boolean settings for this) - if(split[0].equals("/modify") && split[2].equals("commands")) { - return true; - } - //ezlist - if(settings.getInstance().cmdEzModo() && split[0].equals("/ezlist")) { - player.sendMessage("Ezmodo: " + ezmodo); - return true; - } - //slay - if(settings.getInstance().cmdEzModo() && split[0].equals("/slay")) { - Player playerTarget = etc.getServer().matchPlayer(split[1]); - if (!ezmodo.contains(playerTarget.getName())) { - playerTarget.setHealth(0); - other.gmsg(player.getColor() + player.getName() + Colors.LightBlue + " has slain " + playerTarget.getColor() + playerTarget.getName()); - return true; - } - else { - player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha"); - return true; - } - } - //ezmodo - if (settings.getInstance().cmdEzModo() && split[0].equals("/ezmodo")) { - if (ezmodo.contains(player.getName())) { - player.sendMessage(Colors.Red + "ezmodo = off"); - ezmodo.remove(ezmodo.indexOf(player.getName())); - return true; - } 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**"); - ezmodo.add(player.getName()); - player.setHealth(30); - return true; - } - } - //Replacement for /tp - if(settings.getInstance().cmdTp() && split[0].equalsIgnoreCase("/tp")) { - { - if (split.length < 2) { - player.sendMessage(Colors.Rose + "Correct usage is: /tp [player]"); - return true; - } + //Explot fix on /modify + if(split[0].equals("/modify") && split[2].equals("commands")) { + return false; + } - Player playerTarget = etc.getServer().matchPlayer(split[1]); - - if (player.getName().equalsIgnoreCase(split[1])) { - player.sendMessage(Colors.Rose + "You're already here!"); - return true; - } - - if (!player.hasControlOver(playerTarget)) { - player.sendMessage(Colors.Red + "That player has higher permissions than you."); - return true; - } - - if (playerTarget != null) { - log.log(Level.INFO, player.getName() + " teleported to " + playerTarget.getName()); - player.teleportTo(playerTarget); - return true; - } else { - player.sendMessage(Colors.Rose + "Can't find user " + split[1] + "."); - return true; - } - } - } - //Replacement for /tphere - if (settings.getInstance().cmdTphere() && (split[0].equalsIgnoreCase("/tphere") || split[0].equalsIgnoreCase("/s"))) { - if (split.length < 2) { - player.sendMessage(Colors.Rose + "Correct usage is: /tphere [player]"); - return true; - } - - Player playerTarget = etc.getServer().matchPlayer(split[1]); - - if (!player.hasControlOver(playerTarget)) { - player.sendMessage(Colors.Red + "That player has higher permissions than you."); - return true; - } - if (player.getName().equalsIgnoreCase(split[1])) { - player.sendMessage(Colors.Rose + "Wow look at that! You teleported yourself to yourself!"); - return true; - } - - if (playerTarget != null) { - log.log(Level.INFO, player.getName() + " teleported " + player.getName() + " to their self."); - playerTarget.teleportTo(player); - } else { - player.sendMessage(Colors.Rose + "Can't find user " + split[1] + "."); - } - } - //Global messages that should only parse when a command can be successful - if(settings.getInstance().globalmessages() && split[0].equalsIgnoreCase("/kick")) { - Player playerTarget = etc.getServer().matchPlayer(split[1]); - if (playerTarget != null && !playerTarget.hasControlOver(player)) { - other.gmsg(player.getColor()+player.getName()+Colors.Blue+" has kicked "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); - } - } - if(settings.getInstance().globalmessages() && split[0].equalsIgnoreCase("/ban")) { - Player playerTarget = etc.getServer().matchPlayer(split[1]); - if (playerTarget != null && !playerTarget.hasControlOver(player)) { - other.gmsg(player.getColor()+player.getName()+Colors.Blue+" has banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); - } - } - if(settings.getInstance().globalmessages() && split[0].equalsIgnoreCase("/ipban")) { - Player playerTarget = etc.getServer().matchPlayer(split[1]); - if (playerTarget != null && !playerTarget.hasControlOver(player)) { - other.gmsg(player.getColor()+player.getName()+Colors.Blue+" has IP banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); - } - } - if(settings.getInstance().globalmessages() && split[0].equalsIgnoreCase("/time")) { - if (split.length <= 2) { - other.gmsg(Colors.Blue+"Time changes thanks to "+player.getColor()+player.getName()); - return false; - } - } - //Should only reload vminecraft settings if the player is able to use /reload - if(split[0].equalsIgnoreCase("/reload") && player.canUseCommand("/reload")) { - try { - settings.getInstance().loadSettings(); - } catch (IOException ex) { - Logger.getLogger(vminecraftListener.class.getName()).log(Level.SEVERE, null, ex); - } - return false; - } - //Rules - if(settings.getInstance().cmdRules() && split[0].equalsIgnoreCase("/rules")) { - for (String str : settings.getInstance().getRules()) { - player.sendMessage(Colors.Blue+str); - } - return true; - } - //Fabulous - if(split[0].equalsIgnoreCase("/fabulous") && settings.getInstance().cmdFabulous()) { - if (split.length == 1) {return false;} - String temp = ""; - String str = ""; - str = etc.combineSplit(1, split, " "); - String temp2 = "<" + player.getName() + "> "+str; - String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Yellow, Colors.Green, Colors.Blue, Colors.LightPurple, Colors.Purple}; - int counter=0; - if(other.lengthCheck(temp2)) - { - log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\""); - for(int x=0; x " + str; - - other.gmsg(message); - return true; - } else { - player.sendMessage(Colors.Rose + "Message is too long"); - } - return true; - } - /* - //Promote - if (settings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote")) { - if(split.length != 2) - { - player.sendMessage(Colors.Rose + "Usage is /promote [Player]"); + //Copy the arguments into their own array. + String[] args = new String[split.length - 1]; + System.arraycopy(split, 1, args, 0, args.length); + //Return the results of the command + return vminecraftCommands.cl.call(split[0], player, args); + } + + //===================================================================== + //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){ + if (player.getHealth() != vminecraftSettings.getInstance().ezModoHealth() && vminecraftSettings.getInstance().isEzModo(player.getName())) { + player.setHealth(vminecraftSettings.getInstance().ezModoHealth()); - Player playerTarget = null; - if(split.length==2){ - for( Player p : etc.getServer().getPlayerList()) - { - if (p.getName().equalsIgnoreCase(split[1])) - { - playerTarget = p; - } - } - - if( playerTarget!=null) - { - String playerTargetGroup[] = playerTarget.getGroups(); - String playerGroup[] = player.getGroups(); - player.sendMessage("Debug data:"); - player.sendMessage("PlayerTarget: "+playerTargetGroup[0]); - player.sendMessage("Player: "+playerGroup[0]); - if(playerTargetGroup[0].equals("admins")) - { - player.sendMessage(Colors.Rose + "You can not promote " + split[1] + " any higher."); - } - if(playerTargetGroup[0].equals("mods") && (playerGroup[0].equals("owner"))) - { - playerTarget.setGroups(ranks.Admins); - etc.getInstance().getDataSource().modifyPlayer(playerTarget); - String message = Colors.Yellow + split[1] + " was promoted to" + Colors.Rose + " Admin"; - other.gmsg(message); - } - else if (playerTargetGroup[0].equals("trusted") && (playerGroup[0].equals("admins") || playerGroup[0].equals("owner"))) - { - playerTarget.setGroups(ranks.Mods); - playerTargetGroup[0]="Mods"; - etc.getInstance().getDataSource().modifyPlayer(playerTarget); - String message = Colors.Yellow + split[1] + " was promoted to" + Colors.DarkPurple + " Mod"; - other.gmsg(message); - } - else if (playerTargetGroup[0].equals("default") && (playerGroup[0].equals("mods") || playerGroup[0].equals("admins") || player.isInGroup("owner"))) - { - playerTarget.setGroups(ranks.Trusted); - etc.getInstance().getDataSource().modifyPlayer(playerTarget); - String message = Colors.Yellow + split[1] + " was promoted to" + Colors.LightGreen + " Trusted"; - other.gmsg(message); - } - return true; - } - else{ - player.sendMessage(Colors.Rose + "Player not found"); - } - log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" "); -} - } - //Demote - if (settings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote")) -{ - if(split.length != 2) - { - player.sendMessage(Colors.Rose + "Usage is /demote [Player]"); - } - - Player playerTarget = null; - - for( Player p : etc.getServer().getPlayerList()) - { - if (p.getName().equalsIgnoreCase(split[1])) - { - playerTarget = p; - } - } - - if( playerTarget!=null) - { - if(playerTarget.isInGroup("admins") && (player.isInGroup("superadmins"))) - { - playerTarget.setGroups(ranks.Mods); - etc.getInstance().getDataSource().modifyPlayer(playerTarget); - String message = Colors.Yellow + split[1] + " was demoted to" + Colors.DarkPurple + " Mod"; - other.gmsg(message); - } - if(playerTarget.isInGroup("mods") && (player.isInGroup("admins") || player.isInGroup("superadmins"))) - { - playerTarget.setGroups(ranks.Trusted); - etc.getInstance().getDataSource().modifyPlayer(playerTarget); - String message = Colors.Yellow + split[1] + " was demoted to" + Colors.LightGreen + " Trusted"; - other.gmsg(message); - } - else if (playerTarget.isInGroup("trusted") && (player.isInGroup("mods") || player.isInGroup("superadmins") || player.isInGroup("admins"))) - { - playerTarget.setGroups(ranks.Def); - etc.getInstance().getDataSource().modifyPlayer(playerTarget); - String message = Colors.Yellow + split[1] + " was demoted to" + Colors.White + " Default"; - other.gmsg(message); - } - else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins"))) - { - player.sendMessage(Colors.Rose + "You can not demote " + split[1] + " any lower."); - } - } - else{ - player.sendMessage(Colors.Rose + "Player not found"); - } - log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" "); - return true; -} - * - */ - //Whois will display info about a player - if (settings.getInstance().cmdWhoIs() && split[0].equalsIgnoreCase("/whois")) { - if (split.length < 2) { - player.sendMessage(Colors.Rose + "Usage is /whois [player]"); } - String admin =""; - String ignore =""; - String IP = ""; - Player playerTarget = null; - for( Player p : etc.getServer().getPlayerList()) - { - if (p.getName().equalsIgnoreCase(split[1])) - { - playerTarget = p; - } - } - if (playerTarget != null){ - - IP = playerTarget.getIP(); - if (playerTarget.canIgnoreRestrictions()) { - ignore = "True"; - } else { - ignore ="False"; - } - if (playerTarget.canIgnoreRestrictions()) { - admin = "True"; - } else { - admin = "False"; - } - - - //Displaying the information - player.sendMessage(Colors.Blue + "Whois results for "+split[1]+"."); - //Group - for (String group : playerTarget.getGroups()) { - player.sendMessage(Colors.Blue + "Groups: "+group); + else if (vminecraftSettings.getInstance().globalmessages() && player.getHealth() < 1) { + vminecraftChat.gmsg(Colors.Gray + player.getName() + " is no more"); } - //Admin - player.sendMessage(Colors.Blue+"Admin: "+admin); - //IP - player.sendMessage(Colors.Blue+"IP: "+IP); - //Restrictions - player.sendMessage(Colors.Blue+"Can ignore restrictions: "+ignore); - - - } else { - player.sendMessage(Colors.Rose+"Player not found."); - } - return true; - } - //Say - if (settings.getInstance().cmdSay() && (split[0].equalsIgnoreCase("/say"))) { - String sayan; - sayan = etc.combineSplit(1, split, " "); - other.gmsg(Colors.Yellow+sayan); - } - //Should this be included? - else { - return false; - } - //Needs to be included - return true; - } - } + return false; + } +} \ No newline at end of file diff --git a/vminecraftPlugin.java b/vminecraftPlugin.java index 855d49bc3..d8075d20e 100644 --- a/vminecraftPlugin.java +++ b/vminecraftPlugin.java @@ -1,26 +1,24 @@ - import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; -/** - * vminecraft Plugin - * @author Robert, TrapAlice - */ -//This is how we setup the listener +//===================================================================== +//Class: vMinecraftPlugin +//Use: Starts the plugin +//Author: nossr50, TrapAlice, cerevisiae +//===================================================================== public class vminecraftPlugin extends Plugin { static final vminecraftListener listener = new vminecraftListener(); - public void enable() { - //If we had commands we would add them here. - etc.getInstance().addCommand("/masstp", "Teleports those with lower permissions to you"); - etc.getInstance().addCommand("/rules", "Displays the rules"); - etc.getInstance().addCommand("/fabulous", "makes text SUUUPER"); - etc.getInstance().addCommand("/whois", "/whois [user]"); - try { - settings.getInstance().loadSettings(); //Hopefully this will make the plugin load right away - } catch (IOException ex) { - Logger.getLogger(vminecraftPlugin.class.getName()).log(Level.SEVERE, null, ex); - } + protected static final Logger log = Logger.getLogger("Minecraft"); + + public void enable() { + //Hopefully this will make the plugin load right away + try { + vminecraftSettings.getInstance().loadSettings(); + } catch (IOException e) { + log.log(Level.SEVERE, "Exception while loading settings ", e); + } + vminecraftCommands.loadCommands(); } public void disable() { @@ -32,7 +30,7 @@ public class vminecraftPlugin extends Plugin { etc.getLoader().addListener(PluginLoader.Hook.CHAT, listener, this, PluginListener.Priority.MEDIUM); etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH); if(etc.getInstance().isHealthEnabled()){ - etc.getLoader().addListener(PluginLoader.Hook.HEALTH_CHANGE, listener, this, PluginListener.Priority.MEDIUM); - } + etc.getLoader().addListener(PluginLoader.Hook.HEALTH_CHANGE, listener, this, PluginListener.Priority.MEDIUM); + } } } diff --git a/vminecraftSettings.java b/vminecraftSettings.java new file mode 100644 index 000000000..44598c859 --- /dev/null +++ b/vminecraftSettings.java @@ -0,0 +1,190 @@ +import java.io.*; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; +//===================================================================== +//Class: vminecraftSettings +//Use: Controls the settings for vminecraft +//Author: nossr50, TrapAlice, cerevisiae +//===================================================================== +public class vminecraftSettings { + //private final static Object syncLock = new Object(); + protected static final Logger log = Logger.getLogger("Minecraft"); + private static volatile vminecraftSettings instance; + //Invulnerability List + + + //The feature settings + static boolean toggle = true, + adminChat = false, + greentext = false, + FFF = false, + quakeColors = false, + cmdFabulous = false, + cmdPromote = false, + cmdDemote = false, + cmdWhoIs = false, + cmdRules = false, + cmdMasstp = false, + cmdTp = false, + cmdTphere = false, + globalmessages = false, + cmdSay = false, + cmdWho = false, + cmdEzModo = false; + + //An array of players currently in ezmodo + static ArrayList ezModo = new ArrayList(); + //The max health for ezModo + static int ezHealth = 30; + + private PropertiesFile properties; + String file = "vminecraft.properties"; + public String rules[] = null; + + //===================================================================== + //Function: loadSettings + //Input: None + //Output: None + //Use: Loads the settings from the properties + //===================================================================== + public void loadSettings() throws IOException + { + 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("greentext=true\r\n"); + writer.write("quakeColors=true\r\n"); + writer.write("cmdTphere=true\r\n"); + writer.write("cmdFabulous=true\r\n"); + writer.write("cmdWhoIs=true\r\n"); + writer.write("cmdWho=true\r\n"); + writer.write("cmdPromote=true\r\n"); + writer.write("cmdDemote=true\r\n"); + writer.write("cmdMasstp=true\r\n"); + writer.write("cmdSay=true\r\n"); + writer.write("cmdTp=true\r\n"); + writer.write("cmdRules=true\r\n"); + writer.write("globalmessages=true\r\n"); + writer.write("FFF=true\r\n"); + writer.write("adminchat=true\r\n"); + writer.write("cmdEzModo=true\r\n"); + writer.write("ezModo=\r\n"); + writer.write("ezHealth=30\r\n"); + writer.write("rules=Rules@#1: No griefing@#2: No griefing\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("vminecraft.properties"); + properties.load(); + } + + try { + adminChat = properties.getBoolean("adminchat",true); + greentext = properties.getBoolean("greentext",true); + FFF = properties.getBoolean("FFF",true); + quakeColors = properties.getBoolean("quakeColors",true); + cmdFabulous = properties.getBoolean("cmdFabulous",true); + cmdPromote = properties.getBoolean("cmdPromote",true); + cmdDemote = properties.getBoolean("cmdDemote",true); + cmdWhoIs = properties.getBoolean("cmdWhoIs",true); + cmdWhoIs = properties.getBoolean("cmdWho",true); + cmdRules = properties.getBoolean("cmdRules",true); + cmdTp = properties.getBoolean("cmdTp",true); + cmdMasstp = properties.getBoolean("cmdMasstp",true); + cmdTphere = properties.getBoolean("cmdTphere",true); + globalmessages = properties.getBoolean("globalmessages",true); + cmdSay = properties.getBoolean("cmdSay",true); + cmdEzModo = properties.getBoolean("cmdEzModo",true); + rules = properties.getString("rules", "").split("@"); + + String[] tempEz = properties.getString("ezModo").split(","); + ezModo = new ArrayList(); + for(int i = 0; i < tempEz.length; i++) + ezModo.add(tempEz[i]); + + ezHealth = properties.getInt("ezHealth"); + + log.log(Level.INFO, "vminecraft plugin successfully loaded"); + + } + catch (Exception e) + { + log.log(Level.SEVERE, "vminecraft Error: ERROR LOADING PROPERTIES FILE"); + } + } + + //===================================================================== + //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 greentext() {return greentext;} + public boolean FFF() {return FFF;} + public boolean quakeColors() {return quakeColors;} + 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 cmdEzModo() {return cmdEzModo;} + public boolean cmdWho() {return cmdWho;} + + //EzModo functions + public boolean isEzModo(String playerName) {return ezModo.contains(playerName);} + public void removeEzModo(String playerName) {ezModo.remove(ezModo.indexOf(playerName));} + public void addEzModo(String playerName) {ezModo.add(playerName);} + public int ezModoHealth() {return ezHealth;} + public String ezModoList() {return ezModo.toString();} + + + //===================================================================== + //Function: getInstance + //Input: None + //Output: vminecraftSettings: The instance of the settings + //Use: Returns the instance of the settings + //===================================================================== + public static vminecraftSettings getInstance() { + if (instance == null) { + instance = new vminecraftSettings(); + } + 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 From bfb48af50b4155f07d9216bcd230dadb793177a9 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 28 Nov 2010 01:12:23 -0600 Subject: [PATCH 03/82] Reorganized a lot of code. Added tons of comments. Change how commands are added. Encapsulated commands into their own functions. Modified some commands. Recoded others. Added personalized /who that shows name colors. --- other.java | 134 -------------------------------------------------- settings.java | 130 ------------------------------------------------ 2 files changed, 264 deletions(-) delete mode 100644 other.java delete mode 100644 settings.java diff --git a/other.java b/other.java deleted file mode 100644 index 859127dea..000000000 --- a/other.java +++ /dev/null @@ -1,134 +0,0 @@ -//Contains all the java methods for vminecraft -public class other { - public static other gmsg; - public static other gmsg(String msg){ - for (Player p : etc.getServer().getPlayerList()) { - if (p != null) { - p.sendMessage(msg); - } - } - return gmsg; - } - - public static boolean lengthCheck(String str) - { - int length = 0; - for(int x = 0; x\"*()".indexOf(str.charAt(x)) != -1) - { - length+=5; - } - else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1) - { - length+=6; - } - else if("@~".indexOf(str.charAt(x)) != -1) - { - length+=7; - } - else if(str.charAt(x)==' ') - { - length+=4; - } - } - if(length<=316) - { - return true; - } else { return false; } - - } - - public static String colorChange(char colour) - { - String color = ""; - switch(colour) - { - case '0': - color = Colors.Black; - break; - case '1': - color = Colors.Navy; - break; - case '2': - color = Colors.Green; - break; - case '3': - color = Colors.Blue; - break; - case '4': - color = Colors.Red; - break; - case '5': - color = Colors.Purple; - break; - case '6': - color = Colors.Gold; - break; - case '7': - color = Colors.LightGray; - break; - case '8': - color = Colors.Gray; - break; - case '9': - color = Colors.DarkPurple; - break; - case 'a': - color = Colors.LightGreen; - break; - case 'b': - color = Colors.LightBlue; - break; - case 'c': - color = Colors.Rose; - break; - case 'd': - color = Colors.LightPurple; - break; - case 'e': - color = Colors.Yellow; - break; - case 'f': - color = Colors.White; - break; - case 'A': - color = Colors.LightGreen; - break; - case 'B': - color = Colors.LightBlue; - break; - case 'C': - color = Colors.Rose; - break; - case 'D': - color = Colors.LightPurple; - break; - case 'E': - color = Colors.Yellow; - break; - case 'F': - color = Colors.White; - break; - default: - color = Colors.White; - break; - } - - return color; - } - - - } \ No newline at end of file diff --git a/settings.java b/settings.java deleted file mode 100644 index be2adad89..000000000 --- a/settings.java +++ /dev/null @@ -1,130 +0,0 @@ -import java.io.*; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class settings { - private final static Object syncLock = new Object(); - protected static final Logger log = Logger.getLogger("Minecraft"); - private static volatile settings instance; - static boolean toggle = true; - private boolean adminChat = false; - private boolean greentext = false; - private boolean FFF = false; - private boolean quakeColors = false; - private boolean cmdFabulous = false; - private boolean cmdPromote = false; - private boolean cmdDemote = false; - private boolean cmdWhoIs = false; - private boolean cmdRules = false; - private boolean cmdMasstp = false; - private boolean cmdTp = false; - private boolean cmdTphere = false; - private boolean globalmessages = false; - private boolean cmdSay = false; - private boolean cmdEzModo = false; - private PropertiesFile properties; - String file = "vminecraft.properties"; - public String rules[] = null; - - public void loadSettings() throws IOException - { - 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("greentext=true\r\n"); - writer.write("quakeColors=true\r\n"); - writer.write("cmdTphere=true\r\n"); - writer.write("cmdFabulous=true\r\n"); - writer.write("cmdWhoIs=true\r\n"); - writer.write("cmdPromote=true\r\n"); - writer.write("cmdDemote=true\r\n"); - writer.write("cmdMasstp=true\r\n"); - writer.write("cmdSay=true\r\n"); - writer.write("cmdTp=true\r\n"); - writer.write("cmdRules=true\r\n"); - writer.write("globalmessages=true\r\n"); - writer.write("FFF=true\r\n"); - writer.write("adminchat=true\r\n"); - writer.write("cmdEzModo=true\r\n"); - writer.write("rules=Rules@#1: No griefing@#2: No griefing\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("vminecraft.properties"); - properties.load(); - } - - try { - adminChat = properties.getBoolean("adminchat",true); - greentext = properties.getBoolean("greentext",true); - FFF = properties.getBoolean("FFF",true); - quakeColors = properties.getBoolean("quakeColors",true); - cmdFabulous = properties.getBoolean("cmdFabulous",true); - cmdPromote = properties.getBoolean("cmdPromote",true); - cmdDemote = properties.getBoolean("cmdDemote",true); - cmdWhoIs = properties.getBoolean("cmdWhoIs",true); - cmdRules = properties.getBoolean("cmdRules",true); - cmdTp = properties.getBoolean("cmdTp",true); - cmdMasstp = properties.getBoolean("cmdMasstp",true); - cmdTphere = properties.getBoolean("cmdTphere",true); - globalmessages = properties.getBoolean("globalmessages",true); - cmdSay = properties.getBoolean("cmdSay",true); - cmdEzModo = properties.getBoolean("cmdEzModo",true); - rules = properties.getString("rules", "").split("@"); - log.log(Level.INFO, "vminecraft plugin successfully loaded"); - - } - catch (Exception e) - { - log.log(Level.SEVERE, "vminecraft Error: ERROR LOADING PROPERTIES FILE"); - } - } - - public boolean adminchat() {return adminChat;} - public boolean greentext() {return greentext;} - public boolean FFF() {return FFF;} - public boolean quakeColors() {return quakeColors;} - 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 cmdEzModo() {return cmdEzModo;} - - public static settings getInstance() { - if (instance == null) { - instance = new settings(); - } - - return instance; - } - //Will return the rules - public String[] getRules() { - return rules; - } - -} \ No newline at end of file From 66740290d3fdde8a4518597f2c15266c3c6b8698 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Sun, 28 Nov 2010 01:17:52 -0600 Subject: [PATCH 04/82] Reorganized a lot of code. Added tons of comments. Change how commands are added. Encapsulated commands into their own functions. Modified some commands. Recoded others. Added personalized /who that shows name colors. --- vminecraftCommands.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vminecraftCommands.java b/vminecraftCommands.java index f3412bb87..26de3add0 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -32,6 +32,7 @@ public class vminecraftCommands{ cl.register("/rules", "rules", "Displays the rules"); cl.register("/fabulous", "fabulous", "makes text SUUUPER"); cl.register("/whois", "whois", "/whois [user]"); + cl.register("/who", "who"); cl.register("/say", "say"); cl.register("/slay", "slay", "Kill target player"); cl.register("/ezmodo", "invuln", "Toggle invulnerability"); @@ -330,7 +331,7 @@ public class vminecraftCommands{ int maxPlayers = server.getInt("max-players"); //Output the player list - vminecraftChat.gmsg( Color.red + "Players(" + count + "/" + maxPlayers + + vminecraftChat.gmsg( Color.red + "Player List (" + count + "/" + maxPlayers + "): " + tempList); return true; From 343c170d59292629c2009e3ecba73b6bf61eb8ee Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Sun, 28 Nov 2010 17:43:42 -0600 Subject: [PATCH 05/82] Fixed some bugs --- vminecraftChat.java | 333 +++++++++++++++++++++++++++++++--------- vminecraftCommands.java | 160 ++++++++++--------- vminecraftListener.java | 13 +- vminecraftSettings.java | 2 +- 4 files changed, 347 insertions(+), 161 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index b62365350..bf7ef6c49 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -23,6 +23,175 @@ public class vminecraftChat { } } + //===================================================================== + //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 + String[] array = msg.split(" "); + //Create the output array + String[] out = new String[0]; + + //While i is less than the length of the array of words + int i = 0; + while(i < array.length){ + int len = 0; + int j = i; + //Loop through the words finding their length and increasing + //j, the end point for the sub string + while(len <= 316 && j < array.length) + { + len += msgLength(array[j]) + 4; + if( len <= 316) + j++; + + } + String[] temp = new String[j - i]; + + //If it's not the end yet + if(j < array.length) + { + //Copy the words in the selection into a new array + System.arraycopy(array, i, temp, 0, j); + + //Merge them and add them to the output array + String[] tempOut = new String[out.length + 1]; + System.arraycopy(out, 0, tempOut, 0, out.length); + tempOut[tempOut.length - 1] = etc.combineSplit(0, temp, " "); + out = tempOut; + + } + else + { + //Merge the rest and add them to the output array + String[] tempOut = new String[out.length + 1]; + System.arraycopy(out, 0, tempOut, 0, out.length); + tempOut[tempOut.length - 1] = etc.combineSplit(i, array, " "); + out = tempOut; + } + //Make the old front equal to the old end + i = j; + } + return out; + } + + //===================================================================== + //Function: wordWrap + //Input: Player player: To get the player name + // 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(Player player, String msg){ + //Split each word apart + String[] array = msg.split(" "); + //Create the output array + String[] out = new String[0]; + + //While i is less than the length of the array of words + int i = 0; + while(i < array.length){ + int len = 0; + if(out.length == 0) + len = msgLength("<" + player.getName() + "> "); + int j = i; + //Loop through the words finding their length and increasing + //j, the end point for the sub string + while(len <= 316 && j < array.length) + { + len += msgLength(array[j]) + 4; + if( len <= 316) + j++; + + } + String[] temp = new String[j - i]; + + //If it's not the end yet + if(j < array.length) + { + //Copy the words in the selection into a new array + System.arraycopy(array, i, temp, 0, j); + + //Merge them and add them to the output array + String[] tempOut = new String[out.length + 1]; + System.arraycopy(out, 0, tempOut, 0, out.length); + tempOut[tempOut.length - 1] = etc.combineSplit(0, temp, " "); + out = tempOut; + + } + else + { + //Merge the rest and add them to the output array + String[] tempOut = new String[out.length + 1]; + System.arraycopy(out, 0, tempOut, 0, out.length); + tempOut[tempOut.length - 1] = etc.combineSplit(i, array, " "); + out = tempOut; + } + //Make the old front equal to the old end + i = j; + } + return out; + } + + private static int msgLength(String str){ + int length = 0; + for(int x = 0; x\"*()".indexOf(str.charAt(x)) != -1) + { + length+=5; + } + else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1) + { + length+=6; + } + else if("@~".indexOf(str.charAt(x)) != -1) + { + length+=7; + } + else if(str.charAt(x)==' ') + { + length+=4; + } + } + return length; + } + + + public static String rainbow(String msg){ + String temp = ""; + //The array of colors to use + String[] rainbow = new String[] {Colors.Red, Colors.Rose, + Colors.Yellow, Colors.Green, Colors.Blue, + Colors.LightPurple, Colors.Purple}; + int counter=0; + //Loop through the message applying the colors + for(int x=0; x\"*()".indexOf(str.charAt(x)) != -1) - { - length+=5; - } - else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1) - { - length+=6; - } - else if("@~".indexOf(str.charAt(x)) != -1) - { - length+=7; - } - else if(str.charAt(x)==' ') - { - length+=4; - } - } - if(length<=316) - { - return true; - } else { return false; } - - } //===================================================================== //Function: adminChat @@ -177,8 +299,10 @@ public class vminecraftChat { if(player.isAdmin() || player.canUseCommand("/adminchat")) { //Special formatting for adminchat {Username} - String adminchat = Colors.DarkPurple + "{" + player.getColor() - + player.getName() + Colors.DarkPurple +"}" + Colors.White + " "; + String adminchat = Colors.DarkPurple + "{" + nameColor(player) + + Colors.DarkPurple +"}" + Colors.White + " "; + + String[] msg = wordWrap(player, message.substring(1, message.length())); //Get the player from the playerlist to send the message to. for (Player p: etc.getServer().getPlayerList()) { @@ -188,10 +312,15 @@ public class vminecraftChat { //And if p is an admin or has access to adminchat if (p.isAdmin() || (p.canUseCommand("/adminchat"))) { + + //Output the first line + p.sendMessage(adminchat + msg[0]); - //Send them the message - p.sendMessage(adminchat - + message.substring(1, message.length())); + //Get the rest of the lines and display them. + String[] tempOut = new String[msg.length - 1]; + System.arraycopy(msg, 1, tempOut, 0, tempOut.length); + for(String str: tempOut) + p.sendMessage(str); } } } @@ -218,8 +347,19 @@ public class vminecraftChat { if(vminecraftSettings.getInstance().greentext()) { //Log the chat log.log(Level.INFO, "<"+player.getName()+"> "+message); - //Output the message - gmsg(playerName + Colors.LightGreen + message); + + //Get the multi line array + String[] msg = wordWrap(player, message); + + //Output the first line + gmsg( playerName + Colors.LightGreen + msg[0]); + + //Get the rest of the lines and display them. + String[] tempOut = new String[msg.length - 1]; + System.arraycopy(msg, 1, tempOut, 0, tempOut.length); + for(String str: tempOut) + gmsg(Colors.LightGreen + str); + return true; } return false; } @@ -237,7 +377,18 @@ public class vminecraftChat { String playerName = "<" + nameColor(player) + Colors.White +"> "; if (vminecraftSettings.getInstance().FFF()) { log.log(Level.INFO, "<"+player.getName()+"> "+message); - gmsg(playerName + Colors.Red + message); + + //Get the multi line array + String[] msg = wordWrap(player, message); + + //Output the first line + gmsg( playerName + Colors.Red + msg[0]); + + //Get the rest of the lines and display them. + String[] tempOut = new String[msg.length - 1]; + System.arraycopy(msg, 1, tempOut, 0, tempOut.length); + for(String str: tempOut) + gmsg(Colors.Red + str); return true; } return false; @@ -254,28 +405,68 @@ public class vminecraftChat { { //Format the name String playerName = "<" + nameColor(player) + Colors.White +"> "; - if(vminecraftSettings.getInstance().quakeColors()&&message.length()>2 && vminecraftChat.lengthCheck(playerName + message)) { + if(vminecraftSettings.getInstance().quakeColors() && message.length()>2) { - //Loop through the string finding the color codes and inserting them - String temp = ""; - for(int x = 0; x< message.length(); x++) - { - if(message.charAt(x)=='^' && x != message.length() - 1) - { - temp += vminecraftChat.colorChange(message.charAt(x+1)); - x++; - } - else{ - temp+=message.charAt(x); - } - } //Log the chat log.log(Level.INFO, "<"+player.getName()+"> "+message); - //Broadcast the message - gmsg(playerName + temp + " "); + //Get the multi line array + String[] msg = wordWrap(player, message); + //Apply colors to the lines + applyColors(msg); + + //Output the first line + gmsg( playerName + msg[0]); + //Get the rest of the lines and display them. + String[] tempOut = new String[msg.length - 1]; + System.arraycopy(msg, 1, tempOut, 0, tempOut.length); + for(String str: tempOut) + gmsg(str); + + //Loop through the string finding the color codes and inserting them return true; } return false; } + + + //===================================================================== + //Function: applyColors + //Input: String[] message: The lines to be colored + //Output: String[]: The lines, but colorful + //Use: Colors each line + //===================================================================== + private static String[] applyColors(String[] message) + { + + //The color to start the line with + String recentColor = Colors.White; + + //Go through each line + int counter = 0; + for(String msg: message) + { + //Start the line with the most recent color + String temp = recentColor; + + //Loop through looking for a color code + for(int x = 0; x< msg.length(); x++) + { + if(msg.charAt(x)=='^' && x != msg.length() - 1) + { + //Set the most recent color to the new color + recentColor = vminecraftChat.colorChange(msg.charAt(x+1)); + temp += recentColor; + x++; + } + else{ + temp += msg.charAt(x); + } + } + //Replace the message with the colorful message + message[counter] = temp; + counter++; + } + return message; + } } diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 26de3add0..e02bfe730 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -61,9 +61,13 @@ public class vminecraftCommands{ //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 - if (player.getName().equalsIgnoreCase(args[0])) + 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 @@ -72,15 +76,12 @@ public class vminecraftCommands{ "That player has higher permissions than you."); //If the player exists transport the user to the player - else if (playerTarget != null) { + else { log.log(Level.INFO, player.getName() + " teleported to " + playerTarget.getName()); player.teleportTo(playerTarget); //Otherwise inform the user that the player doesn't exist - } else { - player.sendMessage(Colors.Rose + "Can't find user " - + args[0] + "."); } } return true; @@ -133,19 +134,20 @@ public class vminecraftCommands{ } else { //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 - if (!player.hasControlOver(playerTarget)) { + 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])) { + 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 if (playerTarget != null) { + else { log.log(Level.INFO, player.getName() + " teleported " + player.getName() + " to their self."); playerTarget.teleportTo(player); - //Otherwise inform the user that the target doens't exist. - } else { - player.sendMessage(Colors.Rose + "Can't find user " + args[0] + "."); } } return true; @@ -186,7 +188,8 @@ public class vminecraftCommands{ if(vminecraftSettings.getInstance().cmdRules()) { //Display them for (String str : vminecraftSettings.getInstance().getRules()) { - player.sendMessage(Colors.Blue+str); + if(str != null) + player.sendMessage(Colors.Blue+str); } return true; } @@ -207,40 +210,24 @@ public class vminecraftCommands{ if(vminecraftSettings.getInstance().cmdFabulous()) { //Make sure a message has been specified if (args.length < 1) {return false;} - String str = "", - temp = ""; + String str = ""; //Merge the message again - str = etc.combineSplit(0, args, " "); - String playerName = "<" + player.getName() + "> "; - String temp2 = playerName + str; - //The array of colors to use - String[] rainbow = new String[] {Colors.Red, Colors.Rose, - Colors.Yellow, Colors.Green, Colors.Blue, - Colors.LightPurple, Colors.Purple}; - int counter=0; - //If the message isn't too long - if(vminecraftChat.lengthCheck(temp2)) - { - //Output for server - log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\""); - - //Loop through the message applying the colors - for(int x=0; x " + + vminecraftChat.rainbow(message[0])); + + //Get the rest of the lines and display them. + String[] tempOut = new String[message.length - 1]; + System.arraycopy(message, 1, tempOut, 0, tempOut.length); + for(String msg: tempOut) + vminecraftChat.gmsg(vminecraftChat.rainbow(msg)); + return true; } return false; @@ -259,39 +246,40 @@ public class vminecraftCommands{ //If the command is enabled if (vminecraftSettings.getInstance().cmdWhoIs()) { //If a player is specified - if (args.length < 1) { + if (args.length < 1) player.sendMessage(Colors.Rose + "Usage is /whois [player]"); - } - //Get the player by name - Player playerTarget = null; - for( Player p : etc.getServer().getPlayerList()) - { - if (p.getName().equalsIgnoreCase(args[0])) + else { + //Get the player by name + Player playerTarget = null; + for( Player p : etc.getServer().getPlayerList()) { - playerTarget = p; + if (p.getName().equalsIgnoreCase(args[0])) + { + playerTarget = p; + } } - } - //If the player exists - if (playerTarget != null){ + //If the player exists + if (playerTarget != null){ - //Displaying the information - player.sendMessage(Colors.Blue + "Whois results for " + - vminecraftChat.nameColor(playerTarget) + "."); - //Group - player.sendMessage(Colors.Blue + "Groups: " + - playerTarget.getGroups()); - //Admin - player.sendMessage(Colors.Blue+"Admin: " + - String.valueOf(playerTarget.canIgnoreRestrictions())); - //IP - player.sendMessage(Colors.Blue+"IP: " + playerTarget.getIP()); - //Restrictions - player.sendMessage(Colors.Blue+"Can ignore restrictions: " + - String.valueOf(playerTarget.canIgnoreRestrictions())); + //Displaying the information + player.sendMessage(Colors.Blue + "Whois results for " + + vminecraftChat.nameColor(playerTarget)); + //Group + player.sendMessage(Colors.Blue + "Groups: " + + playerTarget.getGroups()); + //Admin + player.sendMessage(Colors.Blue+"Admin: " + + String.valueOf(playerTarget.canIgnoreRestrictions())); + //IP + player.sendMessage(Colors.Blue+"IP: " + playerTarget.getIP()); + //Restrictions + player.sendMessage(Colors.Blue+"Can ignore restrictions: " + + String.valueOf(playerTarget.canIgnoreRestrictions())); - //Give the user an error if the player doesn't exist - } else { - player.sendMessage(Colors.Rose+"Player not found."); + //Give the user an error if the player doesn't exist + } else { + player.sendMessage(Colors.Rose+"Player not found."); + } } return true; } @@ -315,11 +303,13 @@ public class vminecraftCommands{ String tempList = ""; for( Player p : etc.getServer().getPlayerList()) { - if(count == 0) - tempList += vminecraftChat.nameColor(p); - else - tempList += ", " + vminecraftChat.nameColor(p); - count++; + if(p != null){ + if(count == 0) + tempList += vminecraftChat.nameColor(p); + else + tempList += ", " + vminecraftChat.nameColor(p); + count++; + } } //Get the max players from the config PropertiesFile server = new PropertiesFile("server.properties"); @@ -329,10 +319,11 @@ public class vminecraftCommands{ e.printStackTrace(); } int maxPlayers = server.getInt("max-players"); - //Output the player list - vminecraftChat.gmsg( Color.red + "Player List (" + count + "/" + maxPlayers + - "): " + tempList); + String[] tempOut = vminecraftChat.wordWrap(Colors.Rose + "Player List (" + + count + "/" + maxPlayers +"): " + tempList); + for(String msg: tempOut) + player.sendMessage( msg ); return true; } @@ -376,8 +367,11 @@ public class vminecraftCommands{ if(vminecraftSettings.getInstance().cmdEzModo()) { //Get the player by name Player playerTarget = etc.getServer().matchPlayer(args[0]); + //If the player doesn't exist don't run + if(playerTarget == null) + return false; //If the player isn't invulnerable kill them - if (!vminecraftSettings.getInstance().isEzModo(player.getName())) { + if (!vminecraftSettings.getInstance().isEzModo(playerTarget.getName())) { playerTarget.setHealth(0); vminecraftChat.gmsg(player.getColor() + player.getName() + Colors.LightBlue + " has slain " + playerTarget.getColor() + playerTarget.getName()); //Otherwise output error to the user diff --git a/vminecraftListener.java b/vminecraftListener.java index 5a0578f56..784adaec1 100644 --- a/vminecraftListener.java +++ b/vminecraftListener.java @@ -29,18 +29,19 @@ public class vminecraftListener extends PluginListener { public boolean onChat(Player player, String message){ //Quote (Greentext) - if (message.startsWith(">")) - vminecraftChat.quote(player, message); + if (message.startsWith("@")) + return vminecraftChat.adminChat(player, message); + + else if (message.startsWith(">")) + return vminecraftChat.quote(player, message); //Rage (FFF) else if (message.startsWith("FFF")) - vminecraftChat.rage(player, message); + return vminecraftChat.rage(player, message); //Send through quakeColors otherwise else - vminecraftChat.quakeColors(player, message); - - return false; + return vminecraftChat.quakeColors(player, message); } //===================================================================== diff --git a/vminecraftSettings.java b/vminecraftSettings.java index 44598c859..b485cec9f 100644 --- a/vminecraftSettings.java +++ b/vminecraftSettings.java @@ -105,7 +105,7 @@ public class vminecraftSettings { cmdPromote = properties.getBoolean("cmdPromote",true); cmdDemote = properties.getBoolean("cmdDemote",true); cmdWhoIs = properties.getBoolean("cmdWhoIs",true); - cmdWhoIs = properties.getBoolean("cmdWho",true); + cmdWho = properties.getBoolean("cmdWho",true); cmdRules = properties.getBoolean("cmdRules",true); cmdTp = properties.getBoolean("cmdTp",true); cmdMasstp = properties.getBoolean("cmdMasstp",true); From a32cb6058dea238708d027d1084d85903f1f64c1 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Sun, 28 Nov 2010 19:30:34 -0600 Subject: [PATCH 06/82] Fixed aliasing feature --- vminecraftCommands.java | 173 ++++++++++++++++++++++++---------------- vminecraftPlugin.java | 9 +-- vminecraftSettings.java | 8 +- 3 files changed, 113 insertions(+), 77 deletions(-) diff --git a/vminecraftCommands.java b/vminecraftCommands.java index e02bfe730..c7f9259eb 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -1,8 +1,6 @@ -import java.awt.Color; 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; @@ -37,6 +35,7 @@ public class vminecraftCommands{ cl.register("/slay", "slay", "Kill target player"); cl.register("/ezmodo", "invuln", "Toggle invulnerability"); cl.register("/ezlist", "ezlist", "List invulnerable players"); + cl.registerAlias("/playerlist", "/who"); } @@ -165,12 +164,7 @@ public class vminecraftCommands{ //===================================================================== public static boolean reload(Player player, String[] args) { - //Should only reload vminecraft settings if the player is able to use /reload - try { - vminecraftSettings.getInstance().loadSettings(); - } catch (IOException e) { - log.log(Level.SEVERE, "Exception while loading settings", e); - } + vminecraftSettings.getInstance().loadSettings(); return true; } @@ -630,27 +624,60 @@ class commandList { //===================================================================== public boolean registerAlias(String name, String com, String[] args){ - //Check to make sure the alias doesn't already exist - for(int i = 0; i < commands.length; i++) - //The alias already exists - if(commands[i].getName().equalsIgnoreCase(name)) - return false; - //If the command list isn't empty if(commands.length > 0) { + //Check to make sure the command doesn't already exist + for(int i = 0; i < commands.length; i++) + if(commands[i].getName().equalsIgnoreCase(name)) + return false; + //Create a new temp array - command[] temp = new command[commands.length]; + command[] temp = new command[commands.length + 1]; //Copy the old command list over System.arraycopy(commands, 0, temp, 0, commands.length); //Set commands to equal the new array commands = temp; + } else { + commands = new command[1]; + } + + //Add the new function to the list + commands[commands.length - 1] = new commandRef(name, com, args); + + //exit successfully + return true; + } + + //===================================================================== + //Function: register + //Input: String name: The name of the command + // String func: The function to be called + //Output: boolean: Whether the command was input successfully or not + //Use: Registers a command to the command list for checking later + //===================================================================== + public boolean registerAlias(String name, String com){ + + //If the command list isn't empty + if(commands.length > 0) + { + //Check to make sure the command doesn't already exist + for(int i = 0; i < commands.length; i++) + if(commands[i].getName().equalsIgnoreCase(name)) + return false; + + //Create a new temp array + command[] temp = new command[commands.length + 1]; + //Copy the old command list over + System.arraycopy(commands, 0, temp, 0, commands.length); + //Set commands to equal the new array + commands = temp; + } else { + commands = new command[1]; } - - //Add the new function to the list - commands[commands.length] = new commandRef(name, com, args); + commands[commands.length - 1] = new commandRef(name, com); //exit successfully return true; @@ -668,18 +695,19 @@ class commandList { return false; } //Search for the command - for(int i = 0; i < commands.length; i++) + for(command cmd : commands) { //When found - if(commands[i].getName().equalsIgnoreCase(name)) + if(cmd.getName().equalsIgnoreCase(name)) { try { //Call the command and return results - return commands[i].call(player, arg); + return cmd.call(player, arg); } catch (SecurityException e) { log.log(Level.SEVERE, "Exception while running command", e); } catch (IllegalArgumentException e) { - log.log(Level.SEVERE, "Exception while running command", e); + log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e); + return false; } } } @@ -715,9 +743,7 @@ class commandList { //Output: String: The command name //Use: Returns the command name //===================================================================== - public String getName(){ - return commandName; - } + public String getName(){return commandName;} //===================================================================== @@ -726,25 +752,26 @@ class commandList { //Output: boolean: If the command was called successfully //Use: Attempts to call the command //===================================================================== - public boolean call(Player player, String[] arg) + boolean call(Player player, String[] arg) { - try { - Method m = vminecraftCommands.class.getMethod(function, Player.class, String[].class); - m.setAccessible(true); - return (Boolean) m.invoke(null, player, arg); - - } catch (SecurityException e) { - log.log(Level.SEVERE, "Exception while running command", e); - } catch (NoSuchMethodException e) { - log.log(Level.SEVERE, "Exception while running command", e); - } catch (IllegalArgumentException e) { - log.log(Level.SEVERE, "Exception while running command", e); - } catch (IllegalAccessException e) { - log.log(Level.SEVERE, "Exception while running command", e); - } catch (InvocationTargetException e) { - log.log(Level.SEVERE, "Exception while running command", e); - } - return true; + + Method m; + try { + m = vminecraftCommands.class.getMethod(function, Player.class, String[].class); + m.setAccessible(true); + return (Boolean) 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 true; } } @@ -754,13 +781,14 @@ class commandList { //Author: cerevisiae //===================================================================== private class commandRef extends command{ - private String commandName; private String reference; private String[] args; //===================================================================== //Function: command - //Input: None + //Input: String name: The command name + // String com: The command to run + // String[] arg: the arguments to apply //Output: None //Use: Initialize the command //===================================================================== @@ -771,13 +799,16 @@ class commandList { } //===================================================================== - //Function: call - //Input: None - //Output: String: The command name - //Use: Returns the command name + //Function: command + //Input: String name: The command name + // String com: The command to run + //Output: None + //Use: Initialize the command //===================================================================== - public String getName(){ - return commandName; + public commandRef(String name, String com){ + super(name, ""); + reference = com; + args = null; } @@ -787,27 +818,35 @@ class commandList { //Output: boolean: If the command was called successfully //Use: Attempts to call the command //===================================================================== - public boolean call(String[] arg) + boolean call(Player player, String[] arg) { - - //Insert the arguments into the pre-set arguments String[] temp = args; - int lastSet = -1; - for(int i = 0; i < temp.length; i++) - if(temp[i].startsWith("%")) - temp[i] = arg[lastSet = Integer.parseInt(temp[i].substring(1))]; - - //Append the rest of the arguments to the argument array - if(lastSet + 1 < arg.length) + if(args != null) { - String[] temp2 = new String[temp.length + arg.length - lastSet]; - System.arraycopy(temp, 0, temp2, 0, temp.length); - System.arraycopy(arg, lastSet + 1, temp2, - temp.length, arg.length - lastSet); + //Insert the arguments into the pre-set arguments + int lastSet = -1; + for(int i = 0; i < temp.length; i++) + if(temp[i].startsWith("%")) + temp[i] = arg[lastSet = Integer.parseInt(temp[i].substring(1))]; + //Append the rest of the arguments to the argument array + if(lastSet + 1 < arg.length) + { + String[] temp2 = new String[temp.length + arg.length - lastSet]; + System.arraycopy(temp, 0, temp2, 0, temp.length); + System.arraycopy(arg, lastSet + 1, temp2, + temp.length, arg.length - lastSet); + } } - //Call the referenced command - //TODO STILL TO BE WRITTEN + if(temp != null) + player.command(reference + " " + etc.combineSplit(0, temp, " ")); + else + player.command(reference); + + /*if(temp != null) + etc.getServer().useConsoleCommand(reference + " " + etc.combineSplit(0, temp, " "), player); + else + etc.getServer().useConsoleCommand(reference, player);*/ return true; } } diff --git a/vminecraftPlugin.java b/vminecraftPlugin.java index d8075d20e..9dc6f7695 100644 --- a/vminecraftPlugin.java +++ b/vminecraftPlugin.java @@ -1,5 +1,3 @@ -import java.io.IOException; -import java.util.logging.Level; import java.util.logging.Logger; //===================================================================== @@ -12,12 +10,7 @@ public class vminecraftPlugin extends Plugin { protected static final Logger log = Logger.getLogger("Minecraft"); public void enable() { - //Hopefully this will make the plugin load right away - try { - vminecraftSettings.getInstance().loadSettings(); - } catch (IOException e) { - log.log(Level.SEVERE, "Exception while loading settings ", e); - } + vminecraftSettings.getInstance().loadSettings(); vminecraftCommands.loadCommands(); } diff --git a/vminecraftSettings.java b/vminecraftSettings.java index b485cec9f..c4cd4e63c 100644 --- a/vminecraftSettings.java +++ b/vminecraftSettings.java @@ -48,7 +48,7 @@ public class vminecraftSettings { //Output: None //Use: Loads the settings from the properties //===================================================================== - public void loadSettings() throws IOException + public void loadSettings() { File theDir = new File("vminecraft.properties"); if(!theDir.exists()){ @@ -93,7 +93,11 @@ public class vminecraftSettings { } else { properties = new PropertiesFile("vminecraft.properties"); - properties.load(); + try { + properties.load(); + } catch (IOException e) { + e.printStackTrace(); + } } try { From e5d012c2eca5031a2d7914aff5912edcc00369d8 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Sun, 28 Nov 2010 19:30:34 -0600 Subject: [PATCH 07/82] Added settings for stopFire, stopTnt, added hooks for onIgnite and onExplode. Signed-off-by: nossr50 --- vminecraftCommands.java | 173 ++++++++++++++++++++++++---------------- vminecraftListener.java | 1 + vminecraftPlugin.java | 11 +-- vminecraftSettings.java | 18 ++++- 4 files changed, 125 insertions(+), 78 deletions(-) diff --git a/vminecraftCommands.java b/vminecraftCommands.java index e02bfe730..c7f9259eb 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -1,8 +1,6 @@ -import java.awt.Color; 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; @@ -37,6 +35,7 @@ public class vminecraftCommands{ cl.register("/slay", "slay", "Kill target player"); cl.register("/ezmodo", "invuln", "Toggle invulnerability"); cl.register("/ezlist", "ezlist", "List invulnerable players"); + cl.registerAlias("/playerlist", "/who"); } @@ -165,12 +164,7 @@ public class vminecraftCommands{ //===================================================================== public static boolean reload(Player player, String[] args) { - //Should only reload vminecraft settings if the player is able to use /reload - try { - vminecraftSettings.getInstance().loadSettings(); - } catch (IOException e) { - log.log(Level.SEVERE, "Exception while loading settings", e); - } + vminecraftSettings.getInstance().loadSettings(); return true; } @@ -630,27 +624,60 @@ class commandList { //===================================================================== public boolean registerAlias(String name, String com, String[] args){ - //Check to make sure the alias doesn't already exist - for(int i = 0; i < commands.length; i++) - //The alias already exists - if(commands[i].getName().equalsIgnoreCase(name)) - return false; - //If the command list isn't empty if(commands.length > 0) { + //Check to make sure the command doesn't already exist + for(int i = 0; i < commands.length; i++) + if(commands[i].getName().equalsIgnoreCase(name)) + return false; + //Create a new temp array - command[] temp = new command[commands.length]; + command[] temp = new command[commands.length + 1]; //Copy the old command list over System.arraycopy(commands, 0, temp, 0, commands.length); //Set commands to equal the new array commands = temp; + } else { + commands = new command[1]; + } + + //Add the new function to the list + commands[commands.length - 1] = new commandRef(name, com, args); + + //exit successfully + return true; + } + + //===================================================================== + //Function: register + //Input: String name: The name of the command + // String func: The function to be called + //Output: boolean: Whether the command was input successfully or not + //Use: Registers a command to the command list for checking later + //===================================================================== + public boolean registerAlias(String name, String com){ + + //If the command list isn't empty + if(commands.length > 0) + { + //Check to make sure the command doesn't already exist + for(int i = 0; i < commands.length; i++) + if(commands[i].getName().equalsIgnoreCase(name)) + return false; + + //Create a new temp array + command[] temp = new command[commands.length + 1]; + //Copy the old command list over + System.arraycopy(commands, 0, temp, 0, commands.length); + //Set commands to equal the new array + commands = temp; + } else { + commands = new command[1]; } - - //Add the new function to the list - commands[commands.length] = new commandRef(name, com, args); + commands[commands.length - 1] = new commandRef(name, com); //exit successfully return true; @@ -668,18 +695,19 @@ class commandList { return false; } //Search for the command - for(int i = 0; i < commands.length; i++) + for(command cmd : commands) { //When found - if(commands[i].getName().equalsIgnoreCase(name)) + if(cmd.getName().equalsIgnoreCase(name)) { try { //Call the command and return results - return commands[i].call(player, arg); + return cmd.call(player, arg); } catch (SecurityException e) { log.log(Level.SEVERE, "Exception while running command", e); } catch (IllegalArgumentException e) { - log.log(Level.SEVERE, "Exception while running command", e); + log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e); + return false; } } } @@ -715,9 +743,7 @@ class commandList { //Output: String: The command name //Use: Returns the command name //===================================================================== - public String getName(){ - return commandName; - } + public String getName(){return commandName;} //===================================================================== @@ -726,25 +752,26 @@ class commandList { //Output: boolean: If the command was called successfully //Use: Attempts to call the command //===================================================================== - public boolean call(Player player, String[] arg) + boolean call(Player player, String[] arg) { - try { - Method m = vminecraftCommands.class.getMethod(function, Player.class, String[].class); - m.setAccessible(true); - return (Boolean) m.invoke(null, player, arg); - - } catch (SecurityException e) { - log.log(Level.SEVERE, "Exception while running command", e); - } catch (NoSuchMethodException e) { - log.log(Level.SEVERE, "Exception while running command", e); - } catch (IllegalArgumentException e) { - log.log(Level.SEVERE, "Exception while running command", e); - } catch (IllegalAccessException e) { - log.log(Level.SEVERE, "Exception while running command", e); - } catch (InvocationTargetException e) { - log.log(Level.SEVERE, "Exception while running command", e); - } - return true; + + Method m; + try { + m = vminecraftCommands.class.getMethod(function, Player.class, String[].class); + m.setAccessible(true); + return (Boolean) 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 true; } } @@ -754,13 +781,14 @@ class commandList { //Author: cerevisiae //===================================================================== private class commandRef extends command{ - private String commandName; private String reference; private String[] args; //===================================================================== //Function: command - //Input: None + //Input: String name: The command name + // String com: The command to run + // String[] arg: the arguments to apply //Output: None //Use: Initialize the command //===================================================================== @@ -771,13 +799,16 @@ class commandList { } //===================================================================== - //Function: call - //Input: None - //Output: String: The command name - //Use: Returns the command name + //Function: command + //Input: String name: The command name + // String com: The command to run + //Output: None + //Use: Initialize the command //===================================================================== - public String getName(){ - return commandName; + public commandRef(String name, String com){ + super(name, ""); + reference = com; + args = null; } @@ -787,27 +818,35 @@ class commandList { //Output: boolean: If the command was called successfully //Use: Attempts to call the command //===================================================================== - public boolean call(String[] arg) + boolean call(Player player, String[] arg) { - - //Insert the arguments into the pre-set arguments String[] temp = args; - int lastSet = -1; - for(int i = 0; i < temp.length; i++) - if(temp[i].startsWith("%")) - temp[i] = arg[lastSet = Integer.parseInt(temp[i].substring(1))]; - - //Append the rest of the arguments to the argument array - if(lastSet + 1 < arg.length) + if(args != null) { - String[] temp2 = new String[temp.length + arg.length - lastSet]; - System.arraycopy(temp, 0, temp2, 0, temp.length); - System.arraycopy(arg, lastSet + 1, temp2, - temp.length, arg.length - lastSet); + //Insert the arguments into the pre-set arguments + int lastSet = -1; + for(int i = 0; i < temp.length; i++) + if(temp[i].startsWith("%")) + temp[i] = arg[lastSet = Integer.parseInt(temp[i].substring(1))]; + //Append the rest of the arguments to the argument array + if(lastSet + 1 < arg.length) + { + String[] temp2 = new String[temp.length + arg.length - lastSet]; + System.arraycopy(temp, 0, temp2, 0, temp.length); + System.arraycopy(arg, lastSet + 1, temp2, + temp.length, arg.length - lastSet); + } } - //Call the referenced command - //TODO STILL TO BE WRITTEN + if(temp != null) + player.command(reference + " " + etc.combineSplit(0, temp, " ")); + else + player.command(reference); + + /*if(temp != null) + etc.getServer().useConsoleCommand(reference + " " + etc.combineSplit(0, temp, " "), player); + else + etc.getServer().useConsoleCommand(reference, player);*/ return true; } } diff --git a/vminecraftListener.java b/vminecraftListener.java index 784adaec1..c910eae42 100644 --- a/vminecraftListener.java +++ b/vminecraftListener.java @@ -87,4 +87,5 @@ public class vminecraftListener extends PluginListener { } return false; } + } \ No newline at end of file diff --git a/vminecraftPlugin.java b/vminecraftPlugin.java index d8075d20e..37176ff38 100644 --- a/vminecraftPlugin.java +++ b/vminecraftPlugin.java @@ -1,5 +1,3 @@ -import java.io.IOException; -import java.util.logging.Level; import java.util.logging.Logger; //===================================================================== @@ -12,12 +10,7 @@ public class vminecraftPlugin extends Plugin { protected static final Logger log = Logger.getLogger("Minecraft"); public void enable() { - //Hopefully this will make the plugin load right away - try { - vminecraftSettings.getInstance().loadSettings(); - } catch (IOException e) { - log.log(Level.SEVERE, "Exception while loading settings ", e); - } + vminecraftSettings.getInstance().loadSettings(); vminecraftCommands.loadCommands(); } @@ -29,6 +22,8 @@ public class vminecraftPlugin extends Plugin { //Here we add the hook we're going to use. In this case it's the arm swing event. etc.getLoader().addListener(PluginLoader.Hook.CHAT, listener, this, PluginListener.Priority.MEDIUM); etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH); + etc.getLoader().addListener(PluginLoader.Hook.IGNITE, listener, this, PluginListener.Priority.HIGH); + etc.getLoader().addListener(PluginLoader.Hook.EXPLODE, listener, this, PluginListener.Priority.HIGH); if(etc.getInstance().isHealthEnabled()){ etc.getLoader().addListener(PluginLoader.Hook.HEALTH_CHANGE, listener, this, PluginListener.Priority.MEDIUM); } diff --git a/vminecraftSettings.java b/vminecraftSettings.java index b485cec9f..70b96f79f 100644 --- a/vminecraftSettings.java +++ b/vminecraftSettings.java @@ -12,7 +12,7 @@ public class vminecraftSettings { protected static final Logger log = Logger.getLogger("Minecraft"); private static volatile vminecraftSettings instance; //Invulnerability List - + //The feature settings static boolean toggle = true, @@ -31,6 +31,8 @@ public class vminecraftSettings { globalmessages = false, cmdSay = false, cmdWho = false, + stopFire = false, + stopTnt = false, cmdEzModo = false; //An array of players currently in ezmodo @@ -48,7 +50,7 @@ public class vminecraftSettings { //Output: None //Use: Loads the settings from the properties //===================================================================== - public void loadSettings() throws IOException + public void loadSettings() { File theDir = new File("vminecraft.properties"); if(!theDir.exists()){ @@ -78,6 +80,8 @@ public class vminecraftSettings { writer.write("cmdEzModo=true\r\n"); writer.write("ezModo=\r\n"); writer.write("ezHealth=30\r\n"); + writer.write("stopFire=false"); + writer.write("stopTnt=false"); writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n"); } catch (Exception e) { log.log(Level.SEVERE, "Exception while creating " + location, e); @@ -93,7 +97,11 @@ public class vminecraftSettings { } else { properties = new PropertiesFile("vminecraft.properties"); - properties.load(); + try { + properties.load(); + } catch (IOException e) { + e.printStackTrace(); + } } try { @@ -113,6 +121,8 @@ public class vminecraftSettings { globalmessages = properties.getBoolean("globalmessages",true); cmdSay = properties.getBoolean("cmdSay",true); cmdEzModo = properties.getBoolean("cmdEzModo",true); + stopFire = properties.getBoolean("stopFire",true); + stopTnt = properties.getBoolean("stopTNT",true); rules = properties.getString("rules", "").split("@"); String[] tempEz = properties.getString("ezModo").split(","); @@ -155,6 +165,8 @@ public class vminecraftSettings { public boolean cmdMasstp() {return cmdMasstp;} public boolean cmdEzModo() {return cmdEzModo;} public boolean cmdWho() {return cmdWho;} + public boolean stopFire() {return stopFire;} + public boolean stopTnt() {return stopTnt;} //EzModo functions public boolean isEzModo(String playerName) {return ezModo.contains(playerName);} From 8a86cef94ae233958c9742c040f4e0c3fbff574c Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Sun, 28 Nov 2010 21:04:59 -0600 Subject: [PATCH 08/82] Fixed some of the alias argument features. --- vminecraftCommands.java | 45 ++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/vminecraftCommands.java b/vminecraftCommands.java index c7f9259eb..447339194 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -36,6 +36,8 @@ public class vminecraftCommands{ cl.register("/ezmodo", "invuln", "Toggle invulnerability"); cl.register("/ezlist", "ezlist", "List invulnerable players"); cl.registerAlias("/playerlist", "/who"); + cl.registerAlias("/it", "/i", new String[] {"%0", "100"}); + cl.registerAlias("/wood", "/i", new String[] {"wood"}); } @@ -820,27 +822,38 @@ class commandList { //===================================================================== boolean call(Player player, String[] arg) { - String[] temp = args; - if(args != null) - { + if(args != null) { + String[] temp = new String[args.length]; + System.arraycopy(args, 0, temp, 0, args.length); //Insert the arguments into the pre-set arguments - int lastSet = -1; - for(int i = 0; i < temp.length; i++) - if(temp[i].startsWith("%")) - temp[i] = arg[lastSet = Integer.parseInt(temp[i].substring(1))]; - //Append the rest of the arguments to the argument array - if(lastSet + 1 < arg.length) + int lastSet = 0, + argCount = 0; + for(String argument : temp) { - String[] temp2 = new String[temp.length + arg.length - lastSet]; - System.arraycopy(temp, 0, temp2, 0, temp.length); - System.arraycopy(arg, lastSet + 1, temp2, - temp.length, arg.length - lastSet); + if(argument.startsWith("%")) + { + int argNum = Integer.parseInt(argument.substring(1)); + if( argNum < arg.length ) + { + temp[lastSet] = arg[argNum]; + argCount++; + } + } + lastSet++; } - } + //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; + } + //Call the referenced command - if(temp != null) player.command(reference + " " + etc.combineSplit(0, temp, " ")); - else + } else player.command(reference); /*if(temp != null) From b92bd3b65df454e60c462d13c010f5dc0e2fbf35 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Mon, 29 Nov 2010 03:05:53 -0600 Subject: [PATCH 09/82] Fixed the WordWrap function. So now /who works properly. --- vminecraftChat.java | 50 ++++++++++++++++------------------------- vminecraftCommands.java | 10 ++++----- 2 files changed, 23 insertions(+), 37 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index bf7ef6c49..9b11c9198 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -1,3 +1,4 @@ +import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; @@ -32,51 +33,38 @@ public class vminecraftChat { //===================================================================== public static String[] wordWrap(String msg){ //Split each word apart - String[] array = msg.split(" "); + String[] split = msg.split(" "); //Create the output array - String[] out = new String[0]; + int length = (int)msgLength(msg) / 316; + + ArrayList out = new ArrayList(); //While i is less than the length of the array of words int i = 0; - while(i < array.length){ + while(i < split.length){ int len = 0; int j = i; + //Loop through the words finding their length and increasing //j, the end point for the sub string - while(len <= 316 && j < array.length) + while(len <= 316 && i < split.length) { - len += msgLength(array[j]) + 4; + len += msgLength(split[i]) + 4; if( len <= 316) - j++; + i++; } - String[] temp = new String[j - i]; + String[] temp = new String[i - j]; + + //Copy the words in the selection into a new array + System.arraycopy(split, j, temp, 0, i - j); - //If it's not the end yet - if(j < array.length) - { - //Copy the words in the selection into a new array - System.arraycopy(array, i, temp, 0, j); - - //Merge them and add them to the output array - String[] tempOut = new String[out.length + 1]; - System.arraycopy(out, 0, tempOut, 0, out.length); - tempOut[tempOut.length - 1] = etc.combineSplit(0, temp, " "); - out = tempOut; - - } - else - { - //Merge the rest and add them to the output array - String[] tempOut = new String[out.length + 1]; - System.arraycopy(out, 0, tempOut, 0, out.length); - tempOut[tempOut.length - 1] = etc.combineSplit(i, array, " "); - out = tempOut; - } - //Make the old front equal to the old end - i = j; + //Merge them and add them to the output array + out.add( etc.combineSplit(0, temp, " ") ); } - return out; + String[] tempout = new String[out.size()]; + out.toArray(tempout); + return tempout; } //===================================================================== diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 447339194..ccfec0a58 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -36,8 +36,6 @@ public class vminecraftCommands{ cl.register("/ezmodo", "invuln", "Toggle invulnerability"); cl.register("/ezlist", "ezlist", "List invulnerable players"); cl.registerAlias("/playerlist", "/who"); - cl.registerAlias("/it", "/i", new String[] {"%0", "100"}); - cl.registerAlias("/wood", "/i", new String[] {"wood"}); } @@ -215,7 +213,7 @@ public class vminecraftCommands{ String[] message = vminecraftChat.wordWrap(player, str); //Output the first line - vminecraftChat.gmsg( "<" + vminecraftChat.nameColor(player) + "> " + vminecraftChat.gmsg( "<" + vminecraftChat.nameColor(player) + Colors.White + "> " + vminecraftChat.rainbow(message[0])); //Get the rest of the lines and display them. @@ -261,8 +259,8 @@ public class vminecraftCommands{ player.sendMessage(Colors.Blue + "Whois results for " + vminecraftChat.nameColor(playerTarget)); //Group - player.sendMessage(Colors.Blue + "Groups: " + - playerTarget.getGroups()); + for(String group: playerTarget.getGroups()) + player.sendMessage(Colors.Blue + "Groups: " + group); //Admin player.sendMessage(Colors.Blue+"Admin: " + String.valueOf(playerTarget.canIgnoreRestrictions())); @@ -303,7 +301,7 @@ public class vminecraftCommands{ if(count == 0) tempList += vminecraftChat.nameColor(p); else - tempList += ", " + vminecraftChat.nameColor(p); + tempList += Colors.White + ", " + vminecraftChat.nameColor(p); count++; } } From 11dc691220dbb351e9ea1e3036f0821cadab510d Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Mon, 29 Nov 2010 19:13:16 -0600 Subject: [PATCH 10/82] Misc fixes for WordWrap --- vminecraftChat.java | 75 +++++------------------------------------ vminecraftCommands.java | 14 ++++---- vminecraftSettings.java | 22 ++++++------ 3 files changed, 28 insertions(+), 83 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index 9b11c9198..ab429e889 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -34,9 +34,8 @@ public class vminecraftChat { public static String[] wordWrap(String msg){ //Split each word apart String[] split = msg.split(" "); - //Create the output array - int length = (int)msgLength(msg) / 316; + //Create an arraylist for the output ArrayList out = new ArrayList(); //While i is less than the length of the array of words @@ -54,78 +53,20 @@ public class vminecraftChat { i++; } - String[] temp = new String[i - j]; - //Copy the words in the selection into a new array + String[] temp = new String[i - j]; System.arraycopy(split, j, temp, 0, i - j); //Merge them and add them to the output array out.add( etc.combineSplit(0, temp, " ") ); } + + //Convert to an array and return String[] tempout = new String[out.size()]; out.toArray(tempout); return tempout; } - //===================================================================== - //Function: wordWrap - //Input: Player player: To get the player name - // 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(Player player, String msg){ - //Split each word apart - String[] array = msg.split(" "); - //Create the output array - String[] out = new String[0]; - - //While i is less than the length of the array of words - int i = 0; - while(i < array.length){ - int len = 0; - if(out.length == 0) - len = msgLength("<" + player.getName() + "> "); - int j = i; - //Loop through the words finding their length and increasing - //j, the end point for the sub string - while(len <= 316 && j < array.length) - { - len += msgLength(array[j]) + 4; - if( len <= 316) - j++; - - } - String[] temp = new String[j - i]; - - //If it's not the end yet - if(j < array.length) - { - //Copy the words in the selection into a new array - System.arraycopy(array, i, temp, 0, j); - - //Merge them and add them to the output array - String[] tempOut = new String[out.length + 1]; - System.arraycopy(out, 0, tempOut, 0, out.length); - tempOut[tempOut.length - 1] = etc.combineSplit(0, temp, " "); - out = tempOut; - - } - else - { - //Merge the rest and add them to the output array - String[] tempOut = new String[out.length + 1]; - System.arraycopy(out, 0, tempOut, 0, out.length); - tempOut[tempOut.length - 1] = etc.combineSplit(i, array, " "); - out = tempOut; - } - //Make the old front equal to the old end - i = j; - } - return out; - } - private static int msgLength(String str){ int length = 0; for(int x = 0; x "+message); //Get the multi line array - String[] msg = wordWrap(player, message); + String[] msg = wordWrap(playerName + message); //Output the first line gmsg( playerName + Colors.LightGreen + msg[0]); @@ -367,7 +308,7 @@ public class vminecraftChat { log.log(Level.INFO, "<"+player.getName()+"> "+message); //Get the multi line array - String[] msg = wordWrap(player, message); + String[] msg = wordWrap(playerName + message); //Output the first line gmsg( playerName + Colors.Red + msg[0]); @@ -399,7 +340,7 @@ public class vminecraftChat { log.log(Level.INFO, "<"+player.getName()+"> "+message); //Get the multi line array - String[] msg = wordWrap(player, message); + String[] msg = wordWrap(playerName + message); //Apply colors to the lines applyColors(msg); diff --git a/vminecraftCommands.java b/vminecraftCommands.java index ccfec0a58..8d9ef4792 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -179,10 +179,11 @@ public class vminecraftCommands{ public static boolean rules(Player player, String[] args) { //If the rules exist - if(vminecraftSettings.getInstance().cmdRules()) { + if(vminecraftSettings.getInstance().cmdRules() + && vminecraftSettings.getInstance().getRules().length != 0) { //Display them for (String str : vminecraftSettings.getInstance().getRules()) { - if(str != null) + if(str.isEmpty()) player.sendMessage(Colors.Blue+str); } return true; @@ -202,19 +203,20 @@ public class vminecraftCommands{ { //If the command is enabled if(vminecraftSettings.getInstance().cmdFabulous()) { + String playerName = "<" + vminecraftChat.nameColor(player) + + Colors.White + "> "; //Make sure a message has been specified if (args.length < 1) {return false;} - String str = ""; + String str = " "; //Merge the message again str = etc.combineSplit(0, args, " "); //Output for server log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\""); //Prepend the player name - String[] message = vminecraftChat.wordWrap(player, str); + String[] message = vminecraftChat.wordWrap(playerName + str); //Output the first line - vminecraftChat.gmsg( "<" + vminecraftChat.nameColor(player) + Colors.White + "> " - + vminecraftChat.rainbow(message[0])); + vminecraftChat.gmsg( playerName + vminecraftChat.rainbow(message[0])); //Get the rest of the lines and display them. String[] tempOut = new String[message.length - 1]; diff --git a/vminecraftSettings.java b/vminecraftSettings.java index 70b96f79f..8ff4917b3 100644 --- a/vminecraftSettings.java +++ b/vminecraftSettings.java @@ -31,8 +31,8 @@ public class vminecraftSettings { globalmessages = false, cmdSay = false, cmdWho = false, - stopFire = false, - stopTnt = false, + stopFire = false, + stopTnt = false, cmdEzModo = false; //An array of players currently in ezmodo @@ -42,7 +42,7 @@ public class vminecraftSettings { private PropertiesFile properties; String file = "vminecraft.properties"; - public String rules[] = null; + public String rules[] = new String[0]; //===================================================================== //Function: loadSettings @@ -78,10 +78,12 @@ public class vminecraftSettings { writer.write("FFF=true\r\n"); writer.write("adminchat=true\r\n"); writer.write("cmdEzModo=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("#The health ezmodo people will have while in ezmodo. Don't set to 0\r\n"); writer.write("ezHealth=30\r\n"); - writer.write("stopFire=false"); - writer.write("stopTnt=false"); + writer.write("stopFire=false"); + writer.write("stopTnt=false"); writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n"); } catch (Exception e) { log.log(Level.SEVERE, "Exception while creating " + location, e); @@ -100,7 +102,7 @@ public class vminecraftSettings { try { properties.load(); } catch (IOException e) { - e.printStackTrace(); + log.log(Level.SEVERE, "Exception while loading vminecraft.properties", e); } } @@ -121,8 +123,8 @@ public class vminecraftSettings { globalmessages = properties.getBoolean("globalmessages",true); cmdSay = properties.getBoolean("cmdSay",true); cmdEzModo = properties.getBoolean("cmdEzModo",true); - stopFire = properties.getBoolean("stopFire",true); - stopTnt = properties.getBoolean("stopTNT",true); + stopFire = properties.getBoolean("stopFire",true); + stopTnt = properties.getBoolean("stopTNT",true); rules = properties.getString("rules", "").split("@"); String[] tempEz = properties.getString("ezModo").split(","); @@ -165,8 +167,8 @@ public class vminecraftSettings { public boolean cmdMasstp() {return cmdMasstp;} public boolean cmdEzModo() {return cmdEzModo;} public boolean cmdWho() {return cmdWho;} - public boolean stopFire() {return stopFire;} - public boolean stopTnt() {return stopTnt;} + public boolean stopFire() {return stopFire;} + public boolean stopTnt() {return stopTnt;} //EzModo functions public boolean isEzModo(String playerName) {return ezModo.contains(playerName);} From 02ecadbf3c8b172fbaaa25bc9278fd7d779f4cc8 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 29 Nov 2010 18:51:30 -0800 Subject: [PATCH 11/82] Commands - Fixed whois Listener - Added random death messages Plugin - Added hooks for damage Settings - Added random death messages Signed-off-by: nossr50 --- vminecraftCommands.java | 2 +- vminecraftListener.java | 8 +++++++- vminecraftPlugin.java | 1 + vminecraftSettings.java | 20 ++++++++++++++------ 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 8d9ef4792..f36cfe938 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -265,7 +265,7 @@ public class vminecraftCommands{ player.sendMessage(Colors.Blue + "Groups: " + group); //Admin player.sendMessage(Colors.Blue+"Admin: " + - String.valueOf(playerTarget.canIgnoreRestrictions())); + String.valueOf(playerTarget.isAdmin())); //IP player.sendMessage(Colors.Blue+"IP: " + playerTarget.getIP()); //Restrictions diff --git a/vminecraftListener.java b/vminecraftListener.java index c910eae42..7bc1081a6 100644 --- a/vminecraftListener.java +++ b/vminecraftListener.java @@ -83,9 +83,15 @@ public class vminecraftListener extends PluginListener { } else if (vminecraftSettings.getInstance().globalmessages() && player.getHealth() < 1) { - vminecraftChat.gmsg(Colors.Gray + player.getName() + " is no more"); + vminecraftChat.gmsg(Colors.Gray + player.getName() + " " + vminecraftSettings.randomDeathMsg()); } return false; } + /** Not working yet, I posted the issue to hMod on github though + public boolean onDamage(DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { + + return false; + } + **/ } \ No newline at end of file diff --git a/vminecraftPlugin.java b/vminecraftPlugin.java index 37176ff38..160418483 100644 --- a/vminecraftPlugin.java +++ b/vminecraftPlugin.java @@ -23,6 +23,7 @@ public class vminecraftPlugin extends Plugin { etc.getLoader().addListener(PluginLoader.Hook.CHAT, listener, this, PluginListener.Priority.MEDIUM); etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH); etc.getLoader().addListener(PluginLoader.Hook.IGNITE, listener, this, PluginListener.Priority.HIGH); + etc.getLoader().addListener(PluginLoader.Hook.DAMAGE, listener, this, PluginListener.Priority.MEDIUM); etc.getLoader().addListener(PluginLoader.Hook.EXPLODE, listener, this, PluginListener.Priority.HIGH); if(etc.getInstance().isHealthEnabled()){ etc.getLoader().addListener(PluginLoader.Hook.HEALTH_CHANGE, listener, this, PluginListener.Priority.MEDIUM); diff --git a/vminecraftSettings.java b/vminecraftSettings.java index 8ff4917b3..fc2e1d26c 100644 --- a/vminecraftSettings.java +++ b/vminecraftSettings.java @@ -2,6 +2,7 @@ import java.io.*; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.Random; //===================================================================== //Class: vminecraftSettings //Use: Controls the settings for vminecraft @@ -11,7 +12,6 @@ public class vminecraftSettings { //private final static Object syncLock = new Object(); protected static final Logger log = Logger.getLogger("Minecraft"); private static volatile vminecraftSettings instance; - //Invulnerability List //The feature settings @@ -34,7 +34,6 @@ public class vminecraftSettings { stopFire = false, stopTnt = false, cmdEzModo = false; - //An array of players currently in ezmodo static ArrayList ezModo = new ArrayList(); //The max health for ezModo @@ -43,6 +42,7 @@ public class vminecraftSettings { private PropertiesFile properties; String file = "vminecraft.properties"; public String rules[] = new String[0]; + public static String deathMessages[] = new String[0]; //===================================================================== //Function: loadSettings @@ -83,8 +83,10 @@ public class vminecraftSettings { writer.write("#The health ezmodo people will have while in ezmodo. Don't set to 0\r\n"); writer.write("ezHealth=30\r\n"); writer.write("stopFire=false"); - writer.write("stopTnt=false"); + writer.write("stopTnt=false"); writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n"); + writer.write("#Death messages, seperate them by comma. All death messages start with the player name and a space."); + writer.write("deathMessages=is no more,died horribly,went peacefully"); } catch (Exception e) { log.log(Level.SEVERE, "Exception while creating " + location, e); } finally { @@ -126,7 +128,7 @@ public class vminecraftSettings { stopFire = properties.getBoolean("stopFire",true); stopTnt = properties.getBoolean("stopTNT",true); rules = properties.getString("rules", "").split("@"); - + deathMessages = properties.getString("deathmessages", "").split(","); String[] tempEz = properties.getString("ezModo").split(","); ezModo = new ArrayList(); for(int i = 0; i < tempEz.length; i++) @@ -170,13 +172,19 @@ public class vminecraftSettings { public boolean stopFire() {return stopFire;} public boolean stopTnt() {return stopTnt;} - //EzModo functions + //EzModo methods public boolean isEzModo(String playerName) {return ezModo.contains(playerName);} public void removeEzModo(String playerName) {ezModo.remove(ezModo.indexOf(playerName));} public void addEzModo(String playerName) {ezModo.add(playerName);} public int ezModoHealth() {return ezHealth;} 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 From 38a6caae711050a026668d31bbdf622f638a4309 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Mon, 29 Nov 2010 21:00:03 -0600 Subject: [PATCH 12/82] Fixed the functions that call wordWrap so they should no longer output the username multiple times. --- vminecraftChat.java | 41 +++++++++++++++-------------------------- vminecraftCommands.java | 31 +++++++++++++++++++------------ 2 files changed, 34 insertions(+), 38 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index ab429e889..dddbbd7e9 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -272,21 +272,17 @@ public class vminecraftChat { public static boolean quote(Player player, String message) { //Format the name - String playerName = "<" + nameColor(player) + Colors.White +"> "; + String playerName = Colors.White + "<" + nameColor(player) + + Colors.White + "> "; if(vminecraftSettings.getInstance().greentext()) { //Log the chat - log.log(Level.INFO, "<"+player.getName()+"> "+message); + log.log(Level.INFO, "<"+player.getName()+"> " +message); //Get the multi line array - String[] msg = wordWrap(playerName + message); + String[] msg = wordWrap(playerName + Colors.LightGreen + message); - //Output the first line - gmsg( playerName + Colors.LightGreen + msg[0]); - - //Get the rest of the lines and display them. - String[] tempOut = new String[msg.length - 1]; - System.arraycopy(msg, 1, tempOut, 0, tempOut.length); - for(String str: tempOut) + //Output the lines + for(String str: msg) gmsg(Colors.LightGreen + str); return true; } @@ -303,20 +299,16 @@ public class vminecraftChat { public static boolean rage(Player player, String message) { //Format the name - String playerName = "<" + nameColor(player) + Colors.White +"> "; + String playerName = Colors.White + "<" + + nameColor(player) + Colors.White +"> "; if (vminecraftSettings.getInstance().FFF()) { log.log(Level.INFO, "<"+player.getName()+"> "+message); //Get the multi line array - String[] msg = wordWrap(playerName + message); + String[] msg = wordWrap(playerName + Colors.Red + message); - //Output the first line - gmsg( playerName + Colors.Red + msg[0]); - - //Get the rest of the lines and display them. - String[] tempOut = new String[msg.length - 1]; - System.arraycopy(msg, 1, tempOut, 0, tempOut.length); - for(String str: tempOut) + //Output the message + for(String str: msg) gmsg(Colors.Red + str); return true; } @@ -333,7 +325,8 @@ public class vminecraftChat { public static boolean quakeColors(Player player, String message) { //Format the name - String playerName = "<" + nameColor(player) + Colors.White +"> "; + String playerName = Colors.White + "<" + + nameColor(player) + Colors.White +"> "; if(vminecraftSettings.getInstance().quakeColors() && message.length()>2) { //Log the chat @@ -344,12 +337,8 @@ public class vminecraftChat { //Apply colors to the lines applyColors(msg); - //Output the first line - gmsg( playerName + msg[0]); - //Get the rest of the lines and display them. - String[] tempOut = new String[msg.length - 1]; - System.arraycopy(msg, 1, tempOut, 0, tempOut.length); - for(String str: tempOut) + //Output the message + for(String str: msg) gmsg(str); //Loop through the string finding the color codes and inserting them diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 8d9ef4792..617cf5836 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -203,26 +203,33 @@ public class vminecraftCommands{ { //If the command is enabled if(vminecraftSettings.getInstance().cmdFabulous()) { - String playerName = "<" + vminecraftChat.nameColor(player) - + Colors.White + "> "; + + //Format the name + String playerName = Colors.White + "<" + + nameColor(player) + Colors.White +"> "; //Make sure a message has been specified if (args.length < 1) {return false;} String str = " "; + //Merge the message again - str = etc.combineSplit(0, args, " "); + str = etc.combineSplit(0, args, " "); + //Output for server log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\""); - //Prepend the player name + + //Prepend the player name and cut into lines. String[] message = vminecraftChat.wordWrap(playerName + str); - //Output the first line - vminecraftChat.gmsg( playerName + vminecraftChat.rainbow(message[0])); - - //Get the rest of the lines and display them. - String[] tempOut = new String[message.length - 1]; - System.arraycopy(message, 1, tempOut, 0, tempOut.length); - for(String msg: tempOut) - vminecraftChat.gmsg(vminecraftChat.rainbow(msg)); + //Output the message + for(String msg: message) + { + if (msg.contains(playerName)) + vminecraftChat.gmsg( + vminecraftChat.rainbow( + msg.substring(playerName.length() - 1))); + else + vminecraftChat.gmsg(msg); + } return true; } From e84e11f8848ccb43f0d7a9dac8fb567387bd2ad4 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 29 Nov 2010 19:01:00 -0800 Subject: [PATCH 13/82] Updated todo to be up to date and focused on changes upcoming in b8 of vminecraft. --- TODO | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/TODO b/TODO index 380331e09..06d93ed81 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,16 @@ -TODO: -Fix existing bugs in /promote and /demote -Add toggles to all features -If vminecraft.properties doesn't exist make it be written and include default settings -Refine messages when admins use commands --Ready for testing -Change loading to happen when the plugin loads instead of having to wait for a player to speak -Change everything else in settings to be a string like rules instead of booleans +Vminecraft b8 Todo +Heal Command +Antigriefs +/a to toggle admin chat +personal muting +vminecraft version of help that summarizes the mod +Time manipulation +Suicide command +Slap +Toggle for the GG exploit fix -Ideas: -Mass teleport command -A personal muting system for players \ No newline at end of file +DONE +Code was organized +Aliasing was added +Playerlist is now colorful and awesome +Random death messages From 51a3f8d551ec6fcfb979bd68d3475962a6784713 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Mon, 29 Nov 2010 21:02:45 -0600 Subject: [PATCH 14/82] Forgot to put vminecraftChat. before the nameColor call in fabulous --- vminecraftCommands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 75590bf0a..aa37744a9 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -206,7 +206,7 @@ public class vminecraftCommands{ //Format the name String playerName = Colors.White + "<" - + nameColor(player) + Colors.White +"> "; + + vminecraftChat.nameColor(player) + Colors.White +"> "; //Make sure a message has been specified if (args.length < 1) {return false;} String str = " "; From 724db6eab4db17f3fe68813443c09d36399cf603 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Mon, 29 Nov 2010 23:02:23 -0600 Subject: [PATCH 15/82] Added prefix coloring. To get it to work the first character has to be the color you want your name to be followed by your prefix colored as you would any other quake colored line of text. --- vminecraftChat.java | 13 +++++-------- vminecraftCommands.java | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index dddbbd7e9..83ed3cebb 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -128,7 +128,9 @@ public class vminecraftChat { //Use: Returns the colored name; //===================================================================== public static String nameColor(Player player){ - return player.getColor() + player.getName(); + String[] playerPrefix = new String[]{player.getPrefix()}; + return applyColors(playerPrefix)[0].substring(3) + + player.getColor().substring(0,2) + player.getName(); } //===================================================================== @@ -243,12 +245,7 @@ public class vminecraftChat { if (p.isAdmin() || (p.canUseCommand("/adminchat"))) { //Output the first line - p.sendMessage(adminchat + msg[0]); - - //Get the rest of the lines and display them. - String[] tempOut = new String[msg.length - 1]; - System.arraycopy(msg, 1, tempOut, 0, tempOut.length); - for(String str: tempOut) + for(String str: msg) p.sendMessage(str); } } @@ -327,7 +324,7 @@ public class vminecraftChat { //Format the name String playerName = Colors.White + "<" + nameColor(player) + Colors.White +"> "; - if(vminecraftSettings.getInstance().quakeColors() && message.length()>2) { + if(vminecraftSettings.getInstance().quakeColors()) { //Log the chat log.log(Level.INFO, "<"+player.getName()+"> "+message); diff --git a/vminecraftCommands.java b/vminecraftCommands.java index aa37744a9..8c9d2db29 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -224,8 +224,8 @@ public class vminecraftCommands{ for(String msg: message) { if (msg.contains(playerName)) - vminecraftChat.gmsg( - vminecraftChat.rainbow( + vminecraftChat.gmsg( playerName + + vminecraftChat.rainbow( msg.substring(playerName.length() - 1))); else vminecraftChat.gmsg(msg); From 7ae44da043aa67ebe77e11ea21e6e0e99ea31eaa Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 00:25:16 -0600 Subject: [PATCH 16/82] Fixed /who (Again. I seem to break it a lot!) and tweaked the line length function a little. --- vminecraftChat.java | 35 ++++---- vminecraftCommands.java | 172 ++++++++++++++++++++++------------------ vminecraftListener.java | 13 +-- vminecraftSettings.java | 1 - 4 files changed, 120 insertions(+), 101 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index 83ed3cebb..eb912640e 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -71,34 +71,22 @@ public class vminecraftChat { int length = 0; for(int x = 0; x\"*()".indexOf(str.charAt(x)) != -1) - { length+=5; - } else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1) - { length+=6; - } else if("@~".indexOf(str.charAt(x)) != -1) - { length+=7; - } else if(str.charAt(x)==' ') - { length+=4; - } } return length; } @@ -128,9 +116,22 @@ public class vminecraftChat { //Use: Returns the colored name; //===================================================================== public static String nameColor(Player player){ + + //Get the prefix String[] playerPrefix = new String[]{player.getPrefix()}; - return applyColors(playerPrefix)[0].substring(3) - + player.getColor().substring(0,2) + player.getName(); + + //Add the name + String output = player.getName(); + + //Add the color if there is one + if(player.getColor() != null && player.getColor() != "") + output = player.getColor().substring(0,2) + output; + //Add the prefix if there is one + if(playerPrefix[0] != null && playerPrefix[0] != "") + output = applyColors(playerPrefix)[0].substring(3) + output; + + //Return the name + return output; } //===================================================================== diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 8c9d2db29..077c93882 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -12,6 +12,9 @@ import java.util.logging.Logger; public class vminecraftCommands{ //Log output protected static final Logger log = Logger.getLogger("Minecraft"); + static final int EXIT_FAIL = 0, + EXIT_SUCCESS = 1, + EXIT_CONTINUE = 2; //The list of commands for vminecraft public static commandList cl = new commandList(); @@ -35,6 +38,7 @@ public class vminecraftCommands{ cl.register("/slay", "slay", "Kill target player"); cl.register("/ezmodo", "invuln", "Toggle invulnerability"); cl.register("/ezlist", "ezlist", "List invulnerable players"); + cl.register("/modify", "modifySplit"); cl.registerAlias("/playerlist", "/who"); } @@ -44,11 +48,10 @@ public class vminecraftCommands{ //Input: Player player: The player using the command // String[] args: The arguments for the command. Should be a // player name - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Teleports the user to another player //===================================================================== - public static boolean teleport(Player player, String[] args) + public static int teleport(Player player, String[] args) { //Get if the command is enabled if(vminecraftSettings.getInstance().cmdTp()) @@ -83,20 +86,19 @@ public class vminecraftCommands{ //Otherwise inform the user that the player doesn't exist } } - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: masstp (/masstp) //Input: Player player: The player using the command // String[] args: Should be empty or is ignored - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Teleports all players to the user //===================================================================== - public static boolean masstp(Player player, String[] args) + public static int masstp(Player player, String[] args) { //If the command is enabled if(vminecraftSettings.getInstance().cmdMasstp()) { @@ -109,9 +111,9 @@ public class vminecraftCommands{ //Inform the user that the command has executed successfully player.sendMessage(Colors.Blue+"Summoning successful."); - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== @@ -119,11 +121,10 @@ public class vminecraftCommands{ //Input: Player player: The player using the command // String[] args: The arguments for the command. Should be a // player name - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Teleports the user to another player //===================================================================== - public static boolean tphere(Player player, String[] args) + public static int tphere(Player player, String[] args) { //Check if the command is enabled. if (vminecraftSettings.getInstance().cmdTphere()) { @@ -149,34 +150,32 @@ public class vminecraftCommands{ playerTarget.teleportTo(player); } } - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: reload (/reload) //Input: Player player: The player using the command // String[] args: Ignored - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Reloads the settings for vminecraft //===================================================================== - public static boolean reload(Player player, String[] args) + public static int reload(Player player, String[] args) { vminecraftSettings.getInstance().loadSettings(); - return true; + return EXIT_SUCCESS; } //===================================================================== //Function: rules (/rules) //Input: Player player: The player using the command // String[] args: Ignored - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Lists the rules //===================================================================== - public static boolean rules(Player player, String[] args) + public static int rules(Player player, String[] args) { //If the rules exist if(vminecraftSettings.getInstance().cmdRules() @@ -186,20 +185,19 @@ public class vminecraftCommands{ if(str.isEmpty()) player.sendMessage(Colors.Blue+str); } - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: fabulous (/fabulous) //Input: Player player: The player using the command // String[] args: The message to apply the effect to - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Makes the text rainbow colored //===================================================================== - public static boolean fabulous(Player player, String[] args) + public static int fabulous(Player player, String[] args) { //If the command is enabled if(vminecraftSettings.getInstance().cmdFabulous()) { @@ -208,7 +206,7 @@ public class vminecraftCommands{ String playerName = Colors.White + "<" + vminecraftChat.nameColor(player) + Colors.White +"> "; //Make sure a message has been specified - if (args.length < 1) {return false;} + if (args.length < 1) {return EXIT_FAIL;} String str = " "; //Merge the message again @@ -228,23 +226,22 @@ public class vminecraftCommands{ + vminecraftChat.rainbow( msg.substring(playerName.length() - 1))); else - vminecraftChat.gmsg(msg); + vminecraftChat.gmsg(vminecraftChat.rainbow(msg)); } - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: whois (/whois) //Input: Player player: The player using the command // String[] args: The player to find info on - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Displays information about the player specified //===================================================================== - public static boolean whois(Player player, String[] args) + public static int whois(Player player, String[] args) { //If the command is enabled if (vminecraftSettings.getInstance().cmdWhoIs()) { @@ -284,20 +281,19 @@ public class vminecraftCommands{ player.sendMessage(Colors.Rose+"Player not found."); } } - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_SUCCESS; } //===================================================================== //Function: who (/who) //Input: Player player: The player using the command // String[] args: Ignored - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Displays the connected players //===================================================================== - public static boolean who(Player player, String[] args) + public static int who(Player player, String[] args) { //If the command is enabled if (vminecraftSettings.getInstance().cmdWho()) { @@ -328,20 +324,19 @@ public class vminecraftCommands{ for(String msg: tempOut) player.sendMessage( msg ); - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: say (/say) //Input: Player player: The player using the command // String[] args: The message to apply the effect to - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Announces the message to all players //===================================================================== - public static boolean say(Player player, String[] args) + public static int say(Player player, String[] args) { //If the command is enabled if (vminecraftSettings.getInstance().cmdSay()) { @@ -351,20 +346,19 @@ public class vminecraftCommands{ } //Display the message globally vminecraftChat.gmsg(Colors.Yellow + etc.combineSplit(0, args, " ")); - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: slay (/slay) //Input: Player player: The player using the command // String[] args: The target for the command - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Kill the target player //===================================================================== - public static boolean slay(Player player, String[] args) + public static int slay(Player player, String[] args) { //Check if the command is enabled if(vminecraftSettings.getInstance().cmdEzModo()) { @@ -372,7 +366,7 @@ public class vminecraftCommands{ Player playerTarget = etc.getServer().matchPlayer(args[0]); //If the player doesn't exist don't run if(playerTarget == null) - return false; + return EXIT_SUCCESS; //If the player isn't invulnerable kill them if (!vminecraftSettings.getInstance().isEzModo(playerTarget.getName())) { playerTarget.setHealth(0); @@ -381,20 +375,19 @@ public class vminecraftCommands{ } else { player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha"); } - return true; + return EXIT_FAIL; } - return false; + return EXIT_SUCCESS; } //===================================================================== //Function: invuln (/ezmodo) //Input: Player player: The player using the command // String[] args: The target for the command - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: Kill the target player //===================================================================== - public static boolean invuln(Player player, String[] args) + public static int invuln(Player player, String[] args) { //If the command is enabled if (vminecraftSettings.getInstance().cmdEzModo()) { @@ -411,29 +404,56 @@ public class vminecraftCommands{ vminecraftSettings.getInstance().addEzModo(player.getName()); player.setHealth(vminecraftSettings.getInstance().ezModoHealth()); } - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: ezlist (/ezlist) //Input: Player player: The player using the command // String[] args: Ignored - //Output: boolean: If the user has access to the command - // and it is enabled + //Output: int: Exit Code //Use: List all invulnerable players //===================================================================== - public static boolean ezlist(Player player, String[] args) + public static int ezlist(Player player, String[] args) { //If the feature is enabled list the players if(vminecraftSettings.getInstance().cmdEzModo()) { player.sendMessage("Ezmodo: " + vminecraftSettings.getInstance().ezModoList()); - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; + } + + //===================================================================== + //Function: modifySplit (/modify) + //Input: Player player: The player using the command + // String[] args: Player, Command, Arguments + //Output: int: Exit Code + //Use: List all invulnerable players + //===================================================================== + public static int modifySplit(Player player, String[] args) + { + //Exploit fix for people giving themselves commands + if(args[1].equals("commands")) + return EXIT_FAIL; + else if (args[1].equals("tag")) + playerTag(player, args); + return EXIT_CONTINUE; + } + + //===================================================================== + //Function: playerTag (/modify player tag *) + //Input: Player player: The player using the command + // String[] args: Player, Command, Arguments + //Output: int: Exit Code + //Use: List all invulnerable players + //===================================================================== + public static int playerTag(Player player, String[] args) + { + return EXIT_SUCCESS; } - //Disable using /modify to add commands (need to make a boolean settings for this) @@ -563,6 +583,9 @@ log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" class commandList { command[] commands; protected static final Logger log = Logger.getLogger("Minecraft"); + static final int EXIT_FAIL = 0, + EXIT_SUCCESS = 1, + EXIT_CONTINUE = 2; //===================================================================== //Function: commandList @@ -698,10 +721,10 @@ class commandList { //Output: boolean: If the command was called successfully //Use: Attempts to call a command //===================================================================== - public boolean call(String name, Player player, String[] arg){ + public int call(String name, Player player, String[] arg){ //Make sure the user has access to the command if(!player.canUseCommand(name)) { - return false; + return EXIT_FAIL; } //Search for the command for(command cmd : commands) @@ -716,13 +739,13 @@ class commandList { log.log(Level.SEVERE, "Exception while running command", e); } catch (IllegalArgumentException e) { log.log(Level.SEVERE, "The Command Entered Doesn't Exist", e); - return false; + return EXIT_FAIL; } } } //Something went wrong - return false; + return EXIT_FAIL; } //===================================================================== @@ -761,14 +784,14 @@ class commandList { //Output: boolean: If the command was called successfully //Use: Attempts to call the command //===================================================================== - boolean call(Player player, String[] arg) + int call(Player player, String[] arg) { Method m; try { m = vminecraftCommands.class.getMethod(function, Player.class, String[].class); m.setAccessible(true); - return (Boolean) m.invoke(null, player, arg); + return (Integer) m.invoke(null, player, arg); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { @@ -780,7 +803,7 @@ class commandList { } catch (InvocationTargetException e) { e.printStackTrace(); } - return true; + return 1; } } @@ -827,7 +850,7 @@ class commandList { //Output: boolean: If the command was called successfully //Use: Attempts to call the command //===================================================================== - boolean call(Player player, String[] arg) + int call(Player player, String[] arg) { if(args != null) { String[] temp = new String[args.length]; @@ -862,12 +885,7 @@ class commandList { player.command(reference + " " + etc.combineSplit(0, temp, " ")); } else player.command(reference); - - /*if(temp != null) - etc.getServer().useConsoleCommand(reference + " " + etc.combineSplit(0, temp, " "), player); - else - etc.getServer().useConsoleCommand(reference, player);*/ - return true; + return EXIT_SUCCESS; } } } \ No newline at end of file diff --git a/vminecraftListener.java b/vminecraftListener.java index 7bc1081a6..319ebc8e9 100644 --- a/vminecraftListener.java +++ b/vminecraftListener.java @@ -54,17 +54,18 @@ public class vminecraftListener extends PluginListener { //===================================================================== public boolean onCommand(Player player, String[] split) { - //Explot fix on /modify - if(split[0].equals("/modify") && split[2].equals("commands")) { - return false; - } - //Copy the arguments into their own array. String[] args = new String[split.length - 1]; System.arraycopy(split, 1, args, 0, args.length); //Return the results of the command - return vminecraftCommands.cl.call(split[0], player, args); + int exitCode = vminecraftCommands.cl.call(split[0], player, args); + if(exitCode == 0) + return false; + else if(exitCode == 1) + return true; + else + return false; } diff --git a/vminecraftSettings.java b/vminecraftSettings.java index fc2e1d26c..8f0f8574a 100644 --- a/vminecraftSettings.java +++ b/vminecraftSettings.java @@ -2,7 +2,6 @@ import java.io.*; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.Random; //===================================================================== //Class: vminecraftSettings //Use: Controls the settings for vminecraft From 20f62d90c9759f2ab650a40a8514a4dfc5a8c3ae Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 00:32:18 -0600 Subject: [PATCH 17/82] Removed the excess space between the player name and the message in /fabulous --- vminecraftCommands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 077c93882..23f03c980 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -224,7 +224,7 @@ public class vminecraftCommands{ if (msg.contains(playerName)) vminecraftChat.gmsg( playerName + vminecraftChat.rainbow( - msg.substring(playerName.length() - 1))); + msg.substring(playerName.length()))); else vminecraftChat.gmsg(vminecraftChat.rainbow(msg)); } From 0ca264580c2dbd2cd482e24350fa63c6ed00710b Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 00:39:32 -0600 Subject: [PATCH 18/82] I forget exactly >.> --- vminecraftCommands.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 23f03c980..db73fc6b6 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -366,18 +366,20 @@ public class vminecraftCommands{ Player playerTarget = etc.getServer().matchPlayer(args[0]); //If the player doesn't exist don't run if(playerTarget == null) - return EXIT_SUCCESS; + return EXIT_FAIL; //If the player isn't invulnerable kill them if (!vminecraftSettings.getInstance().isEzModo(playerTarget.getName())) { playerTarget.setHealth(0); - vminecraftChat.gmsg(player.getColor() + player.getName() + Colors.LightBlue + " has slain " + playerTarget.getColor() + playerTarget.getName()); + vminecraftChat.gmsg(vminecraftChat.nameColor(player) + + Colors.LightBlue + " has slain " + + vminecraftChat.nameColor(playerTarget)); //Otherwise output error to the user } else { player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha"); } - return EXIT_FAIL; + return EXIT_SUCCESS; } - return EXIT_SUCCESS; + return EXIT_FAIL; } //===================================================================== From 43c933ebb7805c90409a33191e68abfa68a23bed Mon Sep 17 00:00:00 2001 From: nossr50 Date: Mon, 29 Nov 2010 22:58:27 -0800 Subject: [PATCH 19/82] Added /heal and /suicide. Corrected some things in the settings file. Signed-off-by: nossr50 --- vminecraftCommands.java | 44 +++++++++++++++++++++++++++++++++++++++-- vminecraftSettings.java | 15 ++++++++++---- 2 files changed, 53 insertions(+), 6 deletions(-) diff --git a/vminecraftCommands.java b/vminecraftCommands.java index aa37744a9..46acf3cfb 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -35,10 +35,50 @@ public class vminecraftCommands{ cl.register("/slay", "slay", "Kill target player"); cl.register("/ezmodo", "invuln", "Toggle invulnerability"); cl.register("/ezlist", "ezlist", "List invulnerable players"); + cl.register("/heal", "heal", "heal yourself or other players"); + cl.register("/suicide", "suicide", "kill yourself... you loser"); cl.registerAlias("/playerlist", "/who"); + cl.registerAlias("/suicide", "/wrists"); + } + + //Heal + public static boolean heal(Player player, String[] args) + { + if(vminecraftSettings.getInstance().cmdHeal) + { + if (args[1] == null){ + if (player.getHealth() < 20){ + vminecraftChat.gmsg("Your health is restored"); + return true; + } + else if (args[1] != null){ + Player playerTarget = etc.getServer().matchPlayer(args[1]); + if (playerTarget != null){ + playerTarget.setHealth(20); + vminecraftChat.gmsg(Colors.Blue + "You have healed " + playerTarget.getColor() + playerTarget.getName()); + vminecraftChat.gmsg(Colors.Blue + "You have been healed by " + player.getColor() + player.getName()); + return true; + } + else if (playerTarget == null){ + vminecraftChat.gmsg(Colors.Rose + "Couldn't find that player"); + return false; + } + + } + } + } + return false; + } + //Suicide + public static boolean suicide(Player player, String[] args) + { + if(vminecraftSettings.getInstance().cmdSuicide) + { + player.setHealth(0); + return true; + } + return false; } - - //===================================================================== //Function: teleport (/tp) //Input: Player player: The player using the command diff --git a/vminecraftSettings.java b/vminecraftSettings.java index fc2e1d26c..4d764cede 100644 --- a/vminecraftSettings.java +++ b/vminecraftSettings.java @@ -33,6 +33,8 @@ public class vminecraftSettings { cmdWho = false, stopFire = false, stopTnt = false, + cmdHeal = false, + cmdSuicide = false, cmdEzModo = false; //An array of players currently in ezmodo static ArrayList ezModo = new ArrayList(); @@ -74,6 +76,7 @@ public class vminecraftSettings { writer.write("cmdSay=true\r\n"); writer.write("cmdTp=true\r\n"); writer.write("cmdRules=true\r\n"); + writer.write("cmdSuicide=true\r\n"); writer.write("globalmessages=true\r\n"); writer.write("FFF=true\r\n"); writer.write("adminchat=true\r\n"); @@ -82,11 +85,11 @@ public class vminecraftSettings { writer.write("ezModo=\r\n"); writer.write("#The health ezmodo people will have while in ezmodo. Don't set to 0\r\n"); writer.write("ezHealth=30\r\n"); - writer.write("stopFire=false"); - writer.write("stopTnt=false"); + writer.write("stopFire=false\r\n"); + writer.write("stopTnt=false\r\n"); writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n"); - writer.write("#Death messages, seperate them by comma. All death messages start with the player name and a space."); - writer.write("deathMessages=is no more,died horribly,went peacefully"); + writer.write("#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"); } catch (Exception e) { log.log(Level.SEVERE, "Exception while creating " + location, e); } finally { @@ -122,6 +125,8 @@ public class vminecraftSettings { cmdTp = properties.getBoolean("cmdTp",true); cmdMasstp = properties.getBoolean("cmdMasstp",true); cmdTphere = properties.getBoolean("cmdTphere",true); + cmdSuicide = properties.getBoolean("cmdSuicide", true); + cmdHeal = properties.getBoolean("cmdHeal",true); globalmessages = properties.getBoolean("globalmessages",true); cmdSay = properties.getBoolean("cmdSay",true); cmdEzModo = properties.getBoolean("cmdEzModo",true); @@ -171,6 +176,8 @@ public class vminecraftSettings { public boolean cmdWho() {return cmdWho;} public boolean stopFire() {return stopFire;} public boolean stopTnt() {return stopTnt;} + public boolean cmdSuicide() {return cmdSuicide;} + public boolean cmdHeal() {return cmdHeal;} //EzModo methods public boolean isEzModo(String playerName) {return ezModo.contains(playerName);} From 297c461b44bdf64cd9c00cd7f28b4c5bddca0d2c Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 01:15:10 -0600 Subject: [PATCH 20/82] Rearranged the colors for fabulous to make it more rainbowrific --- vminecraftChat.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index eb912640e..a1f7b039f 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -95,9 +95,9 @@ public class vminecraftChat { public static String rainbow(String msg){ String temp = ""; //The array of colors to use - String[] rainbow = new String[] {Colors.Red, Colors.Rose, - Colors.Yellow, Colors.Green, Colors.Blue, - Colors.LightPurple, Colors.Purple}; + String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Gold, + Colors.Yellow, Colors.LightGreen, Colors.Green, Colors.Blue, + Colors.Navy, Colors.DarkPurple, Colors.Purple, Colors.LightPurple}; int counter=0; //Loop through the message applying the colors for(int x=0; x Date: Tue, 30 Nov 2010 01:40:31 -0600 Subject: [PATCH 21/82] Updated Nos's Heal and Suicide functions to fit with the new way command functions return. --- vminecraftCommands.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 62ab55308..3b8aba357 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -45,18 +45,18 @@ public class vminecraftCommands{ cl.register("/modify", "modifySplit"); cl.registerAlias("/playerlist", "/who"); - cl.registerAlias("/suicide", "/wrists"); + cl.registerAlias("/wrists", "/suicide"); } //Heal - public static boolean heal(Player player, String[] args) + public static int heal(Player player, String[] args) { - if(vminecraftSettings.getInstance().cmdHeal) + if(vminecraftSettings.getInstance().cmdHeal()) { if (args[1] == null){ if (player.getHealth() < 20){ vminecraftChat.gmsg("Your health is restored"); - return true; + return EXIT_SUCCESS; } else if (args[1] != null){ Player playerTarget = etc.getServer().matchPlayer(args[1]); @@ -64,27 +64,27 @@ public class vminecraftCommands{ playerTarget.setHealth(20); vminecraftChat.gmsg(Colors.Blue + "You have healed " + playerTarget.getColor() + playerTarget.getName()); vminecraftChat.gmsg(Colors.Blue + "You have been healed by " + player.getColor() + player.getName()); - return true; + return EXIT_SUCCESS; } else if (playerTarget == null){ vminecraftChat.gmsg(Colors.Rose + "Couldn't find that player"); - return false; + return EXIT_FAIL; } } } } - return false; + return EXIT_FAIL; } //Suicide - public static boolean suicide(Player player, String[] args) + public static int suicide(Player player, String[] args) { - if(vminecraftSettings.getInstance().cmdSuicide) + if(vminecraftSettings.getInstance().cmdSuicide()) { player.setHealth(0); - return true; + return EXIT_SUCCESS; } - return false; + return EXIT_FAIL; } //===================================================================== //Function: teleport (/tp) From 42b8bd8ee1d6f76b4f04ccaa42115cf4a1d5704e Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 02:29:50 -0600 Subject: [PATCH 22/82] Attempting to fix /heal --- vminecraftChat.java | 29 ++++++++++++----- vminecraftCommands.java | 72 +++++++++++++++++++++++++---------------- 2 files changed, 65 insertions(+), 36 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index a1f7b039f..21bbbde6c 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -67,8 +67,16 @@ public class vminecraftChat { return tempout; } + //===================================================================== + //Function: msgLength + //Input: String str: The string to find the length of + //Output: int: The length on the screen of a string + //Use: Finds the length on the screen of a string. Ignores colors. + //===================================================================== private static int msgLength(String str){ int length = 0; + //Loop through all the characters, skipping any color characters + //and their following color codes for(int x = 0; x " + message); return true; } @@ -270,7 +283,7 @@ public class vminecraftChat { public static boolean quote(Player player, String message) { //Format the name - String playerName = Colors.White + "<" + nameColor(player) + String playerName = Colors.White + "<" + getName(player) + Colors.White + "> "; if(vminecraftSettings.getInstance().greentext()) { //Log the chat @@ -298,7 +311,7 @@ public class vminecraftChat { { //Format the name String playerName = Colors.White + "<" - + nameColor(player) + Colors.White +"> "; + + getName(player) + Colors.White +"> "; if (vminecraftSettings.getInstance().FFF()) { log.log(Level.INFO, "<"+player.getName()+"> "+message); @@ -324,7 +337,7 @@ public class vminecraftChat { { //Format the name String playerName = Colors.White + "<" - + nameColor(player) + Colors.White +"> "; + + getName(player) + Colors.White +"> "; if(vminecraftSettings.getInstance().quakeColors()) { //Log the chat diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 3b8aba357..8aeda9fbc 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -48,44 +48,60 @@ public class vminecraftCommands{ cl.registerAlias("/wrists", "/suicide"); } - //Heal + //===================================================================== + //Function: heal (/heal) + //Input: Player player: The player using the command + // String[] args: The arguments for the command. Should be a + // player name or blank + //Output: int: Exit Code + //Use: Heals yourself or a specified player. + //===================================================================== public static int heal(Player player, String[] args) { if(vminecraftSettings.getInstance().cmdHeal()) { - if (args[1] == null){ - if (player.getHealth() < 20){ - vminecraftChat.gmsg("Your health is restored"); - return EXIT_SUCCESS; - } - else if (args[1] != null){ - Player playerTarget = etc.getServer().matchPlayer(args[1]); - if (playerTarget != null){ - playerTarget.setHealth(20); - vminecraftChat.gmsg(Colors.Blue + "You have healed " + playerTarget.getColor() + playerTarget.getName()); - vminecraftChat.gmsg(Colors.Blue + "You have been healed by " + player.getColor() + player.getName()); - return EXIT_SUCCESS; - } - else if (playerTarget == null){ - vminecraftChat.gmsg(Colors.Rose + "Couldn't find that player"); - return EXIT_FAIL; - } - - } + //If a target wasn't specified, heal the user. + if (args == null){ + if (player.getHealth() < 20){ + vminecraftChat.gmsg("Your health is restored"); + } + //If a target was specified, try to find them and then heal them + //Otherwise report the error + } else if (args != null){ + Player playerTarget = etc.getServer().matchPlayer(args[0]); + + if (playerTarget != null){ + playerTarget.setHealth(20); + player.sendMessage(Colors.Blue + "You have healed " + vminecraftChat.getName(playerTarget)); + playerTarget.sendMessage(Colors.Blue + "You have been healed by " + vminecraftChat.getName(player)); + } + else if (playerTarget == null){ + vminecraftChat.gmsg(Colors.Rose + "Couldn't find that player"); + } } + return EXIT_SUCCESS; } return EXIT_FAIL; - } - //Suicide + } + + //===================================================================== + //Function: suicide (/suicide, /wrists) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: int: Exit Code + //Use: Kills yourself + //===================================================================== public static int suicide(Player player, String[] args) { if(vminecraftSettings.getInstance().cmdSuicide()) { + //Set your health to 0. Not much to it. player.setHealth(0); return EXIT_SUCCESS; } return EXIT_FAIL; } + //===================================================================== //Function: teleport (/tp) //Input: Player player: The player using the command @@ -247,7 +263,7 @@ public class vminecraftCommands{ //Format the name String playerName = Colors.White + "<" - + vminecraftChat.nameColor(player) + Colors.White +"> "; + + vminecraftChat.getName(player) + Colors.White +"> "; //Make sure a message has been specified if (args.length < 1) {return EXIT_FAIL;} String str = " "; @@ -306,7 +322,7 @@ public class vminecraftCommands{ //Displaying the information player.sendMessage(Colors.Blue + "Whois results for " + - vminecraftChat.nameColor(playerTarget)); + vminecraftChat.getName(playerTarget)); //Group for(String group: playerTarget.getGroups()) player.sendMessage(Colors.Blue + "Groups: " + group); @@ -347,9 +363,9 @@ public class vminecraftCommands{ { if(p != null){ if(count == 0) - tempList += vminecraftChat.nameColor(p); + tempList += vminecraftChat.getName(p); else - tempList += Colors.White + ", " + vminecraftChat.nameColor(p); + tempList += Colors.White + ", " + vminecraftChat.getName(p); count++; } } @@ -413,9 +429,9 @@ public class vminecraftCommands{ //If the player isn't invulnerable kill them if (!vminecraftSettings.getInstance().isEzModo(playerTarget.getName())) { playerTarget.setHealth(0); - vminecraftChat.gmsg(vminecraftChat.nameColor(player) + vminecraftChat.gmsg(vminecraftChat.getName(player) + Colors.LightBlue + " has slain " - + vminecraftChat.nameColor(playerTarget)); + + vminecraftChat.getName(playerTarget)); //Otherwise output error to the user } else { player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha"); From 21e5213c000ee984571d4e60787606d27b7f4364 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 30 Nov 2010 00:31:04 -0800 Subject: [PATCH 23/82] Fixed reload to fire off hMod's reload too. --- vminecraftCommands.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 3b8aba357..6d424f22b 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -208,7 +208,7 @@ public class vminecraftCommands{ public static int reload(Player player, String[] args) { vminecraftSettings.getInstance().loadSettings(); - return EXIT_SUCCESS; + return EXIT_FAIL; } //===================================================================== From d2b64044e2fe4d068903019e062110e604799d7b Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 03:40:47 -0600 Subject: [PATCH 24/82] Added checking to make sure that the next character after a ^ is color code. --- vminecraftChat.java | 24 +++++++++++++++++------- vminecraftCommands.java | 9 ++++----- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index 21bbbde6c..70fdddb0c 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -225,7 +225,7 @@ public class vminecraftChat { color = Colors.White; break; default: - color = Colors.White; + color = null; break; } return color; @@ -381,14 +381,24 @@ public class vminecraftChat { //Loop through looking for a color code for(int x = 0; x< msg.length(); x++) { + //If the char is a ^ if(msg.charAt(x)=='^' && x != msg.length() - 1) { - //Set the most recent color to the new color - recentColor = vminecraftChat.colorChange(msg.charAt(x+1)); - temp += recentColor; - x++; - } - else{ + //If the following character is a color code + if(vminecraftChat.colorChange(msg.charAt(x+1)) != null) + { + //Set the most recent color to the new color + recentColor = vminecraftChat.colorChange(msg.charAt(x+1)); + //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); } } diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 8aeda9fbc..b6484d766 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -61,13 +61,12 @@ public class vminecraftCommands{ if(vminecraftSettings.getInstance().cmdHeal()) { //If a target wasn't specified, heal the user. - if (args == null){ - if (player.getHealth() < 20){ - vminecraftChat.gmsg("Your health is restored"); - } + if (args.length < 1){ + player.setHealth(20); + player.sendMessage("Your health is restored"); //If a target was specified, try to find them and then heal them //Otherwise report the error - } else if (args != null){ + } else if (args.length > 0){ Player playerTarget = etc.getServer().matchPlayer(args[0]); if (playerTarget != null){ From 036adfee465bc954892585ea91a1140ad02f5a49 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 30 Nov 2010 01:45:17 -0800 Subject: [PATCH 25/82] Changed TODO to match our progress --- TODO | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index 06d93ed81..51f79a5bf 100644 --- a/TODO +++ b/TODO @@ -1,11 +1,10 @@ Vminecraft b8 Todo -Heal Command Antigriefs /a to toggle admin chat personal muting vminecraft version of help that summarizes the mod Time manipulation -Suicide command + Slap Toggle for the GG exploit fix @@ -14,3 +13,8 @@ Code was organized Aliasing was added Playerlist is now colorful and awesome Random death messages +Suicide command +Heal Command +Colored Prefixes +Emotes such as ^^ ^_^ now possible +Multi Line color fix, now we can have color on multiple lines without crashing the client From db8ac45ad5f7519199a9f2586c6b4ff0f2a696aa Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 11:47:25 -0600 Subject: [PATCH 26/82] Misc Updates --- vminecraftChat.java | 133 ++++++++++++++++++++++++++++++---------- vminecraftCommands.java | 14 +++-- vminecraftSettings.java | 21 ++++--- 3 files changed, 120 insertions(+), 48 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index 70fdddb0c..f49eb2db8 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -131,7 +131,7 @@ public class vminecraftChat { public static String getName(Player player){ //Get the prefix - String[] playerPrefix = new String[]{player.getPrefix()}; + String playerPrefix = player.getPrefix(); //Add the name String output = player.getName(); @@ -140,8 +140,8 @@ public class vminecraftChat { if(player.getColor() != null && player.getColor() != "") output = player.getColor().substring(0,2) + output; //Add the prefix if there is one - if(playerPrefix[0] != null && playerPrefix[0] != "") - output = applyColors(playerPrefix)[0].substring(3) + output; + if(playerPrefix != null && playerPrefix != "") + output = applyColors(playerPrefix).substring(3) + output; //Return the name return output; @@ -365,46 +365,111 @@ public class vminecraftChat { //Output: String[]: The lines, but colorful //Use: Colors each line //===================================================================== - private static String[] applyColors(String[] message) + public static String[] applyColors(String[] message) { - - //The color to start the line with - String recentColor = Colors.White; - - //Go through each line - int counter = 0; - for(String msg: message) - { - //Start the line with the most recent color - String temp = recentColor; + if(message != null && message[0] != null && !message[0].equals("")){ + //The color to start the line with + String recentColor = Colors.White; - //Loop through looking for a color code - for(int x = 0; x< msg.length(); x++) - { - //If the char is a ^ - if(msg.charAt(x)=='^' && x != msg.length() - 1) + //Go through each line + int counter = 0; + for(String msg: message) + { + //Start the line with the most recent color + String temp = recentColor; + + //Loop through looking for a color code + for(int x = 0; x< msg.length(); x++) { - //If the following character is a color code - if(vminecraftChat.colorChange(msg.charAt(x+1)) != null) + //If the char is a ^ or § + if(msg.charAt(x) == '^' || msg.charAt(x) == '§') { - //Set the most recent color to the new color - recentColor = vminecraftChat.colorChange(msg.charAt(x+1)); - //Add the color - temp += recentColor; - //Skip these chars - x++; - //Otherwise ignore it. + if(x != msg.length() - 1) + { + //If the following character is a color code + if(vminecraftChat.colorChange(msg.charAt(x+1)) != null) + { + //Set the most recent color to the new color + recentColor = vminecraftChat.colorChange(msg.charAt(x+1)); + //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); } - //Insert the character - } else { - temp += msg.charAt(x); } + //Replace the message with the colorful message + message[counter] = temp; + counter++; + } + } + return message; + } + + //===================================================================== + //Function: applyColors + //Input: String message: The line to be colored + //Output: String: The line, but colorful + //Use: Colors a line + //===================================================================== + public static String applyColors(String message) + { + return applyColors(message, Colors.White); + } + + //===================================================================== + //Function: applyColors + //Input: String message: The line to be colored + // String color: The color to start the line with + //Output: String: The line, but colorful + //Use: Colors a line + //===================================================================== + public static String applyColors(String message, String color) + { + if(message != null && !message.equals("")) + { + //The color to start the line with + if(color == null) + color = Colors.White; + + //Start the line with the most recent color + String temp = color; + + //Loop through looking for a color code + for(int x = 0; x< message.length(); x++) + { + //If the char is a ^ or § + if(message.charAt(x) == '^' || message.charAt(x) == '§') + { + if(x != message.length() - 1) + { + //If the following character is a color code + if(vminecraftChat.colorChange(message.charAt(x+1)) != null) + { + //Set the most recent color to the new color + color = vminecraftChat.colorChange(message.charAt(x+1)); + //Add the color + temp += color; + //Skip these chars + x++; + //Otherwise ignore it. + } else { + temp += message.charAt(x); + } + //Insert the character + } else { + temp += message.charAt(x); + } + } + } - //Replace the message with the colorful message - message[counter] = temp; - counter++; } return message; } diff --git a/vminecraftCommands.java b/vminecraftCommands.java index c173d9da6..4524049aa 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -237,11 +237,17 @@ public class vminecraftCommands{ { //If the rules exist if(vminecraftSettings.getInstance().cmdRules() - && vminecraftSettings.getInstance().getRules().length != 0) { + && vminecraftSettings.getInstance().getRules().length > 0) { + + //Apply QuakeCode Colors to the rules + String[] rules = vminecraftChat.applyColors( + vminecraftSettings.getInstance().getRules()); //Display them - for (String str : vminecraftSettings.getInstance().getRules()) { - if(str.isEmpty()) - player.sendMessage(Colors.Blue+str); + 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; } diff --git a/vminecraftSettings.java b/vminecraftSettings.java index 8397526a4..04c145ee5 100644 --- a/vminecraftSettings.java +++ b/vminecraftSettings.java @@ -124,8 +124,8 @@ public class vminecraftSettings { cmdTp = properties.getBoolean("cmdTp",true); cmdMasstp = properties.getBoolean("cmdMasstp",true); cmdTphere = properties.getBoolean("cmdTphere",true); - cmdSuicide = properties.getBoolean("cmdSuicide", true); - cmdHeal = properties.getBoolean("cmdHeal",true); + cmdSuicide = properties.getBoolean("cmdSuicide", true); + cmdHeal = properties.getBoolean("cmdHeal",true); globalmessages = properties.getBoolean("globalmessages",true); cmdSay = properties.getBoolean("cmdSay",true); cmdEzModo = properties.getBoolean("cmdEzModo",true); @@ -171,7 +171,6 @@ public class vminecraftSettings { public boolean cmdRules() {return cmdRules;} public boolean globalmessages() {return globalmessages;} public boolean cmdMasstp() {return cmdMasstp;} - public boolean cmdEzModo() {return cmdEzModo;} public boolean cmdWho() {return cmdWho;} public boolean stopFire() {return stopFire;} public boolean stopTnt() {return stopTnt;} @@ -179,18 +178,20 @@ public class vminecraftSettings { public boolean cmdHeal() {return cmdHeal;} //EzModo methods + public boolean cmdEzModo() {return cmdEzModo;} public boolean isEzModo(String playerName) {return ezModo.contains(playerName);} public void removeEzModo(String playerName) {ezModo.remove(ezModo.indexOf(playerName));} public void addEzModo(String playerName) {ezModo.add(playerName);} public int ezModoHealth() {return ezHealth;} 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)]; - } + + //Random death message method + public static String randomDeathMsg() { + if (deathMessages == null) { + return "died"; + } + return deathMessages[ (int) (Math.random() * deathMessages.length)]; + } //===================================================================== //Function: getInstance From 81b54bbb3bab9ab99497d62c4dc58b7a8c8e5779 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 14:46:25 -0600 Subject: [PATCH 27/82] Added a few things we need to get done. --- TODO | 5 + vminecraftCommands.java | 273 ++++++++++++++++++++-------------------- 2 files changed, 144 insertions(+), 134 deletions(-) diff --git a/TODO b/TODO index 51f79a5bf..a84f174a9 100644 --- a/TODO +++ b/TODO @@ -4,6 +4,11 @@ Antigriefs personal muting vminecraft version of help that summarizes the mod Time manipulation +Aliasing Commands (Global Aliases and Personal Aliases) +Recode /msg and add a /reply (/r) feature +Quick recode of /me to use the new getName function + +Overload /modify(?) --We talked about potentially doing this and I think I would like to now to add in further functionality Slap Toggle for the GG exploit fix diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 4524049aa..8fc3a7e62 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -504,22 +504,23 @@ public class vminecraftCommands{ //Exploit fix for people giving themselves commands if(args[1].equals("commands")) return EXIT_FAIL; - else if (args[1].equals("tag")) - playerTag(player, args); return EXIT_CONTINUE; } //===================================================================== - //Function: playerTag (/modify player tag *) - //Input: Player player: The player using the command - // String[] args: Player, Command, Arguments + //Function: Time Reverse + //Input: long time: The time to reverse to. //Output: int: Exit Code //Use: List all invulnerable players //===================================================================== - public static int playerTag(Player player, String[] args) + public static int timeReverse(long tarTime) { + long curTime = etc.getServer().getRelativeTime(); + if(cur) return EXIT_SUCCESS; } + + //Disable using /modify to add commands (need to make a boolean settings for this) @@ -814,144 +815,148 @@ class commandList { return EXIT_FAIL; } + + + //===================================================================== + //Class: command + //Use: The specific command + //Author: cerevisiae + //===================================================================== + private class command + { + private String commandName; + private String function; + //===================================================================== - //Class: command - //Use: The specific command - //Author: cerevisiae + //Function: command + //Input: None + //Output: None + //Use: Initialize the command //===================================================================== - 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 = vminecraftCommands.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; - } + public command(String name, String func){ + commandName = name; + function = func; } - + + //===================================================================== - //Class: commandRef - //Use: A command referencing another command - //Author: cerevisiae + //Function: getName + //Input: None + //Output: String: The command name + //Use: Returns the command name //===================================================================== - 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 - // String[] arg: the arguments to apply - //Output: None - //Use: Initialize the command - //===================================================================== - public commandRef(String name, String com, String[] arg){ - super(name, ""); - reference = com; - args = arg; - } - - //===================================================================== - //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, ""); - reference = com; - args = null; - } + 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) - { - if(args != null) { - String[] temp = new String[args.length]; - System.arraycopy(args, 0, temp, 0, args.length); - //Insert the arguments into the pre-set arguments - int lastSet = 0, - argCount = 0; - for(String argument : temp) + //===================================================================== + //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 = vminecraftCommands.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; + } + } + + //===================================================================== + //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 + // String[] arg: the arguments to apply + //Output: None + //Use: Initialize the command + //===================================================================== + public commandRef(String name, String com, String[] arg){ + super(name, ""); + reference = com; + args = arg; + } + + //===================================================================== + //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, ""); + reference = com; + args = null; + } + + + //===================================================================== + //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) + { + if(args != null) { + String[] temp = new String[args.length]; + System.arraycopy(args, 0, temp, 0, args.length); + //Insert the arguments into the pre-set arguments + int lastSet = 0, + argCount = 0; + for(String argument : temp) + { + if(argument.startsWith("%")) { - if(argument.startsWith("%")) + int argNum = Integer.parseInt(argument.substring(1)); + if( argNum < arg.length ) { - int argNum = Integer.parseInt(argument.substring(1)); - if( argNum < arg.length ) - { - temp[lastSet] = arg[argNum]; - argCount++; - } + temp[lastSet] = arg[argNum]; + argCount++; } - lastSet++; } - //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; - } - - //Call the referenced command - player.command(reference + " " + etc.combineSplit(0, temp, " ")); - } else - player.command(reference); - return EXIT_SUCCESS; - } + lastSet++; + } + //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; + } + + //Call the referenced command + player.command(reference + " " + etc.combineSplit(0, temp, " ")); + } else + player.command(reference); + return EXIT_SUCCESS; } + } } \ No newline at end of file From 76cf4823ea3288591226d16a3eb44d87c93660c2 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 14:58:55 -0600 Subject: [PATCH 28/82] Further organized TODO --- TODO | 61 +++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/TODO b/TODO index a84f174a9..983a5bc85 100644 --- a/TODO +++ b/TODO @@ -1,25 +1,40 @@ -Vminecraft b8 Todo -Antigriefs -/a to toggle admin chat -personal muting -vminecraft version of help that summarizes the mod -Time manipulation -Aliasing Commands (Global Aliases and Personal Aliases) -Recode /msg and add a /reply (/r) feature -Quick recode of /me to use the new getName function - -Overload /modify(?) --We talked about potentially doing this and I think I would like to now to add in further functionality - -Slap -Toggle for the GG exploit fix +Vminecraft b8 Todo: + + Antigriefs + + /a to toggle admin chat + + vminecraft Help + * Specialized help message for vminecraft + ? /vhelp? + + Time manipulation Working on this + * Have time changes not be instant but move the sky faster + to get to the time entered + * Loop through specific times of the day and then rewind + ex: Sunrise to sunset, mid-morning to noon + + Aliasing Commands (Global Aliases and Personal Aliases) + + Recode Messaging + * Reply Feature + * Personal Muting + + Quick recode of /me to use the new getName function + + Different types of /slay + * /slay fire to burn them to death + * /slay drown to drown them + * /slay boil to burn them with lava + ? Overload /modify + We talked about potentially doing this and I think + I would like to now to add in further functionality and + further limit what features of /modify groups can access DONE -Code was organized -Aliasing was added -Playerlist is now colorful and awesome -Random death messages -Suicide command -Heal Command -Colored Prefixes -Emotes such as ^^ ^_^ now possible -Multi Line color fix, now we can have color on multiple lines without crashing the client + + Code was organized + + Aliasing was added + + Playerlist is now colorful and awesome + + Random death messages + + Suicide command + + Heal Command + + Colored Prefixes + + Color Codes only removed when actual colors are specified + * Allows use of ^ for emotes and whatever else they + might be needed for. + + Multi Line color fix + * Now we can have color on multiple lines without + crashing the client + * Also does not cut words in half From 2bf3a6c1cdd44a8e112cf08cc1a283a09505bdb6 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 30 Nov 2010 16:02:24 -0800 Subject: [PATCH 29/82] Added admin chat toggle, also added shortcut for clearinvetory to be /ci --- vminecraftChat.java | 29 ++++++-- vminecraftCommands.java | 148 ++++++---------------------------------- vminecraftListener.java | 2 + vminecraftSettings.java | 9 +++ 4 files changed, 57 insertions(+), 131 deletions(-) diff --git a/vminecraftChat.java b/vminecraftChat.java index f49eb2db8..026892dc2 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -79,7 +79,7 @@ public class vminecraftChat { //and their following color codes for(int x = 0; x " + message); + return true; + } + return false; + } //===================================================================== //Function: quote @@ -381,8 +400,8 @@ public class vminecraftChat { //Loop through looking for a color code for(int x = 0; x< msg.length(); x++) { - //If the char is a ^ or § - if(msg.charAt(x) == '^' || msg.charAt(x) == '§') + //If the char is a ^ or � + if(msg.charAt(x) == '^' || msg.charAt(x) == '�') { if(x != msg.length() - 1) { @@ -445,8 +464,8 @@ public class vminecraftChat { //Loop through looking for a color code for(int x = 0; x< message.length(); x++) { - //If the char is a ^ or § - if(message.charAt(x) == '^' || message.charAt(x) == '§') + //If the char is a ^ or � + if(message.charAt(x) == '^' || message.charAt(x) == '�') { if(x != message.length() - 1) { diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 8fc3a7e62..9020fe39d 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -38,16 +38,33 @@ public class vminecraftCommands{ cl.register("/slay", "slay", "Kill target player"); cl.register("/ezmodo", "invuln", "Toggle invulnerability"); cl.register("/ezlist", "ezlist", "List invulnerable players"); - cl.register("/heal", "heal", "heal yourself or other players"); cl.register("/suicide", "suicide", "kill yourself... you loser"); - + cl.register("/a", "adminChatToggle", "toggle admin chat for every message"); cl.register("/modify", "modifySplit"); - cl.registerAlias("/playerlist", "/who"); cl.registerAlias("/wrists", "/suicide"); + cl.registerAlias("/ci", "/clearinventory"); } - +public static int adminChatToggle(Player player, String[] args) +{ + if(vminecraftSettings.getInstance().adminChatToggle()) + { + if (vminecraftSettings.getInstance().cmdAdminToggle) { + //If the player is already toggled for admin chat, remove them + if (vminecraftSettings.getInstance().isAdminToggled(player.getName())) { + player.sendMessage(Colors.Red + "Admin Chat Toggle = off"); + vminecraftSettings.getInstance().removeAdminToggled(player.getName()); + //Otherwise include them + } else { + player.sendMessage(Colors.Blue + "Admin Chat Toggled on"); + vminecraftSettings.getInstance().addAdminToggled(player.getName()); + } + return EXIT_SUCCESS; + } + } + return EXIT_FAIL; +} //===================================================================== //Function: heal (/heal) //Input: Player player: The player using the command @@ -516,130 +533,9 @@ public class vminecraftCommands{ public static int timeReverse(long tarTime) { long curTime = etc.getServer().getRelativeTime(); - if(cur) + //if(cur) return EXIT_SUCCESS; } - - - - //Disable using /modify to add commands (need to make a boolean settings for this) - - //ezlist -//ezmodo - - - /* - //Promote - if (vminecraftSettings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote")) { -if(split.length != 2) -{ - player.sendMessage(Colors.Rose + "Usage is /promote [Player]"); - -} - -Player playerTarget = null; - if(split.length==2){ -for( Player p : etc.getServer().getPlayerList()) -{ - if (p.getName().equalsIgnoreCase(split[1])) - { - playerTarget = p; - } -} - -if( playerTarget!=null) -{ - String playerTargetGroup[] = playerTarget.getGroups(); - String playerGroup[] = player.getGroups(); - player.sendMessage("Debug data:"); - player.sendMessage("PlayerTarget: "+playerTargetGroup[0]); - player.sendMessage("Player: "+playerGroup[0]); - if(playerTargetGroup[0].equals("admins")) - { - player.sendMessage(Colors.Rose + "You can not promote " + split[1] + " any higher."); - } - if(playerTargetGroup[0].equals("mods") && (playerGroup[0].equals("owner"))) - { - playerTarget.setGroups(ranks.Admins); - etc.getInstance().getDataSource().modifyPlayer(playerTarget); - String message = Colors.Yellow + split[1] + " was promoted to" + Colors.Rose + " Admin"; - other.gmsg(message); - } - else if (playerTargetGroup[0].equals("trusted") && (playerGroup[0].equals("admins") || playerGroup[0].equals("owner"))) - { - playerTarget.setGroups(ranks.Mods); - playerTargetGroup[0]="Mods"; - etc.getInstance().getDataSource().modifyPlayer(playerTarget); - String message = Colors.Yellow + split[1] + " was promoted to" + Colors.DarkPurple + " Mod"; - other.gmsg(message); - } - else if (playerTargetGroup[0].equals("default") && (playerGroup[0].equals("mods") || playerGroup[0].equals("admins") || player.isInGroup("owner"))) - { - playerTarget.setGroups(ranks.Trusted); - etc.getInstance().getDataSource().modifyPlayer(playerTarget); - String message = Colors.Yellow + split[1] + " was promoted to" + Colors.LightGreen + " Trusted"; - other.gmsg(message); - } - return true; -} -else{ - player.sendMessage(Colors.Rose + "Player not found"); -} -log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" "); -} - } - //Demote - if (vminecraftSettings.getInstance().cmdPromote() && split[0].equalsIgnoreCase("/promote")) -{ -if(split.length != 2) -{ - player.sendMessage(Colors.Rose + "Usage is /demote [Player]"); -} - -Player playerTarget = null; - -for( Player p : etc.getServer().getPlayerList()) -{ - if (p.getName().equalsIgnoreCase(split[1])) - { - playerTarget = p; - } -} - -if( playerTarget!=null) -{ - if(playerTarget.isInGroup("admins") && (player.isInGroup("superadmins"))) - { - playerTarget.setGroups(ranks.Mods); - etc.getInstance().getDataSource().modifyPlayer(playerTarget); - String message = Colors.Yellow + split[1] + " was demoted to" + Colors.DarkPurple + " Mod"; - other.gmsg(message); - } - if(playerTarget.isInGroup("mods") && (player.isInGroup("admins") || player.isInGroup("superadmins"))) - { - playerTarget.setGroups(ranks.Trusted); - etc.getInstance().getDataSource().modifyPlayer(playerTarget); - String message = Colors.Yellow + split[1] + " was demoted to" + Colors.LightGreen + " Trusted"; - other.gmsg(message); - } - else if (playerTarget.isInGroup("trusted") && (player.isInGroup("mods") || player.isInGroup("superadmins") || player.isInGroup("admins"))) - { - playerTarget.setGroups(ranks.Def); - etc.getInstance().getDataSource().modifyPlayer(playerTarget); - String message = Colors.Yellow + split[1] + " was demoted to" + Colors.White + " Default"; - other.gmsg(message); - } - else if (playerTarget.isInGroup("default") && (player.isInGroup("mods") || player.isInGroup("admins") || player.isInGroup("superadmins"))) - { - player.sendMessage(Colors.Rose + "You can not demote " + split[1] + " any lower."); - } -} -else{ - player.sendMessage(Colors.Rose + "Player not found"); -} -log.log(Level.INFO, "Command used by " + player + " " + split[0] +" "+split[1]+" "); - return true; -}*/ } //===================================================================== diff --git a/vminecraftListener.java b/vminecraftListener.java index 319ebc8e9..0bf545c1d 100644 --- a/vminecraftListener.java +++ b/vminecraftListener.java @@ -31,6 +31,8 @@ public class vminecraftListener extends PluginListener { //Quote (Greentext) if (message.startsWith("@")) return vminecraftChat.adminChat(player, message); + if (vminecraftSettings.getInstance().isAdminToggled(player.getName())) + return vminecraftChat.adminChatToggle(player, message); else if (message.startsWith(">")) return vminecraftChat.quote(player, message); diff --git a/vminecraftSettings.java b/vminecraftSettings.java index 04c145ee5..177bca7ea 100644 --- a/vminecraftSettings.java +++ b/vminecraftSettings.java @@ -34,9 +34,12 @@ public class vminecraftSettings { stopTnt = 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 toggled for admin chat + static ArrayList adminChatList = new ArrayList(); //The max health for ezModo static int ezHealth = 30; @@ -76,6 +79,7 @@ public class vminecraftSettings { writer.write("cmdTp=true\r\n"); writer.write("cmdRules=true\r\n"); writer.write("cmdSuicide=true\r\n"); + writer.write("cmdAdminToggle=true\r\n"); writer.write("globalmessages=true\r\n"); writer.write("FFF=true\r\n"); writer.write("adminchat=true\r\n"); @@ -126,6 +130,7 @@ public class vminecraftSettings { cmdTphere = properties.getBoolean("cmdTphere",true); cmdSuicide = properties.getBoolean("cmdSuicide", true); cmdHeal = properties.getBoolean("cmdHeal",true); + cmdAdminToggle = properties.getBoolean("cmdAdminToggle", true); globalmessages = properties.getBoolean("globalmessages",true); cmdSay = properties.getBoolean("cmdSay",true); cmdEzModo = properties.getBoolean("cmdEzModo",true); @@ -158,6 +163,7 @@ public class vminecraftSettings { //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;} @@ -180,8 +186,11 @@ public class vminecraftSettings { //EzModo methods public boolean cmdEzModo() {return cmdEzModo;} public boolean isEzModo(String playerName) {return ezModo.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 int ezModoHealth() {return ezHealth;} public String ezModoList() {return ezModo.toString();} From 0abd500f63fc1f55e4301e87d9c02a47e2765825 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 30 Nov 2010 16:17:43 -0800 Subject: [PATCH 30/82] Even more up to date :3 --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index 983a5bc85..ea0f077ea 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,6 @@ Vminecraft b8 Todo: + Antigriefs + + Allow players to nickname themselves or others + /a to toggle admin chat + vminecraft Help * Specialized help message for vminecraft From e013ac787d9bd4efc7ee86c297e3bb436521dd7e Mon Sep 17 00:00:00 2001 From: nossr50 Date: Tue, 30 Nov 2010 20:14:47 -0800 Subject: [PATCH 31/82] Removed pointless check, added comment for adminChatToggle in vminecraftCommands. --- vminecraftCommands.java | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 9020fe39d..5e7e9a056 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -46,22 +46,28 @@ public class vminecraftCommands{ cl.registerAlias("/wrists", "/suicide"); cl.registerAlias("/ci", "/clearinventory"); } -public static int adminChatToggle(Player player, String[] args) + //===================================================================== + //Function: adminChatToggle (/a) + //Input: Player player: The player using the command + //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) { if(vminecraftSettings.getInstance().adminChatToggle()) { - if (vminecraftSettings.getInstance().cmdAdminToggle) { - //If the player is already toggled for admin chat, remove them - if (vminecraftSettings.getInstance().isAdminToggled(player.getName())) { - player.sendMessage(Colors.Red + "Admin Chat Toggle = off"); - vminecraftSettings.getInstance().removeAdminToggled(player.getName()); - //Otherwise include them - } else { - player.sendMessage(Colors.Blue + "Admin Chat Toggled on"); - vminecraftSettings.getInstance().addAdminToggled(player.getName()); - } - return EXIT_SUCCESS; + //If the player is already toggled for admin chat, remove them + if (vminecraftSettings.getInstance().isAdminToggled(player.getName())) { + player.sendMessage(Colors.Red + "Admin Chat Toggle = off"); + vminecraftSettings.getInstance().removeAdminToggled(player.getName()); + //Otherwise include them + } else { + player.sendMessage(Colors.Blue + "Admin Chat Toggled on"); + vminecraftSettings.getInstance().addAdminToggled(player.getName()); } + return EXIT_SUCCESS; } return EXIT_FAIL; } From 4a328146c967d94724c0ed05e1f828f443cfa1bc Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 22:39:50 -0600 Subject: [PATCH 32/82] Renaming the plugin from vminecraftPlugin to just vMinecraft --- vMinecraft.java | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 vMinecraft.java diff --git a/vMinecraft.java b/vMinecraft.java new file mode 100644 index 000000000..654be29fd --- /dev/null +++ b/vMinecraft.java @@ -0,0 +1,32 @@ +import java.util.logging.Logger; + +//===================================================================== +//Class: vMinecraftPlugin +//Use: Starts the plugin +//Author: nossr50, TrapAlice, cerevisiae +//===================================================================== +public class vMinecraft extends Plugin { + static final vMinecraftListener listener = new vMinecraftListener(); + protected static final Logger log = Logger.getLogger("Minecraft"); + + public void enable() { + vMinecraftSettings.getInstance().loadSettings(); + vMinecraftCommands.loadCommands(); + } + + public void disable() { + //And remove the commands here. + } + + public void initialize() { + //Here we add the hook we're going to use. In this case it's the arm swing event. + etc.getLoader().addListener(PluginLoader.Hook.CHAT, listener, this, PluginListener.Priority.MEDIUM); + etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH); + etc.getLoader().addListener(PluginLoader.Hook.IGNITE, listener, this, PluginListener.Priority.HIGH); + etc.getLoader().addListener(PluginLoader.Hook.DAMAGE, listener, this, PluginListener.Priority.MEDIUM); + etc.getLoader().addListener(PluginLoader.Hook.EXPLODE, listener, this, PluginListener.Priority.HIGH); + if(etc.getInstance().isHealthEnabled()){ + etc.getLoader().addListener(PluginLoader.Hook.HEALTH_CHANGE, listener, this, PluginListener.Priority.MEDIUM); + } + } +} From 6f973cb9b4804a7b3b854091289c3934c85c3253 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 22:41:30 -0600 Subject: [PATCH 33/82] Renaming the plugin from vminecraftPlugin to vMinecraft --- vminecraftAnnouncements.java | 12 ++--- vminecraftChat.java | 24 ++++----- vminecraftCommands.java | 94 ++++++++++++++++++------------------ vminecraftListener.java | 30 ++++++------ vminecraftSettings.java | 33 +++++++------ 5 files changed, 97 insertions(+), 96 deletions(-) diff --git a/vminecraftAnnouncements.java b/vminecraftAnnouncements.java index 8f7f14700..c93db1b96 100644 --- a/vminecraftAnnouncements.java +++ b/vminecraftAnnouncements.java @@ -4,7 +4,7 @@ // run //Author: nossr50, TrapAlice, cerevisiae //===================================================================== -public class vminecraftAnnouncements { +public class vMinecraftAnnouncements { //===================================================================== //Function: onCommand @@ -20,30 +20,30 @@ public class vminecraftAnnouncements { return false; } //Only run if the global message feature is enabled - if(vminecraftSettings.getInstance().globalmessages()) + if(vMinecraftSettings.getInstance().globalmessages()) { //Global messages that should only parse when a command can be successful if(split[0].equalsIgnoreCase("/kick")) { Player playerTarget = etc.getServer().matchPlayer(split[1]); if (playerTarget != null && !playerTarget.hasControlOver(player)) { - vminecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has kicked "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); + vMinecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has kicked "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); } } if(split[0].equalsIgnoreCase("/ban")) { Player playerTarget = etc.getServer().matchPlayer(split[1]); if (playerTarget != null && !playerTarget.hasControlOver(player)) { - vminecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); + vMinecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); } } if(split[0].equalsIgnoreCase("/ipban")) { Player playerTarget = etc.getServer().matchPlayer(split[1]); if (playerTarget != null && !playerTarget.hasControlOver(player)) { - vminecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has IP banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); + vMinecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has IP banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); } } if(split[0].equalsIgnoreCase("/time")) { if (split.length <= 2) { - vminecraftChat.gmsg(Colors.Blue+"Time changes thanks to "+player.getColor()+player.getName()); + vMinecraftChat.gmsg(Colors.Blue+"Time changes thanks to "+player.getColor()+player.getName()); } } } diff --git a/vminecraftChat.java b/vminecraftChat.java index 026892dc2..3f6463855 100644 --- a/vminecraftChat.java +++ b/vminecraftChat.java @@ -7,7 +7,7 @@ import java.util.logging.Logger; //Use: Encapsulates all chat commands added by this mod //Author: nossr50, TrapAlice, cerevisiae //===================================================================== -public class vminecraftChat { +public class vMinecraftChat { protected static final Logger log = Logger.getLogger("Minecraft"); //===================================================================== @@ -79,7 +79,7 @@ public class vminecraftChat { //and their following color codes for(int x = 0; x "; - if(vminecraftSettings.getInstance().greentext()) { + if(vMinecraftSettings.getInstance().greentext()) { //Log the chat log.log(Level.INFO, "<"+player.getName()+"> " +message); @@ -331,7 +331,7 @@ public class vminecraftChat { //Format the name String playerName = Colors.White + "<" + getName(player) + Colors.White +"> "; - if (vminecraftSettings.getInstance().FFF()) { + if (vMinecraftSettings.getInstance().FFF()) { log.log(Level.INFO, "<"+player.getName()+"> "+message); //Get the multi line array @@ -357,7 +357,7 @@ public class vminecraftChat { //Format the name String playerName = Colors.White + "<" + getName(player) + Colors.White +"> "; - if(vminecraftSettings.getInstance().quakeColors()) { + if(vMinecraftSettings.getInstance().quakeColors()) { //Log the chat log.log(Level.INFO, "<"+player.getName()+"> "+message); @@ -401,15 +401,15 @@ public class vminecraftChat { for(int x = 0; x< msg.length(); x++) { //If the char is a ^ or � - if(msg.charAt(x) == '^' || msg.charAt(x) == '�') + if(msg.charAt(x) == '^' || msg.charAt(x) == '§') { if(x != msg.length() - 1) { //If the following character is a color code - if(vminecraftChat.colorChange(msg.charAt(x+1)) != null) + if(vMinecraftChat.colorChange(msg.charAt(x+1)) != null) { //Set the most recent color to the new color - recentColor = vminecraftChat.colorChange(msg.charAt(x+1)); + recentColor = vMinecraftChat.colorChange(msg.charAt(x+1)); //Add the color temp += recentColor; //Skip these chars @@ -465,15 +465,15 @@ public class vminecraftChat { for(int x = 0; x< message.length(); x++) { //If the char is a ^ or � - if(message.charAt(x) == '^' || message.charAt(x) == '�') + if(message.charAt(x) == '^' || message.charAt(x) == '§') { if(x != message.length() - 1) { //If the following character is a color code - if(vminecraftChat.colorChange(message.charAt(x+1)) != null) + if(vMinecraftChat.colorChange(message.charAt(x+1)) != null) { //Set the most recent color to the new color - color = vminecraftChat.colorChange(message.charAt(x+1)); + color = vMinecraftChat.colorChange(message.charAt(x+1)); //Add the color temp += color; //Skip these chars diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 5e7e9a056..90c88ed8f 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -5,18 +5,18 @@ import java.util.logging.Level; import java.util.logging.Logger; //===================================================================== -//Class: vminecraftCommands +//Class: vMinecraftCommands //Use: Encapsulates all commands added by this mod //Author: nos, trapalice, cerevisiae //===================================================================== -public class vminecraftCommands{ +public class vMinecraftCommands{ //Log output protected static final Logger log = Logger.getLogger("Minecraft"); static final int EXIT_FAIL = 0, EXIT_SUCCESS = 1, EXIT_CONTINUE = 2; - //The list of commands for vminecraft + //The list of commands for vMinecraft public static commandList cl = new commandList(); //===================================================================== @@ -56,16 +56,16 @@ public class vminecraftCommands{ public static int adminChatToggle(Player player) { - if(vminecraftSettings.getInstance().adminChatToggle()) + if(vMinecraftSettings.getInstance().adminChatToggle()) { //If the player is already toggled for admin chat, remove them - if (vminecraftSettings.getInstance().isAdminToggled(player.getName())) { + if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) { player.sendMessage(Colors.Red + "Admin Chat Toggle = off"); - vminecraftSettings.getInstance().removeAdminToggled(player.getName()); + vMinecraftSettings.getInstance().removeAdminToggled(player.getName()); //Otherwise include them } else { player.sendMessage(Colors.Blue + "Admin Chat Toggled on"); - vminecraftSettings.getInstance().addAdminToggled(player.getName()); + vMinecraftSettings.getInstance().addAdminToggled(player.getName()); } return EXIT_SUCCESS; } @@ -81,7 +81,7 @@ public class vminecraftCommands{ //===================================================================== public static int heal(Player player, String[] args) { - if(vminecraftSettings.getInstance().cmdHeal()) + if(vMinecraftSettings.getInstance().cmdHeal()) { //If a target wasn't specified, heal the user. if (args.length < 1){ @@ -94,11 +94,11 @@ public class vminecraftCommands{ if (playerTarget != null){ playerTarget.setHealth(20); - player.sendMessage(Colors.Blue + "You have healed " + vminecraftChat.getName(playerTarget)); - playerTarget.sendMessage(Colors.Blue + "You have been healed by " + vminecraftChat.getName(player)); + player.sendMessage(Colors.Blue + "You have healed " + vMinecraftChat.getName(playerTarget)); + playerTarget.sendMessage(Colors.Blue + "You have been healed by " + vMinecraftChat.getName(player)); } else if (playerTarget == null){ - vminecraftChat.gmsg(Colors.Rose + "Couldn't find that player"); + vMinecraftChat.gmsg(Colors.Rose + "Couldn't find that player"); } } return EXIT_SUCCESS; @@ -115,7 +115,7 @@ public class vminecraftCommands{ //===================================================================== public static int suicide(Player player, String[] args) { - if(vminecraftSettings.getInstance().cmdSuicide()) + if(vMinecraftSettings.getInstance().cmdSuicide()) { //Set your health to 0. Not much to it. player.setHealth(0); @@ -135,7 +135,7 @@ public class vminecraftCommands{ public static int teleport(Player player, String[] args) { //Get if the command is enabled - if(vminecraftSettings.getInstance().cmdTp()) + if(vMinecraftSettings.getInstance().cmdTp()) { //Make sure a player has been specified and return an error if not if (args.length < 1) { @@ -182,7 +182,7 @@ public class vminecraftCommands{ public static int masstp(Player player, String[] args) { //If the command is enabled - if(vminecraftSettings.getInstance().cmdMasstp()) { + if(vMinecraftSettings.getInstance().cmdMasstp()) { //Go through all players and move them to the user for (Player p : etc.getServer().getPlayerList()) { if (!p.hasControlOver(player)) { @@ -208,7 +208,7 @@ public class vminecraftCommands{ public static int tphere(Player player, String[] args) { //Check if the command is enabled. - if (vminecraftSettings.getInstance().cmdTphere()) { + if (vMinecraftSettings.getInstance().cmdTphere()) { //Make sure a player is specified if (args.length < 1) { player.sendMessage(Colors.Rose + "Correct usage is: /tphere [player]"); @@ -241,11 +241,11 @@ public class vminecraftCommands{ //Input: Player player: The player using the command // String[] args: Ignored //Output: int: Exit Code - //Use: Reloads the settings for vminecraft + //Use: Reloads the settings for vMinecraft //===================================================================== public static int reload(Player player, String[] args) { - vminecraftSettings.getInstance().loadSettings(); + vMinecraftSettings.getInstance().loadSettings(); return EXIT_FAIL; } @@ -259,12 +259,12 @@ public class vminecraftCommands{ public static int rules(Player player, String[] args) { //If the rules exist - if(vminecraftSettings.getInstance().cmdRules() - && vminecraftSettings.getInstance().getRules().length > 0) { + if(vMinecraftSettings.getInstance().cmdRules() + && vMinecraftSettings.getInstance().getRules().length > 0) { //Apply QuakeCode Colors to the rules - String[] rules = vminecraftChat.applyColors( - vminecraftSettings.getInstance().getRules()); + String[] rules = vMinecraftChat.applyColors( + vMinecraftSettings.getInstance().getRules()); //Display them for (String str : rules ) { if(!str.isEmpty()) @@ -287,11 +287,11 @@ public class vminecraftCommands{ public static int fabulous(Player player, String[] args) { //If the command is enabled - if(vminecraftSettings.getInstance().cmdFabulous()) { + if(vMinecraftSettings.getInstance().cmdFabulous()) { //Format the name String playerName = Colors.White + "<" - + vminecraftChat.getName(player) + Colors.White +"> "; + + vMinecraftChat.getName(player) + Colors.White +"> "; //Make sure a message has been specified if (args.length < 1) {return EXIT_FAIL;} String str = " "; @@ -303,17 +303,17 @@ public class vminecraftCommands{ log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\""); //Prepend the player name and cut into lines. - String[] message = vminecraftChat.wordWrap(playerName + str); + String[] message = vMinecraftChat.wordWrap(playerName + str); //Output the message for(String msg: message) { if (msg.contains(playerName)) - vminecraftChat.gmsg( playerName - + vminecraftChat.rainbow( + vMinecraftChat.gmsg( playerName + + vMinecraftChat.rainbow( msg.substring(playerName.length()))); else - vminecraftChat.gmsg(vminecraftChat.rainbow(msg)); + vMinecraftChat.gmsg(vMinecraftChat.rainbow(msg)); } return EXIT_SUCCESS; @@ -331,7 +331,7 @@ public class vminecraftCommands{ public static int whois(Player player, String[] args) { //If the command is enabled - if (vminecraftSettings.getInstance().cmdWhoIs()) { + if (vMinecraftSettings.getInstance().cmdWhoIs()) { //If a player is specified if (args.length < 1) player.sendMessage(Colors.Rose + "Usage is /whois [player]"); @@ -350,7 +350,7 @@ public class vminecraftCommands{ //Displaying the information player.sendMessage(Colors.Blue + "Whois results for " + - vminecraftChat.getName(playerTarget)); + vMinecraftChat.getName(playerTarget)); //Group for(String group: playerTarget.getGroups()) player.sendMessage(Colors.Blue + "Groups: " + group); @@ -383,7 +383,7 @@ public class vminecraftCommands{ public static int who(Player player, String[] args) { //If the command is enabled - if (vminecraftSettings.getInstance().cmdWho()) { + if (vMinecraftSettings.getInstance().cmdWho()) { //Loop through all players counting them and adding to the list int count=0; String tempList = ""; @@ -391,9 +391,9 @@ public class vminecraftCommands{ { if(p != null){ if(count == 0) - tempList += vminecraftChat.getName(p); + tempList += vMinecraftChat.getName(p); else - tempList += Colors.White + ", " + vminecraftChat.getName(p); + tempList += Colors.White + ", " + vMinecraftChat.getName(p); count++; } } @@ -406,7 +406,7 @@ public class vminecraftCommands{ } int maxPlayers = server.getInt("max-players"); //Output the player list - String[] tempOut = vminecraftChat.wordWrap(Colors.Rose + "Player List (" + String[] tempOut = vMinecraftChat.wordWrap(Colors.Rose + "Player List (" + count + "/" + maxPlayers +"): " + tempList); for(String msg: tempOut) player.sendMessage( msg ); @@ -426,13 +426,13 @@ public class vminecraftCommands{ public static int say(Player player, String[] args) { //If the command is enabled - if (vminecraftSettings.getInstance().cmdSay()) { + if (vMinecraftSettings.getInstance().cmdSay()) { //Make sure a message is supplied or output an error if (args.length < 1) { player.sendMessage(Colors.Rose + "Usage is /say [message]"); } //Display the message globally - vminecraftChat.gmsg(Colors.Yellow + etc.combineSplit(0, args, " ")); + vMinecraftChat.gmsg(Colors.Yellow + etc.combineSplit(0, args, " ")); return EXIT_SUCCESS; } return EXIT_FAIL; @@ -448,18 +448,18 @@ public class vminecraftCommands{ public static int slay(Player player, String[] args) { //Check if the command is enabled - if(vminecraftSettings.getInstance().cmdEzModo()) { + if(vMinecraftSettings.getInstance().cmdEzModo()) { //Get the player by name Player playerTarget = etc.getServer().matchPlayer(args[0]); //If the player doesn't exist don't run if(playerTarget == null) return EXIT_FAIL; //If the player isn't invulnerable kill them - if (!vminecraftSettings.getInstance().isEzModo(playerTarget.getName())) { + if (!vMinecraftSettings.getInstance().isEzModo(playerTarget.getName())) { playerTarget.setHealth(0); - vminecraftChat.gmsg(vminecraftChat.getName(player) + vMinecraftChat.gmsg(vMinecraftChat.getName(player) + Colors.LightBlue + " has slain " - + vminecraftChat.getName(playerTarget)); + + vMinecraftChat.getName(playerTarget)); //Otherwise output error to the user } else { player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha"); @@ -479,19 +479,19 @@ public class vminecraftCommands{ public static int invuln(Player player, String[] args) { //If the command is enabled - if (vminecraftSettings.getInstance().cmdEzModo()) { + if (vMinecraftSettings.getInstance().cmdEzModo()) { //If the player is already invulnerable, turn ezmodo off. - if (vminecraftSettings.getInstance().isEzModo(player.getName())) { + if (vMinecraftSettings.getInstance().isEzModo(player.getName())) { player.sendMessage(Colors.Red + "ezmodo = off"); - vminecraftSettings.getInstance().removeEzModo(player.getName()); + vMinecraftSettings.getInstance().removeEzModo(player.getName()); //Otherwise make them invulnerable } else { player.sendMessage(Colors.LightBlue + "eh- maji? ezmodo!?"); player.sendMessage(Colors.Rose + "kimo-i"); player.sendMessage(Colors.LightBlue + "Easy Mode ga yurusareru no wa shougakusei made dayo ne"); player.sendMessage(Colors.Red + "**Laughter**"); - vminecraftSettings.getInstance().addEzModo(player.getName()); - player.setHealth(vminecraftSettings.getInstance().ezModoHealth()); + vMinecraftSettings.getInstance().addEzModo(player.getName()); + player.setHealth(vMinecraftSettings.getInstance().ezModoHealth()); } return EXIT_SUCCESS; } @@ -508,8 +508,8 @@ public class vminecraftCommands{ public static int ezlist(Player player, String[] args) { //If the feature is enabled list the players - if(vminecraftSettings.getInstance().cmdEzModo()) { - player.sendMessage("Ezmodo: " + vminecraftSettings.getInstance().ezModoList()); + if(vMinecraftSettings.getInstance().cmdEzModo()) { + player.sendMessage("Ezmodo: " + vMinecraftSettings.getInstance().ezModoList()); return EXIT_SUCCESS; } return EXIT_FAIL; @@ -761,7 +761,7 @@ class commandList { Method m; try { - m = vminecraftCommands.class.getMethod(function, Player.class, String[].class); + m = vMinecraftCommands.class.getMethod(function, Player.class, String[].class); m.setAccessible(true); return (Integer) m.invoke(null, player, arg); } catch (SecurityException e) { diff --git a/vminecraftListener.java b/vminecraftListener.java index 0bf545c1d..a89cfda06 100644 --- a/vminecraftListener.java +++ b/vminecraftListener.java @@ -1,21 +1,21 @@ import java.util.logging.Level; import java.util.logging.Logger; //===================================================================== -//Class: vminecraftListener +//Class: vMinecraftListener //Use: The listener to catch incoming chat and commands //Author: nossr50, TrapAlice, cerevisiae //===================================================================== -public class vminecraftListener extends PluginListener { +public class vMinecraftListener 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? ;) + //Use: Disables vMinecraft, but why would you want to do that? ;) //===================================================================== public void disable() { - log.log(Level.INFO, "vminecraft disabled"); + log.log(Level.INFO, "vMinecraft disabled"); } //===================================================================== @@ -30,20 +30,20 @@ public class vminecraftListener extends PluginListener { //Quote (Greentext) if (message.startsWith("@")) - return vminecraftChat.adminChat(player, message); - if (vminecraftSettings.getInstance().isAdminToggled(player.getName())) - return vminecraftChat.adminChatToggle(player, message); + return vMinecraftChat.adminChat(player, message); + if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) + return vMinecraftChat.adminChatToggle(player, message); else if (message.startsWith(">")) - return vminecraftChat.quote(player, message); + return vMinecraftChat.quote(player, message); //Rage (FFF) else if (message.startsWith("FFF")) - return vminecraftChat.rage(player, message); + return vMinecraftChat.rage(player, message); //Send through quakeColors otherwise else - return vminecraftChat.quakeColors(player, message); + return vMinecraftChat.quakeColors(player, message); } //===================================================================== @@ -61,7 +61,7 @@ public class vminecraftListener extends PluginListener { System.arraycopy(split, 1, args, 0, args.length); //Return the results of the command - int exitCode = vminecraftCommands.cl.call(split[0], player, args); + int exitCode = vMinecraftCommands.cl.call(split[0], player, args); if(exitCode == 0) return false; else if(exitCode == 1) @@ -81,12 +81,12 @@ public class vminecraftListener extends PluginListener { //Use: Checks for exploits and runs the commands //===================================================================== public boolean onHealthChange(Player player,int oldValue,int newValue){ - if (player.getHealth() != vminecraftSettings.getInstance().ezModoHealth() && vminecraftSettings.getInstance().isEzModo(player.getName())) { - player.setHealth(vminecraftSettings.getInstance().ezModoHealth()); + if (player.getHealth() != vMinecraftSettings.getInstance().ezModoHealth() && vMinecraftSettings.getInstance().isEzModo(player.getName())) { + player.setHealth(vMinecraftSettings.getInstance().ezModoHealth()); } - else if (vminecraftSettings.getInstance().globalmessages() && player.getHealth() < 1) { - vminecraftChat.gmsg(Colors.Gray + player.getName() + " " + vminecraftSettings.randomDeathMsg()); + else if (vMinecraftSettings.getInstance().globalmessages() && player.getHealth() < 1) { + vMinecraftChat.gmsg(Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); } return false; } diff --git a/vminecraftSettings.java b/vminecraftSettings.java index 177bca7ea..71f4c26ea 100644 --- a/vminecraftSettings.java +++ b/vminecraftSettings.java @@ -7,10 +7,10 @@ import java.util.logging.Logger; //Use: Controls the settings for vminecraft //Author: nossr50, TrapAlice, cerevisiae //===================================================================== -public class vminecraftSettings { +public class vMinecraftSettings { //private final static Object syncLock = new Object(); protected static final Logger log = Logger.getLogger("Minecraft"); - private static volatile vminecraftSettings instance; + private static volatile vMinecraftSettings instance; //The feature settings @@ -32,9 +32,9 @@ public class vminecraftSettings { cmdWho = false, stopFire = false, stopTnt = false, - cmdHeal = false, - cmdSuicide = false, - cmdAdminToggle = false, + cmdHeal = false, + cmdSuicide = false, + cmdAdminToggle = false, cmdEzModo = false; //An array of players currently in ezmodo static ArrayList ezModo = new ArrayList(); @@ -78,8 +78,8 @@ public class vminecraftSettings { writer.write("cmdSay=true\r\n"); writer.write("cmdTp=true\r\n"); writer.write("cmdRules=true\r\n"); - writer.write("cmdSuicide=true\r\n"); - writer.write("cmdAdminToggle=true\r\n"); + writer.write("cmdSuicide=true\r\n"); + writer.write("cmdAdminToggle=true\r\n"); writer.write("globalmessages=true\r\n"); writer.write("FFF=true\r\n"); writer.write("adminchat=true\r\n"); @@ -89,10 +89,10 @@ public class vminecraftSettings { writer.write("#The health ezmodo people will have while in ezmodo. Don't set to 0\r\n"); writer.write("ezHealth=30\r\n"); writer.write("stopFire=false\r\n"); - writer.write("stopTnt=false\r\n"); + writer.write("stopTnt=false\r\n"); writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n"); - writer.write("#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("#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"); } catch (Exception e) { log.log(Level.SEVERE, "Exception while creating " + location, e); } finally { @@ -130,18 +130,19 @@ public class vminecraftSettings { cmdTphere = properties.getBoolean("cmdTphere",true); cmdSuicide = properties.getBoolean("cmdSuicide", true); cmdHeal = properties.getBoolean("cmdHeal",true); - cmdAdminToggle = properties.getBoolean("cmdAdminToggle", true); + cmdAdminToggle = properties.getBoolean("cmdAdminToggle", true); globalmessages = properties.getBoolean("globalmessages",true); cmdSay = properties.getBoolean("cmdSay",true); cmdEzModo = properties.getBoolean("cmdEzModo",true); stopFire = properties.getBoolean("stopFire",true); stopTnt = properties.getBoolean("stopTNT",true); rules = properties.getString("rules", "").split("@"); - deathMessages = properties.getString("deathmessages", "").split(","); + deathMessages = properties.getString("deathmessages", "").split(","); + String[] tempEz = properties.getString("ezModo").split(","); ezModo = new ArrayList(); - for(int i = 0; i < tempEz.length; i++) - ezModo.add(tempEz[i]); + for(String ezName : tempEz) + ezModo.add(ezName); ezHealth = properties.getInt("ezHealth"); @@ -208,9 +209,9 @@ public class vminecraftSettings { //Output: vminecraftSettings: The instance of the settings //Use: Returns the instance of the settings //===================================================================== - public static vminecraftSettings getInstance() { + public static vMinecraftSettings getInstance() { if (instance == null) { - instance = new vminecraftSettings(); + instance = new vMinecraftSettings(); } return instance; } From dcf31b638b52811905a49749657144c5c3a42c0c Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 22:42:41 -0600 Subject: [PATCH 34/82] Renaming the plugin from vminecraftPlugin to vMinecraft --- vminecraftPlugin.java | 32 -------------------------------- 1 file changed, 32 deletions(-) delete mode 100644 vminecraftPlugin.java diff --git a/vminecraftPlugin.java b/vminecraftPlugin.java deleted file mode 100644 index 160418483..000000000 --- a/vminecraftPlugin.java +++ /dev/null @@ -1,32 +0,0 @@ -import java.util.logging.Logger; - -//===================================================================== -//Class: vMinecraftPlugin -//Use: Starts the plugin -//Author: nossr50, TrapAlice, cerevisiae -//===================================================================== -public class vminecraftPlugin extends Plugin { - static final vminecraftListener listener = new vminecraftListener(); - protected static final Logger log = Logger.getLogger("Minecraft"); - - public void enable() { - vminecraftSettings.getInstance().loadSettings(); - vminecraftCommands.loadCommands(); - } - - public void disable() { - //And remove the commands here. - } - - public void initialize() { - //Here we add the hook we're going to use. In this case it's the arm swing event. - etc.getLoader().addListener(PluginLoader.Hook.CHAT, listener, this, PluginListener.Priority.MEDIUM); - etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH); - etc.getLoader().addListener(PluginLoader.Hook.IGNITE, listener, this, PluginListener.Priority.HIGH); - etc.getLoader().addListener(PluginLoader.Hook.DAMAGE, listener, this, PluginListener.Priority.MEDIUM); - etc.getLoader().addListener(PluginLoader.Hook.EXPLODE, listener, this, PluginListener.Priority.HIGH); - if(etc.getInstance().isHealthEnabled()){ - etc.getLoader().addListener(PluginLoader.Hook.HEALTH_CHANGE, listener, this, PluginListener.Priority.MEDIUM); - } - } -} From 6638fb5dbae533e59b154285b2aa93a3e4e12e9e Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 22:46:46 -0600 Subject: [PATCH 35/82] Renaming the plugin from vminecraftPlugin to vMinecraft --- vMinecraft.java | 32 --- vminecraftAnnouncements.java | 53 ---- vminecraftChat.java | 495 ----------------------------------- vminecraftListener.java | 100 ------- vminecraftSettings.java | 229 ---------------- 5 files changed, 909 deletions(-) delete mode 100644 vMinecraft.java delete mode 100644 vminecraftAnnouncements.java delete mode 100644 vminecraftChat.java delete mode 100644 vminecraftListener.java delete mode 100644 vminecraftSettings.java diff --git a/vMinecraft.java b/vMinecraft.java deleted file mode 100644 index 654be29fd..000000000 --- a/vMinecraft.java +++ /dev/null @@ -1,32 +0,0 @@ -import java.util.logging.Logger; - -//===================================================================== -//Class: vMinecraftPlugin -//Use: Starts the plugin -//Author: nossr50, TrapAlice, cerevisiae -//===================================================================== -public class vMinecraft extends Plugin { - static final vMinecraftListener listener = new vMinecraftListener(); - protected static final Logger log = Logger.getLogger("Minecraft"); - - public void enable() { - vMinecraftSettings.getInstance().loadSettings(); - vMinecraftCommands.loadCommands(); - } - - public void disable() { - //And remove the commands here. - } - - public void initialize() { - //Here we add the hook we're going to use. In this case it's the arm swing event. - etc.getLoader().addListener(PluginLoader.Hook.CHAT, listener, this, PluginListener.Priority.MEDIUM); - etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH); - etc.getLoader().addListener(PluginLoader.Hook.IGNITE, listener, this, PluginListener.Priority.HIGH); - etc.getLoader().addListener(PluginLoader.Hook.DAMAGE, listener, this, PluginListener.Priority.MEDIUM); - etc.getLoader().addListener(PluginLoader.Hook.EXPLODE, listener, this, PluginListener.Priority.HIGH); - if(etc.getInstance().isHealthEnabled()){ - etc.getLoader().addListener(PluginLoader.Hook.HEALTH_CHANGE, listener, this, PluginListener.Priority.MEDIUM); - } - } -} diff --git a/vminecraftAnnouncements.java b/vminecraftAnnouncements.java deleted file mode 100644 index c93db1b96..000000000 --- a/vminecraftAnnouncements.java +++ /dev/null @@ -1,53 +0,0 @@ -//===================================================================== -//Class: vMinecraftAnnouncements -//Use: Encapsulates all announcements broadcast when commands are -// run -//Author: nossr50, TrapAlice, cerevisiae -//===================================================================== -public class vMinecraftAnnouncements { - - //===================================================================== - //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 if /kick, /ban, /ipban, and /time are run and - // displays a global message - //===================================================================== - public boolean onCommand(Player player, String[] split) { - if(!player.canUseCommand(split[0])) { - return false; - } - //Only run if the global message feature is enabled - if(vMinecraftSettings.getInstance().globalmessages()) - { - //Global messages that should only parse when a command can be successful - if(split[0].equalsIgnoreCase("/kick")) { - Player playerTarget = etc.getServer().matchPlayer(split[1]); - if (playerTarget != null && !playerTarget.hasControlOver(player)) { - vMinecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has kicked "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); - } - } - if(split[0].equalsIgnoreCase("/ban")) { - Player playerTarget = etc.getServer().matchPlayer(split[1]); - if (playerTarget != null && !playerTarget.hasControlOver(player)) { - vMinecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); - } - } - if(split[0].equalsIgnoreCase("/ipban")) { - Player playerTarget = etc.getServer().matchPlayer(split[1]); - if (playerTarget != null && !playerTarget.hasControlOver(player)) { - vMinecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has IP banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); - } - } - if(split[0].equalsIgnoreCase("/time")) { - if (split.length <= 2) { - vMinecraftChat.gmsg(Colors.Blue+"Time changes thanks to "+player.getColor()+player.getName()); - } - } - } - - return true; - } -} diff --git a/vminecraftChat.java b/vminecraftChat.java deleted file mode 100644 index 3f6463855..000000000 --- a/vminecraftChat.java +++ /dev/null @@ -1,495 +0,0 @@ -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 vMinecraftChat { - protected static final Logger log = Logger.getLogger("Minecraft"); - - //===================================================================== - //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){ - for (Player p : etc.getServer().getPlayerList()) { - if (p != null) { - p.sendMessage(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 - String[] split = msg.split(" "); - - //Create an arraylist for the output - ArrayList out = new ArrayList(); - - //While i is less than the length of the array of words - int i = 0; - while(i < split.length){ - int len = 0; - int j = i; - - //Loop through the words finding their length and increasing - //j, the end point for the sub string - while(len <= 316 && i < split.length) - { - len += msgLength(split[i]) + 4; - if( len <= 316) - i++; - - } - //Copy the words in the selection into a new array - String[] temp = new String[i - j]; - System.arraycopy(split, j, temp, 0, i - j); - - //Merge them and add them to the output array - out.add( etc.combineSplit(0, temp, " ") ); - } - - //Convert to an array and return - String[] tempout = new String[out.size()]; - out.toArray(tempout); - return tempout; - } - - //===================================================================== - //Function: msgLength - //Input: String str: The string to find the length of - //Output: int: The length on the screen of a string - //Use: Finds the length on the screen of a string. Ignores colors. - //===================================================================== - private static int msgLength(String str){ - int length = 0; - //Loop through all the characters, skipping any color characters - //and their following color codes - for(int x = 0; x\"*()".indexOf(str.charAt(x)) != -1) - length+=5; - else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1) - length+=6; - else if("@~".indexOf(str.charAt(x)) != -1) - length+=7; - else if(str.charAt(x)==' ') - length+=4; - } - return length; - } - - //===================================================================== - //Function: rainbow - //Input: String msg: The string to colorify - //Output: String: The rainbowed result - //Use: Rainbowifies a string; - //===================================================================== - public static String rainbow(String msg){ - String temp = ""; - //The array of colors to use - String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Gold, - Colors.Yellow, Colors.LightGreen, Colors.Green, Colors.Blue, - Colors.Navy, Colors.DarkPurple, Colors.Purple, Colors.LightPurple}; - int counter=0; - //Loop through the message applying the colors - for(int x=0; x " + message); - return true; - } - return false; - } - public static boolean adminChatToggle(Player player, String message){ - if(vMinecraftSettings.getInstance().isAdminToggled(player.getName())) { - String adminchat = Colors.DarkPurple + "{" + getName(player) - + Colors.DarkPurple +"}" + Colors.White + " "; - String[] msg = wordWrap(adminchat + message.substring(1, message.length())); - for (Player p: etc.getServer().getPlayerList()) { - if (p != null) { - if (p.isAdmin() || p.canUseCommand("/adminchat")) { - for(String str: msg) - p.sendMessage(str); - } - } - } - log.log(Level.INFO, "@" + "<" + getName(player) - + Colors.White +"> " + 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(vMinecraftSettings.getInstance().greentext()) { - //Log the chat - log.log(Level.INFO, "<"+player.getName()+"> " +message); - - //Get the multi line array - String[] msg = wordWrap(playerName + Colors.LightGreen + message); - - //Output the lines - for(String str: msg) - gmsg(Colors.LightGreen + str); - 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 (vMinecraftSettings.getInstance().FFF()) { - log.log(Level.INFO, "<"+player.getName()+"> "+message); - - //Get the multi line array - String[] msg = wordWrap(playerName + Colors.Red + message); - - //Output the message - for(String str: msg) - gmsg(Colors.Red + str); - 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(vMinecraftSettings.getInstance().quakeColors()) { - - //Log the chat - log.log(Level.INFO, "<"+player.getName()+"> "+message); - - //Get the multi line array - String[] msg = wordWrap(playerName + message); - //Apply colors to the lines - applyColors(msg); - - //Output the message - for(String str: msg) - gmsg(str); - - //Loop through the string finding the color codes and inserting them - return true; - } - return false; - } - - - //===================================================================== - //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].equals("")){ - //The color to start the line with - String recentColor = Colors.White; - - //Go through each line - int counter = 0; - for(String msg: message) - { - //Start the line with the most recent color - String temp = recentColor; - - //Loop through looking for a color code - for(int x = 0; x< msg.length(); x++) - { - //If the char is a ^ or � - if(msg.charAt(x) == '^' || msg.charAt(x) == '§') - { - if(x != msg.length() - 1) - { - //If the following character is a color code - if(vMinecraftChat.colorChange(msg.charAt(x+1)) != null) - { - //Set the most recent color to the new color - recentColor = vMinecraftChat.colorChange(msg.charAt(x+1)); - //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); - } - } - //Replace the message with the colorful message - message[counter] = temp; - counter++; - } - } - return message; - } - - //===================================================================== - //Function: applyColors - //Input: String message: The line to be colored - //Output: String: The line, but colorful - //Use: Colors a line - //===================================================================== - public static String applyColors(String message) - { - return applyColors(message, Colors.White); - } - - //===================================================================== - //Function: applyColors - //Input: String message: The line to be colored - // String color: The color to start the line with - //Output: String: The line, but colorful - //Use: Colors a line - //===================================================================== - public static String applyColors(String message, String color) - { - if(message != null && !message.equals("")) - { - //The color to start the line with - if(color == null) - color = Colors.White; - - //Start the line with the most recent color - String temp = color; - - //Loop through looking for a color code - for(int x = 0; x< message.length(); x++) - { - //If the char is a ^ or � - if(message.charAt(x) == '^' || message.charAt(x) == '§') - { - if(x != message.length() - 1) - { - //If the following character is a color code - if(vMinecraftChat.colorChange(message.charAt(x+1)) != null) - { - //Set the most recent color to the new color - color = vMinecraftChat.colorChange(message.charAt(x+1)); - //Add the color - temp += color; - //Skip these chars - x++; - //Otherwise ignore it. - } else { - temp += message.charAt(x); - } - //Insert the character - } else { - temp += message.charAt(x); - } - } - - } - } - return message; - } -} diff --git a/vminecraftListener.java b/vminecraftListener.java deleted file mode 100644 index a89cfda06..000000000 --- a/vminecraftListener.java +++ /dev/null @@ -1,100 +0,0 @@ -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 vMinecraftListener 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"); - } - - //===================================================================== - //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("@")) - return vMinecraftChat.adminChat(player, message); - if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) - return vMinecraftChat.adminChatToggle(player, message); - - else if (message.startsWith(">")) - return vMinecraftChat.quote(player, message); - - //Rage (FFF) - else if (message.startsWith("FFF")) - return vMinecraftChat.rage(player, message); - - //Send through quakeColors otherwise - else - return vMinecraftChat.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 = vMinecraftCommands.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){ - if (player.getHealth() != vMinecraftSettings.getInstance().ezModoHealth() && vMinecraftSettings.getInstance().isEzModo(player.getName())) { - player.setHealth(vMinecraftSettings.getInstance().ezModoHealth()); - - } - else if (vMinecraftSettings.getInstance().globalmessages() && player.getHealth() < 1) { - vMinecraftChat.gmsg(Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); - } - return false; - } - /** Not working yet, I posted the issue to hMod on github though - public boolean onDamage(DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { - - return false; - } - **/ - -} \ No newline at end of file diff --git a/vminecraftSettings.java b/vminecraftSettings.java deleted file mode 100644 index 71f4c26ea..000000000 --- a/vminecraftSettings.java +++ /dev/null @@ -1,229 +0,0 @@ -import java.io.*; -import java.util.ArrayList; -import java.util.logging.Level; -import java.util.logging.Logger; -//===================================================================== -//Class: vminecraftSettings -//Use: Controls the settings for vminecraft -//Author: nossr50, TrapAlice, cerevisiae -//===================================================================== -public class vMinecraftSettings { - //private final static Object syncLock = new Object(); - protected static final Logger log = Logger.getLogger("Minecraft"); - private static volatile vMinecraftSettings instance; - - - //The feature settings - static boolean toggle = true, - adminChat = false, - greentext = false, - FFF = false, - quakeColors = 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, - stopTnt = 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 toggled for admin chat - static ArrayList adminChatList = new ArrayList(); - //The max health for ezModo - static int ezHealth = 30; - - private PropertiesFile properties; - String file = "vminecraft.properties"; - public String rules[] = new String[0]; - public static String deathMessages[] = 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("greentext=true\r\n"); - writer.write("quakeColors=true\r\n"); - writer.write("cmdTphere=true\r\n"); - writer.write("cmdFabulous=true\r\n"); - writer.write("cmdWhoIs=true\r\n"); - writer.write("cmdWho=true\r\n"); - writer.write("cmdPromote=true\r\n"); - writer.write("cmdDemote=true\r\n"); - writer.write("cmdMasstp=true\r\n"); - writer.write("cmdSay=true\r\n"); - writer.write("cmdTp=true\r\n"); - writer.write("cmdRules=true\r\n"); - writer.write("cmdSuicide=true\r\n"); - writer.write("cmdAdminToggle=true\r\n"); - writer.write("globalmessages=true\r\n"); - writer.write("FFF=true\r\n"); - writer.write("adminchat=true\r\n"); - writer.write("cmdEzModo=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("#The health ezmodo people will have while in ezmodo. Don't set to 0\r\n"); - writer.write("ezHealth=30\r\n"); - writer.write("stopFire=false\r\n"); - writer.write("stopTnt=false\r\n"); - writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n"); - writer.write("#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"); - } 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); - greentext = properties.getBoolean("greentext",true); - FFF = properties.getBoolean("FFF",true); - quakeColors = properties.getBoolean("quakeColors",true); - cmdFabulous = properties.getBoolean("cmdFabulous",true); - cmdPromote = properties.getBoolean("cmdPromote",true); - cmdDemote = properties.getBoolean("cmdDemote",true); - cmdWhoIs = properties.getBoolean("cmdWhoIs",true); - cmdWho = properties.getBoolean("cmdWho",true); - cmdRules = properties.getBoolean("cmdRules",true); - cmdTp = properties.getBoolean("cmdTp",true); - cmdMasstp = properties.getBoolean("cmdMasstp",true); - cmdTphere = properties.getBoolean("cmdTphere",true); - cmdSuicide = properties.getBoolean("cmdSuicide", true); - cmdHeal = properties.getBoolean("cmdHeal",true); - cmdAdminToggle = properties.getBoolean("cmdAdminToggle", true); - globalmessages = properties.getBoolean("globalmessages",true); - cmdSay = properties.getBoolean("cmdSay",true); - cmdEzModo = properties.getBoolean("cmdEzModo",true); - stopFire = properties.getBoolean("stopFire",true); - stopTnt = properties.getBoolean("stopTNT",true); - rules = properties.getString("rules", "").split("@"); - deathMessages = properties.getString("deathmessages", "").split(","); - - String[] tempEz = properties.getString("ezModo").split(","); - ezModo = new ArrayList(); - for(String ezName : tempEz) - ezModo.add(ezName); - - ezHealth = properties.getInt("ezHealth"); - - log.log(Level.INFO, "vminecraft plugin successfully loaded"); - - } - catch (Exception e) - { - log.log(Level.SEVERE, "vminecraft Error: ERROR LOADING PROPERTIES FILE"); - } - } - - //===================================================================== - //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 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 stopTnt() {return stopTnt;} - public boolean cmdSuicide() {return cmdSuicide;} - public boolean cmdHeal() {return cmdHeal;} - - //EzModo methods - public boolean cmdEzModo() {return cmdEzModo;} - public boolean isEzModo(String playerName) {return ezModo.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 int ezModoHealth() {return ezHealth;} - 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 vMinecraftSettings getInstance() { - if (instance == null) { - instance = new vMinecraftSettings(); - } - 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 From 39d48a3bb7ba9e1108076705530ea49d9e3ced93 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 30 Nov 2010 22:47:24 -0600 Subject: [PATCH 36/82] Renaming the plugin from vminecraftPlugin to vMinecraft --- vMinecraft.java | 32 +++ vMinecraftAnnouncements.java | 53 ++++ vMinecraftChat.java | 495 +++++++++++++++++++++++++++++++++++ vMinecraftListener.java | 100 +++++++ vMinecraftSettings.java | 229 ++++++++++++++++ 5 files changed, 909 insertions(+) create mode 100644 vMinecraft.java create mode 100644 vMinecraftAnnouncements.java create mode 100644 vMinecraftChat.java create mode 100644 vMinecraftListener.java create mode 100644 vMinecraftSettings.java diff --git a/vMinecraft.java b/vMinecraft.java new file mode 100644 index 000000000..654be29fd --- /dev/null +++ b/vMinecraft.java @@ -0,0 +1,32 @@ +import java.util.logging.Logger; + +//===================================================================== +//Class: vMinecraftPlugin +//Use: Starts the plugin +//Author: nossr50, TrapAlice, cerevisiae +//===================================================================== +public class vMinecraft extends Plugin { + static final vMinecraftListener listener = new vMinecraftListener(); + protected static final Logger log = Logger.getLogger("Minecraft"); + + public void enable() { + vMinecraftSettings.getInstance().loadSettings(); + vMinecraftCommands.loadCommands(); + } + + public void disable() { + //And remove the commands here. + } + + public void initialize() { + //Here we add the hook we're going to use. In this case it's the arm swing event. + etc.getLoader().addListener(PluginLoader.Hook.CHAT, listener, this, PluginListener.Priority.MEDIUM); + etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH); + etc.getLoader().addListener(PluginLoader.Hook.IGNITE, listener, this, PluginListener.Priority.HIGH); + etc.getLoader().addListener(PluginLoader.Hook.DAMAGE, listener, this, PluginListener.Priority.MEDIUM); + etc.getLoader().addListener(PluginLoader.Hook.EXPLODE, listener, this, PluginListener.Priority.HIGH); + if(etc.getInstance().isHealthEnabled()){ + etc.getLoader().addListener(PluginLoader.Hook.HEALTH_CHANGE, listener, this, PluginListener.Priority.MEDIUM); + } + } +} diff --git a/vMinecraftAnnouncements.java b/vMinecraftAnnouncements.java new file mode 100644 index 000000000..c93db1b96 --- /dev/null +++ b/vMinecraftAnnouncements.java @@ -0,0 +1,53 @@ +//===================================================================== +//Class: vMinecraftAnnouncements +//Use: Encapsulates all announcements broadcast when commands are +// run +//Author: nossr50, TrapAlice, cerevisiae +//===================================================================== +public class vMinecraftAnnouncements { + + //===================================================================== + //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 if /kick, /ban, /ipban, and /time are run and + // displays a global message + //===================================================================== + public boolean onCommand(Player player, String[] split) { + if(!player.canUseCommand(split[0])) { + return false; + } + //Only run if the global message feature is enabled + if(vMinecraftSettings.getInstance().globalmessages()) + { + //Global messages that should only parse when a command can be successful + if(split[0].equalsIgnoreCase("/kick")) { + Player playerTarget = etc.getServer().matchPlayer(split[1]); + if (playerTarget != null && !playerTarget.hasControlOver(player)) { + vMinecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has kicked "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); + } + } + if(split[0].equalsIgnoreCase("/ban")) { + Player playerTarget = etc.getServer().matchPlayer(split[1]); + if (playerTarget != null && !playerTarget.hasControlOver(player)) { + vMinecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); + } + } + if(split[0].equalsIgnoreCase("/ipban")) { + Player playerTarget = etc.getServer().matchPlayer(split[1]); + if (playerTarget != null && !playerTarget.hasControlOver(player)) { + vMinecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has IP banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); + } + } + if(split[0].equalsIgnoreCase("/time")) { + if (split.length <= 2) { + vMinecraftChat.gmsg(Colors.Blue+"Time changes thanks to "+player.getColor()+player.getName()); + } + } + } + + return true; + } +} diff --git a/vMinecraftChat.java b/vMinecraftChat.java new file mode 100644 index 000000000..3f6463855 --- /dev/null +++ b/vMinecraftChat.java @@ -0,0 +1,495 @@ +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 vMinecraftChat { + protected static final Logger log = Logger.getLogger("Minecraft"); + + //===================================================================== + //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){ + for (Player p : etc.getServer().getPlayerList()) { + if (p != null) { + p.sendMessage(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 + String[] split = msg.split(" "); + + //Create an arraylist for the output + ArrayList out = new ArrayList(); + + //While i is less than the length of the array of words + int i = 0; + while(i < split.length){ + int len = 0; + int j = i; + + //Loop through the words finding their length and increasing + //j, the end point for the sub string + while(len <= 316 && i < split.length) + { + len += msgLength(split[i]) + 4; + if( len <= 316) + i++; + + } + //Copy the words in the selection into a new array + String[] temp = new String[i - j]; + System.arraycopy(split, j, temp, 0, i - j); + + //Merge them and add them to the output array + out.add( etc.combineSplit(0, temp, " ") ); + } + + //Convert to an array and return + String[] tempout = new String[out.size()]; + out.toArray(tempout); + return tempout; + } + + //===================================================================== + //Function: msgLength + //Input: String str: The string to find the length of + //Output: int: The length on the screen of a string + //Use: Finds the length on the screen of a string. Ignores colors. + //===================================================================== + private static int msgLength(String str){ + int length = 0; + //Loop through all the characters, skipping any color characters + //and their following color codes + for(int x = 0; x\"*()".indexOf(str.charAt(x)) != -1) + length+=5; + else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1) + length+=6; + else if("@~".indexOf(str.charAt(x)) != -1) + length+=7; + else if(str.charAt(x)==' ') + length+=4; + } + return length; + } + + //===================================================================== + //Function: rainbow + //Input: String msg: The string to colorify + //Output: String: The rainbowed result + //Use: Rainbowifies a string; + //===================================================================== + public static String rainbow(String msg){ + String temp = ""; + //The array of colors to use + String[] rainbow = new String[] {Colors.Red, Colors.Rose, Colors.Gold, + Colors.Yellow, Colors.LightGreen, Colors.Green, Colors.Blue, + Colors.Navy, Colors.DarkPurple, Colors.Purple, Colors.LightPurple}; + int counter=0; + //Loop through the message applying the colors + for(int x=0; x " + message); + return true; + } + return false; + } + public static boolean adminChatToggle(Player player, String message){ + if(vMinecraftSettings.getInstance().isAdminToggled(player.getName())) { + String adminchat = Colors.DarkPurple + "{" + getName(player) + + Colors.DarkPurple +"}" + Colors.White + " "; + String[] msg = wordWrap(adminchat + message.substring(1, message.length())); + for (Player p: etc.getServer().getPlayerList()) { + if (p != null) { + if (p.isAdmin() || p.canUseCommand("/adminchat")) { + for(String str: msg) + p.sendMessage(str); + } + } + } + log.log(Level.INFO, "@" + "<" + getName(player) + + Colors.White +"> " + 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(vMinecraftSettings.getInstance().greentext()) { + //Log the chat + log.log(Level.INFO, "<"+player.getName()+"> " +message); + + //Get the multi line array + String[] msg = wordWrap(playerName + Colors.LightGreen + message); + + //Output the lines + for(String str: msg) + gmsg(Colors.LightGreen + str); + 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 (vMinecraftSettings.getInstance().FFF()) { + log.log(Level.INFO, "<"+player.getName()+"> "+message); + + //Get the multi line array + String[] msg = wordWrap(playerName + Colors.Red + message); + + //Output the message + for(String str: msg) + gmsg(Colors.Red + str); + 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(vMinecraftSettings.getInstance().quakeColors()) { + + //Log the chat + log.log(Level.INFO, "<"+player.getName()+"> "+message); + + //Get the multi line array + String[] msg = wordWrap(playerName + message); + //Apply colors to the lines + applyColors(msg); + + //Output the message + for(String str: msg) + gmsg(str); + + //Loop through the string finding the color codes and inserting them + return true; + } + return false; + } + + + //===================================================================== + //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].equals("")){ + //The color to start the line with + String recentColor = Colors.White; + + //Go through each line + int counter = 0; + for(String msg: message) + { + //Start the line with the most recent color + String temp = recentColor; + + //Loop through looking for a color code + for(int x = 0; x< msg.length(); x++) + { + //If the char is a ^ or � + if(msg.charAt(x) == '^' || msg.charAt(x) == '§') + { + if(x != msg.length() - 1) + { + //If the following character is a color code + if(vMinecraftChat.colorChange(msg.charAt(x+1)) != null) + { + //Set the most recent color to the new color + recentColor = vMinecraftChat.colorChange(msg.charAt(x+1)); + //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); + } + } + //Replace the message with the colorful message + message[counter] = temp; + counter++; + } + } + return message; + } + + //===================================================================== + //Function: applyColors + //Input: String message: The line to be colored + //Output: String: The line, but colorful + //Use: Colors a line + //===================================================================== + public static String applyColors(String message) + { + return applyColors(message, Colors.White); + } + + //===================================================================== + //Function: applyColors + //Input: String message: The line to be colored + // String color: The color to start the line with + //Output: String: The line, but colorful + //Use: Colors a line + //===================================================================== + public static String applyColors(String message, String color) + { + if(message != null && !message.equals("")) + { + //The color to start the line with + if(color == null) + color = Colors.White; + + //Start the line with the most recent color + String temp = color; + + //Loop through looking for a color code + for(int x = 0; x< message.length(); x++) + { + //If the char is a ^ or � + if(message.charAt(x) == '^' || message.charAt(x) == '§') + { + if(x != message.length() - 1) + { + //If the following character is a color code + if(vMinecraftChat.colorChange(message.charAt(x+1)) != null) + { + //Set the most recent color to the new color + color = vMinecraftChat.colorChange(message.charAt(x+1)); + //Add the color + temp += color; + //Skip these chars + x++; + //Otherwise ignore it. + } else { + temp += message.charAt(x); + } + //Insert the character + } else { + temp += message.charAt(x); + } + } + + } + } + return message; + } +} diff --git a/vMinecraftListener.java b/vMinecraftListener.java new file mode 100644 index 000000000..a89cfda06 --- /dev/null +++ b/vMinecraftListener.java @@ -0,0 +1,100 @@ +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 vMinecraftListener 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"); + } + + //===================================================================== + //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("@")) + return vMinecraftChat.adminChat(player, message); + if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) + return vMinecraftChat.adminChatToggle(player, message); + + else if (message.startsWith(">")) + return vMinecraftChat.quote(player, message); + + //Rage (FFF) + else if (message.startsWith("FFF")) + return vMinecraftChat.rage(player, message); + + //Send through quakeColors otherwise + else + return vMinecraftChat.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 = vMinecraftCommands.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){ + if (player.getHealth() != vMinecraftSettings.getInstance().ezModoHealth() && vMinecraftSettings.getInstance().isEzModo(player.getName())) { + player.setHealth(vMinecraftSettings.getInstance().ezModoHealth()); + + } + else if (vMinecraftSettings.getInstance().globalmessages() && player.getHealth() < 1) { + vMinecraftChat.gmsg(Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); + } + return false; + } + /** Not working yet, I posted the issue to hMod on github though + public boolean onDamage(DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { + + return false; + } + **/ + +} \ No newline at end of file diff --git a/vMinecraftSettings.java b/vMinecraftSettings.java new file mode 100644 index 000000000..71f4c26ea --- /dev/null +++ b/vMinecraftSettings.java @@ -0,0 +1,229 @@ +import java.io.*; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; +//===================================================================== +//Class: vminecraftSettings +//Use: Controls the settings for vminecraft +//Author: nossr50, TrapAlice, cerevisiae +//===================================================================== +public class vMinecraftSettings { + //private final static Object syncLock = new Object(); + protected static final Logger log = Logger.getLogger("Minecraft"); + private static volatile vMinecraftSettings instance; + + + //The feature settings + static boolean toggle = true, + adminChat = false, + greentext = false, + FFF = false, + quakeColors = 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, + stopTnt = 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 toggled for admin chat + static ArrayList adminChatList = new ArrayList(); + //The max health for ezModo + static int ezHealth = 30; + + private PropertiesFile properties; + String file = "vminecraft.properties"; + public String rules[] = new String[0]; + public static String deathMessages[] = 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("greentext=true\r\n"); + writer.write("quakeColors=true\r\n"); + writer.write("cmdTphere=true\r\n"); + writer.write("cmdFabulous=true\r\n"); + writer.write("cmdWhoIs=true\r\n"); + writer.write("cmdWho=true\r\n"); + writer.write("cmdPromote=true\r\n"); + writer.write("cmdDemote=true\r\n"); + writer.write("cmdMasstp=true\r\n"); + writer.write("cmdSay=true\r\n"); + writer.write("cmdTp=true\r\n"); + writer.write("cmdRules=true\r\n"); + writer.write("cmdSuicide=true\r\n"); + writer.write("cmdAdminToggle=true\r\n"); + writer.write("globalmessages=true\r\n"); + writer.write("FFF=true\r\n"); + writer.write("adminchat=true\r\n"); + writer.write("cmdEzModo=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("#The health ezmodo people will have while in ezmodo. Don't set to 0\r\n"); + writer.write("ezHealth=30\r\n"); + writer.write("stopFire=false\r\n"); + writer.write("stopTnt=false\r\n"); + writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n"); + writer.write("#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"); + } 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); + greentext = properties.getBoolean("greentext",true); + FFF = properties.getBoolean("FFF",true); + quakeColors = properties.getBoolean("quakeColors",true); + cmdFabulous = properties.getBoolean("cmdFabulous",true); + cmdPromote = properties.getBoolean("cmdPromote",true); + cmdDemote = properties.getBoolean("cmdDemote",true); + cmdWhoIs = properties.getBoolean("cmdWhoIs",true); + cmdWho = properties.getBoolean("cmdWho",true); + cmdRules = properties.getBoolean("cmdRules",true); + cmdTp = properties.getBoolean("cmdTp",true); + cmdMasstp = properties.getBoolean("cmdMasstp",true); + cmdTphere = properties.getBoolean("cmdTphere",true); + cmdSuicide = properties.getBoolean("cmdSuicide", true); + cmdHeal = properties.getBoolean("cmdHeal",true); + cmdAdminToggle = properties.getBoolean("cmdAdminToggle", true); + globalmessages = properties.getBoolean("globalmessages",true); + cmdSay = properties.getBoolean("cmdSay",true); + cmdEzModo = properties.getBoolean("cmdEzModo",true); + stopFire = properties.getBoolean("stopFire",true); + stopTnt = properties.getBoolean("stopTNT",true); + rules = properties.getString("rules", "").split("@"); + deathMessages = properties.getString("deathmessages", "").split(","); + + String[] tempEz = properties.getString("ezModo").split(","); + ezModo = new ArrayList(); + for(String ezName : tempEz) + ezModo.add(ezName); + + ezHealth = properties.getInt("ezHealth"); + + log.log(Level.INFO, "vminecraft plugin successfully loaded"); + + } + catch (Exception e) + { + log.log(Level.SEVERE, "vminecraft Error: ERROR LOADING PROPERTIES FILE"); + } + } + + //===================================================================== + //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 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 stopTnt() {return stopTnt;} + public boolean cmdSuicide() {return cmdSuicide;} + public boolean cmdHeal() {return cmdHeal;} + + //EzModo methods + public boolean cmdEzModo() {return cmdEzModo;} + public boolean isEzModo(String playerName) {return ezModo.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 int ezModoHealth() {return ezHealth;} + 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 vMinecraftSettings getInstance() { + if (instance == null) { + instance = new vMinecraftSettings(); + } + 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 From b2c33b779d7f83cc4f7de2d25fb26bebe7e560b3 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 00:47:58 -0600 Subject: [PATCH 37/82] Fixed prefixes again --- vMinecraftChat.java | 57 +++++++++++++++++++++++------------------ vMinecraftListener.java | 15 ++++++----- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/vMinecraftChat.java b/vMinecraftChat.java index 3f6463855..53bd6affc 100644 --- a/vMinecraftChat.java +++ b/vMinecraftChat.java @@ -79,7 +79,7 @@ public class vMinecraftChat { //and their following color codes for(int x = 0; x " + message); - return true; } - return false; + log.log(Level.INFO, "@" + "<" + getName(player) + + Colors.White +"> " + message); + return true; } + return false; + } //===================================================================== //Function: quote @@ -386,7 +387,7 @@ public class vMinecraftChat { //===================================================================== public static String[] applyColors(String[] message) { - if(message != null && message[0] != null && !message[0].equals("")){ + if(message != null && message[0] != null && !message[0].isEmpty()){ //The color to start the line with String recentColor = Colors.White; @@ -400,8 +401,8 @@ public class vMinecraftChat { //Loop through looking for a color code for(int x = 0; x< msg.length(); x++) { - //If the char is a ^ or � - if(msg.charAt(x) == '^' || msg.charAt(x) == '§') + //If the char is a ^ or § + if(msg.charAt(x) == '^' || msg.charAt(x) == Colors.White.charAt(0)) { if(x != msg.length() - 1) { @@ -419,6 +420,8 @@ public class vMinecraftChat { temp += msg.charAt(x); } //Insert the character + } else { + temp += msg.charAt(x); } } else { temp += msg.charAt(x); @@ -452,7 +455,7 @@ public class vMinecraftChat { //===================================================================== public static String applyColors(String message, String color) { - if(message != null && !message.equals("")) + if(message != null && !message.isEmpty()) { //The color to start the line with if(color == null) @@ -464,8 +467,8 @@ public class vMinecraftChat { //Loop through looking for a color code for(int x = 0; x< message.length(); x++) { - //If the char is a ^ or � - if(message.charAt(x) == '^' || message.charAt(x) == '§') + //If the char is a ^ or '§' + if(message.charAt(x) == '^' || message.charAt(x) == Colors.White.charAt(0)) { if(x != message.length() - 1) { @@ -486,9 +489,13 @@ public class vMinecraftChat { } else { temp += message.charAt(x); } + //Insert the character + } else { + temp += message.charAt(x); } - + } + message = temp; } return message; } diff --git a/vMinecraftListener.java b/vMinecraftListener.java index a89cfda06..3d1aa54d1 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -81,15 +81,16 @@ public class vMinecraftListener extends PluginListener { //Use: Checks for exploits and runs the commands //===================================================================== public boolean onHealthChange(Player player,int oldValue,int newValue){ - if (player.getHealth() != vMinecraftSettings.getInstance().ezModoHealth() && vMinecraftSettings.getInstance().isEzModo(player.getName())) { - player.setHealth(vMinecraftSettings.getInstance().ezModoHealth()); + if (player.getHealth() != vMinecraftSettings.getInstance().ezModoHealth() + && vMinecraftSettings.getInstance().isEzModo(player.getName())) { + player.setHealth(vMinecraftSettings.getInstance().ezModoHealth()); - } - else if (vMinecraftSettings.getInstance().globalmessages() && player.getHealth() < 1) { - vMinecraftChat.gmsg(Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); - } - return false; } + else if (vMinecraftSettings.getInstance().globalmessages() && player.getHealth() < 1) { + vMinecraftChat.gmsg(Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); + } + return false; + } /** Not working yet, I posted the issue to hMod on github though public boolean onDamage(DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { From acf1b5261d1670367b0e6dba1de1c8d4647afc8d Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 00:56:52 -0600 Subject: [PATCH 38/82] Fixed /a --- vMinecraftChat.java | 26 +++++--------------------- vMinecraftListener.java | 5 ++--- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/vMinecraftChat.java b/vMinecraftChat.java index 53bd6affc..3f55bb844 100644 --- a/vMinecraftChat.java +++ b/vMinecraftChat.java @@ -247,7 +247,11 @@ public class vMinecraftChat { String adminchat = Colors.DarkPurple + "{" + getName(player) + Colors.DarkPurple +"}" + Colors.White + " "; - String[] msg = wordWrap(adminchat + message.substring(1, message.length())); + //Cut off the @ prefix + if(message.startsWith("@")) + message = message.substring(1, message.length()); + + String[] msg = wordWrap(adminchat + message); //Get the player from the playerlist to send the message to. for (Player p: etc.getServer().getPlayerList()) { @@ -272,26 +276,6 @@ public class vMinecraftChat { } return false; } - - public static boolean adminChatToggle(Player player, String message){ - if(vMinecraftSettings.getInstance().isAdminToggled(player.getName())) { - String adminchat = Colors.DarkPurple + "{" + getName(player) - + Colors.DarkPurple +"}" + Colors.White + " "; - String[] msg = wordWrap(adminchat + message.substring(1, message.length())); - for (Player p: etc.getServer().getPlayerList()) { - if (p != null) { - if (p.isAdmin() || p.canUseCommand("/adminchat")) { - for(String str: msg) - p.sendMessage(str); - } - } - } - log.log(Level.INFO, "@" + "<" + getName(player) - + Colors.White +"> " + message); - return true; - } - return false; - } //===================================================================== //Function: quote diff --git a/vMinecraftListener.java b/vMinecraftListener.java index 3d1aa54d1..6c4add0ec 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -29,10 +29,9 @@ public class vMinecraftListener extends PluginListener { public boolean onChat(Player player, String message){ //Quote (Greentext) - if (message.startsWith("@")) + if (message.startsWith("@") || + vMinecraftSettings.getInstance().isAdminToggled(player.getName())) return vMinecraftChat.adminChat(player, message); - if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) - return vMinecraftChat.adminChatToggle(player, message); else if (message.startsWith(">")) return vMinecraftChat.quote(player, message); From a9bc2a0b31b9d931845ab6be9282afea644da983 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 1 Dec 2010 00:10:24 -0800 Subject: [PATCH 39/82] Fixed aliasing for suicide and clearinventory. --- vMinecraftCommands.java | 864 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 864 insertions(+) create mode 100644 vMinecraftCommands.java diff --git a/vMinecraftCommands.java b/vMinecraftCommands.java new file mode 100644 index 000000000..c4106df93 --- /dev/null +++ b/vMinecraftCommands.java @@ -0,0 +1,864 @@ +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; + +//===================================================================== +//Class: vMinecraftCommands +//Use: Encapsulates all commands added by this mod +//Author: nos, trapalice, cerevisiae +//===================================================================== +public class vMinecraftCommands{ + //Log output + protected static final Logger log = Logger.getLogger("Minecraft"); + 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. + cl.register("/tp", "teleport"); + cl.register("/masstp", "masstp", "Teleports those with lower permissions to you"); + cl.register("/reload", "reload"); + cl.register("/rules", "rules", "Displays the rules"); + cl.register("/fabulous", "fabulous", "makes text SUUUPER"); + cl.register("/whois", "whois", "/whois [user]"); + cl.register("/who", "who"); + cl.register("/say", "say"); + cl.register("/slay", "slay", "Kill target player"); + cl.register("/ezmodo", "invuln", "Toggle invulnerability"); + cl.register("/ezlist", "ezlist", "List invulnerable players"); + cl.register("/heal", "heal", "heal yourself or other players"); + cl.register("/suicide", "suicide", "kill yourself... you loser"); + cl.register("/a", "adminChatToggle", "toggle admin chat for every message"); + cl.register("/modify", "modifySplit"); + cl.registerAlias("/playerlist", "/who"); + cl.registerAlias("/suicide", "/wrists"); + cl.registerAlias("/clearinventory", "/ci"); + } + //===================================================================== + //Function: adminChatToggle (/a) + //Input: Player player: The player using the command + //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) +{ + if(vMinecraftSettings.getInstance().adminChatToggle()) + { + //If the player is already toggled for admin chat, remove them + if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) { + player.sendMessage(Colors.Red + "Admin Chat Toggle = off"); + vMinecraftSettings.getInstance().removeAdminToggled(player.getName()); + //Otherwise include them + } else { + player.sendMessage(Colors.Blue + "Admin Chat Toggled on"); + vMinecraftSettings.getInstance().addAdminToggled(player.getName()); + } + return EXIT_SUCCESS; + } + return EXIT_FAIL; +} + //===================================================================== + //Function: heal (/heal) + //Input: Player player: The player using the command + // String[] args: The arguments for the command. Should be a + // player name or blank + //Output: int: Exit Code + //Use: Heals yourself or a specified player. + //===================================================================== + public static int heal(Player player, String[] args) + { + if(vMinecraftSettings.getInstance().cmdHeal()) + { + //If a target wasn't specified, heal the user. + if (args.length < 1){ + player.setHealth(20); + player.sendMessage("Your health is restored"); + //If a target was specified, try to find them and then heal them + //Otherwise report the error + } else if (args.length > 0){ + Player playerTarget = etc.getServer().matchPlayer(args[0]); + + if (playerTarget != null){ + playerTarget.setHealth(20); + player.sendMessage(Colors.Blue + "You have healed " + vMinecraftChat.getName(playerTarget)); + playerTarget.sendMessage(Colors.Blue + "You have been healed by " + vMinecraftChat.getName(player)); + } + else if (playerTarget == null){ + vMinecraftChat.gmsg(Colors.Rose + "Couldn't find that player"); + } + } + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + + //===================================================================== + //Function: suicide (/suicide, /wrists) + //Input: Player player: The player using the command + // String[] args: Ignored + //Output: int: Exit Code + //Use: Kills yourself + //===================================================================== + public static int suicide(Player player, String[] args) + { + if(vMinecraftSettings.getInstance().cmdSuicide()) + { + //Set your health to 0. Not much to it. + player.setHealth(0); + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + + //===================================================================== + //Function: teleport (/tp) + //Input: Player player: The player using the command + // 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) + { + //Get if the command is enabled + if(vMinecraftSettings.getInstance().cmdTp()) + { + //Make sure a player has been specified and return an error if not + if (args.length < 1) { + player.sendMessage(Colors.Rose + "Correct usage is: /tp [player]"); + } else { + + //Find the player by name + Player playerTarget = etc.getServer().matchPlayer(args[0]); + + //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 { + log.log(Level.INFO, player.getName() + " teleported to " + + playerTarget.getName()); + player.teleportTo(playerTarget); + + //Otherwise inform the user that the player doesn't exist + } + } + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + + //===================================================================== + //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) + { + //If the command is enabled + if(vMinecraftSettings.getInstance().cmdMasstp()) { + //Go through all players and move them to the user + for (Player p : etc.getServer().getPlayerList()) { + if (!p.hasControlOver(player)) { + p.teleportTo(player); + } + } + //Inform the user that the command has executed successfully + player.sendMessage(Colors.Blue+"Summoning successful."); + + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + + //===================================================================== + //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) + { + //Check if the command is enabled. + if (vMinecraftSettings.getInstance().cmdTphere()) { + //Make sure a player is specified + if (args.length < 1) { + player.sendMessage(Colors.Rose + "Correct usage is: /tphere [player]"); + } else { + //Get the player by name + Player playerTarget = etc.getServer().matchPlayer(args[0]); + + //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 " + player.getName() + " to their self."); + playerTarget.teleportTo(player); + } + } + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + + //===================================================================== + //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) + { + vMinecraftSettings.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(vMinecraftSettings.getInstance().cmdRules() + && vMinecraftSettings.getInstance().getRules().length > 0) { + + //Apply QuakeCode Colors to the rules + String[] rules = vMinecraftChat.applyColors( + vMinecraftSettings.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; + } + return EXIT_FAIL; + } + + //===================================================================== + //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(vMinecraftSettings.getInstance().cmdFabulous()) { + + //Format the name + String playerName = Colors.White + "<" + + vMinecraftChat.getName(player) + Colors.White +"> "; + //Make sure a message has been specified + if (args.length < 1) {return EXIT_FAIL;} + String str = " "; + + //Merge the message again + 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. + String[] message = vMinecraftChat.wordWrap(playerName + str); + + //Output the message + for(String msg: message) + { + if (msg.contains(playerName)) + vMinecraftChat.gmsg( playerName + + vMinecraftChat.rainbow( + msg.substring(playerName.length()))); + else + vMinecraftChat.gmsg(vMinecraftChat.rainbow(msg)); + } + + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + + //===================================================================== + //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) + { + //If the command is enabled + if (vMinecraftSettings.getInstance().cmdWhoIs()) { + //If a player is specified + if (args.length < 1) + player.sendMessage(Colors.Rose + "Usage is /whois [player]"); + else { + //Get the player by name + Player playerTarget = null; + for( Player p : etc.getServer().getPlayerList()) + { + if (p.getName().equalsIgnoreCase(args[0])) + { + playerTarget = p; + } + } + //If the player exists + if (playerTarget != null){ + + //Displaying the information + player.sendMessage(Colors.Blue + "Whois results for " + + vMinecraftChat.getName(playerTarget)); + //Group + for(String group: playerTarget.getGroups()) + player.sendMessage(Colors.Blue + "Groups: " + group); + //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())); + + //Give the user an error if the player doesn't exist + } else { + player.sendMessage(Colors.Rose+"Player not found."); + } + } + return EXIT_SUCCESS; + } + 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 (vMinecraftSettings.getInstance().cmdWho()) { + //Loop through all players counting them and adding to the list + int count=0; + String tempList = ""; + for( Player p : etc.getServer().getPlayerList()) + { + if(p != null){ + if(count == 0) + tempList += vMinecraftChat.getName(p); + else + tempList += Colors.White + ", " + vMinecraftChat.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 + String[] tempOut = vMinecraftChat.wordWrap(Colors.Rose + "Player List (" + + count + "/" + maxPlayers +"): " + tempList); + for(String msg: tempOut) + player.sendMessage( msg ); + + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + + //===================================================================== + //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) + { + //If the command is enabled + if (vMinecraftSettings.getInstance().cmdSay()) { + //Make sure a message is supplied or output an error + if (args.length < 1) { + player.sendMessage(Colors.Rose + "Usage is /say [message]"); + } + //Display the message globally + vMinecraftChat.gmsg(Colors.Yellow + etc.combineSplit(0, args, " ")); + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + + //===================================================================== + //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) + { + //Check if the command is enabled + if(vMinecraftSettings.getInstance().cmdEzModo()) { + //Get the player by name + Player playerTarget = etc.getServer().matchPlayer(args[0]); + //If the player doesn't exist don't run + if(playerTarget == null) + return EXIT_FAIL; + //If the player isn't invulnerable kill them + if (!vMinecraftSettings.getInstance().isEzModo(playerTarget.getName())) { + playerTarget.setHealth(0); + vMinecraftChat.gmsg(vMinecraftChat.getName(player) + + Colors.LightBlue + " has slain " + + vMinecraftChat.getName(playerTarget)); + //Otherwise output error to the user + } else { + player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha"); + } + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + + //===================================================================== + //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) + { + //If the command is enabled + if (vMinecraftSettings.getInstance().cmdEzModo()) { + //If the player is already invulnerable, turn ezmodo off. + if (vMinecraftSettings.getInstance().isEzModo(player.getName())) { + player.sendMessage(Colors.Red + "ezmodo = off"); + vMinecraftSettings.getInstance().removeEzModo(player.getName()); + //Otherwise make them invulnerable + } else { + player.sendMessage(Colors.LightBlue + "eh- maji? ezmodo!?"); + player.sendMessage(Colors.Rose + "kimo-i"); + player.sendMessage(Colors.LightBlue + "Easy Mode ga yurusareru no wa shougakusei made dayo ne"); + player.sendMessage(Colors.Red + "**Laughter**"); + vMinecraftSettings.getInstance().addEzModo(player.getName()); + player.setHealth(vMinecraftSettings.getInstance().ezModoHealth()); + } + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + + //===================================================================== + //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) + { + //If the feature is enabled list the players + if(vMinecraftSettings.getInstance().cmdEzModo()) { + player.sendMessage("Ezmodo: " + vMinecraftSettings.getInstance().ezModoList()); + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + + //===================================================================== + //Function: modifySplit (/modify) + //Input: Player player: The player using the command + // String[] args: Player, Command, Arguments + //Output: int: Exit Code + //Use: List all invulnerable players + //===================================================================== + public static int modifySplit(Player player, String[] args) + { + //Exploit fix for people giving themselves commands + if(args[1].equals("commands")) + return EXIT_FAIL; + return EXIT_CONTINUE; + } + + //===================================================================== + //Function: Time Reverse + //Input: long time: The time to reverse to. + //Output: int: Exit Code + //Use: List all invulnerable players + //===================================================================== + public static int timeReverse(long tarTime) + { + long curTime = etc.getServer().getRelativeTime(); + //if(cur) + return EXIT_SUCCESS; + } +} + +//===================================================================== +//Class: commandList +//Use: The list of commands that will be checked for +//Author: cerevisiae +//===================================================================== +class commandList { + command[] commands; + protected static final Logger log = Logger.getLogger("Minecraft"); + 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 command[0]; + } + + //===================================================================== + //Function: register + //Input: String name: The name of the command + // String func: The function to be called + //Output: boolean: Whether the command was input successfully or not + //Use: Registers a command to the command list for checking later + //===================================================================== + public boolean register(String name, String func){ + + //If the command list isn't empty + if(commands.length > 0) + { + //Check to make sure the command doesn't already exist + for(int i = 0; i < commands.length; i++) + if(commands[i].getName().equalsIgnoreCase(name)) + return false; + + //Create a new temp array + command[] temp = new command[commands.length + 1]; + //Copy the old command list over + System.arraycopy(commands, 0, temp, 0, commands.length); + //Set commands to equal the new array + commands = temp; + } else { + commands = new command[1]; + } + + //Add the new function to the list + commands[commands.length - 1] = new command(name, func); + + //exit successfully + return true; + } + + //===================================================================== + //Function: register + //Input: String name: The name of the command + // String func: The function to be called + // String info: The information for the command to put in help + //Output: boolean: Whether the command was input successfully or not + //Use: Registers a command to the command list for checking later + //===================================================================== + public boolean register(String name, String func, String info){ + //Add to the /help list + etc.getInstance().addCommand(name, info); + + //Finish registering + return register(name, func); + } + + //===================================================================== + //Function: register + //Input: String name: The name of the command + // String func: The function to be called + //Output: boolean: Whether the command was input successfully or not + //Use: Registers a command to the command list for checking later + //===================================================================== + public boolean registerAlias(String name, String com, String[] args){ + + //If the command list isn't empty + if(commands.length > 0) + { + //Check to make sure the command doesn't already exist + for(int i = 0; i < commands.length; i++) + if(commands[i].getName().equalsIgnoreCase(name)) + return false; + + //Create a new temp array + command[] temp = new command[commands.length + 1]; + //Copy the old command list over + System.arraycopy(commands, 0, temp, 0, commands.length); + //Set commands to equal the new array + commands = temp; + } else { + commands = new command[1]; + } + + //Add the new function to the list + commands[commands.length - 1] = new commandRef(name, com, args); + + //exit successfully + return true; + } + + //===================================================================== + //Function: register + //Input: String name: The name of the command + // String func: The function to be called + //Output: boolean: Whether the command was input successfully or not + //Use: Registers a command to the command list for checking later + //===================================================================== + public boolean registerAlias(String name, String com){ + + //If the command list isn't empty + if(commands.length > 0) + { + //Check to make sure the command doesn't already exist + for(int i = 0; i < commands.length; i++) + if(commands[i].getName().equalsIgnoreCase(name)) + return false; + + //Create a new temp array + command[] temp = new command[commands.length + 1]; + //Copy the old command list over + System.arraycopy(commands, 0, temp, 0, commands.length); + //Set commands to equal the new array + commands = temp; + } else { + commands = new command[1]; + } + + //Add the new function to the list + commands[commands.length - 1] = new commandRef(name, com); + + //exit successfully + return true; + } + + //===================================================================== + //Function: call + //Input: String name: The name of the command to be run + //Output: boolean: If the command was called successfully + //Use: Attempts to call a command + //===================================================================== + public int call(String name, Player player, String[] arg){ + //Make sure the user has access to the command + if(!player.canUseCommand(name)) { + return EXIT_FAIL; + } + //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; + } + + + + //===================================================================== + //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 = vMinecraftCommands.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; + } + } + + //===================================================================== + //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 + // String[] arg: the arguments to apply + //Output: None + //Use: Initialize the command + //===================================================================== + public commandRef(String name, String com, String[] arg){ + super(name, ""); + reference = com; + args = arg; + } + + //===================================================================== + //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, ""); + reference = com; + args = null; + } + + + //===================================================================== + //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) + { + if(args != null) { + String[] temp = new String[args.length]; + System.arraycopy(args, 0, temp, 0, args.length); + //Insert the arguments into the pre-set arguments + int lastSet = 0, + argCount = 0; + for(String argument : temp) + { + if(argument.startsWith("%")) + { + int argNum = Integer.parseInt(argument.substring(1)); + if( argNum < arg.length ) + { + temp[lastSet] = arg[argNum]; + argCount++; + } + } + lastSet++; + } + //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; + } + + //Call the referenced command + player.command(reference + " " + etc.combineSplit(0, temp, " ")); + } else + player.command(reference); + return EXIT_SUCCESS; + } + } +} \ No newline at end of file From 91a9e1350b52b08cd6ee82138081ea4225848b25 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 1 Dec 2010 07:17:59 -0800 Subject: [PATCH 40/82] Added half-functional /me recode --- vMinecraft.java | 5 ++--- vMinecraftChat.java | 18 ++++++++++++++++-- vMinecraftCommands.java | 15 +++++++++++++-- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/vMinecraft.java b/vMinecraft.java index 654be29fd..fd7336dd7 100644 --- a/vMinecraft.java +++ b/vMinecraft.java @@ -25,8 +25,7 @@ public class vMinecraft extends Plugin { etc.getLoader().addListener(PluginLoader.Hook.IGNITE, listener, this, PluginListener.Priority.HIGH); etc.getLoader().addListener(PluginLoader.Hook.DAMAGE, listener, this, PluginListener.Priority.MEDIUM); etc.getLoader().addListener(PluginLoader.Hook.EXPLODE, listener, this, PluginListener.Priority.HIGH); - if(etc.getInstance().isHealthEnabled()){ - etc.getLoader().addListener(PluginLoader.Hook.HEALTH_CHANGE, listener, this, PluginListener.Priority.MEDIUM); + etc.getLoader().addListener(PluginLoader.Hook.HEALTH_CHANGE, listener, this, PluginListener.Priority.MEDIUM); } } -} + diff --git a/vMinecraftChat.java b/vMinecraftChat.java index 3f55bb844..6aa09c260 100644 --- a/vMinecraftChat.java +++ b/vMinecraftChat.java @@ -361,6 +361,20 @@ public class vMinecraftChat { } 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) + { + String[] msg = wordWrap("* " + getName(player) + Colors.White + message); + for(String str: msg) + gmsg(str); + return true; + } //===================================================================== @@ -385,7 +399,7 @@ public class vMinecraftChat { //Loop through looking for a color code for(int x = 0; x< msg.length(); x++) { - //If the char is a ^ or § + //If the char is a ^ or � if(msg.charAt(x) == '^' || msg.charAt(x) == Colors.White.charAt(0)) { if(x != msg.length() - 1) @@ -451,7 +465,7 @@ public class vMinecraftChat { //Loop through looking for a color code for(int x = 0; x< message.length(); x++) { - //If the char is a ^ or '§' + //If the char is a ^ or '�' if(message.charAt(x) == '^' || message.charAt(x) == Colors.White.charAt(0)) { if(x != message.length() - 1) diff --git a/vMinecraftCommands.java b/vMinecraftCommands.java index c4106df93..9f7ca15d0 100644 --- a/vMinecraftCommands.java +++ b/vMinecraftCommands.java @@ -42,9 +42,21 @@ public class vMinecraftCommands{ cl.register("/suicide", "suicide", "kill yourself... you loser"); cl.register("/a", "adminChatToggle", "toggle admin chat for every message"); cl.register("/modify", "modifySplit"); + cl.register("/me", "me"); cl.registerAlias("/playerlist", "/who"); cl.registerAlias("/suicide", "/wrists"); cl.registerAlias("/clearinventory", "/ci"); + } + //===================================================================== + //Function: me (/me) + //Input: Player player: The player using the command + //Output: int: Exit Code + //Use: The player uses this to emote, but now its colorful. + //===================================================================== + public static int me(Player player, String[] args) + { + vMinecraftChat.emote(player, args); + return EXIT_SUCCESS; } //===================================================================== //Function: adminChatToggle (/a) @@ -53,8 +65,7 @@ public class vMinecraftCommands{ //Use: Toggles the player into admin chat. Every message they // send will be piped to admin chat. //===================================================================== - - public static int adminChatToggle(Player player) + public static int adminChatToggle(Player player, String[] args) { if(vMinecraftSettings.getInstance().adminChatToggle()) { From 58c1c95dafcf068b098c5bfb14adba75fb8cb81c Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 1 Dec 2010 07:50:00 -0800 Subject: [PATCH 41/82] Fixed /me to work, confirmed to work! --- vMinecraftChat.java | 5 +++-- vMinecraftCommands.java | 4 +++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/vMinecraftChat.java b/vMinecraftChat.java index 6aa09c260..3f57430f6 100644 --- a/vMinecraftChat.java +++ b/vMinecraftChat.java @@ -368,9 +368,10 @@ public class vMinecraftChat { //Output: boolean: If this feature is enabled //Use: /me but with our custom colors applied //===================================================================== - public static boolean emote(Player player, String[] message) + public static boolean emote(Player player, String message) { - String[] msg = wordWrap("* " + getName(player) + Colors.White + message); + String temp = message.toString(); + String[] msg = wordWrap("* " + getName(player) + " " + Colors.White + temp); for(String str: msg) gmsg(str); return true; diff --git a/vMinecraftCommands.java b/vMinecraftCommands.java index 9f7ca15d0..9917dddab 100644 --- a/vMinecraftCommands.java +++ b/vMinecraftCommands.java @@ -55,7 +55,9 @@ public class vMinecraftCommands{ //===================================================================== public static int me(Player player, String[] args) { - vMinecraftChat.emote(player, args); + String str = etc.combineSplit(0, args, " "); + if (args.length < 1) {return EXIT_FAIL;} + vMinecraftChat.emote(player, str); return EXIT_SUCCESS; } //===================================================================== From 7a7400a5150a806cbd18f624b17dab08d603070e Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 1 Dec 2010 08:15:48 -0800 Subject: [PATCH 42/82] Updated TODO --- TODO | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/TODO b/TODO index ea0f077ea..27325c66f 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,7 @@ Vminecraft b8 Todo: + Antigriefs + Allow players to nickname themselves or others - + /a to toggle admin chat + + vminecraft Help * Specialized help message for vminecraft ? /vhelp? @@ -14,7 +14,6 @@ Vminecraft b8 Todo: + Recode Messaging * Reply Feature * Personal Muting - + Quick recode of /me to use the new getName function + Different types of /slay * /slay fire to burn them to death * /slay drown to drown them @@ -25,6 +24,8 @@ Vminecraft b8 Todo: further limit what features of /modify groups can access DONE + + Quick recode of /me to use the new getName function + + /a to toggle admin chat + Code was organized + Aliasing was added + Playerlist is now colorful and awesome From 830053d97cece1addebc6e39eaf248ba65a07477 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 1 Dec 2010 08:15:48 -0800 Subject: [PATCH 43/82] Updated TODO, now with more stuff --- TODO | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index ea0f077ea..fefb779f0 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,7 @@ Vminecraft b8 Todo: - + Antigriefs + + Antigriefs Working on this, waiting for hMod to fix player health + Allow players to nickname themselves or others - + /a to toggle admin chat + + vminecraft Help * Specialized help message for vminecraft ? /vhelp? @@ -14,7 +14,6 @@ Vminecraft b8 Todo: + Recode Messaging * Reply Feature * Personal Muting - + Quick recode of /me to use the new getName function + Different types of /slay * /slay fire to burn them to death * /slay drown to drown them @@ -23,8 +22,11 @@ Vminecraft b8 Todo: We talked about potentially doing this and I think I would like to now to add in further functionality and further limit what features of /modify groups can access + We should definitely add suffixes to /modify at least DONE + + Quick recode of /me to use the new getName function + + /a to toggle admin chat + Code was organized + Aliasing was added + Playerlist is now colorful and awesome From 2fb729fbfe1e5295a1937aed1366a26b03b1110a Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 10:39:57 -0600 Subject: [PATCH 44/82] Misc Fixes --- vminecraftCommands.java | 42 +++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/vminecraftCommands.java b/vminecraftCommands.java index 90c88ed8f..b15f9a6b8 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -34,16 +34,17 @@ public class vMinecraftCommands{ cl.register("/fabulous", "fabulous", "makes text SUUUPER"); cl.register("/whois", "whois", "/whois [user]"); cl.register("/who", "who"); + cl.registerAlias("/playerlist", "/who"); cl.register("/say", "say"); cl.register("/slay", "slay", "Kill target player"); cl.register("/ezmodo", "invuln", "Toggle invulnerability"); cl.register("/ezlist", "ezlist", "List invulnerable players"); cl.register("/heal", "heal", "heal yourself or other players"); cl.register("/suicide", "suicide", "kill yourself... you loser"); - cl.register("/a", "adminChatToggle", "toggle admin chat for every message"); - cl.register("/modify", "modifySplit"); - cl.registerAlias("/playerlist", "/who"); cl.registerAlias("/wrists", "/suicide"); + cl.register("/a", "adminChatToggle", "toggle admin chat for every message"); + cl.registerAlias("/admin", "/a"); + cl.register("/modify", "modifySplit"); cl.registerAlias("/ci", "/clearinventory"); } //===================================================================== @@ -54,23 +55,24 @@ public class vMinecraftCommands{ // send will be piped to admin chat. //===================================================================== - public static int adminChatToggle(Player player) -{ - if(vMinecraftSettings.getInstance().adminChatToggle()) - { - //If the player is already toggled for admin chat, remove them - if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) { - player.sendMessage(Colors.Red + "Admin Chat Toggle = off"); - vMinecraftSettings.getInstance().removeAdminToggled(player.getName()); - //Otherwise include them - } else { - player.sendMessage(Colors.Blue + "Admin Chat Toggled on"); - vMinecraftSettings.getInstance().addAdminToggled(player.getName()); - } - return EXIT_SUCCESS; - } - return EXIT_FAIL; -} + public static int adminChatToggle(Player player, String[] args) + { + if(vMinecraftSettings.getInstance().adminChatToggle()) + { + //If the player is already toggled for admin chat, remove them + if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) { + player.sendMessage(Colors.Red + "Admin Chat Toggle = off"); + vMinecraftSettings.getInstance().removeAdminToggled(player.getName()); + //Otherwise include them + } else { + player.sendMessage(Colors.Blue + "Admin Chat Toggled on"); + vMinecraftSettings.getInstance().addAdminToggled(player.getName()); + } + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } + //===================================================================== //Function: heal (/heal) //Input: Player player: The player using the command From 535c42be0b226cb757d651bba0c020a62e5d7207 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 11:44:32 -0600 Subject: [PATCH 45/82] Formatting --- TODO | 1 - vMinecraftChat.java | 8 ++++---- vminecraftCommands.java | 25 +++++++++++++++++++------ 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/TODO b/TODO index fefb779f0..33ae124a9 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,6 @@ Vminecraft b8 Todo: + Antigriefs Working on this, waiting for hMod to fix player health + Allow players to nickname themselves or others - + vminecraft Help * Specialized help message for vminecraft ? /vhelp? diff --git a/vMinecraftChat.java b/vMinecraftChat.java index 3f57430f6..e3e9b9694 100644 --- a/vMinecraftChat.java +++ b/vMinecraftChat.java @@ -46,10 +46,10 @@ public class vMinecraftChat { //Loop through the words finding their length and increasing //j, the end point for the sub string - while(len <= 316 && i < split.length) + while(len <= 300 && i < split.length) { len += msgLength(split[i]) + 4; - if( len <= 316) + if( len <= 300) i++; } @@ -57,8 +57,8 @@ public class vMinecraftChat { String[] temp = new String[i - j]; System.arraycopy(split, j, temp, 0, i - j); - //Merge them and add them to the output array - out.add( etc.combineSplit(0, temp, " ") ); + //Merge them and add them to the output array. + out.add( applyColors(etc.combineSplit(0, temp, " ")) ); } //Convert to an array and return diff --git a/vminecraftCommands.java b/vminecraftCommands.java index b15f9a6b8..d55e481c6 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -34,19 +34,34 @@ public class vMinecraftCommands{ cl.register("/fabulous", "fabulous", "makes text SUUUPER"); cl.register("/whois", "whois", "/whois [user]"); cl.register("/who", "who"); - cl.registerAlias("/playerlist", "/who"); cl.register("/say", "say"); cl.register("/slay", "slay", "Kill target player"); cl.register("/ezmodo", "invuln", "Toggle invulnerability"); cl.register("/ezlist", "ezlist", "List invulnerable players"); cl.register("/heal", "heal", "heal yourself or other players"); cl.register("/suicide", "suicide", "kill yourself... you loser"); - cl.registerAlias("/wrists", "/suicide"); cl.register("/a", "adminChatToggle", "toggle admin chat for every message"); - cl.registerAlias("/admin", "/a"); cl.register("/modify", "modifySplit"); - cl.registerAlias("/ci", "/clearinventory"); + cl.register("/me", "me"); + cl.registerAlias("/playerlist", "/who"); + cl.registerAlias("/suicide", "/wrists"); + cl.registerAlias("/clearinventory", "/ci"); } + + //===================================================================== + //Function: me (/me) + //Input: Player player: The player using the command + //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;} + vMinecraftChat.emote(player, str); + return EXIT_SUCCESS; + } + //===================================================================== //Function: adminChatToggle (/a) //Input: Player player: The player using the command @@ -54,7 +69,6 @@ public class vMinecraftCommands{ //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) { if(vMinecraftSettings.getInstance().adminChatToggle()) @@ -72,7 +86,6 @@ public class vMinecraftCommands{ } return EXIT_FAIL; } - //===================================================================== //Function: heal (/heal) //Input: Player player: The player using the command From 9713bdc2a5e8c1c07782e510c32f51325ce6dfd9 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 12:36:42 -0600 Subject: [PATCH 46/82] Created a wrapper for Player.sendMessage() That automatically applies Quake Colors and Word Wrap --- vMinecraftChat.java | 58 +++++++++++++++++------------------------ vminecraftCommands.java | 18 +++---------- 2 files changed, 27 insertions(+), 49 deletions(-) diff --git a/vMinecraftChat.java b/vMinecraftChat.java index e3e9b9694..75d3f2148 100644 --- a/vMinecraftChat.java +++ b/vMinecraftChat.java @@ -19,11 +19,23 @@ public class vMinecraftChat { public static void gmsg(String msg){ for (Player p : etc.getServer().getPlayerList()) { if (p != null) { - p.sendMessage(msg); + sendMessage(p, msg); } } } + //===================================================================== + //Function: sendMessage + //Input: String msg: The message to be broadcast to all players + //Output: None + //Use: Outputs a message to everybody + //===================================================================== + public static void sendMessage(Player player, String msg){ + String[] message = applyColors(wordWrap(msg)); + for(String out : message) + player.sendMessage(out + " "); + } + //===================================================================== //Function: wordWrap //Input: String msg: The message to be wrapped @@ -58,7 +70,7 @@ public class vMinecraftChat { System.arraycopy(split, j, temp, 0, i - j); //Merge them and add them to the output array. - out.add( applyColors(etc.combineSplit(0, temp, " ")) ); + out.add( etc.combineSplit(0, temp, " ") ); } //Convert to an array and return @@ -251,20 +263,15 @@ public class vMinecraftChat { if(message.startsWith("@")) message = message.substring(1, message.length()); - String[] msg = wordWrap(adminchat + message); - //Get the player from the playerlist to send the message to. 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 + //And if p is an admin or has access to adminchat send message if (p.isAdmin() || (p.canUseCommand("/adminchat"))) { - - //Output the first line - for(String str: msg) - p.sendMessage(str); + sendMessage(p, adminchat + message); } } } @@ -292,13 +299,9 @@ public class vMinecraftChat { if(vMinecraftSettings.getInstance().greentext()) { //Log the chat log.log(Level.INFO, "<"+player.getName()+"> " +message); - - //Get the multi line array - String[] msg = wordWrap(playerName + Colors.LightGreen + message); - //Output the lines - for(String str: msg) - gmsg(Colors.LightGreen + str); + //Output the message + gmsg(playerName + Colors.LightGreen + message); return true; } return false; @@ -318,13 +321,9 @@ public class vMinecraftChat { + getName(player) + Colors.White +"> "; if (vMinecraftSettings.getInstance().FFF()) { log.log(Level.INFO, "<"+player.getName()+"> "+message); - - //Get the multi line array - String[] msg = wordWrap(playerName + Colors.Red + message); - + //Output the message - for(String str: msg) - gmsg(Colors.Red + str); + gmsg(playerName + Colors.Red + message); return true; } return false; @@ -341,20 +340,14 @@ public class vMinecraftChat { { //Format the name String playerName = Colors.White + "<" - + getName(player) + Colors.White +"> "; + + getName(player) + Colors.White +"> "; if(vMinecraftSettings.getInstance().quakeColors()) { //Log the chat log.log(Level.INFO, "<"+player.getName()+"> "+message); - //Get the multi line array - String[] msg = wordWrap(playerName + message); - //Apply colors to the lines - applyColors(msg); - //Output the message - for(String str: msg) - gmsg(str); + gmsg(playerName + message); //Loop through the string finding the color codes and inserting them return true; @@ -370,10 +363,7 @@ public class vMinecraftChat { //===================================================================== public static boolean emote(Player player, String message) { - String temp = message.toString(); - String[] msg = wordWrap("* " + getName(player) + " " + Colors.White + temp); - for(String str: msg) - gmsg(str); + gmsg("* " + getName(player) + " " + Colors.White + message); return true; } @@ -401,7 +391,7 @@ public class vMinecraftChat { for(int x = 0; x< msg.length(); x++) { //If the char is a ^ or � - if(msg.charAt(x) == '^' || msg.charAt(x) == Colors.White.charAt(0)) + if(msg.charAt(x) == '^') { if(x != msg.length() - 1) { diff --git a/vminecraftCommands.java b/vminecraftCommands.java index d55e481c6..52869d3a1 100644 --- a/vminecraftCommands.java +++ b/vminecraftCommands.java @@ -318,18 +318,7 @@ public class vMinecraftCommands{ log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\""); //Prepend the player name and cut into lines. - String[] message = vMinecraftChat.wordWrap(playerName + str); - - //Output the message - for(String msg: message) - { - if (msg.contains(playerName)) - vMinecraftChat.gmsg( playerName - + vMinecraftChat.rainbow( - msg.substring(playerName.length()))); - else - vMinecraftChat.gmsg(vMinecraftChat.rainbow(msg)); - } + vMinecraftChat.gmsg(playerName + vMinecraftChat.rainbow(str)); return EXIT_SUCCESS; } @@ -420,11 +409,10 @@ public class vMinecraftCommands{ e.printStackTrace(); } int maxPlayers = server.getInt("max-players"); + //Output the player list - String[] tempOut = vMinecraftChat.wordWrap(Colors.Rose + "Player List (" + vMinecraftChat.sendMessage(player, Colors.Rose + "Player List (" + count + "/" + maxPlayers +"): " + tempList); - for(String msg: tempOut) - player.sendMessage( msg ); return EXIT_SUCCESS; } From bf1381213e9e952bb1633d5715ae7616dd186bb9 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 12:38:25 -0600 Subject: [PATCH 47/82] Fixing duplicate files --- vminecraftCommands.java | 867 ---------------------------------------- 1 file changed, 867 deletions(-) delete mode 100644 vminecraftCommands.java diff --git a/vminecraftCommands.java b/vminecraftCommands.java deleted file mode 100644 index 52869d3a1..000000000 --- a/vminecraftCommands.java +++ /dev/null @@ -1,867 +0,0 @@ -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.logging.Level; -import java.util.logging.Logger; - -//===================================================================== -//Class: vMinecraftCommands -//Use: Encapsulates all commands added by this mod -//Author: nos, trapalice, cerevisiae -//===================================================================== -public class vMinecraftCommands{ - //Log output - protected static final Logger log = Logger.getLogger("Minecraft"); - 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. - cl.register("/tp", "teleport"); - cl.register("/masstp", "masstp", "Teleports those with lower permissions to you"); - cl.register("/reload", "reload"); - cl.register("/rules", "rules", "Displays the rules"); - cl.register("/fabulous", "fabulous", "makes text SUUUPER"); - cl.register("/whois", "whois", "/whois [user]"); - cl.register("/who", "who"); - cl.register("/say", "say"); - cl.register("/slay", "slay", "Kill target player"); - cl.register("/ezmodo", "invuln", "Toggle invulnerability"); - cl.register("/ezlist", "ezlist", "List invulnerable players"); - cl.register("/heal", "heal", "heal yourself or other players"); - cl.register("/suicide", "suicide", "kill yourself... you loser"); - cl.register("/a", "adminChatToggle", "toggle admin chat for every message"); - cl.register("/modify", "modifySplit"); - cl.register("/me", "me"); - cl.registerAlias("/playerlist", "/who"); - cl.registerAlias("/suicide", "/wrists"); - cl.registerAlias("/clearinventory", "/ci"); - } - - //===================================================================== - //Function: me (/me) - //Input: Player player: The player using the command - //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;} - vMinecraftChat.emote(player, str); - return EXIT_SUCCESS; - } - - //===================================================================== - //Function: adminChatToggle (/a) - //Input: Player player: The player using the command - //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) - { - if(vMinecraftSettings.getInstance().adminChatToggle()) - { - //If the player is already toggled for admin chat, remove them - if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) { - player.sendMessage(Colors.Red + "Admin Chat Toggle = off"); - vMinecraftSettings.getInstance().removeAdminToggled(player.getName()); - //Otherwise include them - } else { - player.sendMessage(Colors.Blue + "Admin Chat Toggled on"); - vMinecraftSettings.getInstance().addAdminToggled(player.getName()); - } - return EXIT_SUCCESS; - } - return EXIT_FAIL; - } - //===================================================================== - //Function: heal (/heal) - //Input: Player player: The player using the command - // String[] args: The arguments for the command. Should be a - // player name or blank - //Output: int: Exit Code - //Use: Heals yourself or a specified player. - //===================================================================== - public static int heal(Player player, String[] args) - { - if(vMinecraftSettings.getInstance().cmdHeal()) - { - //If a target wasn't specified, heal the user. - if (args.length < 1){ - player.setHealth(20); - player.sendMessage("Your health is restored"); - //If a target was specified, try to find them and then heal them - //Otherwise report the error - } else if (args.length > 0){ - Player playerTarget = etc.getServer().matchPlayer(args[0]); - - if (playerTarget != null){ - playerTarget.setHealth(20); - player.sendMessage(Colors.Blue + "You have healed " + vMinecraftChat.getName(playerTarget)); - playerTarget.sendMessage(Colors.Blue + "You have been healed by " + vMinecraftChat.getName(player)); - } - else if (playerTarget == null){ - vMinecraftChat.gmsg(Colors.Rose + "Couldn't find that player"); - } - } - return EXIT_SUCCESS; - } - return EXIT_FAIL; - } - - //===================================================================== - //Function: suicide (/suicide, /wrists) - //Input: Player player: The player using the command - // String[] args: Ignored - //Output: int: Exit Code - //Use: Kills yourself - //===================================================================== - public static int suicide(Player player, String[] args) - { - if(vMinecraftSettings.getInstance().cmdSuicide()) - { - //Set your health to 0. Not much to it. - player.setHealth(0); - return EXIT_SUCCESS; - } - return EXIT_FAIL; - } - - //===================================================================== - //Function: teleport (/tp) - //Input: Player player: The player using the command - // 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) - { - //Get if the command is enabled - if(vMinecraftSettings.getInstance().cmdTp()) - { - //Make sure a player has been specified and return an error if not - if (args.length < 1) { - player.sendMessage(Colors.Rose + "Correct usage is: /tp [player]"); - } else { - - //Find the player by name - Player playerTarget = etc.getServer().matchPlayer(args[0]); - - //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 { - log.log(Level.INFO, player.getName() + " teleported to " + - playerTarget.getName()); - player.teleportTo(playerTarget); - - //Otherwise inform the user that the player doesn't exist - } - } - return EXIT_SUCCESS; - } - return EXIT_FAIL; - } - - //===================================================================== - //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) - { - //If the command is enabled - if(vMinecraftSettings.getInstance().cmdMasstp()) { - //Go through all players and move them to the user - for (Player p : etc.getServer().getPlayerList()) { - if (!p.hasControlOver(player)) { - p.teleportTo(player); - } - } - //Inform the user that the command has executed successfully - player.sendMessage(Colors.Blue+"Summoning successful."); - - return EXIT_SUCCESS; - } - return EXIT_FAIL; - } - - //===================================================================== - //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) - { - //Check if the command is enabled. - if (vMinecraftSettings.getInstance().cmdTphere()) { - //Make sure a player is specified - if (args.length < 1) { - player.sendMessage(Colors.Rose + "Correct usage is: /tphere [player]"); - } else { - //Get the player by name - Player playerTarget = etc.getServer().matchPlayer(args[0]); - - //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 " + player.getName() + " to their self."); - playerTarget.teleportTo(player); - } - } - return EXIT_SUCCESS; - } - return EXIT_FAIL; - } - - //===================================================================== - //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) - { - vMinecraftSettings.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(vMinecraftSettings.getInstance().cmdRules() - && vMinecraftSettings.getInstance().getRules().length > 0) { - - //Apply QuakeCode Colors to the rules - String[] rules = vMinecraftChat.applyColors( - vMinecraftSettings.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; - } - return EXIT_FAIL; - } - - //===================================================================== - //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(vMinecraftSettings.getInstance().cmdFabulous()) { - - //Format the name - String playerName = Colors.White + "<" - + vMinecraftChat.getName(player) + Colors.White +"> "; - //Make sure a message has been specified - if (args.length < 1) {return EXIT_FAIL;} - String str = " "; - - //Merge the message again - 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. - vMinecraftChat.gmsg(playerName + vMinecraftChat.rainbow(str)); - - return EXIT_SUCCESS; - } - return EXIT_FAIL; - } - - //===================================================================== - //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) - { - //If the command is enabled - if (vMinecraftSettings.getInstance().cmdWhoIs()) { - //If a player is specified - if (args.length < 1) - player.sendMessage(Colors.Rose + "Usage is /whois [player]"); - else { - //Get the player by name - Player playerTarget = null; - for( Player p : etc.getServer().getPlayerList()) - { - if (p.getName().equalsIgnoreCase(args[0])) - { - playerTarget = p; - } - } - //If the player exists - if (playerTarget != null){ - - //Displaying the information - player.sendMessage(Colors.Blue + "Whois results for " + - vMinecraftChat.getName(playerTarget)); - //Group - for(String group: playerTarget.getGroups()) - player.sendMessage(Colors.Blue + "Groups: " + group); - //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())); - - //Give the user an error if the player doesn't exist - } else { - player.sendMessage(Colors.Rose+"Player not found."); - } - } - return EXIT_SUCCESS; - } - 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 (vMinecraftSettings.getInstance().cmdWho()) { - //Loop through all players counting them and adding to the list - int count=0; - String tempList = ""; - for( Player p : etc.getServer().getPlayerList()) - { - if(p != null){ - if(count == 0) - tempList += vMinecraftChat.getName(p); - else - tempList += Colors.White + ", " + vMinecraftChat.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 - vMinecraftChat.sendMessage(player, Colors.Rose + "Player List (" - + count + "/" + maxPlayers +"): " + tempList); - - return EXIT_SUCCESS; - } - return EXIT_FAIL; - } - - //===================================================================== - //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) - { - //If the command is enabled - if (vMinecraftSettings.getInstance().cmdSay()) { - //Make sure a message is supplied or output an error - if (args.length < 1) { - player.sendMessage(Colors.Rose + "Usage is /say [message]"); - } - //Display the message globally - vMinecraftChat.gmsg(Colors.Yellow + etc.combineSplit(0, args, " ")); - return EXIT_SUCCESS; - } - return EXIT_FAIL; - } - - //===================================================================== - //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) - { - //Check if the command is enabled - if(vMinecraftSettings.getInstance().cmdEzModo()) { - //Get the player by name - Player playerTarget = etc.getServer().matchPlayer(args[0]); - //If the player doesn't exist don't run - if(playerTarget == null) - return EXIT_FAIL; - //If the player isn't invulnerable kill them - if (!vMinecraftSettings.getInstance().isEzModo(playerTarget.getName())) { - playerTarget.setHealth(0); - vMinecraftChat.gmsg(vMinecraftChat.getName(player) - + Colors.LightBlue + " has slain " - + vMinecraftChat.getName(playerTarget)); - //Otherwise output error to the user - } else { - player.sendMessage(Colors.Rose + "That player is currently in ezmodo! Hahahaha"); - } - return EXIT_SUCCESS; - } - return EXIT_FAIL; - } - - //===================================================================== - //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) - { - //If the command is enabled - if (vMinecraftSettings.getInstance().cmdEzModo()) { - //If the player is already invulnerable, turn ezmodo off. - if (vMinecraftSettings.getInstance().isEzModo(player.getName())) { - player.sendMessage(Colors.Red + "ezmodo = off"); - vMinecraftSettings.getInstance().removeEzModo(player.getName()); - //Otherwise make them invulnerable - } else { - player.sendMessage(Colors.LightBlue + "eh- maji? ezmodo!?"); - player.sendMessage(Colors.Rose + "kimo-i"); - player.sendMessage(Colors.LightBlue + "Easy Mode ga yurusareru no wa shougakusei made dayo ne"); - player.sendMessage(Colors.Red + "**Laughter**"); - vMinecraftSettings.getInstance().addEzModo(player.getName()); - player.setHealth(vMinecraftSettings.getInstance().ezModoHealth()); - } - return EXIT_SUCCESS; - } - return EXIT_FAIL; - } - - //===================================================================== - //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) - { - //If the feature is enabled list the players - if(vMinecraftSettings.getInstance().cmdEzModo()) { - player.sendMessage("Ezmodo: " + vMinecraftSettings.getInstance().ezModoList()); - return EXIT_SUCCESS; - } - return EXIT_FAIL; - } - - //===================================================================== - //Function: modifySplit (/modify) - //Input: Player player: The player using the command - // String[] args: Player, Command, Arguments - //Output: int: Exit Code - //Use: List all invulnerable players - //===================================================================== - public static int modifySplit(Player player, String[] args) - { - //Exploit fix for people giving themselves commands - if(args[1].equals("commands")) - return EXIT_FAIL; - return EXIT_CONTINUE; - } - - //===================================================================== - //Function: Time Reverse - //Input: long time: The time to reverse to. - //Output: int: Exit Code - //Use: List all invulnerable players - //===================================================================== - public static int timeReverse(long tarTime) - { - long curTime = etc.getServer().getRelativeTime(); - //if(cur) - return EXIT_SUCCESS; - } -} - -//===================================================================== -//Class: commandList -//Use: The list of commands that will be checked for -//Author: cerevisiae -//===================================================================== -class commandList { - command[] commands; - protected static final Logger log = Logger.getLogger("Minecraft"); - 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 command[0]; - } - - //===================================================================== - //Function: register - //Input: String name: The name of the command - // String func: The function to be called - //Output: boolean: Whether the command was input successfully or not - //Use: Registers a command to the command list for checking later - //===================================================================== - public boolean register(String name, String func){ - - //If the command list isn't empty - if(commands.length > 0) - { - //Check to make sure the command doesn't already exist - for(int i = 0; i < commands.length; i++) - if(commands[i].getName().equalsIgnoreCase(name)) - return false; - - //Create a new temp array - command[] temp = new command[commands.length + 1]; - //Copy the old command list over - System.arraycopy(commands, 0, temp, 0, commands.length); - //Set commands to equal the new array - commands = temp; - } else { - commands = new command[1]; - } - - //Add the new function to the list - commands[commands.length - 1] = new command(name, func); - - //exit successfully - return true; - } - - //===================================================================== - //Function: register - //Input: String name: The name of the command - // String func: The function to be called - // String info: The information for the command to put in help - //Output: boolean: Whether the command was input successfully or not - //Use: Registers a command to the command list for checking later - //===================================================================== - public boolean register(String name, String func, String info){ - //Add to the /help list - etc.getInstance().addCommand(name, info); - - //Finish registering - return register(name, func); - } - - //===================================================================== - //Function: register - //Input: String name: The name of the command - // String func: The function to be called - //Output: boolean: Whether the command was input successfully or not - //Use: Registers a command to the command list for checking later - //===================================================================== - public boolean registerAlias(String name, String com, String[] args){ - - //If the command list isn't empty - if(commands.length > 0) - { - //Check to make sure the command doesn't already exist - for(int i = 0; i < commands.length; i++) - if(commands[i].getName().equalsIgnoreCase(name)) - return false; - - //Create a new temp array - command[] temp = new command[commands.length + 1]; - //Copy the old command list over - System.arraycopy(commands, 0, temp, 0, commands.length); - //Set commands to equal the new array - commands = temp; - } else { - commands = new command[1]; - } - - //Add the new function to the list - commands[commands.length - 1] = new commandRef(name, com, args); - - //exit successfully - return true; - } - - //===================================================================== - //Function: register - //Input: String name: The name of the command - // String func: The function to be called - //Output: boolean: Whether the command was input successfully or not - //Use: Registers a command to the command list for checking later - //===================================================================== - public boolean registerAlias(String name, String com){ - - //If the command list isn't empty - if(commands.length > 0) - { - //Check to make sure the command doesn't already exist - for(int i = 0; i < commands.length; i++) - if(commands[i].getName().equalsIgnoreCase(name)) - return false; - - //Create a new temp array - command[] temp = new command[commands.length + 1]; - //Copy the old command list over - System.arraycopy(commands, 0, temp, 0, commands.length); - //Set commands to equal the new array - commands = temp; - } else { - commands = new command[1]; - } - - //Add the new function to the list - commands[commands.length - 1] = new commandRef(name, com); - - //exit successfully - return true; - } - - //===================================================================== - //Function: call - //Input: String name: The name of the command to be run - //Output: boolean: If the command was called successfully - //Use: Attempts to call a command - //===================================================================== - public int call(String name, Player player, String[] arg){ - //Make sure the user has access to the command - if(!player.canUseCommand(name)) { - return EXIT_FAIL; - } - //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; - } - - - - //===================================================================== - //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 = vMinecraftCommands.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; - } - } - - //===================================================================== - //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 - // String[] arg: the arguments to apply - //Output: None - //Use: Initialize the command - //===================================================================== - public commandRef(String name, String com, String[] arg){ - super(name, ""); - reference = com; - args = arg; - } - - //===================================================================== - //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, ""); - reference = com; - args = null; - } - - - //===================================================================== - //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) - { - if(args != null) { - String[] temp = new String[args.length]; - System.arraycopy(args, 0, temp, 0, args.length); - //Insert the arguments into the pre-set arguments - int lastSet = 0, - argCount = 0; - for(String argument : temp) - { - if(argument.startsWith("%")) - { - int argNum = Integer.parseInt(argument.substring(1)); - if( argNum < arg.length ) - { - temp[lastSet] = arg[argNum]; - argCount++; - } - } - lastSet++; - } - //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; - } - - //Call the referenced command - player.command(reference + " " + etc.combineSplit(0, temp, " ")); - } else - player.command(reference); - return EXIT_SUCCESS; - } - } -} \ No newline at end of file From f129b36849cc729e12d73984959fab627c6dacbd Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 12:39:14 -0600 Subject: [PATCH 48/82] Created a wrapper for Player.sendMessage() That automatically applies Quake Colors and Word Wrap --- vMinecraftCommands.java | 54 +++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 32 deletions(-) diff --git a/vMinecraftCommands.java b/vMinecraftCommands.java index 9917dddab..52869d3a1 100644 --- a/vMinecraftCommands.java +++ b/vMinecraftCommands.java @@ -47,7 +47,8 @@ public class vMinecraftCommands{ cl.registerAlias("/suicide", "/wrists"); cl.registerAlias("/clearinventory", "/ci"); } - //===================================================================== + + //===================================================================== //Function: me (/me) //Input: Player player: The player using the command //Output: int: Exit Code @@ -60,6 +61,7 @@ public class vMinecraftCommands{ vMinecraftChat.emote(player, str); return EXIT_SUCCESS; } + //===================================================================== //Function: adminChatToggle (/a) //Input: Player player: The player using the command @@ -68,22 +70,22 @@ public class vMinecraftCommands{ // send will be piped to admin chat. //===================================================================== public static int adminChatToggle(Player player, String[] args) -{ - if(vMinecraftSettings.getInstance().adminChatToggle()) - { - //If the player is already toggled for admin chat, remove them - if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) { - player.sendMessage(Colors.Red + "Admin Chat Toggle = off"); - vMinecraftSettings.getInstance().removeAdminToggled(player.getName()); - //Otherwise include them - } else { - player.sendMessage(Colors.Blue + "Admin Chat Toggled on"); - vMinecraftSettings.getInstance().addAdminToggled(player.getName()); - } - return EXIT_SUCCESS; - } - return EXIT_FAIL; -} + { + if(vMinecraftSettings.getInstance().adminChatToggle()) + { + //If the player is already toggled for admin chat, remove them + if (vMinecraftSettings.getInstance().isAdminToggled(player.getName())) { + player.sendMessage(Colors.Red + "Admin Chat Toggle = off"); + vMinecraftSettings.getInstance().removeAdminToggled(player.getName()); + //Otherwise include them + } else { + player.sendMessage(Colors.Blue + "Admin Chat Toggled on"); + vMinecraftSettings.getInstance().addAdminToggled(player.getName()); + } + return EXIT_SUCCESS; + } + return EXIT_FAIL; + } //===================================================================== //Function: heal (/heal) //Input: Player player: The player using the command @@ -316,18 +318,7 @@ public class vMinecraftCommands{ log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\""); //Prepend the player name and cut into lines. - String[] message = vMinecraftChat.wordWrap(playerName + str); - - //Output the message - for(String msg: message) - { - if (msg.contains(playerName)) - vMinecraftChat.gmsg( playerName - + vMinecraftChat.rainbow( - msg.substring(playerName.length()))); - else - vMinecraftChat.gmsg(vMinecraftChat.rainbow(msg)); - } + vMinecraftChat.gmsg(playerName + vMinecraftChat.rainbow(str)); return EXIT_SUCCESS; } @@ -418,11 +409,10 @@ public class vMinecraftCommands{ e.printStackTrace(); } int maxPlayers = server.getInt("max-players"); + //Output the player list - String[] tempOut = vMinecraftChat.wordWrap(Colors.Rose + "Player List (" + vMinecraftChat.sendMessage(player, Colors.Rose + "Player List (" + count + "/" + maxPlayers +"): " + tempList); - for(String msg: tempOut) - player.sendMessage( msg ); return EXIT_SUCCESS; } From ce26a1c52476ede43badb74c28505e65f940e5eb Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 12:40:25 -0600 Subject: [PATCH 49/82] Fixing aliased commands --- vMinecraftCommands.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vMinecraftCommands.java b/vMinecraftCommands.java index 52869d3a1..1f498a87e 100644 --- a/vMinecraftCommands.java +++ b/vMinecraftCommands.java @@ -44,8 +44,8 @@ public class vMinecraftCommands{ cl.register("/modify", "modifySplit"); cl.register("/me", "me"); cl.registerAlias("/playerlist", "/who"); - cl.registerAlias("/suicide", "/wrists"); - cl.registerAlias("/clearinventory", "/ci"); + cl.registerAlias("/wrists", "/suicide"); + cl.registerAlias("/ci", "/clearinventory"); } //===================================================================== From 04f46a5527669d0cd4bd5ac45a1a55f07a1636d5 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 1 Dec 2010 10:59:51 -0800 Subject: [PATCH 50/82] Early version of setting up a users txt file --- vMinecraft.java | 3 +++ vMinecraftListener.java | 4 +++ vMinecraftUsers.java | 58 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 vMinecraftUsers.java diff --git a/vMinecraft.java b/vMinecraft.java index fd7336dd7..65bb1fdc8 100644 --- a/vMinecraft.java +++ b/vMinecraft.java @@ -11,7 +11,9 @@ public class vMinecraft extends Plugin { public void enable() { vMinecraftSettings.getInstance().loadSettings(); + vMinecraftUsers.getInstance().loadUsers(); vMinecraftCommands.loadCommands(); + } public void disable() { @@ -21,6 +23,7 @@ public class vMinecraft extends Plugin { public void initialize() { //Here we add the hook we're going to use. In this case it's the arm swing event. etc.getLoader().addListener(PluginLoader.Hook.CHAT, listener, this, PluginListener.Priority.MEDIUM); + etc.getLoader().addListener(PluginLoader.Hook.LOGIN, listener, this, PluginListener.Priority.MEDIUM); etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH); etc.getLoader().addListener(PluginLoader.Hook.IGNITE, listener, this, PluginListener.Priority.HIGH); etc.getLoader().addListener(PluginLoader.Hook.DAMAGE, listener, this, PluginListener.Priority.MEDIUM); diff --git a/vMinecraftListener.java b/vMinecraftListener.java index 6c4add0ec..ba3bfcc4e 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -90,6 +90,10 @@ public class vMinecraftListener extends PluginListener { } return false; } + + public void onLogin(Player player){ + vMinecraftUsers.addUser(player); + } /** Not working yet, I posted the issue to hMod on github though public boolean onDamage(DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java new file mode 100644 index 000000000..4d7b5675d --- /dev/null +++ b/vMinecraftUsers.java @@ -0,0 +1,58 @@ +import java.io.*; +import java.util.ArrayList; +import java.util.logging.Level; +import java.util.logging.Logger; +public class vMinecraftUsers { + private static volatile vMinecraftUsers instance; + protected static final Logger log = Logger.getLogger("Minecraft"); + String file = "vminecraftusers.txt"; + private PropertiesFile properties; + String location = "vminecraftusers.txt"; + public void loadUsers(){ + File theDir = new File("vminecraftusers.txt"); + if(!theDir.exists()){ + properties = new PropertiesFile("vminecraftusers.txt"); + FileWriter writer = null; + try { + writer = new FileWriter(location); + writer.write("#Storage place for user information\r\n"); + writer.write("#username:nickname:suffix: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("vminecraftusers.txt"); + try { + properties.load(); + } catch (IOException e) { + log.log(Level.SEVERE, "Exception while loading vminecraftusers.txt", e); + } + } + } + public static void addUser(Player player){ + FileWriter writer = null; + String location = "vminecraftusers.txt"; + try { + writer = new FileWriter(location); + writer.write(player.getName()+"::::"); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while trying to add user with writer to " + location, e); + } + + } + public static vMinecraftUsers getInstance() { + if (instance == null) { + instance = new vMinecraftUsers(); + } + return instance; + } +} From ccf75c04295e52635098a3ff7ea09db905834b9b Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 13:40:18 -0600 Subject: [PATCH 51/82] Fixed /whois requiring full name --- vMinecraftCommands.java | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/vMinecraftCommands.java b/vMinecraftCommands.java index 1f498a87e..9dbd788e9 100644 --- a/vMinecraftCommands.java +++ b/vMinecraftCommands.java @@ -341,14 +341,8 @@ public class vMinecraftCommands{ player.sendMessage(Colors.Rose + "Usage is /whois [player]"); else { //Get the player by name - Player playerTarget = null; - for( Player p : etc.getServer().getPlayerList()) - { - if (p.getName().equalsIgnoreCase(args[0])) - { - playerTarget = p; - } - } + Player playerTarget = etc.getServer().matchPlayer(args[0]); + //If the player exists if (playerTarget != null){ From ce46e2d0118bcc69bb5a12a4ddb28cf277614da8 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 14:28:50 -0600 Subject: [PATCH 52/82] Fixed the writer for vminecraftusers --- vMinecraftListener.java | 6 ------ vMinecraftUsers.java | 12 ++++++++++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/vMinecraftListener.java b/vMinecraftListener.java index ba3bfcc4e..6faeb1aaa 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -94,11 +94,5 @@ public class vMinecraftListener extends PluginListener { public void onLogin(Player player){ vMinecraftUsers.addUser(player); } - /** Not working yet, I posted the issue to hMod on github though - public boolean onDamage(DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { - - return false; - } - **/ } \ No newline at end of file diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index 4d7b5675d..e4c69026c 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -43,10 +43,18 @@ public class vMinecraftUsers { String location = "vminecraftusers.txt"; try { writer = new FileWriter(location); - writer.write(player.getName()+"::::"); + writer.append(player.getName()+"::::"); } catch (Exception e) { log.log(Level.SEVERE, "Exception while trying to add user with writer to " + location, e); - } + } finally { + try { + if (writer != null) { + writer.close(); + } + } catch (IOException e) { + log.log(Level.SEVERE, "Exception while closing writer for " + location, e); + } + } } public static vMinecraftUsers getInstance() { From e5a97641b3df84320103c524ba42fea333a19ca7 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 1 Dec 2010 13:15:37 -0800 Subject: [PATCH 53/82] some more tweaking done --- vMinecraftUsers.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index e4c69026c..cf2682bfe 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -2,6 +2,7 @@ import java.io.*; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; + public class vMinecraftUsers { private static volatile vMinecraftUsers instance; protected static final Logger log = Logger.getLogger("Minecraft"); @@ -41,11 +42,13 @@ public class vMinecraftUsers { public static void addUser(Player player){ FileWriter writer = null; String location = "vminecraftusers.txt"; + BufferedWriter bw = new BufferedWriter(new FileWriter(location, true)); try { - writer = new FileWriter(location); - writer.append(player.getName()+"::::"); - } catch (Exception e) { - log.log(Level.SEVERE, "Exception while trying to add user with writer to " + location, e); + bw.append(player.getName()+"::::\r\n"); + bw.newLine(); + bw.close(); + } catch (IOException e) { + log.log(Level.SEVERE, "Exception while trying to add user with BufferedWriter to " + location, e); } finally { try { if (writer != null) { @@ -63,4 +66,7 @@ public class vMinecraftUsers { } return instance; } + public static void getRow(){ + + } } From 3659ae80e4ca814a4248240ab14aba5112c963f1 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 15:17:18 -0600 Subject: [PATCH 54/82] Fixed the IOException --- vMinecraftUsers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index cf2682bfe..a0a498b40 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -42,8 +42,8 @@ public class vMinecraftUsers { public static void addUser(Player player){ FileWriter writer = null; String location = "vminecraftusers.txt"; - BufferedWriter bw = new BufferedWriter(new FileWriter(location, true)); try { + BufferedWriter bw = new BufferedWriter(new FileWriter(location, true)); bw.append(player.getName()+"::::\r\n"); bw.newLine(); bw.close(); From 61a8781f62778c4b62088240a196b5dd5fe2bf14 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Wed, 1 Dec 2010 13:33:20 -0800 Subject: [PATCH 55/82] fixed unecessary new line insertions, hopefully --- vMinecraftUsers.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index a0a498b40..6f103db87 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -44,10 +44,10 @@ public class vMinecraftUsers { String location = "vminecraftusers.txt"; try { BufferedWriter bw = new BufferedWriter(new FileWriter(location, true)); - bw.append(player.getName()+"::::\r\n"); + bw.append(player.getName()+"::::\r"); bw.newLine(); bw.close(); - } catch (IOException e) { + } catch (Exception e) { log.log(Level.SEVERE, "Exception while trying to add user with BufferedWriter to " + location, e); } finally { try { @@ -55,7 +55,7 @@ public class vMinecraftUsers { writer.close(); } } catch (IOException e) { - log.log(Level.SEVERE, "Exception while closing writer for " + location, e); + log.log(Level.SEVERE, "Exception while closing BufferedWriter to " + location, e); } } From 461e9985376a6ac06d18100b245b010f4dfaf3a1 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 21:25:45 -0600 Subject: [PATCH 56/82] Fixing words too long to fit on a single line. --- vMinecraftAnnouncements.java | 8 +- vMinecraftChat.java | 138 +++++++++++++++++++++++------------ vMinecraftCommands.java | 10 +-- vMinecraftListener.java | 2 +- 4 files changed, 102 insertions(+), 56 deletions(-) diff --git a/vMinecraftAnnouncements.java b/vMinecraftAnnouncements.java index c93db1b96..9b78b7fa7 100644 --- a/vMinecraftAnnouncements.java +++ b/vMinecraftAnnouncements.java @@ -26,24 +26,24 @@ public class vMinecraftAnnouncements { if(split[0].equalsIgnoreCase("/kick")) { Player playerTarget = etc.getServer().matchPlayer(split[1]); if (playerTarget != null && !playerTarget.hasControlOver(player)) { - vMinecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has kicked "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); + vMinecraftChat.gmsg(player, player.getColor()+player.getName()+Colors.Blue+" has kicked "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); } } if(split[0].equalsIgnoreCase("/ban")) { Player playerTarget = etc.getServer().matchPlayer(split[1]); if (playerTarget != null && !playerTarget.hasControlOver(player)) { - vMinecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); + vMinecraftChat.gmsg(player, player.getColor()+player.getName()+Colors.Blue+" has banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); } } if(split[0].equalsIgnoreCase("/ipban")) { Player playerTarget = etc.getServer().matchPlayer(split[1]); if (playerTarget != null && !playerTarget.hasControlOver(player)) { - vMinecraftChat.gmsg(player.getColor()+player.getName()+Colors.Blue+" has IP banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); + vMinecraftChat.gmsg(player, player.getColor()+player.getName()+Colors.Blue+" has IP banned "+Colors.Red+playerTarget.getColor()+playerTarget.getName()); } } if(split[0].equalsIgnoreCase("/time")) { if (split.length <= 2) { - vMinecraftChat.gmsg(Colors.Blue+"Time changes thanks to "+player.getColor()+player.getName()); + vMinecraftChat.gmsg(player, Colors.Blue+"Time changes thanks to "+player.getColor()+player.getName()); } } } diff --git a/vMinecraftChat.java b/vMinecraftChat.java index 75d3f2148..e0b19b786 100644 --- a/vMinecraftChat.java +++ b/vMinecraftChat.java @@ -16,10 +16,10 @@ public class vMinecraftChat { //Output: None //Use: Outputs a message to everybody //===================================================================== - public static void gmsg(String msg){ - for (Player p : etc.getServer().getPlayerList()) { - if (p != null) { - sendMessage(p, msg); + public static void gmsg(Player sender, String msg){ + for (Player receiver : etc.getServer().getPlayerList()) { + if (receiver != null) { + sendMessage(sender, receiver, msg); } } } @@ -30,10 +30,10 @@ public class vMinecraftChat { //Output: None //Use: Outputs a message to everybody //===================================================================== - public static void sendMessage(Player player, String msg){ + public static void sendMessage(Player sender, Player receiver, String msg){ String[] message = applyColors(wordWrap(msg)); for(String out : message) - player.sendMessage(out + " "); + receiver.sendMessage(out + " "); } //===================================================================== @@ -45,38 +45,49 @@ public class vMinecraftChat { //===================================================================== public static String[] wordWrap(String msg){ //Split each word apart - String[] split = msg.split(" "); + 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 - int i = 0; - while(i < split.length){ + while(!split.isEmpty()){ int len = 0; - int j = i; - + + //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(len <= 300 && i < split.length) + while(len <= 316 && !split.isEmpty()) { - len += msgLength(split[i]) + 4; - if( len <= 300) - i++; + int wordLength = msgLength(split.get(0)) + 4; + + //If a word is too long for a line + if(wordLength > 316) + { + String[] tempArray = wordCut(len, split.remove(0)); + words.add(tempArray[0]); + split.add(tempArray[1]); + log.log(Level.INFO, tempArray[0]); + log.log(Level.INFO, tempArray[1]); + } + //If the word is not too long to fit + len += wordLength; + log.log(Level.INFO, String.valueOf(len)); + if( len < 316) + words.add(split.remove(0)); } - //Copy the words in the selection into a new array - String[] temp = new String[i - j]; - System.arraycopy(split, j, temp, 0, i - j); - //Merge them and add them to the output array. - out.add( etc.combineSplit(0, temp, " ") ); + log.log(Level.INFO, etc.combineSplit(0, + words.toArray(new String[out.size()]), " ")); + out.add( etc.combineSplit(0, + words.toArray(new String[out.size()]), " ") ); } - //Convert to an array and return - String[] tempout = new String[out.size()]; - out.toArray(tempout); - return tempout; + return out.toArray(new String[out.size()]); } //===================================================================== @@ -91,25 +102,60 @@ public class vMinecraftChat { //and their following color codes for(int x = 0; x 0) + length += len; + else x++; - else if("i;,.:|!".indexOf(str.charAt(x)) != -1) - length+=2; - else if("l'".indexOf(str.charAt(x)) != -1) - length+=3; - else if("tI[]".indexOf(str.charAt(x)) != -1) - length+=4; - else if("kf{}<>\"*()".indexOf(str.charAt(x)) != -1) - length+=5; - else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(str.charAt(x)) != -1) - length+=6; - else if("@~".indexOf(str.charAt(x)) != -1) - length+=7; - else if(str.charAt(x)==' ') - length+=4; } return length; } + + //===================================================================== + //Function: wordCut + //Input: String str: The string to find the length of + //Output: String[]: The cut up word + //Use: Cuts apart a word that is too long to fit on one line + //===================================================================== + private static String[] wordCut(int lengthBefore, String str){ + int length = lengthBefore; + //Loop through all the characters, skipping any color characters + //and their following color codes + String[] output = new String[2]; + int x = 0; + while(length < 316 && x < str.length()) + { + int len = charLength(str.charAt(x)); + if( len > 0) + length += len; + x++; + } + //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; + } + + 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("kf{}<>\"*()".indexOf(x) != -1) + return 5; + else if("hequcbrownxjmpsvazydgTHEQUCKBROWNFXJMPSVLAZYDG1234567890#\\/?$%-=_+&".indexOf(x) != -1) + return 6; + else if("@~".indexOf(x) != -1) + return 7; + else if(x==' ') + return 4; + else + return -1; + } //===================================================================== //Function: rainbow @@ -271,7 +317,7 @@ public class vMinecraftChat { //And if p is an admin or has access to adminchat send message if (p.isAdmin() || (p.canUseCommand("/adminchat"))) { - sendMessage(p, adminchat + message); + sendMessage(player, p, adminchat + message); } } } @@ -301,7 +347,7 @@ public class vMinecraftChat { log.log(Level.INFO, "<"+player.getName()+"> " +message); //Output the message - gmsg(playerName + Colors.LightGreen + message); + gmsg(player, playerName + Colors.LightGreen + message); return true; } return false; @@ -323,7 +369,7 @@ public class vMinecraftChat { log.log(Level.INFO, "<"+player.getName()+"> "+message); //Output the message - gmsg(playerName + Colors.Red + message); + gmsg(player, playerName + Colors.Red + message); return true; } return false; @@ -347,7 +393,7 @@ public class vMinecraftChat { log.log(Level.INFO, "<"+player.getName()+"> "+message); //Output the message - gmsg(playerName + message); + gmsg(player, playerName + message); //Loop through the string finding the color codes and inserting them return true; @@ -363,7 +409,7 @@ public class vMinecraftChat { //===================================================================== public static boolean emote(Player player, String message) { - gmsg("* " + getName(player) + " " + Colors.White + message); + gmsg(player, "* " + getName(player) + " " + Colors.White + message); return true; } @@ -391,7 +437,7 @@ public class vMinecraftChat { for(int x = 0; x< msg.length(); x++) { //If the char is a ^ or � - if(msg.charAt(x) == '^') + if(msg.charAt(x) == '^' || msg.charAt(x) == Colors.White.charAt(0)) { if(x != msg.length() - 1) { diff --git a/vMinecraftCommands.java b/vMinecraftCommands.java index 9dbd788e9..a57f40744 100644 --- a/vMinecraftCommands.java +++ b/vMinecraftCommands.java @@ -113,7 +113,7 @@ public class vMinecraftCommands{ playerTarget.sendMessage(Colors.Blue + "You have been healed by " + vMinecraftChat.getName(player)); } else if (playerTarget == null){ - vMinecraftChat.gmsg(Colors.Rose + "Couldn't find that player"); + player.sendMessage(Colors.Rose + "Couldn't find that player"); } } return EXIT_SUCCESS; @@ -318,7 +318,7 @@ public class vMinecraftCommands{ log.log(Level.INFO, player.getName()+" fabulously said \""+ str+"\""); //Prepend the player name and cut into lines. - vMinecraftChat.gmsg(playerName + vMinecraftChat.rainbow(str)); + vMinecraftChat.gmsg(player, playerName + vMinecraftChat.rainbow(str)); return EXIT_SUCCESS; } @@ -405,7 +405,7 @@ public class vMinecraftCommands{ int maxPlayers = server.getInt("max-players"); //Output the player list - vMinecraftChat.sendMessage(player, Colors.Rose + "Player List (" + vMinecraftChat.sendMessage(player, player, Colors.Rose + "Player List (" + count + "/" + maxPlayers +"): " + tempList); return EXIT_SUCCESS; @@ -429,7 +429,7 @@ public class vMinecraftCommands{ player.sendMessage(Colors.Rose + "Usage is /say [message]"); } //Display the message globally - vMinecraftChat.gmsg(Colors.Yellow + etc.combineSplit(0, args, " ")); + vMinecraftChat.gmsg(player, Colors.Yellow + etc.combineSplit(0, args, " ")); return EXIT_SUCCESS; } return EXIT_FAIL; @@ -454,7 +454,7 @@ public class vMinecraftCommands{ //If the player isn't invulnerable kill them if (!vMinecraftSettings.getInstance().isEzModo(playerTarget.getName())) { playerTarget.setHealth(0); - vMinecraftChat.gmsg(vMinecraftChat.getName(player) + vMinecraftChat.gmsg(player, vMinecraftChat.getName(player) + Colors.LightBlue + " has slain " + vMinecraftChat.getName(playerTarget)); //Otherwise output error to the user diff --git a/vMinecraftListener.java b/vMinecraftListener.java index 6faeb1aaa..0318de5ae 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -86,7 +86,7 @@ public class vMinecraftListener extends PluginListener { } else if (vMinecraftSettings.getInstance().globalmessages() && player.getHealth() < 1) { - vMinecraftChat.gmsg(Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); + vMinecraftChat.gmsg(player, Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); } return false; } From 6c922a02c85de914dae89e04c62bb0512d23d185 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 21:26:18 -0600 Subject: [PATCH 57/82] Fixing words too long to fit on a single line. --- vMinecraftChat.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/vMinecraftChat.java b/vMinecraftChat.java index e0b19b786..483bda1e9 100644 --- a/vMinecraftChat.java +++ b/vMinecraftChat.java @@ -70,19 +70,14 @@ public class vMinecraftChat { String[] tempArray = wordCut(len, split.remove(0)); words.add(tempArray[0]); split.add(tempArray[1]); - log.log(Level.INFO, tempArray[0]); - log.log(Level.INFO, tempArray[1]); } //If the word is not too long to fit len += wordLength; - log.log(Level.INFO, String.valueOf(len)); if( len < 316) words.add(split.remove(0)); } //Merge them and add them to the output array. - log.log(Level.INFO, etc.combineSplit(0, - words.toArray(new String[out.size()]), " ")); out.add( etc.combineSplit(0, words.toArray(new String[out.size()]), " ") ); } From a0552c1f31ad102d81a2846c8ca43dfe4677f74b Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Wed, 1 Dec 2010 21:29:50 -0600 Subject: [PATCH 58/82] Comments added to charLength function --- vMinecraftChat.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/vMinecraftChat.java b/vMinecraftChat.java index 483bda1e9..9fc79c175 100644 --- a/vMinecraftChat.java +++ b/vMinecraftChat.java @@ -132,6 +132,12 @@ public class vMinecraftChat { 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) From 76cadca12f0effcc7db1580fecb93f1daa0957ba Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Thu, 2 Dec 2010 00:17:42 -0600 Subject: [PATCH 59/82] Starting coding for PlayerProfiles class to store aliases, personal muting, tag, and nickname --- vMinecraftCommands.java | 14 +++ vMinecraftUsers.java | 190 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 204 insertions(+) diff --git a/vMinecraftCommands.java b/vMinecraftCommands.java index a57f40744..2cff35139 100644 --- a/vMinecraftCommands.java +++ b/vMinecraftCommands.java @@ -10,6 +10,7 @@ import java.util.logging.Logger; //Author: nos, trapalice, cerevisiae //===================================================================== public class vMinecraftCommands{ + //Log output protected static final Logger log = Logger.getLogger("Minecraft"); static final int EXIT_FAIL = 0, @@ -539,6 +540,19 @@ public class vMinecraftCommands{ //if(cur) return EXIT_SUCCESS; } + + //===================================================================== + //Function: privateMessage(/msg) + //Input: long time: The time to reverse to. + //Output: int: Exit Code + //Use: List all invulnerable players + //===================================================================== + public static int privateMessage(Player player, String[] message) + { + long curTime = etc.getServer().getRelativeTime(); + //if(cur) + return EXIT_SUCCESS; + } } //===================================================================== diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index 6f103db87..65f95fbbe 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -70,3 +70,193 @@ public class vMinecraftUsers { } } + +//===================================================================== +//Class: PlayerList +//Use: Encapsulates the player list +//Author: cerevisiae +//===================================================================== +class PlayerList +{ + 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 + //===================================================================== + private PlayerProfile findProfile(Player player) + { + for(PlayerProfile ply : players) + { + if(ply.getPlayer().equals(player)) + return ply; + } + return null; + } + + //===================================================================== + //Class: PlayerProfile + //Use: Encapsulates all commands for player options + //Author: cerevisiae + //===================================================================== + class PlayerProfile + { + private Player playerName; + private String nickName; + private String tag; + 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) + { + ignoreList = new ArrayList(); + aliasList = new commandList(); + } + + //===================================================================== + //Function: getPlayer + //Input: None + //Output: Player: The player this profile belongs to + //Use: Finds if the specified player is in the ignore list + //===================================================================== + public Player getPlayer(){return 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);} + + //===================================================================== + //Function: addIgnore + //Input: Player name: The player to ignore + //Output: None + //Use: Ignores a player. + //===================================================================== + public void addIgnore(Player name) + { + if(!ignoreList.contains(name)) + ignoreList.add(name); + } + + //===================================================================== + //Function: removeIgnore + //Input: Player name: The player to ignore + //Output: None + //Use: Ignores a player. + //===================================================================== + public void removeIgnore(Player name) + { + if(ignoreList.contains(name)) + ignoreList.remove(name); + } + + //===================================================================== + //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); + } + + //===================================================================== + //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, String[] args) + { + aliasList.registerAlias(name, callCommand, args); + } + + //===================================================================== + //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; } + + //===================================================================== + //Function: getTag + //Input: None + //Output: String: The player tag + //Use: Gets a player tag + //===================================================================== + public String getTag() { return tag; } + } +} + From 34612f93d1338de0e6dd5b4e633262bff9de48e3 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 00:06:03 -0800 Subject: [PATCH 60/82] Added check to see if the user exists before appending file. Also borrowed some code from hMod to tweak into functions for vMinecraftUsers, also put in placeholders for things I'm going to write soon. :P --- vMinecraftUsers.java | 60 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index 65f95fbbe..bbef620cb 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -2,6 +2,7 @@ import java.io.*; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.Scanner; public class vMinecraftUsers { private static volatile vMinecraftUsers instance; @@ -17,7 +18,7 @@ public class vMinecraftUsers { try { writer = new FileWriter(location); writer.write("#Storage place for user information\r\n"); - writer.write("#username:nickname:suffix:ignore,list,names:alias,commands,here\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 { @@ -39,9 +40,64 @@ public class vMinecraftUsers { } } } + + public boolean doesPlayerExist(String player) { + try { + Scanner scanner = new Scanner(new File(location)); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + if (line.startsWith("#") || line.equals("") || line.startsWith("")) { + continue; + } + String[] split = line.split(":"); + if (!split[0].equalsIgnoreCase(player)) { + continue; + } + return true; + } + scanner.close(); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); + } + return false; + } + public Player getPlayer(String name) { + Player player = new Player(); + try { + Scanner scanner = new Scanner(new File(location)); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + if (line.startsWith("#") || line.equals("") || line.startsWith("")) { + continue; + } + String[] split = line.split(":"); + if (!split[0].equalsIgnoreCase(name)) { + continue; + } + if (split.length >= 2) { + //player.setNickname(split[1] + } + if (split.length >= 3) { + //player.setSuffix(split[2]); + } + if (split.length >= 5) { + //player.setIgnoreList(split[4].split(",")); + } + if (split.length >= 6) { + //player.setAlias(split[5].split(",")); + } + } + scanner.close(); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); + } + return player; + } public static void addUser(Player player){ FileWriter writer = null; String location = "vminecraftusers.txt"; + String playerName = player.getName(); + if (vMinecraftUsers.getInstance().doesPlayerExist(playerName)){ //Check to see if the player exists before writing try { BufferedWriter bw = new BufferedWriter(new FileWriter(location, true)); bw.append(player.getName()+"::::\r"); @@ -58,7 +114,7 @@ public class vMinecraftUsers { log.log(Level.SEVERE, "Exception while closing BufferedWriter to " + location, e); } } - + } } public static vMinecraftUsers getInstance() { if (instance == null) { From 0e171e8ecc9b89b586a7a49e7c4f270a32a88283 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 00:06:03 -0800 Subject: [PATCH 61/82] Added check to see if the user exists before appending file. Also borrowed some code from hMod to tweak into functions for vMinecraftUsers, also put in placeholders for things I'm going to write soon. :P --- vMinecraftUsers.java | 62 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index 65f95fbbe..bed0b4cab 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -2,6 +2,7 @@ import java.io.*; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.Scanner; public class vMinecraftUsers { private static volatile vMinecraftUsers instance; @@ -17,7 +18,7 @@ public class vMinecraftUsers { try { writer = new FileWriter(location); writer.write("#Storage place for user information\r\n"); - writer.write("#username:nickname:suffix:ignore,list,names:alias,commands,here\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 { @@ -39,12 +40,67 @@ public class vMinecraftUsers { } } } + + public boolean doesPlayerExist(String player) { + try { + Scanner scanner = new Scanner(new File(location)); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + if (line.startsWith("#") || line.equals("") || line.startsWith("")) { + continue; + } + String[] split = line.split(":"); + if (!split[0].equalsIgnoreCase(player)) { + continue; + } + return true; + } + scanner.close(); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); + } + return false; + } + public Player getPlayer(String name) { + Player player = new Player(); + try { + Scanner scanner = new Scanner(new File(location)); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + if (line.startsWith("#") || line.equals("") || line.startsWith("")) { + continue; + } + String[] split = line.split(":"); + if (!split[0].equalsIgnoreCase(name)) { + continue; + } + if (split.length >= 2) { + //player.setNickname(split[1] + } + if (split.length >= 3) { + //player.setSuffix(split[2]); + } + if (split.length >= 5) { + //player.setIgnoreList(split[4].split(",")); + } + if (split.length >= 6) { + //player.setAlias(split[5].split(",")); + } + } + scanner.close(); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); + } + return player; + } public static void addUser(Player player){ FileWriter writer = null; String location = "vminecraftusers.txt"; + String playerName = player.getName(); + if (vMinecraftUsers.getInstance().doesPlayerExist(playerName)){ //Check to see if the player exists before writing try { BufferedWriter bw = new BufferedWriter(new FileWriter(location, true)); - bw.append(player.getName()+"::::\r"); + bw.append(player.getName()+":::::\r"); bw.newLine(); bw.close(); } catch (Exception e) { @@ -58,7 +114,7 @@ public class vMinecraftUsers { log.log(Level.SEVERE, "Exception while closing BufferedWriter to " + location, e); } } - + } } public static vMinecraftUsers getInstance() { if (instance == null) { From c79241158925042a1a7cd09212fb3ec26f8e6fe8 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 00:16:22 -0800 Subject: [PATCH 62/82] Whoops --- vMinecraftUsers.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index bed0b4cab..efda9b5dd 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -97,7 +97,7 @@ public class vMinecraftUsers { FileWriter writer = null; String location = "vminecraftusers.txt"; String playerName = player.getName(); - if (vMinecraftUsers.getInstance().doesPlayerExist(playerName)){ //Check to see if the player exists before writing + if (!vMinecraftUsers.getInstance().doesPlayerExist(playerName)){ //Check to see if the player exists before writing try { BufferedWriter bw = new BufferedWriter(new FileWriter(location, true)); bw.append(player.getName()+":::::\r"); From f36a842fc74a372986ad583a8d00c0a098370e82 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 01:39:17 -0800 Subject: [PATCH 63/82] Very early version of trying to get this stuff to work, its half done and won't compile as is. Got sleepy. Not even sure If I'm approaching it right, I'll look at it with a clear head in the morning. Feel free to tweak it if you want, I'll resume once I wake up if not. --- vMinecraftUsers.java | 71 +++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 34 deletions(-) diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index efda9b5dd..029d8205c 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -10,6 +10,8 @@ public class vMinecraftUsers { String file = "vminecraftusers.txt"; private PropertiesFile properties; String location = "vminecraftusers.txt"; + private String[] ignoreList = new String[]{""}; //For datafiles + private String[] aliasList = new String[]{""}; //For datafiles public void loadUsers(){ File theDir = new File("vminecraftusers.txt"); if(!theDir.exists()){ @@ -40,7 +42,6 @@ public class vMinecraftUsers { } } } - public boolean doesPlayerExist(String player) { try { Scanner scanner = new Scanner(new File(location)); @@ -61,38 +62,6 @@ public class vMinecraftUsers { } return false; } - public Player getPlayer(String name) { - Player player = new Player(); - try { - Scanner scanner = new Scanner(new File(location)); - while (scanner.hasNextLine()) { - String line = scanner.nextLine(); - if (line.startsWith("#") || line.equals("") || line.startsWith("")) { - continue; - } - String[] split = line.split(":"); - if (!split[0].equalsIgnoreCase(name)) { - continue; - } - if (split.length >= 2) { - //player.setNickname(split[1] - } - if (split.length >= 3) { - //player.setSuffix(split[2]); - } - if (split.length >= 5) { - //player.setIgnoreList(split[4].split(",")); - } - if (split.length >= 6) { - //player.setAlias(split[5].split(",")); - } - } - scanner.close(); - } catch (Exception e) { - log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); - } - return player; - } public static void addUser(Player player){ FileWriter writer = null; String location = "vminecraftusers.txt"; @@ -192,6 +161,7 @@ class PlayerList private Player playerName; private String nickName; private String tag; + private String suffix; private ArrayList ignoreList; private commandList aliasList; @@ -208,8 +178,41 @@ class PlayerList //===================================================================== public PlayerProfile(Player player) { + //Declare things ignoreList = new ArrayList(); - aliasList = new commandList(); + aliasList = new commandList(); + nickName = new String(); + tag = new String(); + suffix = new String(); + //Try to apply what we can + try { + Scanner scanner = new Scanner(new File(location)); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + if (line.startsWith("#") || line.equals("") || line.startsWith("")) { + continue; + } + String[] split = line.split(":"); + if (!split[0].equalsIgnoreCase(name)) { + continue; + } + nickName = (split[1].split(",").toString()); + + if (split.length >= 4) { + tag = (split[3]); + } + if (split.length >= 5) { + //ignoreList = (split[4]); + } + if (split.length >= 6) { + //aliasList + } + } + scanner.close(); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); + } + } //===================================================================== From 9e293645a30538d7c1761cc900168274e6b71a58 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 01:55:15 -0800 Subject: [PATCH 64/82] Added a few more things to TODO --- TODO | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 33ae124a9..fbe70fb90 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,7 @@ Vminecraft b8 Todo: - + Antigriefs Working on this, waiting for hMod to fix player health + + ^r for rainbow color code + + Finish work on the flat file system + + Antigriefs Working on this, waiting for hMod to fix player health + Allow players to nickname themselves or others + vminecraft Help * Specialized help message for vminecraft @@ -40,3 +42,5 @@ DONE * Now we can have color on multiple lines without crashing the client * Also does not cut words in half + +Notes: Let's try to to finish as much of this list as possible tomorrow and push for a b8 release soon :P From 04c385d0dc968e6b3b5b2122cd39856630977e69 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Thu, 2 Dec 2010 14:45:24 -0600 Subject: [PATCH 65/82] Added in some parsing of the loading from vminecraftusers.txt --- vMinecraftChat.java | 12 +++++- vMinecraftUsers.java | 92 +++++++++++++++++++++++++++----------------- 2 files changed, 67 insertions(+), 37 deletions(-) diff --git a/vMinecraftChat.java b/vMinecraftChat.java index 9fc79c175..c3721001c 100644 --- a/vMinecraftChat.java +++ b/vMinecraftChat.java @@ -32,6 +32,7 @@ public class vMinecraftChat { //===================================================================== public static void sendMessage(Player sender, Player receiver, String msg){ String[] message = applyColors(wordWrap(msg)); + if for(String out : message) receiver.sendMessage(out + " "); } @@ -283,6 +284,12 @@ public class vMinecraftChat { case 'F': color = Colors.White; break; + case 'R': + color = "~"; + break; + case 'r': + color = "~"; + break; default: color = null; break; @@ -401,10 +408,11 @@ public class vMinecraftChat { } return false; } - //===================================================================== + + //===================================================================== //Function: emote //Input: Player player: The player talking - // String message: The message to apply the effect to + // String message: The message to apply the effect to //Output: boolean: If this feature is enabled //Use: /me but with our custom colors applied //===================================================================== diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index 029d8205c..8a591e516 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -10,8 +10,10 @@ public class vMinecraftUsers { String file = "vminecraftusers.txt"; private PropertiesFile properties; String location = "vminecraftusers.txt"; - private String[] ignoreList = new String[]{""}; //For datafiles - private String[] aliasList = new String[]{""}; //For datafiles + + ArrayList players = new ArrayList(); + + public void loadUsers(){ File theDir = new File("vminecraftusers.txt"); if(!theDir.exists()){ @@ -158,6 +160,7 @@ class PlayerList //===================================================================== class PlayerProfile { + protected final Logger log = Logger.getLogger("Minecraft"); private Player playerName; private String nickName; private String tag; @@ -180,39 +183,58 @@ class PlayerList { //Declare things ignoreList = new ArrayList(); - aliasList = new commandList(); - nickName = new String(); - tag = new String(); - suffix = new String(); - //Try to apply what we can - try { - Scanner scanner = new Scanner(new File(location)); - while (scanner.hasNextLine()) { - String line = scanner.nextLine(); - if (line.startsWith("#") || line.equals("") || line.startsWith("")) { - continue; - } - String[] split = line.split(":"); - if (!split[0].equalsIgnoreCase(name)) { - continue; - } - nickName = (split[1].split(",").toString()); - - if (split.length >= 4) { - tag = (split[3]); - } - if (split.length >= 5) { - //ignoreList = (split[4]); - } - if (split.length >= 6) { - //aliasList - } - } - scanner.close(); - } catch (Exception e) { - log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); - } - + aliasList = new commandList(); + nickName = new String(); + tag = new String(); + suffix = new String(); + String location = "vminecraftusers.txt"; + //Try to apply what we can + try { + Scanner scanner = new Scanner(new File(location)); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + if (line.startsWith("#") || line.equals("") || line.startsWith("")) { + continue; + } + String[] split = line.split(":"); + if (!split[0].equalsIgnoreCase(player.getName())) { + continue; + } + nickName = (split[1].split(",").toString()); + + if (split.length >= 4) { + tag = (split[3]); + } + + //Add all the ignored people to the player's ignore list + if (split.length >= 5) { + for(String name : split[4].split(",")) + ignoreList.add(etc.getServer().getPlayer(name)); + } + if (split.length >= 6) { + //Loop through all the aliases + for(String alias : split[5].split(",")) + { + //Break apart the two parts of the alias + String[] parts = alias.split("@"); + if(parts.length > 1) + { + //Get the arguments for the alias if there are any + String[] command = parts[1].split(" "); + String[] args = null; + if(command.length > 1) + System.arraycopy(command, 1, args, 0, command.length - 2); + + //Register the alias to the player's aliasList + aliasList.registerAlias(parts[0], command[0], args); + } + } + } + } + scanner.close(); + } catch (Exception e) { + log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); + } } //===================================================================== From 3a85abadfa3bb5602232d7a8a7fad23b5828a8ec Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 13:42:59 -0800 Subject: [PATCH 66/82] save() added to PlayerProfile, won't compile as is. But this should do the trick for us. --- vMinecraftUsers.java | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index 8a591e516..ce9e93364 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -104,7 +104,7 @@ public class vMinecraftUsers { //Author: cerevisiae //===================================================================== class PlayerList -{ +{ ArrayList players; //===================================================================== @@ -235,6 +235,33 @@ class PlayerList } catch (Exception e) { log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); } + //===================================================================== + // Function: save + // Input: none + // Output: Writes current values of PlayerProfile to disk + // Use: Call this function to save current values + //===================================================================== + public void save(){ + try { + String location = "vminecraftusers.txt"; + BufferedWriter bw = new BufferedWriter(new FileWriter(location, true)); + Scanner scanner = new Scanner(new File(location)); + while (scanner.hasNextLine()) { + String line = scanner.nextLine(); + if (line.startsWith("#") || line.equals("") || line.startsWith("")) { + continue; + } + String[] split = line.split(":"); + if (!split[0].equalsIgnoreCase(playerName.toString())) { + continue; + } + bw.write(playerName + ":" + nickName + ":" + suffix + ":" + tag + ":" + ignoreList + ":" + aliasList); + } + scanner.close(); + } catch (Exception e) { + String location = "vminecraftusers.txt"; + log.log(Level.SEVERE, "Exception while writing to " + location + " (Are you sure you formatted it correctly?)", e); + } } //===================================================================== From c92e434389c2b9d654e2596d4f465228cad086e0 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Thu, 2 Dec 2010 15:46:50 -0600 Subject: [PATCH 67/82] Minor fix --- vMinecraftChat.java | 1 - vMinecraftUsers.java | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/vMinecraftChat.java b/vMinecraftChat.java index c3721001c..541d26184 100644 --- a/vMinecraftChat.java +++ b/vMinecraftChat.java @@ -32,7 +32,6 @@ public class vMinecraftChat { //===================================================================== public static void sendMessage(Player sender, Player receiver, String msg){ String[] message = applyColors(wordWrap(msg)); - if for(String out : message) receiver.sendMessage(out + " "); } diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index ce9e93364..7e1a95054 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -235,11 +235,14 @@ class PlayerList } catch (Exception e) { log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); } - //===================================================================== + } + + //===================================================================== // Function: save // Input: none - // Output: Writes current values of PlayerProfile to disk - // Use: Call this function to save current values + // Output: None + // Use: Writes current values of PlayerProfile to disk + // Call this function to save current values //===================================================================== public void save(){ try { From 83f1ed4a8f40cadf10986260aa2e013065a6f0fb Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 14:13:23 -0800 Subject: [PATCH 68/82] Fix for ezmodo, removed ezHealth --- vMinecraftCommands.java | 1 - vMinecraftListener.java | 8 +++----- vMinecraftSettings.java | 6 ++---- vMinecraftUsers.java | 2 ++ 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/vMinecraftCommands.java b/vMinecraftCommands.java index 2cff35139..f8e83d82c 100644 --- a/vMinecraftCommands.java +++ b/vMinecraftCommands.java @@ -489,7 +489,6 @@ public class vMinecraftCommands{ player.sendMessage(Colors.LightBlue + "Easy Mode ga yurusareru no wa shougakusei made dayo ne"); player.sendMessage(Colors.Red + "**Laughter**"); vMinecraftSettings.getInstance().addEzModo(player.getName()); - player.setHealth(vMinecraftSettings.getInstance().ezModoHealth()); } return EXIT_SUCCESS; } diff --git a/vMinecraftListener.java b/vMinecraftListener.java index 0318de5ae..3abb80a1e 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -80,11 +80,9 @@ public class vMinecraftListener extends PluginListener { //Use: Checks for exploits and runs the commands //===================================================================== public boolean onHealthChange(Player player,int oldValue,int newValue){ - if (player.getHealth() != vMinecraftSettings.getInstance().ezModoHealth() - && vMinecraftSettings.getInstance().isEzModo(player.getName())) { - player.setHealth(vMinecraftSettings.getInstance().ezModoHealth()); - - } + if (vMinecraftSettings.getInstance().isEzModo(player.getName())) { + return oldValue > newValue; + } else if (vMinecraftSettings.getInstance().globalmessages() && player.getHealth() < 1) { vMinecraftChat.gmsg(player, Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); } diff --git a/vMinecraftSettings.java b/vMinecraftSettings.java index 71f4c26ea..9679f1910 100644 --- a/vMinecraftSettings.java +++ b/vMinecraftSettings.java @@ -40,8 +40,7 @@ public class vMinecraftSettings { static ArrayList ezModo = new ArrayList(); //An array of players currently toggled for admin chat static ArrayList adminChatList = new ArrayList(); - //The max health for ezModo - static int ezHealth = 30; + private PropertiesFile properties; String file = "vminecraft.properties"; @@ -144,7 +143,7 @@ public class vMinecraftSettings { for(String ezName : tempEz) ezModo.add(ezName); - ezHealth = properties.getInt("ezHealth"); + log.log(Level.INFO, "vminecraft plugin successfully loaded"); @@ -192,7 +191,6 @@ public class vMinecraftSettings { 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 int ezModoHealth() {return ezHealth;} public String ezModoList() {return ezModo.toString();} //Random death message method diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index ce9e93364..cded3212a 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -264,6 +264,7 @@ class PlayerList } } + //===================================================================== //Function: getPlayer //Input: None @@ -368,3 +369,4 @@ class PlayerList } } + From 0c96c140458f5e3caca717b876ecf786d5e24a3a Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 14:27:36 -0800 Subject: [PATCH 69/82] Death messages are fixed now. --- vMinecraftListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vMinecraftListener.java b/vMinecraftListener.java index 3abb80a1e..14a017e21 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -83,7 +83,7 @@ public class vMinecraftListener extends PluginListener { if (vMinecraftSettings.getInstance().isEzModo(player.getName())) { return oldValue > newValue; } - else if (vMinecraftSettings.getInstance().globalmessages() && player.getHealth() < 1) { + if (vMinecraftSettings.getInstance().globalmessages() && newValue < 1) { vMinecraftChat.gmsg(player, Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); } return false; From f99bb09d4471f89d853f213df592dad262e757ee Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 14:34:03 -0800 Subject: [PATCH 70/82] Updated --- TODO | 1 + 1 file changed, 1 insertion(+) diff --git a/TODO b/TODO index fbe70fb90..7f6defcea 100644 --- a/TODO +++ b/TODO @@ -26,6 +26,7 @@ Vminecraft b8 Todo: We should definitely add suffixes to /modify at least DONE + + Fixed death messages and ezModo + Quick recode of /me to use the new getName function + /a to toggle admin chat + Code was organized From d3aff7d2d69e54ebce00aa2e37cfdc6f5dfc65e0 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 17:25:02 -0800 Subject: [PATCH 71/82] Setting up the foundation for specific death messages. This version will post information on attacker/defender entity IDs and dmg amount to the server console. --- vMinecraftListener.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vMinecraftListener.java b/vMinecraftListener.java index 14a017e21..a004079e3 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -6,6 +6,9 @@ import java.util.logging.Logger; //Author: nossr50, TrapAlice, cerevisiae //===================================================================== public class vMinecraftListener extends PluginListener { + public int bAttacker; + public int bDefender; + public int bAmount; protected static final Logger log = Logger.getLogger("Minecraft"); //===================================================================== @@ -92,5 +95,12 @@ public class vMinecraftListener extends PluginListener { public void onLogin(Player player){ vMinecraftUsers.addUser(player); } + public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { + bAttacker = attacker.getId(); + bDefender = defender.getId(); + bAmount = amount; + log.log(Level.INFO, "Attacker ID: " + bAttacker + ", Defender ID: " + bDefender + ", Amount: " + bAmount); + return false; + } } \ No newline at end of file From 41c9feb13e2f7a06f87ab043fea264e0b476a6bd Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 18:13:19 -0800 Subject: [PATCH 72/82] Fixed onDamage to report damagetypes to a public int. --- vMinecraftListener.java | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/vMinecraftListener.java b/vMinecraftListener.java index a004079e3..f15483729 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -6,9 +6,7 @@ import java.util.logging.Logger; //Author: nossr50, TrapAlice, cerevisiae //===================================================================== public class vMinecraftListener extends PluginListener { - public int bAttacker; - public int bDefender; - public int bAmount; + public int damagetype; protected static final Logger log = Logger.getLogger("Minecraft"); //===================================================================== @@ -96,11 +94,20 @@ public class vMinecraftListener extends PluginListener { vMinecraftUsers.addUser(player); } public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { - bAttacker = attacker.getId(); - bDefender = defender.getId(); - bAmount = amount; - log.log(Level.INFO, "Attacker ID: " + bAttacker + ", Defender ID: " + bDefender + ", Amount: " + bAmount); - return false; + if(type == type.CREEPER_EXPLOSION){ + damagetype = 1; //Creeper + } else if(type == type.FALL){ + damagetype = 2; //Fall + } else if(type == type.FIRE){ + damagetype = 3; //Fire going to make it share with firetick since its similar + } else if (type == type.FIRE_TICK){ + damagetype = 4; //Firetick + } else if (type == type.LAVA){ + damagetype = 5; //Lava + } else if (type == type.WATER){ + damagetype = 6; //Water + } + return false; } } \ No newline at end of file From f26f5cca733bc7c430927811c5052deb85f47271 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 18:27:04 -0800 Subject: [PATCH 73/82] Early version of specific death messages, needs testing. --- vMinecraftListener.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/vMinecraftListener.java b/vMinecraftListener.java index f15483729..78c4e47e2 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -84,11 +84,26 @@ public class vMinecraftListener extends PluginListener { if (vMinecraftSettings.getInstance().isEzModo(player.getName())) { return oldValue > newValue; } + //These are place holders until I make random messages for everything and also to see if these work correctly if (vMinecraftSettings.getInstance().globalmessages() && newValue < 1) { + if (damagetype == 1){ + vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " was blown to bits by a creeper"); + } else if (damagetype == 2) { + vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " fell to death!"); + } else if (damagetype ==3){ + vMinecraftChat.gmsg(player, player.getName() + Colors.Red + " was incinerated"); + } else if (damagetype == 4){ + vMinecraftChat.gmsg(player, Colors.Red + " Stop drop and roll, not scream, run, and burn " + player.getName()); + } else if (damagetype == 5){ + vMinecraftChat.gmsg(player, Colors.Red + player.getName() + " drowned in lava"); + } else if (damagetype == 6){ + vMinecraftChat.gmsg(player, Colors.Blue + player.getName() + " should've attended that swimming class"); + } else { vMinecraftChat.gmsg(player, Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); - } - return false; + } } + return false; + } public void onLogin(Player player){ vMinecraftUsers.addUser(player); From aa3cb69fe852eeaaf8c84dd965c059033e155f93 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 19:03:54 -0800 Subject: [PATCH 74/82] Revisions to how onDamage works --- vMinecraftListener.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/vMinecraftListener.java b/vMinecraftListener.java index 78c4e47e2..e96c0ed67 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -109,6 +109,9 @@ public class vMinecraftListener extends PluginListener { vMinecraftUsers.addUser(player); } public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { + Player player; + for(Player p : etc.getServer().getPlayerList()){ + if (p.getId() == defender.getId() && p.getHealth() < 1){ if(type == type.CREEPER_EXPLOSION){ damagetype = 1; //Creeper } else if(type == type.FALL){ @@ -122,6 +125,8 @@ public class vMinecraftListener extends PluginListener { } else if (type == type.WATER){ damagetype = 6; //Water } + } + } return false; } From 8899f2d4c4a929d4f6b8e1982456d507027b0589 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 19:09:35 -0800 Subject: [PATCH 75/82] Revisions to onDamage v2 --- vMinecraftListener.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/vMinecraftListener.java b/vMinecraftListener.java index e96c0ed67..f6ddd5b28 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -109,9 +109,7 @@ public class vMinecraftListener extends PluginListener { vMinecraftUsers.addUser(player); } public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { - Player player; - for(Player p : etc.getServer().getPlayerList()){ - if (p.getId() == defender.getId() && p.getHealth() < 1){ + if(defender.isPlayer()){ if(type == type.CREEPER_EXPLOSION){ damagetype = 1; //Creeper } else if(type == type.FALL){ @@ -124,8 +122,7 @@ public class vMinecraftListener extends PluginListener { damagetype = 5; //Lava } else if (type == type.WATER){ damagetype = 6; //Water - } - } + } } return false; } From f521bd6fe957ba6421b9f647e263157c30f877dc Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 19:34:35 -0800 Subject: [PATCH 76/82] Added checks for pvp in death messages --- vMinecraftListener.java | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/vMinecraftListener.java b/vMinecraftListener.java index f6ddd5b28..4bbfccae3 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -109,7 +109,9 @@ public class vMinecraftListener extends PluginListener { vMinecraftUsers.addUser(player); } public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { - if(defender.isPlayer()){ + if(defender.isPlayer() && !attacker.isPlayer()){ + Player player = (Player)defender; + if(player.getHealth() < 1) { if(type == type.CREEPER_EXPLOSION){ damagetype = 1; //Creeper } else if(type == type.FALL){ @@ -122,7 +124,31 @@ public class vMinecraftListener extends PluginListener { damagetype = 5; //Lava } else if (type == type.WATER){ damagetype = 6; //Water - } + } else{ + damagetype = 0; + } + if (defender.isPlayer() && attacker.isPlayer()) { + Player pAttacker = (Player)attacker; + Player pDefender = (Player)defender; + damagetype = 0; + vMinecraftChat.gmsg(player, pAttacker.getName() + " has murdered " + pDefender.getName()); + } + if (damagetype == 1 && !attacker.isPlayer()){ + vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " was blown to bits by a creeper"); + } else if (damagetype == 2) { + vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " fell to death!"); + } else if (damagetype ==3){ + vMinecraftChat.gmsg(player, player.getName() + Colors.Red + " was incinerated"); + } else if (damagetype == 4){ + vMinecraftChat.gmsg(player, Colors.Red + " Stop drop and roll, not scream, run, and burn " + player.getName()); + } else if (damagetype == 5){ + vMinecraftChat.gmsg(player, Colors.Red + player.getName() + " drowned in lava"); + } else if (damagetype == 6){ + vMinecraftChat.gmsg(player, Colors.Blue + player.getName() + " should've attended that swimming class"); + } else { + vMinecraftChat.gmsg(player, Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); + } + } } return false; } From 278c24650a7155fd433f3b7f30332359cf1a9faf Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 19:46:21 -0800 Subject: [PATCH 77/82] Further revisions, moved death messages to onDamager. --- vMinecraftListener.java | 42 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/vMinecraftListener.java b/vMinecraftListener.java index 4bbfccae3..fa2c9a993 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -6,7 +6,6 @@ import java.util.logging.Logger; //Author: nossr50, TrapAlice, cerevisiae //===================================================================== public class vMinecraftListener extends PluginListener { - public int damagetype; protected static final Logger log = Logger.getLogger("Minecraft"); //===================================================================== @@ -84,24 +83,6 @@ public class vMinecraftListener extends PluginListener { if (vMinecraftSettings.getInstance().isEzModo(player.getName())) { return oldValue > newValue; } - //These are place holders until I make random messages for everything and also to see if these work correctly - if (vMinecraftSettings.getInstance().globalmessages() && newValue < 1) { - if (damagetype == 1){ - vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " was blown to bits by a creeper"); - } else if (damagetype == 2) { - vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " fell to death!"); - } else if (damagetype ==3){ - vMinecraftChat.gmsg(player, player.getName() + Colors.Red + " was incinerated"); - } else if (damagetype == 4){ - vMinecraftChat.gmsg(player, Colors.Red + " Stop drop and roll, not scream, run, and burn " + player.getName()); - } else if (damagetype == 5){ - vMinecraftChat.gmsg(player, Colors.Red + player.getName() + " drowned in lava"); - } else if (damagetype == 6){ - vMinecraftChat.gmsg(player, Colors.Blue + player.getName() + " should've attended that swimming class"); - } else { - vMinecraftChat.gmsg(player, Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); - } - } return false; } @@ -109,10 +90,12 @@ public class vMinecraftListener extends PluginListener { vMinecraftUsers.addUser(player); } public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { - if(defender.isPlayer() && !attacker.isPlayer()){ - Player player = (Player)defender; - if(player.getHealth() < 1) { - if(type == type.CREEPER_EXPLOSION){ + if(defender.isPlayer()){ + int damagetype = 0; //Set to 0 to begin with + Player player = (Player)defender; + if(defender.isPlayer() && player.getHealth() < 1 && !attacker.isPlayer()) + { + if (type == type.CREEPER_EXPLOSION) { damagetype = 1; //Creeper } else if(type == type.FALL){ damagetype = 2; //Fall @@ -124,16 +107,19 @@ public class vMinecraftListener extends PluginListener { damagetype = 5; //Lava } else if (type == type.WATER){ damagetype = 6; //Water - } else{ - damagetype = 0; } + } if (defender.isPlayer() && attacker.isPlayer()) { Player pAttacker = (Player)attacker; Player pDefender = (Player)defender; - damagetype = 0; - vMinecraftChat.gmsg(player, pAttacker.getName() + " has murdered " + pDefender.getName()); + if(pDefender.getHealth() < 1){ + damagetype =0; //Reset damagetype to 0 + vMinecraftChat.gmsg(player, pAttacker.getName() + " has murdered " + pDefender.getName()); + } + } - if (damagetype == 1 && !attacker.isPlayer()){ + if (player.getHealth() < 1 && !attacker.isPlayer()) { + if (damagetype == 1){ vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " was blown to bits by a creeper"); } else if (damagetype == 2) { vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " fell to death!"); From 8b3f83941fe4190ac8da2824210c7c4f63371f9a Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 19:57:08 -0800 Subject: [PATCH 78/82] Moved the damagetype int declarations after the check to see if the attacker is not a player. --- vMinecraftListener.java | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/vMinecraftListener.java b/vMinecraftListener.java index fa2c9a993..0415dbeaa 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -91,10 +91,15 @@ public class vMinecraftListener extends PluginListener { } public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { if(defender.isPlayer()){ - int damagetype = 0; //Set to 0 to begin with - Player player = (Player)defender; - if(defender.isPlayer() && player.getHealth() < 1 && !attacker.isPlayer()) - { + int damagetype = 0; //Set to 0 to begin with + Player player = (Player)defender; + if (attacker.isPlayer()) { + Player pAttacker = (Player)attacker; + if(player.getHealth() < 1){ + vMinecraftChat.gmsg(player, pAttacker.getName() + " has murdered " + player.getName()); + } + } + if (player.getHealth() < 1 && !attacker.isPlayer()) { if (type == type.CREEPER_EXPLOSION) { damagetype = 1; //Creeper } else if(type == type.FALL){ @@ -108,18 +113,6 @@ public class vMinecraftListener extends PluginListener { } else if (type == type.WATER){ damagetype = 6; //Water } - } - if (defender.isPlayer() && attacker.isPlayer()) { - Player pAttacker = (Player)attacker; - Player pDefender = (Player)defender; - if(pDefender.getHealth() < 1){ - damagetype =0; //Reset damagetype to 0 - vMinecraftChat.gmsg(player, pAttacker.getName() + " has murdered " + pDefender.getName()); - } - - } - if (player.getHealth() < 1 && !attacker.isPlayer()) { - if (damagetype == 1){ vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " was blown to bits by a creeper"); } else if (damagetype == 2) { vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " fell to death!"); @@ -134,7 +127,6 @@ public class vMinecraftListener extends PluginListener { } else { vMinecraftChat.gmsg(player, Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); } - } } return false; } From c518cfdc83c4def375d755b652376135c18bb298 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 19:58:29 -0800 Subject: [PATCH 79/82] Whoops --- vMinecraftListener.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vMinecraftListener.java b/vMinecraftListener.java index 0415dbeaa..76c6c0450 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -113,6 +113,8 @@ public class vMinecraftListener extends PluginListener { } else if (type == type.WATER){ damagetype = 6; //Water } + } + if(damagetype == 1){ vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " was blown to bits by a creeper"); } else if (damagetype == 2) { vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " fell to death!"); From 2fdd930db1604533a65bcef5480fd164737635d8 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 20:10:28 -0800 Subject: [PATCH 80/82] Latest version, just doesn't seem to work for player damage though. --- vMinecraftListener.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/vMinecraftListener.java b/vMinecraftListener.java index 76c6c0450..d700e1906 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -113,20 +113,34 @@ public class vMinecraftListener extends PluginListener { } else if (type == type.WATER){ damagetype = 6; //Water } - } + //This should trigger the player death message + } else if (player.getHealth() < 1 && attacker.isPlayer()){ + damagetype = 7; //Player + } if(damagetype == 1){ vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " was blown to bits by a creeper"); + damagetype = 0; } else if (damagetype == 2) { vMinecraftChat.gmsg(player,player.getName() + Colors.Red + " fell to death!"); + damagetype = 0; } else if (damagetype ==3){ vMinecraftChat.gmsg(player, player.getName() + Colors.Red + " was incinerated"); + damagetype = 0; } else if (damagetype == 4){ vMinecraftChat.gmsg(player, Colors.Red + " Stop drop and roll, not scream, run, and burn " + player.getName()); + damagetype = 0; } else if (damagetype == 5){ vMinecraftChat.gmsg(player, Colors.Red + player.getName() + " drowned in lava"); + damagetype = 0; } else if (damagetype == 6){ vMinecraftChat.gmsg(player, Colors.Blue + player.getName() + " should've attended that swimming class"); - } else { + damagetype = 0; + } else if (damagetype == 7){ + Player pAttacker = (Player)attacker; + vMinecraftChat.gmsg(player, pAttacker.getName() + " has murdered " + player.getName()); + damagetype = 0; + } + else { vMinecraftChat.gmsg(player, Colors.Gray + player.getName() + " " + vMinecraftSettings.randomDeathMsg()); } } From a8f544a3417ba2edcde42da545b43513f532ae53 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Thu, 2 Dec 2010 20:14:30 -0800 Subject: [PATCH 81/82] Can't remember --- vMinecraftListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vMinecraftListener.java b/vMinecraftListener.java index d700e1906..25965391f 100644 --- a/vMinecraftListener.java +++ b/vMinecraftListener.java @@ -6,6 +6,7 @@ import java.util.logging.Logger; //Author: nossr50, TrapAlice, cerevisiae //===================================================================== public class vMinecraftListener extends PluginListener { + public int damagetype; protected static final Logger log = Logger.getLogger("Minecraft"); //===================================================================== @@ -91,7 +92,6 @@ public class vMinecraftListener extends PluginListener { } public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker, BaseEntity defender, int amount) { if(defender.isPlayer()){ - int damagetype = 0; //Set to 0 to begin with Player player = (Player)defender; if (attacker.isPlayer()) { Player pAttacker = (Player)attacker; From 42c7688c1a2732be987c2f7a469580d6adfb47cc Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Tue, 7 Dec 2010 22:00:32 -0600 Subject: [PATCH 82/82] Added /msg and /reply --- vMinecraftChat.java | 2 +- vMinecraftCommands.java | 65 ++++++++++++++++++- vMinecraftUsers.java | 134 ++++++++++++++++++++++++++-------------- 3 files changed, 151 insertions(+), 50 deletions(-) diff --git a/vMinecraftChat.java b/vMinecraftChat.java index 495d43448..c0dab6a04 100644 --- a/vMinecraftChat.java +++ b/vMinecraftChat.java @@ -61,7 +61,7 @@ public class vMinecraftChat { //Loop through the words finding their length and increasing //j, the end point for the sub string - while(len <= lineLength && !split.isEmpty()) + while(split.get(0) != null && len <= lineLength && !split.isEmpty()) { int wordLength = msgLength(split.get(0)) + 4; diff --git a/vMinecraftCommands.java b/vMinecraftCommands.java index 8322821f6..b218cca64 100644 --- a/vMinecraftCommands.java +++ b/vMinecraftCommands.java @@ -44,7 +44,11 @@ public class vMinecraftCommands{ cl.register("/a", "adminChatToggle", "toggle admin chat for every message"); cl.register("/modify", "modifySplit"); cl.register("/me", "me"); + cl.register("/msg", "message"); + cl.register("/reply", "reply"); cl.registerAlias("/playerlist", "/who"); + cl.registerAlias("/r", "/reply"); + cl.registerAlias("/w", "/msg"); cl.registerAlias("/wrists", "/suicide"); cl.registerAlias("/ci", "/clearinventory"); } @@ -62,6 +66,65 @@ public class vMinecraftCommands{ vMinecraftChat.emote(player, str); return EXIT_SUCCESS; } + + //===================================================================== + //Function: message (/msg, /w, /whisper) + //Input: Player player: The player using the command + //Output: int: Exit Code + //Use: Send a message to a player + //===================================================================== + public static int message(Player player, String[] args) + { + String msg = etc.combineSplit(1, args, " "); + Player toPlayer = etc.getServer().matchPlayer(args[0]); + if (args.length < 1) { + return EXIT_FAIL; + } else if (toPlayer != null) { + //Send the message to the targeted player and the sender + vMinecraftChat.sendMessage(player, toPlayer, + Colors.LightGreen + "[" + Colors.White + "From:" + + vMinecraftChat.getName(player) + Colors.LightGreen + "]" + msg); + vMinecraftChat.sendMessage(player, player, + Colors.LightGreen + "[" + Colors.White + "To:" + + vMinecraftChat.getName(toPlayer) + Colors.LightGreen + "]" + msg); + //Set the last massager for each player + vMinecraftUsers.players.findProfile(player).setMessage(toPlayer); + vMinecraftUsers.players.findProfile(toPlayer).setMessage(player); + } else { + vMinecraftChat.sendMessage(player, player, Colors.Red + + "No player by the name of " + args[0] + " could be found."); + } + return EXIT_SUCCESS; + } + + //===================================================================== + //Function: reply (/r, /reply) + //Input: Player player: The player using the command + //Output: int: Exit Code + //Use: Send a message to a player + //===================================================================== + public static int reply(Player player, String[] args) + { + Player toPlayer = vMinecraftUsers.players.findProfile(player).getMessage(); + if (toPlayer != null) { + String msg = etc.combineSplit(1, args, " "); + //Send the message to the targeted player and the sender + vMinecraftChat.sendMessage(player, toPlayer, + Colors.LightGreen + "[" + Colors.White + "From:" + + vMinecraftChat.getName(player) + Colors.LightGreen + "] " + msg); + vMinecraftChat.sendMessage(player, player, + Colors.LightGreen + "[" + Colors.White + "To:" + + vMinecraftChat.getName(toPlayer) + Colors.LightGreen + "] " + msg); + + //Set the last messager for each player + vMinecraftUsers.players.findProfile(player).setMessage(toPlayer); + vMinecraftUsers.players.findProfile(toPlayer).setMessage(player); + } else { + vMinecraftChat.sendMessage(player, player, + Colors.Red + "That person is no longer logged in."); + } + return EXIT_SUCCESS; + } //===================================================================== //Function: adminChatToggle (/a) @@ -523,7 +586,7 @@ public class vMinecraftCommands{ { //Exploit fix for people giving themselves commands if(args[1].equals("commands")) - return EXIT_FAIL; + return EXIT_SUCCESS; return EXIT_CONTINUE; } diff --git a/vMinecraftUsers.java b/vMinecraftUsers.java index 40b383376..9b12ab477 100644 --- a/vMinecraftUsers.java +++ b/vMinecraftUsers.java @@ -11,7 +11,7 @@ public class vMinecraftUsers { private PropertiesFile properties; String location = "vminecraftusers.txt"; - ArrayList players = new ArrayList(); + public static PlayerList players = new PlayerList(); public void loadUsers(){ @@ -143,11 +143,11 @@ class PlayerList //Output: PlayerProfile: The profile of the specified player //Use: Get the profile for the specified player //===================================================================== - private PlayerProfile findProfile(Player player) + public PlayerProfile findProfile(Player player) { for(PlayerProfile ply : players) { - if(ply.getPlayer().equals(player)) + if(ply.isPlayer(player)) return ply; } return null; @@ -161,10 +161,11 @@ class PlayerList class PlayerProfile { protected final Logger log = Logger.getLogger("Minecraft"); - private Player playerName; - private String nickName; - private String tag; - private String suffix; + private String playerName, + lastMessage, + nickName, + tag, + suffix; private ArrayList ignoreList; private commandList aliasList; @@ -181,13 +182,14 @@ class PlayerList //===================================================================== public PlayerProfile(Player player) { - //Declare things - ignoreList = new ArrayList(); - aliasList = new commandList(); + //Declare things nickName = new String(); tag = new String(); suffix = new String(); + ignoreList = new ArrayList(); + aliasList = new commandList(); String location = "vminecraftusers.txt"; + //Try to apply what we can try { Scanner scanner = new Scanner(new File(location)); @@ -197,43 +199,55 @@ class PlayerList continue; } String[] split = line.split(":"); - if (!split[0].equalsIgnoreCase(player.getName())) { - continue; - } - nickName = (split[1].split(",").toString()); - - if (split.length >= 4) { - tag = (split[3]); - } - - //Add all the ignored people to the player's ignore list - if (split.length >= 5) { - for(String name : split[4].split(",")) - ignoreList.add(etc.getServer().getPlayer(name)); - } - if (split.length >= 6) { - //Loop through all the aliases - for(String alias : split[5].split(",")) - { - //Break apart the two parts of the alias - String[] parts = alias.split("@"); - if(parts.length > 1) - { - //Get the arguments for the alias if there are any - String[] command = parts[1].split(" "); - String[] args = null; - if(command.length > 1) - System.arraycopy(command, 1, args, 0, command.length - 2); - - //Register the alias to the player's aliasList - aliasList.registerAlias(parts[0], command[0], args); - } - } + + //If the player name is equal to the name in the list + if (split.length > 0 && split[0].equalsIgnoreCase(player.getName())) { + + //Get the tag from the 1st split + nickName = (split[1].split(",").toString()); + + //Get the tag from the 2nd split + suffix = split[2]; + + //Get the tag from the 3rd split + if (split.length >= 4) { + tag = (split[3]); + } + + //Add all the ignored people to the player's ignore list + if (split.length >= 5) { + for(String name : split[4].split(",")) + ignoreList.add(etc.getServer().getPlayer(name)); + } + + //Get the alias list, from the 5th split + if (split.length >= 6) { + //Loop through all the aliases + for(String alias : split[5].split(",")) + { + //Break apart the two parts of the alias + String[] parts = alias.split("@"); + if(parts.length > 1) + { + //Get the arguments for the alias if there are any + String[] command = parts[1].split(" "); + String[] args = null; + if(command.length > 1) + System.arraycopy(command, 1, args, + 0, command.length - 2); + + //Register the alias to the player's aliasList + aliasList.registerAlias(parts[0], command[0], args); + } + } + } + break; } } scanner.close(); } catch (Exception e) { - log.log(Level.SEVERE, "Exception while reading " + location + " (Are you sure you formatted it correctly?)", e); + log.log(Level.SEVERE, "Exception while reading " + + location + " (Are you sure you formatted it correctly?)", e); } } @@ -255,7 +269,7 @@ class PlayerList continue; } String[] split = line.split(":"); - if (!split[0].equalsIgnoreCase(playerName.toString())) { + if (!split[0].equalsIgnoreCase(playerName)) { continue; } bw.write(playerName + ":" + nickName + ":" + suffix + ":" + tag + ":" + ignoreList + ":" + aliasList); @@ -267,14 +281,16 @@ class PlayerList } } - //===================================================================== - //Function: getPlayer + //Function: isPlayer //Input: None //Output: Player: The player this profile belongs to - //Use: Finds if the specified player is in the ignore list + //Use: Finds if this profile belongs to a specified player //===================================================================== - public Player getPlayer(){return playerName;} + public boolean isPlayer(Player player) + { + return player.getName().equals(playerName); + } //===================================================================== //Function: isIgnored @@ -369,6 +385,28 @@ class PlayerList //Use: Gets a player tag //===================================================================== public String getTag() { return tag; } + + //===================================================================== + //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() + { + + return etc.getServer().matchPlayer(lastMessage); + } } }