use of com.denizenscript.denizencore.scripts.queues.core.TimedQueue 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.TimedQueue in project Denizen-For-Bukkit by DenizenScript.
the class ExSustainedCommandHandler method getOrMakeQueue.
public TimedQueue getOrMakeQueue(final Player player, boolean quiet) {
UUID id;
if (player == null) {
id = new UUID(0, 0);
} else {
id = player.getUniqueId();
}
TimedQueue queue = playerQueues.get(id);
if (queue != null && !queue.isStopped) {
return queue;
}
queue = new TimedQueue("EX_SUSTAINED_COMMAND", 0);
queue.waitWhenEmpty = true;
playerQueues.put(id, queue);
return queue;
}
use of com.denizenscript.denizencore.scripts.queues.core.TimedQueue in project Denizen-For-Bukkit by DenizenScript.
the class ExSustainedCommandHandler method onCommand.
@Override
public boolean onCommand(CommandSender sender, Command cmd, String alias, String[] args) {
if (cmd.getName().equalsIgnoreCase("exs")) {
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("/exs (-q) <denizen script command> (arguments)");
return true;
}
TimedQueue queue = getOrMakeQueue(sender instanceof Player ? (Player) sender : null, quiet);
if (!quiet && sender instanceof Player) {
Player player = (Player) sender;
queue.debugOutput = (s) -> {
player.spigot().sendMessage(FormattedTextHelper.parse(s, net.md_5.bungee.api.ChatColor.WHITE));
};
} else {
queue.debugOutput = null;
}
if (queue.isPaused() || queue.isDelayed()) {
sender.sendMessage(ChatColor.YELLOW + "Sustained queue is currently paused or waiting, adding command to queue for later execution.");
} else 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);
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 (!queue.is_started) {
queue.start();
} else {
queue.onStart();
}
return true;
}
return false;
}
Aggregations