Added settings for stopFire, stopTnt, added hooks for onIgnite and onExplode.

Signed-off-by: nossr50 <nossr50@gmail.com>
This commit is contained in:
cerevisiae 2010-11-28 19:30:34 -06:00 committed by nossr50
parent 343c170d59
commit e5d012c2ec
4 changed files with 125 additions and 78 deletions

View File

@ -1,8 +1,6 @@
import java.awt.Color;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
@ -37,6 +35,7 @@ public class vminecraftCommands{
cl.register("/slay", "slay", "Kill target player"); cl.register("/slay", "slay", "Kill target player");
cl.register("/ezmodo", "invuln", "Toggle invulnerability"); cl.register("/ezmodo", "invuln", "Toggle invulnerability");
cl.register("/ezlist", "ezlist", "List invulnerable players"); cl.register("/ezlist", "ezlist", "List invulnerable players");
cl.registerAlias("/playerlist", "/who");
} }
@ -165,12 +164,7 @@ public class vminecraftCommands{
//===================================================================== //=====================================================================
public static boolean reload(Player player, String[] args) public static boolean reload(Player player, String[] args)
{ {
//Should only reload vminecraft settings if the player is able to use /reload vminecraftSettings.getInstance().loadSettings();
try {
vminecraftSettings.getInstance().loadSettings();
} catch (IOException e) {
log.log(Level.SEVERE, "Exception while loading settings", e);
}
return true; return true;
} }
@ -630,27 +624,60 @@ class commandList {
//===================================================================== //=====================================================================
public boolean registerAlias(String name, String com, String[] args){ 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 the command list isn't empty
if(commands.length > 0) 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 //Create a new temp array
command[] temp = new command[commands.length]; command[] temp = new command[commands.length + 1];
//Copy the old command list over //Copy the old command list over
System.arraycopy(commands, 0, temp, 0, commands.length); System.arraycopy(commands, 0, temp, 0, commands.length);
//Set commands to equal the new array //Set commands to equal the new array
commands = temp; 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 //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 //exit successfully
return true; return true;
@ -668,18 +695,19 @@ class commandList {
return false; return false;
} }
//Search for the command //Search for the command
for(int i = 0; i < commands.length; i++) for(command cmd : commands)
{ {
//When found //When found
if(commands[i].getName().equalsIgnoreCase(name)) if(cmd.getName().equalsIgnoreCase(name))
{ {
try { try {
//Call the command and return results //Call the command and return results
return commands[i].call(player, arg); return cmd.call(player, arg);
} catch (SecurityException e) { } catch (SecurityException e) {
log.log(Level.SEVERE, "Exception while running command", e); log.log(Level.SEVERE, "Exception while running command", e);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
log.log(Level.SEVERE, "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 //Output: String: The command name
//Use: Returns the command name //Use: Returns the command name
//===================================================================== //=====================================================================
public String getName(){ public String getName(){return commandName;}
return commandName;
}
//===================================================================== //=====================================================================
@ -726,25 +752,26 @@ class commandList {
//Output: boolean: If the command was called successfully //Output: boolean: If the command was called successfully
//Use: Attempts to call the command //Use: Attempts to call the command
//===================================================================== //=====================================================================
public boolean call(Player player, String[] arg) boolean call(Player player, String[] arg)
{ {
try {
Method m = vminecraftCommands.class.getMethod(function, Player.class, String[].class); Method m;
m.setAccessible(true); try {
return (Boolean) m.invoke(null, player, arg); m = vminecraftCommands.class.getMethod(function, Player.class, String[].class);
m.setAccessible(true);
} catch (SecurityException e) { return (Boolean) m.invoke(null, player, arg);
log.log(Level.SEVERE, "Exception while running command", e); } catch (SecurityException e) {
} catch (NoSuchMethodException e) { e.printStackTrace();
log.log(Level.SEVERE, "Exception while running command", e); } catch (NoSuchMethodException e) {
} catch (IllegalArgumentException e) { e.printStackTrace();
log.log(Level.SEVERE, "Exception while running command", e); } catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) { e.printStackTrace();
log.log(Level.SEVERE, "Exception while running command", e); } catch (IllegalAccessException e) {
} catch (InvocationTargetException e) { e.printStackTrace();
log.log(Level.SEVERE, "Exception while running command", e); } catch (InvocationTargetException e) {
} e.printStackTrace();
return true; }
return true;
} }
} }
@ -754,13 +781,14 @@ class commandList {
//Author: cerevisiae //Author: cerevisiae
//===================================================================== //=====================================================================
private class commandRef extends command{ private class commandRef extends command{
private String commandName;
private String reference; private String reference;
private String[] args; private String[] args;
//===================================================================== //=====================================================================
//Function: command //Function: command
//Input: None //Input: String name: The command name
// String com: The command to run
// String[] arg: the arguments to apply
//Output: None //Output: None
//Use: Initialize the command //Use: Initialize the command
//===================================================================== //=====================================================================
@ -771,13 +799,16 @@ class commandList {
} }
//===================================================================== //=====================================================================
//Function: call //Function: command
//Input: None //Input: String name: The command name
//Output: String: The command name // String com: The command to run
//Use: Returns the command name //Output: None
//Use: Initialize the command
//===================================================================== //=====================================================================
public String getName(){ public commandRef(String name, String com){
return commandName; super(name, "");
reference = com;
args = null;
} }
@ -787,27 +818,35 @@ class commandList {
//Output: boolean: If the command was called successfully //Output: boolean: If the command was called successfully
//Use: Attempts to call the command //Use: Attempts to call the command
//===================================================================== //=====================================================================
public boolean call(String[] arg) boolean call(Player player, String[] arg)
{ {
//Insert the arguments into the pre-set arguments
String[] temp = args; String[] temp = args;
int lastSet = -1; if(args != null)
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]; //Insert the arguments into the pre-set arguments
System.arraycopy(temp, 0, temp2, 0, temp.length); int lastSet = -1;
System.arraycopy(arg, lastSet + 1, temp2, for(int i = 0; i < temp.length; i++)
temp.length, arg.length - lastSet); 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 //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; return true;
} }
} }

View File

@ -87,4 +87,5 @@ public class vminecraftListener extends PluginListener {
} }
return false; return false;
} }
} }

View File

@ -1,5 +1,3 @@
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
//===================================================================== //=====================================================================
@ -12,12 +10,7 @@ public class vminecraftPlugin extends Plugin {
protected static final Logger log = Logger.getLogger("Minecraft"); protected static final Logger log = Logger.getLogger("Minecraft");
public void enable() { public void enable() {
//Hopefully this will make the plugin load right away vminecraftSettings.getInstance().loadSettings();
try {
vminecraftSettings.getInstance().loadSettings();
} catch (IOException e) {
log.log(Level.SEVERE, "Exception while loading settings ", e);
}
vminecraftCommands.loadCommands(); 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. //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.CHAT, listener, this, PluginListener.Priority.MEDIUM);
etc.getLoader().addListener(PluginLoader.Hook.COMMAND, listener, this, PluginListener.Priority.HIGH); 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()){ 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);
} }

View File

@ -12,7 +12,7 @@ public class vminecraftSettings {
protected static final Logger log = Logger.getLogger("Minecraft"); protected static final Logger log = Logger.getLogger("Minecraft");
private static volatile vminecraftSettings instance; private static volatile vminecraftSettings instance;
//Invulnerability List //Invulnerability List
//The feature settings //The feature settings
static boolean toggle = true, static boolean toggle = true,
@ -31,6 +31,8 @@ public class vminecraftSettings {
globalmessages = false, globalmessages = false,
cmdSay = false, cmdSay = false,
cmdWho = false, cmdWho = false,
stopFire = false,
stopTnt = false,
cmdEzModo = false; cmdEzModo = false;
//An array of players currently in ezmodo //An array of players currently in ezmodo
@ -48,7 +50,7 @@ public class vminecraftSettings {
//Output: None //Output: None
//Use: Loads the settings from the properties //Use: Loads the settings from the properties
//===================================================================== //=====================================================================
public void loadSettings() throws IOException public void loadSettings()
{ {
File theDir = new File("vminecraft.properties"); File theDir = new File("vminecraft.properties");
if(!theDir.exists()){ if(!theDir.exists()){
@ -78,6 +80,8 @@ public class vminecraftSettings {
writer.write("cmdEzModo=true\r\n"); writer.write("cmdEzModo=true\r\n");
writer.write("ezModo=\r\n"); writer.write("ezModo=\r\n");
writer.write("ezHealth=30\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"); writer.write("rules=Rules@#1: No griefing@#2: No griefing\r\n");
} catch (Exception e) { } catch (Exception e) {
log.log(Level.SEVERE, "Exception while creating " + location, e); log.log(Level.SEVERE, "Exception while creating " + location, e);
@ -93,7 +97,11 @@ public class vminecraftSettings {
} else { } else {
properties = new PropertiesFile("vminecraft.properties"); properties = new PropertiesFile("vminecraft.properties");
properties.load(); try {
properties.load();
} catch (IOException e) {
e.printStackTrace();
}
} }
try { try {
@ -113,6 +121,8 @@ public class vminecraftSettings {
globalmessages = properties.getBoolean("globalmessages",true); globalmessages = properties.getBoolean("globalmessages",true);
cmdSay = properties.getBoolean("cmdSay",true); cmdSay = properties.getBoolean("cmdSay",true);
cmdEzModo = properties.getBoolean("cmdEzModo",true); cmdEzModo = properties.getBoolean("cmdEzModo",true);
stopFire = properties.getBoolean("stopFire",true);
stopTnt = properties.getBoolean("stopTNT",true);
rules = properties.getString("rules", "").split("@"); rules = properties.getString("rules", "").split("@");
String[] tempEz = properties.getString("ezModo").split(","); String[] tempEz = properties.getString("ezModo").split(",");
@ -155,6 +165,8 @@ public class vminecraftSettings {
public boolean cmdMasstp() {return cmdMasstp;} public boolean cmdMasstp() {return cmdMasstp;}
public boolean cmdEzModo() {return cmdEzModo;} public boolean cmdEzModo() {return cmdEzModo;}
public boolean cmdWho() {return cmdWho;} public boolean cmdWho() {return cmdWho;}
public boolean stopFire() {return stopFire;}
public boolean stopTnt() {return stopTnt;}
//EzModo functions //EzModo functions
public boolean isEzModo(String playerName) {return ezModo.contains(playerName);} public boolean isEzModo(String playerName) {return ezModo.contains(playerName);}