use of com.denizenscript.denizencore.scripts.queues.core.InstantQueue in project Denizen-For-Bukkit by DenizenScript.
the class ActionHandler method doAction.
public ListTag doAction(String actionName, NPCTag npc, PlayerTag player, AssignmentScriptContainer assignment, Map<String, ObjectTag> context) {
if (context == null) {
context = new HashMap<>();
}
if (assignment == null) {
return null;
}
if (!assignment.containsScriptSection("actions.on " + actionName)) {
return null;
}
Debug.report(assignment, "Action", ArgumentHelper.debugObj("Type", "On " + actionName), npc, assignment.getAsScriptArg(), player);
// Fetch script from Actions
List<ScriptEntry> script = assignment.getEntries(new BukkitScriptEntryData(player, npc), "actions.on " + actionName);
if (script.isEmpty()) {
return null;
}
Debug.echoDebug(assignment, DebugElement.Header, "Building action 'On " + actionName.toUpperCase() + "' for " + npc.toString());
// Add entries and context to the queue
ScriptQueue queue = new InstantQueue(assignment.getName());
queue.addEntries(script);
ContextSource.SimpleMap src = new ContextSource.SimpleMap();
src.contexts = context;
src.contexts.put("event_header", new ElementTag(actionName));
queue.setContextSource(src);
// Start the queue!
queue.start();
return queue.determinations;
}
use of com.denizenscript.denizencore.scripts.queues.core.InstantQueue in project Denizen-For-Bukkit by DenizenScript.
the class AbstractTrigger method parse.
public boolean parse(NPCTag npc, PlayerTag player, InteractScriptContainer script, String id, Map<String, ObjectTag> context) {
if (npc == null || player == null || script == null) {
return false;
}
List<ScriptEntry> entries = script.getEntriesFor(this.getClass(), player, npc, id, true);
if (entries.isEmpty()) {
return false;
}
Debug.echoDebug(script, DebugElement.Header, "Parsing " + name + " trigger: n@" + npc.getName() + "/p@" + player.getName());
// Create Queue
long speedTicks;
if (script.contains("SPEED", String.class)) {
speedTicks = DurationTag.valueOf(script.getString("SPEED", "0"), new BukkitTagContext(script)).getTicks();
} else {
speedTicks = DurationTag.valueOf(Settings.interactQueueSpeed(), new BukkitTagContext(script)).getTicks();
}
ScriptQueue queue;
if (speedTicks > 0) {
queue = new TimedQueue(script.getName()).setSpeed(speedTicks);
} else {
queue = new InstantQueue(script.getName());
}
// Add all entries to set it up
queue.addEntries(entries);
// Add context
if (context != null) {
ContextSource.SimpleMap src = new ContextSource.SimpleMap();
src.contexts = context;
queue.setContextSource(src);
}
if (!npc.getTriggerTrait().properly_set.get(name)) {
if (missetWarning.testShouldWarn()) {
Debug.echoError(missetWarning.message.replace("{NAME}", name).replace("{NPC}", npc.getId() + "/" + npc.getName()));
}
}
// Start it
queue.start();
return true;
}
use of com.denizenscript.denizencore.scripts.queues.core.InstantQueue in project Denizen-For-Bukkit by DenizenScript.
the class CommandScriptContainer method runAllowedHelpProcedure.
public boolean runAllowedHelpProcedure(PlayerTag player, NPCTag npc, Map<String, ObjectTag> context) {
List<ScriptEntry> entries = getEntries(new BukkitScriptEntryData(player, npc), "allowed help");
ScriptQueue queue = new InstantQueue(getName());
queue.addEntries(entries);
if (context != null) {
ContextSource.SimpleMap src = new ContextSource.SimpleMap();
src.contexts = context;
queue.setContextSource(src);
}
queue.start();
return queue.determinations != null && queue.determinations.size() > 0 && queue.determinations.get(0).equalsIgnoreCase("true");
}
use of com.denizenscript.denizencore.scripts.queues.core.InstantQueue in project Denizen-For-Bukkit by DenizenScript.
the class CommandScriptContainer method runTabCompleteProcedure.
public List<String> runTabCompleteProcedure(PlayerTag player, NPCTag npc, Map<String, ObjectTag> context, String[] originalArguments) {
BukkitTagContext tagContext = new BukkitTagContext(player, npc, new ScriptTag(this));
ContextSource contextSrc = null;
if (context != null) {
ContextSource.SimpleMap src = new ContextSource.SimpleMap();
src.contexts = context;
tagContext.contextSource = src;
contextSrc = src;
}
List<String> list = new ArrayList<>();
if (tabCompletionTaggables != null) {
int argCount = Math.max(originalArguments.length, 1);
String taggable = tabCompletionTaggables.get(argCount);
if (taggable == null) {
taggable = tabCompletionTaggables.get(-1);
}
if (taggable != null) {
String argLow = originalArguments.length == 0 ? "" : CoreUtilities.toLowerCase(originalArguments[originalArguments.length - 1]);
for (String value : ListTag.getListFor(TagManager.tagObject(taggable, tagContext), tagContext)) {
if (CoreUtilities.toLowerCase(value).startsWith(argLow)) {
list.add(value);
}
}
}
}
if (hasProcStyleTabComplete) {
List<ScriptEntry> entries = getEntries(new BukkitScriptEntryData(player, npc), "tab complete");
ScriptQueue queue = new InstantQueue(getName());
queue.addEntries(entries);
if (contextSrc != null) {
queue.setContextSource(contextSrc);
}
queue.start();
if (queue.determinations != null && queue.determinations.size() > 0) {
list.addAll(ListTag.getListFor(queue.determinations.getObject(0), tagContext));
}
}
return list;
}
use of com.denizenscript.denizencore.scripts.queues.core.InstantQueue in project Denizen-For-Bukkit by DenizenScript.
the class ExCommandHandler method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
if (cmd.getName().equalsIgnoreCase("ex")) {
List<Object> entries = new ArrayList<>();
String entry = String.join(" ", args);
boolean quiet = !Settings.showExDebug();
if (entry.length() > 3 && entry.startsWith("-q ")) {
quiet = !quiet;
entry = entry.substring("-q ".length());
}
if (entry.length() < 2) {
sender.sendMessage("/ex (-q) <denizen script command> (arguments)");
return true;
}
if (Settings.showExHelp()) {
if (Debug.showDebug) {
if (quiet) {
sender.sendMessage(ChatColor.YELLOW + "Executing Denizen script command... check the console for full debug output!");
} else {
// sender.sendMessage(ChatColor.YELLOW + "Executing Denizen script command...");
}
} else {
sender.sendMessage(ChatColor.YELLOW + "Executing Denizen script command... to see debug, use /denizen debug");
}
}
entries.add(entry);
InstantQueue queue = new InstantQueue("EXCOMMAND");
NPCTag npc = null;
if (Depends.citizens != null && Depends.citizens.getNPCSelector().getSelected(sender) != null) {
npc = new NPCTag(Depends.citizens.getNPCSelector().getSelected(sender));
}
List<ScriptEntry> scriptEntries = ScriptBuilder.buildScriptEntries(entries, null, new BukkitScriptEntryData(sender instanceof Player ? new PlayerTag((Player) sender) : null, npc));
queue.addEntries(scriptEntries);
if (!quiet && sender instanceof Player) {
final Player player = (Player) sender;
queue.debugOutput = (s) -> {
player.spigot().sendMessage(FormattedTextHelper.parse(s, net.md_5.bungee.api.ChatColor.WHITE));
};
}
queue.start();
return true;
}
return false;
}
Aggregations