use of com.denizenscript.denizencore.scripts.ScriptEntry 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.ScriptEntry 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;
}
use of com.denizenscript.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.
the class DenizenCoreImplementation method setSpecialDef.
@Override
public boolean setSpecialDef(String def, ScriptQueue queue, ObjectTag value) {
if (def.equals("__player")) {
BukkitScriptEntryData baseData = getScriptEntryData(queue);
if (baseData == null) {
return true;
}
PlayerTag player = value == null ? null : value.asType(PlayerTag.class, baseData.getTagContext());
if (queue.getLastEntryExecuted() != null) {
((BukkitScriptEntryData) queue.getLastEntryExecuted().entryData).setPlayer(player);
}
for (ScriptEntry entry : queue.getEntries()) {
((BukkitScriptEntryData) entry.entryData).setPlayer(player);
}
return true;
} else if (def.equals("__npc")) {
BukkitScriptEntryData baseData = getScriptEntryData(queue);
if (baseData == null) {
return true;
}
NPCTag npc = value == null ? null : value.asType(NPCTag.class, baseData.getTagContext());
if (queue.getLastEntryExecuted() != null) {
((BukkitScriptEntryData) queue.getLastEntryExecuted().entryData).setNPC(npc);
}
for (ScriptEntry entry : queue.getEntries()) {
((BukkitScriptEntryData) entry.entryData).setNPC(npc);
}
return true;
}
return false;
}
use of com.denizenscript.denizencore.scripts.ScriptEntry 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;
}
use of com.denizenscript.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.
the class BukkitQueueProperties method adjust.
@Override
public void adjust(Mechanism mechanism) {
// -->
if (mechanism.matches("linked_player") && mechanism.requireObject(PlayerTag.class)) {
PlayerTag player = mechanism.valueAsType(PlayerTag.class);
for (ScriptEntry entry : queue.getEntries()) {
BukkitScriptEntryData data = (BukkitScriptEntryData) entry.entryData;
data.setPlayer(player);
}
}
// -->
if (mechanism.matches("linked_npc") && mechanism.requireObject(NPCTag.class)) {
NPCTag npc = mechanism.valueAsType(NPCTag.class);
for (ScriptEntry entry : queue.getEntries()) {
BukkitScriptEntryData data = (BukkitScriptEntryData) entry.entryData;
data.setNPC(npc);
}
}
}
Aggregations