use of net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer in project Denizen-For-Bukkit by DenizenScript.
the class NarrateCommand method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
List<dPlayer> targets = (List<dPlayer>) scriptEntry.getObject("targets");
String text = scriptEntry.getElement("text").asString();
FormatScriptContainer format = (FormatScriptContainer) scriptEntry.getObject("format");
// Report to dB
dB.report(scriptEntry, getName(), aH.debugObj("Narrating", text) + aH.debugList("Targets", targets) + (format != null ? aH.debugObj("Format", format.getName()) : ""));
if (targets == null) {
Bukkit.getServer().getConsoleSender().sendMessage(format != null ? format.getFormattedText(scriptEntry) : text);
return;
}
for (dPlayer player : targets) {
if (player != null && player.isOnline()) {
player.getPlayerEntity().sendMessage(format != null ? format.getFormattedText(scriptEntry) : text);
} else {
dB.echoError("Narrated to non-existent or offline player!");
}
}
}
use of net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer in project Denizen-For-Bukkit by DenizenScript.
the class NarrateCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
if (scriptEntry.getArguments().size() > 4) {
// TODO: Use this more often!
throw new InvalidArgumentsException("Too many arguments! Did you forget a 'quote'?");
}
// Iterate through arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format", "f")) {
String formatStr = arg.getValue();
FormatScriptContainer format = ScriptRegistry.getScriptContainer(formatStr);
if (format == null) {
dB.echoError("Could not find format script matching '" + formatStr + '\'');
}
scriptEntry.addObject("format", format);
} else // Add players to target list
if (!scriptEntry.hasObject("targets") && arg.matchesPrefix("target", "targets", "t")) {
scriptEntry.addObject("targets", arg.asType(dList.class).filter(dPlayer.class));
} else // Use raw_value as to not accidentally strip a value before any :'s.
if (!scriptEntry.hasObject("text")) {
scriptEntry.addObject("text", new Element(TagManager.cleanOutputFully(arg.raw_value)));
} else {
arg.reportUnhandled();
}
}
// to the targets
if (!scriptEntry.hasObject("targets")) {
scriptEntry.addObject("targets", (((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? Arrays.asList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer()) : null));
}
if (!scriptEntry.hasObject("text")) {
throw new InvalidArgumentsException("Missing any text!");
}
}
use of net.aufdemrand.denizen.scripts.containers.core.FormatScriptContainer in project Denizen-For-Bukkit by DenizenScript.
the class AnnounceCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
// let's check if there are more argument than usual.
if (scriptEntry.getArguments().size() > 3) {
throw new InvalidArgumentsException("Too many arguments! Did you forget a 'quote'?");
}
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("type") && arg.matches("to_ops")) {
scriptEntry.addObject("type", AnnounceType.TO_OPS);
} else if (!scriptEntry.hasObject("type") && arg.matches("to_console")) {
scriptEntry.addObject("type", AnnounceType.TO_CONSOLE);
} else if (!scriptEntry.hasObject("type") && arg.matchesPrefix("to_flagged")) {
scriptEntry.addObject("type", AnnounceType.TO_FLAGGED);
scriptEntry.addObject("flag", arg.asElement());
} else if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format")) {
FormatScriptContainer format = null;
String formatStr = arg.getValue();
format = ScriptRegistry.getScriptContainer(formatStr);
if (format == null) {
dB.echoError("Could not find format script matching '" + formatStr + '\'');
}
scriptEntry.addObject("format", format);
} else if (!scriptEntry.hasObject("text")) {
scriptEntry.addObject("text", new Element(arg.raw_value));
}
}
// If text is missing, alert the console.
if (!scriptEntry.hasObject("text")) {
throw new InvalidArgumentsException("Missing text argument!");
}
scriptEntry.defaultObject("type", AnnounceType.ALL);
}
Aggregations