use of watson.db.Filters in project watson by totemo.
the class WatsonCommand method processCommand.
// --------------------------------------------------------------------------
/**
* @see net.minecraft.src.ICommand#processCommand(net.minecraft.src.ICommandSender,
* java.lang.String[])
*/
@Override
public void processCommand(ICommandSender sender, String[] args) {
DisplaySettings display = Controller.instance.getDisplaySettings();
if (args.length == 0) {
help(sender);
return;
} else if (args.length == 1) {
if (args[0].equals("help")) {
help(sender);
return;
} else if (args[0].equals("clear")) {
Controller.instance.clearBlockEditSet();
return;
} else if (args[0].equals("ratio")) {
Controller.instance.getBlockEditSet().getOreDB().showRatios();
return;
} else if (args[0].equals("servertime")) {
ServerTime.instance.queryServerTime(true);
return;
}
}
// "/w ore [<page>]"
if (args.length >= 1 && args[0].equals("ore")) {
if (args.length == 1) {
Controller.instance.getBlockEditSet().getOreDB().listDeposits(1);
return;
} else if (args.length == 2) {
boolean validPage = false;
try {
int page = Integer.parseInt(args[1]);
if (page > 0) {
validPage = true;
Controller.instance.getBlockEditSet().getOreDB().listDeposits(page);
}
} catch (NumberFormatException ex) {
// Handled by validPage check.
}
if (!validPage) {
localError(sender, "The page number should be greater than zero.");
}
return;
}
}
// "/w pre [<count>]"
if (args.length >= 1 && args[0].equals("pre")) {
if (args.length == 1) {
Controller.instance.queryPreEdits(Configuration.instance.getPreCount());
return;
} else if (args.length == 2) {
boolean validCount = false;
try {
int count = Integer.parseInt(args[1]);
if (count > 0) {
validCount = true;
Controller.instance.queryPreEdits(count);
}
} catch (NumberFormatException ex) {
// Handled by validCount test.
}
if (!validCount) {
localError(sender, "The count parameter should be a positive number of edits to fetch.");
}
return;
}
}
// "/w post [<count>]"
if (args.length >= 1 && args[0].equals("post")) {
if (args.length == 1) {
Controller.instance.queryPostEdits(Configuration.instance.getPostCount());
return;
} else if (args.length == 2) {
boolean validCount = false;
try {
int count = Integer.parseInt(args[1]);
if (count > 0) {
validCount = true;
Controller.instance.queryPostEdits(count);
}
} catch (NumberFormatException ex) {
// Handled by validCount test.
}
if (!validCount) {
localError(sender, "The count parameter should be a positive number of edits to fetch.");
}
return;
}
}
// "display" command.
if (args.length >= 1 && args[0].equals("display")) {
if (args.length == 1) {
// Toggle display.
display.setDisplayed(!display.isDisplayed());
return;
} else if (args.length == 2) {
if (args[1].equals("on")) {
display.setDisplayed(true);
return;
} else if (args[1].equals("off")) {
display.setDisplayed(false);
return;
}
}
}
// "outline" command.
if (args.length >= 1 && args[0].equals("outline")) {
if (args.length == 1) {
// Toggle display.
display.setOutlineShown(!display.isOutlineShown());
return;
} else if (args.length == 2) {
if (args[1].equals("on")) {
display.setOutlineShown(true);
return;
} else if (args[1].equals("off")) {
display.setOutlineShown(false);
return;
}
}
}
// "/w anno" command.
if (args.length >= 1 && args[0].equals("anno")) {
if (args.length == 1) {
// Toggle display.
display.setAnnotationsShown(!display.areAnnotationsShown());
return;
} else if (args.length == 2) {
if (args[1].equals("on")) {
display.setAnnotationsShown(true);
return;
} else if (args[1].equals("off")) {
display.setAnnotationsShown(false);
return;
}
}
}
// "vector" command.
if (args.length >= 1 && args[0].equals("vector")) {
if (handleVectorCommand(sender, args)) {
return;
}
}
// "/w label" command.
if (args.length >= 1 && args[0].equals("label")) {
if (args.length == 1) {
// Toggle display.
display.setLabelsShown(!display.areLabelsShown());
return;
} else if (args.length == 2) {
if (args[1].equals("on")) {
display.setLabelsShown(true);
return;
} else if (args[1].equals("off")) {
display.setLabelsShown(false);
return;
}
}
}
// Ore teleport commands: /w tp [next|prev|<number>]
if (args.length >= 1 && args[0].equals("tp")) {
OreDB oreDB = Controller.instance.getBlockEditSet().getOreDB();
if (args.length == 1) {
oreDB.tpNext();
return;
} else if (args.length == 2) {
if (args[1].equals("next")) {
oreDB.tpNext();
return;
} else if (args[1].equals("prev")) {
oreDB.tpPrev();
return;
} else {
try {
oreDB.tpIndex(Integer.parseInt(args[1]));
} catch (NumberFormatException ex) {
localError(sender, "The tp argument should be next, prev or an integer.");
}
return;
}
}
}
// "/w edits" command.
if (args[0].equals("edits")) {
if (args.length == 1 || (args.length == 2 && args[1].equals("list"))) {
Controller.instance.getBlockEditSet().listEdits();
return;
} else if (args.length >= 3) {
if (args[1].equals("hide") || args[1].equals("show")) {
for (int i = 2; i < args.length; ++i) {
Controller.instance.getBlockEditSet().setEditVisibility(args[i], args[1].equals("show"));
}
return;
} else if (args[1].equals("remove")) {
for (int i = 2; i < args.length; ++i) {
Controller.instance.getBlockEditSet().removeEdits(args[i]);
}
return;
}
}
}
// "/w filter" command.
if (args[0].equals("filter")) {
Filters filters = Controller.instance.getFilters();
if (args.length == 1 || (args.length == 2 && args[1].equals("list"))) {
filters.list();
return;
} else if (args.length == 2 && args[1].equals("clear")) {
filters.clear();
return;
} else if (args.length >= 3) {
if (args[1].equals("add")) {
for (int i = 2; i < args.length; ++i) {
filters.addPlayer(args[i]);
}
return;
} else if (args[1].equals("remove")) {
for (int i = 2; i < args.length; ++i) {
filters.removePlayer(args[i]);
}
return;
}
}
}
// File commands.
if (args.length >= 2 && args[0].equals("file")) {
if (args[1].equals("list")) {
if (args.length == 2) {
Controller.instance.listBlockEditFiles("*", 1);
return;
} else if (args.length == 3) {
Controller.instance.listBlockEditFiles(args[2], 1);
return;
} else if (args.length == 4) {
boolean validPage = false;
try {
int page = Integer.parseInt(args[3]);
if (page > 0) {
validPage = true;
Controller.instance.listBlockEditFiles(args[2], page);
}
} catch (NumberFormatException ex) {
// Handled by validPage check.
}
if (!validPage) {
localError(sender, "The page number should be greater than zero.");
}
return;
}
} else if (args[1].equals("delete") && args.length == 3) {
Controller.instance.deleteBlockEditFiles(args[2]);
return;
} else if (args[1].equals("expire") && args.length == 3) {
Controller.instance.expireBlockEditFiles(args[2]);
return;
} else if (args[1].equals("load") && args.length == 3) {
// args[2] is either a full file name or a player name.
Controller.instance.loadBlockEditFile(args[2]);
return;
} else if (args[1].equals("save")) {
if (args.length == 2) {
Controller.instance.saveBlockEditFile(null);
return;
} else if (args.length == 3) {
Controller.instance.saveBlockEditFile(args[2]);
return;
}
}
}
// "/w config" command with parameters.
if (args.length >= 2 && args[0].equals("config")) {
if (handleConfigCommand(sender, args)) {
return;
}
}
// "/w config" with no parameters, direct to /w config help
if (args.length == 1 && args[0].equals("config")) {
String w = Configuration.instance.getWatsonPrefix();
localOutput(sender, "Type \"/" + w + " config help\" for help with configuration options.");
return;
}
// config with no parameters
localError(sender, "Invalid command syntax.");
}
Aggregations