mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-25 06:36:45 +01:00
Fixed aliasing feature
This commit is contained in:
parent
343c170d59
commit
a32cb6058d
@ -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
|
|
||||||
try {
|
|
||||||
vminecraftSettings.getInstance().loadSettings();
|
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,23 +752,24 @@ 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)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Method m;
|
||||||
try {
|
try {
|
||||||
Method m = vminecraftCommands.class.getMethod(function, Player.class, String[].class);
|
m = vminecraftCommands.class.getMethod(function, Player.class, String[].class);
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
return (Boolean) m.invoke(null, player, arg);
|
return (Boolean) m.invoke(null, player, arg);
|
||||||
|
|
||||||
} catch (SecurityException e) {
|
} catch (SecurityException e) {
|
||||||
log.log(Level.SEVERE, "Exception while running command", e);
|
e.printStackTrace();
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (NoSuchMethodException e) {
|
||||||
log.log(Level.SEVERE, "Exception while running command", e);
|
e.printStackTrace();
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
log.log(Level.SEVERE, "Exception while running command", e);
|
e.printStackTrace();
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
log.log(Level.SEVERE, "Exception while running command", e);
|
e.printStackTrace();
|
||||||
} catch (InvocationTargetException e) {
|
} catch (InvocationTargetException e) {
|
||||||
log.log(Level.SEVERE, "Exception while running command", 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,16 +818,16 @@ 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;
|
||||||
|
if(args != null)
|
||||||
|
{
|
||||||
|
//Insert the arguments into the pre-set arguments
|
||||||
int lastSet = -1;
|
int lastSet = -1;
|
||||||
for(int i = 0; i < temp.length; i++)
|
for(int i = 0; i < temp.length; i++)
|
||||||
if(temp[i].startsWith("%"))
|
if(temp[i].startsWith("%"))
|
||||||
temp[i] = arg[lastSet = Integer.parseInt(temp[i].substring(1))];
|
temp[i] = arg[lastSet = Integer.parseInt(temp[i].substring(1))];
|
||||||
|
|
||||||
//Append the rest of the arguments to the argument array
|
//Append the rest of the arguments to the argument array
|
||||||
if(lastSet + 1 < arg.length)
|
if(lastSet + 1 < arg.length)
|
||||||
{
|
{
|
||||||
@ -805,9 +836,17 @@ class commandList {
|
|||||||
System.arraycopy(arg, lastSet + 1, temp2,
|
System.arraycopy(arg, lastSet + 1, temp2,
|
||||||
temp.length, arg.length - lastSet);
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
||||||
try {
|
|
||||||
vminecraftSettings.getInstance().loadSettings();
|
vminecraftSettings.getInstance().loadSettings();
|
||||||
} catch (IOException e) {
|
|
||||||
log.log(Level.SEVERE, "Exception while loading settings ", e);
|
|
||||||
}
|
|
||||||
vminecraftCommands.loadCommands();
|
vminecraftCommands.loadCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,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()){
|
||||||
@ -93,7 +93,11 @@ public class vminecraftSettings {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
properties = new PropertiesFile("vminecraft.properties");
|
properties = new PropertiesFile("vminecraft.properties");
|
||||||
|
try {
|
||||||
properties.load();
|
properties.load();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
Reference in New Issue
Block a user