use of com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer in project Denizen-For-Bukkit by DenizenScript.
the class ChatScriptEvent method applyDetermination.
@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (determinationObj instanceof ElementTag) {
String determination = determinationObj.toString();
String lower = CoreUtilities.toLowerCase(determination);
if (lower.startsWith("format:")) {
String name = determination.substring("format:".length());
FormatScriptContainer formatscr = ScriptRegistry.getScriptContainer(name);
if (formatscr == null) {
Debug.echoError("Could not find format script matching '" + name + '\'');
} else {
String formatstr = formatscr.getFormatText(null, player);
if (Debug.verbose) {
Debug.log("Setting format to " + formatstr);
}
if (pcEvent != null) {
pcEvent.setFormat(formatstr);
} else {
apcEvent.setFormat(formatstr);
}
}
return true;
} else if (lower.startsWith("raw_format:")) {
String form = determination.substring("raw_format:".length());
if (pcEvent != null) {
pcEvent.setFormat(form);
} else {
apcEvent.setFormat(form);
}
return true;
} else if (lower.startsWith("recipients:")) {
String rec_new = determination.substring("recipients:".length());
ListTag recs = ListTag.valueOf(rec_new, getTagContext(path));
List<PlayerTag> players = recs.filter(PlayerTag.class, path.container, true);
Set<Player> recipients;
if (pcEvent != null) {
recipients = pcEvent.getRecipients();
} else {
recipients = apcEvent.getRecipients();
}
recipients.clear();
for (PlayerTag player : players) {
recipients.add(player.getPlayerEntity());
}
return true;
} else {
if (pcEvent != null) {
pcEvent.setMessage(determination);
} else {
apcEvent.setMessage(determination);
}
return true;
}
}
return super.applyDetermination(path, determinationObj);
}
use of com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer in project Denizen-For-Bukkit by DenizenScript.
the class AnnounceCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
if (scriptEntry.getResidingQueue().procedural) {
Debug.echoError("'Announce' should not be used in a procedure script. Consider the 'debug' command instead.");
}
ElementTag text = scriptEntry.getElement("text");
AnnounceType type = (AnnounceType) scriptEntry.getObject("type");
FormatScriptContainer format = (FormatScriptContainer) scriptEntry.getObject("format");
ElementTag flag = scriptEntry.getElement("flag");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("message", text), (format != null ? db("format", format.getName()) : ""), db("type", type.name()), flag);
}
String message = format != null ? format.getFormattedText(text.asString(), scriptEntry) : text.asString();
// Use Bukkit to broadcast the message to everybody in the server.
switch(type) {
case ALL:
Denizen.getInstance().getServer().spigot().broadcast(FormattedTextHelper.parse(message, ChatColor.WHITE));
break;
case TO_OPS:
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.isOp()) {
player.spigot().sendMessage(FormattedTextHelper.parse(message, ChatColor.WHITE));
}
}
break;
case TO_PERMISSION:
for (Player player : Bukkit.getOnlinePlayers()) {
if (player.hasPermission(flag.asString())) {
player.spigot().sendMessage(FormattedTextHelper.parse(message, ChatColor.WHITE));
}
}
case TO_FLAGGED:
for (Player player : Bukkit.getOnlinePlayers()) {
if (new PlayerTag(player).getFlagTracker().hasFlag(flag.asString())) {
player.spigot().sendMessage(FormattedTextHelper.parse(message, ChatColor.WHITE));
}
}
break;
case TO_CONSOLE:
Bukkit.getServer().getConsoleSender().spigot().sendMessage(FormattedTextHelper.parse(message, ChatColor.WHITE));
break;
}
}
use of com.denizenscript.denizen.scripts.containers.core.FormatScriptContainer in project Denizen-For-Bukkit by DenizenScript.
the class NarrateCommand method parseArgs.
// <--[command]
// @Name Narrate
// @Syntax narrate [<text>] (targets:<player>|...) (format:<script>) (per_player) (from:<uuid>)
// @Required 1
// @Maximum 5
// @Short Shows some text to the player.
// @Group player
//
// @Description
// Prints some text into the target's chat area. If no target is specified it will default to the attached player or the console.
//
// Accepts the 'format:<script>' argument, which will reformat the text according to the specified format script. See <@link language Format Script Containers>.
//
// Optionally use 'per_player' with a list of player targets, to have the tags in the text input be reparsed for each and every player.
// So, for example, "- narrate 'hello <player.name>' targets:<server.online_players>"
// would normally say "hello bob" to every player (every player sees the exact same name in the text, ie bob sees "hello bob", steve also sees "hello bob", etc)
// but if you use "per_player", each player online would see their own name (so bob sees "hello bob", steve sees "hello steve", etc).
//
// Optionally, specify 'from:<uuid>' to indicate that message came from a specific UUID (used for things like the vanilla client social interaction block option).
//
// @Tags
// None
//
// @Usage
// Use to narrate text to the player.
// - narrate "Hello World!"
//
// @Usage
// Use to narrate text to a list of players.
// - narrate "Hello there." targets:<[player]>|<[someplayer]>|<[thatplayer]>
//
// @Usage
// Use to narrate text to a unique message to every player on the server.
// - narrate "Hello <player.name>, your secret code is <util.random.duuid>." targets:<server.online_players> per_player
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : ArgumentHelper.interpret(scriptEntry, scriptEntry.getOriginalArguments())) {
if (!scriptEntry.hasObject("format") && arg.matchesPrefix("format", "f")) {
String formatStr = TagManager.tag(arg.getValue(), scriptEntry.getContext());
FormatScriptContainer format = ScriptRegistry.getScriptContainer(formatStr);
if (format == null) {
Debug.echoError("Could not find format script matching '" + formatStr + "'");
}
scriptEntry.addObject("format", new ScriptTag(format));
} else if (!scriptEntry.hasObject("targets") && arg.matchesPrefix("target", "targets", "t")) {
scriptEntry.addObject("targets", ListTag.getListFor(TagManager.tagObject(arg.getValue(), scriptEntry.getContext()), scriptEntry.getContext()).filter(PlayerTag.class, scriptEntry));
} else if (!scriptEntry.hasObject("from") && arg.matchesPrefix("from")) {
scriptEntry.addObject("from", TagManager.tagObject(arg.getValue(), scriptEntry.getContext()));
} else if (!scriptEntry.hasObject("per_player") && arg.matches("per_player")) {
scriptEntry.addObject("per_player", new ElementTag(true));
} else if (!scriptEntry.hasObject("text")) {
scriptEntry.addObject("text", arg.getRawElement());
} else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("targets")) {
scriptEntry.addObject("targets", (Utilities.entryHasPlayer(scriptEntry) ? Collections.singletonList(Utilities.getEntryPlayer(scriptEntry)) : null));
}
if (!scriptEntry.hasObject("text")) {
throw new InvalidArgumentsException("Missing any text!");
}
}
Aggregations