From e5d012c2eca5031a2d7914aff5912edcc00369d8 Mon Sep 17 00:00:00 2001 From: cerevisiae Date: Sun, 28 Nov 2010 19:30:34 -0600 Subject: [PATCH] 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);}