use of com.denizenscript.denizencore.objects.core.ScriptTag in project Denizen-For-Bukkit by DenizenScript.
the class AssignmentCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ScriptTag script = scriptEntry.getObjectTag("script");
Action action = (Action) scriptEntry.getObject("action");
List<NPCTag> npcs = (List<NPCTag>) scriptEntry.getObject("npcs");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("action", action), script, db("npc", npcs));
}
PlayerTag player = Utilities.getEntryPlayer(scriptEntry);
for (NPCTag npc : npcs) {
switch(action) {
case SET:
{
if (script == null) {
throw new InvalidArgumentsRuntimeException("Missing script!");
}
AssignmentTrait assignment = npc.getCitizen().getOrAddTrait(AssignmentTrait.class);
assignment.clearAssignments(player);
assignment.addAssignmentScript((AssignmentScriptContainer) script.getContainer(), player);
break;
}
case ADD:
if (script == null) {
throw new InvalidArgumentsRuntimeException("Missing script!");
}
npc.getCitizen().getOrAddTrait(AssignmentTrait.class).addAssignmentScript((AssignmentScriptContainer) script.getContainer(), player);
break;
case REMOVE:
if (script == null) {
Deprecations.assignmentRemove.warn(scriptEntry);
if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
npc.getCitizen().getOrAddTrait(AssignmentTrait.class).clearAssignments(player);
npc.getCitizen().removeTrait(AssignmentTrait.class);
}
} else {
if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
AssignmentTrait trait = npc.getCitizen().getOrAddTrait(AssignmentTrait.class);
trait.removeAssignmentScript(script.getName(), player);
trait.checkAutoRemove();
}
}
break;
case CLEAR:
if (npc.getCitizen().hasTrait(AssignmentTrait.class)) {
npc.getCitizen().getOrAddTrait(AssignmentTrait.class).clearAssignments(player);
npc.getCitizen().removeTrait(AssignmentTrait.class);
}
break;
}
}
}
use of com.denizenscript.denizencore.objects.core.ScriptTag in project Denizen-For-Bukkit by DenizenScript.
the class ScribeCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
Deprecations.scribeCommand.warn(scriptEntry);
// Retrieve objects from ScriptEntry
BookAction action = (BookAction) scriptEntry.getObject("action");
ItemTag book = scriptEntry.getObjectTag("item");
ScriptTag script = scriptEntry.getObjectTag("script");
LocationTag location = scriptEntry.getObjectTag("location");
BookScriptContainer bookScript = (BookScriptContainer) script.getContainer();
book = bookScript.writeBookTo(book, scriptEntry.getContext());
// Post-write action? Can be NONE.
switch(action) {
case DROP:
dropBook(location, book.getItemStack());
break;
case GIVE:
giveBook(Utilities.getEntryPlayer(scriptEntry).getPlayerEntity(), book.getItemStack());
// Update player's inventory
Utilities.getEntryPlayer(scriptEntry).getPlayerEntity().updateInventory();
break;
case EQUIP:
equipBook(Utilities.getEntryPlayer(scriptEntry).getPlayerEntity(), book.getItemStack());
// Update player's inventory
Utilities.getEntryPlayer(scriptEntry).getPlayerEntity().updateInventory();
break;
case NONE:
break;
}
}
use of com.denizenscript.denizencore.objects.core.ScriptTag 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