use of net.aufdemrand.denizen.utilities.command.exceptions.CommandException in project Denizen-For-Bukkit by DenizenScript.
the class CommandContext method parseLocation.
public static Location parseLocation(Location currentLocation, String flag) throws CommandException {
boolean denizen = flag.startsWith("l@");
String[] parts = flag.replaceFirst("l@", "").split("[,]|[:]");
if (parts.length > 0) {
String worldName = currentLocation != null ? currentLocation.getWorld().getName() : "";
double x = 0, y = 0, z = 0;
float yaw = 0F, pitch = 0F;
switch(parts.length) {
case 6:
if (denizen) {
worldName = parts[5].replaceFirst("w@", "");
} else {
pitch = Float.parseFloat(parts[5]);
}
case 5:
if (denizen) {
pitch = Float.parseFloat(parts[4]);
} else {
yaw = Float.parseFloat(parts[4]);
}
case 4:
if (denizen && parts.length > 4) {
yaw = Float.parseFloat(parts[3]);
} else {
worldName = parts[3].replaceFirst("w@", "");
}
case 3:
x = Double.parseDouble(parts[0]);
y = Double.parseDouble(parts[1]);
z = Double.parseDouble(parts[2]);
break;
default:
throw new CommandException("Location could not be parsed or was not found.");
}
World world = Bukkit.getWorld(worldName);
if (world == null) {
throw new CommandException("Location could not be parsed or was not found.");
}
return new Location(world, x, y, z, yaw, pitch);
} else {
Player search = Bukkit.getPlayerExact(flag);
if (search == null) {
throw new CommandException("No player could be found by that name.");
}
return search.getLocation();
}
}
use of net.aufdemrand.denizen.utilities.command.exceptions.CommandException in project Denizen-For-Bukkit by DenizenScript.
the class DenizenCommandHandler method scripts.
/*
* DENIZEN SCRIPTS
*/
@Command(aliases = { "denizen" }, usage = "scripts (--type assignment|task|...) (--filter string)", desc = "Lists currently loaded dScripts.", modifiers = { "scripts" }, min = 1, max = 4, permission = "denizen.basic")
public void scripts(CommandContext args, CommandSender sender) throws CommandException {
// Fill arguments
String type = null;
if (args.hasValueFlag("type")) {
type = args.getFlag("type");
}
String filter = null;
if (args.hasValueFlag("filter")) {
filter = args.getFlag("filter");
}
// Get script names from the scripts.yml in memory
Set<String> scripts = ScriptRegistry._getScriptNames();
// New Paginator to display script names
Paginator paginator = new Paginator().header("Scripts");
paginator.addLine("<e>Key: <a>Type <b>Name");
// Add scripts to Paginator
for (String script : scripts) {
ScriptContainer scriptContainer = ScriptRegistry.getScriptContainer(script);
// If a --type has been specified...
if (type != null) {
if (scriptContainer.getContainerType().equalsIgnoreCase(type)) {
if (filter != null) {
if (script.contains(filter.toUpperCase())) {
paginator.addLine("<a>" + scriptContainer.getContainerType().substring(0, 3) + " <b>" + script);
}
} else {
paginator.addLine("<a>" + scriptContainer.getContainerType().substring(0, 3) + " <b>" + script);
}
}
// If a --filter has been specified...
} else if (filter != null) {
if (script.contains(filter.toUpperCase())) {
paginator.addLine("<a>" + scriptContainer.getContainerType().substring(0, 3) + " <b>" + script);
}
} else {
paginator.addLine("<a>" + scriptContainer.getContainerType().substring(0, 3) + " <b>" + script);
}
}
// Send the contents of the Paginator to the Player (or Console)
if (!paginator.sendPage(sender, args.getInteger(1, 1))) {
throw new CommandException("The page " + args.getInteger(1, 1) + " does not exist.");
}
}
use of net.aufdemrand.denizen.utilities.command.exceptions.CommandException in project Denizen-For-Bukkit by DenizenScript.
the class DenizenCommandHandler method listener.
/*
* DENIZEN LISTENER
*/
@Command(aliases = { "denizen" }, usage = "listener (--player) --id listener_id --report|cancel|finish", desc = "Checks/cancels/finishes listeners in progress.", modifiers = { "listener" }, min = 1, max = 3, permission = "denizen.basic", flags = "s")
public void listener(CommandContext args, CommandSender sender) throws CommandException {
dPlayer player = null;
if (sender instanceof Player) {
player = dPlayer.mirrorBukkitPlayer((Player) sender);
}
if (args.hasValueFlag("player")) {
player = dPlayer.valueOf(args.getFlag("player"));
}
if (player == null) {
throw new CommandException("Specified player not online or not found!");
}
Map<String, AbstractListener> listeners = denizen.getListenerRegistry().getListenersFor(player);
if (listeners == null || listeners.isEmpty()) {
Messaging.send(sender, player.getName() + " has no active listeners.");
return;
}
if (args.hasValueFlag("report")) {
for (AbstractListener quest : denizen.getListenerRegistry().getListenersFor(player).values()) {
if (quest.getListenerId().equalsIgnoreCase(args.getFlag("report"))) {
Messaging.send(sender, quest.report());
}
}
return;
} else if (args.hasValueFlag("cancel")) {
for (AbstractListener quest : denizen.getListenerRegistry().getListenersFor(player).values()) {
if (quest.getListenerId().equalsIgnoreCase(args.getFlag("cancel"))) {
Messaging.send(sender, "Cancelling '" + quest.getListenerId() + "' for " + player.getName() + ".");
quest.cancel();
}
}
return;
} else if (args.hasValueFlag("finish")) {
for (AbstractListener quest : denizen.getListenerRegistry().getListenersFor(player).values()) {
if (quest.getListenerId().equalsIgnoreCase(args.getFlag("finish"))) {
Messaging.send(sender, "Force-finishing '" + quest.getListenerId() + "' for " + player.getName() + ".");
quest.finish();
}
}
return;
} else if (args.length() > 2 && args.getInteger(1, 0) < 1) {
Messaging.send(sender, "");
Messaging.send(sender, "<f>Use '--report|cancel|finish id' to modify/view a specific quest listener.");
Messaging.send(sender, "<b>Example: /denizen listener --report \"Journey 1\"");
Messaging.send(sender, "");
return;
}
Paginator paginator = new Paginator();
paginator.header("Active quest listeners for " + player.getName() + ":");
paginator.addLine("<e>Key: <a>Type <b>ID");
if (listeners == null || listeners.isEmpty()) {
paginator.addLine("None.");
} else {
for (AbstractListener quest : listeners.values()) {
paginator.addLine("<a>" + quest.getListenerType() + " <b>" + quest.getListenerId());
}
}
paginator.sendPage(sender, args.getInteger(1, 1));
}
Aggregations