Minor cleanup of code.

This commit is contained in:
sk89q 2010-10-03 12:16:09 -07:00
parent e2ac828228
commit 4eb40b039f

View File

@ -26,6 +26,7 @@ import org.mozilla.javascript.*;
import com.sk89q.worldedit.*; import com.sk89q.worldedit.*;
/** /**
* Plugin entry point for Hey0's mod.
* *
* @author sk89q * @author sk89q
*/ */
@ -39,12 +40,11 @@ public class WorldEdit extends Plugin {
private HashMap<String,String> commands = new HashMap<String,String>(); private HashMap<String,String> commands = new HashMap<String,String>();
private PropertiesFile properties; private PropertiesFile properties;
/**
* List of allowed blocks as a list of numbers as Strings. Not converted
* to a more usuable format.
*/
private String[] allowedBlocks; private String[] allowedBlocks;
/**
* Construct an instance of the plugin.
*/
public WorldEdit() { public WorldEdit() {
super(); super();
@ -67,38 +67,6 @@ public class WorldEdit extends Plugin {
commands.put("/editscript", "[Filename] <Args...> - Run an editscript"); commands.put("/editscript", "[Filename] <Args...> - Run an editscript");
} }
/**
* Enables the plugin.
*/
public void enable() {
if (properties == null) {
properties = new PropertiesFile("worldedit.properties");
} else {
properties.load();
}
allowedBlocks = properties.getString("allowed-blocks", DEFAULT_ALLOWED_BLOCKS).split(",");
etc controller = etc.getInstance();
for (Map.Entry<String,String> entry : commands.entrySet()) {
controller.addCommand(entry.getKey(), entry.getValue());
}
}
/**
* Disables the plugin.
*/
public void disable() {
etc controller = etc.getInstance();
for (String key : commands.keySet()) {
controller.removeCommand(key);
}
sessions.clear();
}
/** /**
* Gets the WorldEdit session for a player. * Gets the WorldEdit session for a player.
* *
@ -166,20 +134,65 @@ public class WorldEdit extends Plugin {
/** /**
* *
* @override
* @param player * @param player
*/ */
@Override
public void onDisconnect(Player player) { public void onDisconnect(Player player) {
sessions.remove(player.getName()); sessions.remove(player.getName());
} }
/**
* Checks to make sure that there are enough arguments.
*
* @param args
* @param min
* @throws InsufficientArgumentsException
*/
private void checkArgs(String[] args, int min) throws InsufficientArgumentsException {
if (args.length <= min) {
throw new InsufficientArgumentsException(String.format("Min. %d arguments required", min));
}
}
/**
* Enables the plugin.
*/
public void enable() {
if (properties == null) {
properties = new PropertiesFile("worldedit.properties");
} else {
properties.load();
}
allowedBlocks = properties.getString("allowed-blocks", DEFAULT_ALLOWED_BLOCKS).split(",");
etc controller = etc.getInstance();
for (Map.Entry<String,String> entry : commands.entrySet()) {
controller.addCommand(entry.getKey(), entry.getValue());
}
}
/**
* Disables the plugin.
*/
public void disable() {
etc controller = etc.getInstance();
for (String key : commands.keySet()) {
controller.removeCommand(key);
}
sessions.clear();
}
/** /**
* *
* @override
* @param player * @param player
* @param split * @param split
* @return * @return
*/ */
@Override
public boolean onCommand(Player player, String[] split) { public boolean onCommand(Player player, String[] split) {
try { try {
if (commands.containsKey(split[0])) { if (commands.containsKey(split[0])) {
@ -208,18 +221,16 @@ public class WorldEdit extends Plugin {
} }
/** /**
* Checks to make sure that there are enough arguments. * The main meat of command processing.
* *
* @param args * @param player
* @param min * @param split
* @return
* @throws UnknownItemException
* @throws IncompleteRegionException
* @throws InsufficientArgumentsException * @throws InsufficientArgumentsException
* @throws DisallowedItemException
*/ */
private void checkArgs(String[] args, int min) throws InsufficientArgumentsException {
if (args.length <= min) {
throw new InsufficientArgumentsException(String.format("Min. %d arguments required", min));
}
}
private boolean handleEditCommand(Player player, String[] split) private boolean handleEditCommand(Player player, String[] split)
throws UnknownItemException, IncompleteRegionException, throws UnknownItemException, IncompleteRegionException,
InsufficientArgumentsException, DisallowedItemException InsufficientArgumentsException, DisallowedItemException
@ -264,13 +275,13 @@ public class WorldEdit extends Plugin {
// Clear undo history // Clear undo history
} else if (split[0].equalsIgnoreCase("/clearhistory")) { } else if (split[0].equalsIgnoreCase("/clearhistory")) {
session.clearHistory(); session.clearHistory();
player.sendMessage(Colors.LightPurple + "History cleared.");; player.sendMessage(Colors.LightPurple + "History cleared.");
return true; return true;
// Clear clipboard // Clear clipboard
} else if (split[0].equalsIgnoreCase("/clearclipboard")) { } else if (split[0].equalsIgnoreCase("/clearclipboard")) {
session.setClipboard(null); session.setClipboard(null);
player.sendMessage(Colors.LightPurple + "Clipboard cleared.");; player.sendMessage(Colors.LightPurple + "Clipboard cleared.");
return true; return true;
// Paste // Paste