use of com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class BukkitScriptProperties method registerTags.
public static void registerTags() {
// <--[tag]
// @attribute <ScriptTag.cooled_down[<player>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether the script is currently cooled down for the player. Any global
// cooldown present on the script will also be taken into account. Not specifying a player will result in
// using the attached player available in the script entry. Not having a valid player will result in 'null'.
// -->
PropertyParser.<BukkitScriptProperties, ElementTag>registerTag(ElementTag.class, "cooled_down", (attribute, script) -> {
PlayerTag player = (attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer());
if (player != null && player.isValid()) {
return new ElementTag(CooldownCommand.checkCooldown(player, script.script.getContainer().getName()));
} else {
return null;
}
});
// <--[tag]
// @attribute <ScriptTag.cooldown[<player>]>
// @returns DurationTag
// @description
// Returns the time left for the player to cooldown for the script.
// -->
PropertyParser.<BukkitScriptProperties, DurationTag>registerTag(DurationTag.class, "cooldown", (attribute, script) -> {
PlayerTag player = (attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer());
return CooldownCommand.getCooldownDuration(player, script.script.getName());
});
// <--[tag]
// @attribute <ScriptTag.step[(<player>)]>
// @returns ElementTag
// @description
// Returns the name of a script step that the player is currently on.
// Must be an INTERACT script.
// -->
PropertyParser.<BukkitScriptProperties, ElementTag>registerTag(ElementTag.class, "step", (attribute, script) -> {
PlayerTag player = attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer();
if (player != null && player.isValid()) {
return new ElementTag(InteractScriptHelper.getCurrentStep(player, script.script.getContainer().getName()));
} else {
return null;
}
});
// <--[tag]
// @attribute <ScriptTag.step_expiration[(<player>)]>
// @returns TimeTag
// @description
// Returns the time that an interact script step expires at, if applied by <@link command zap> with a duration limit.
// -->
PropertyParser.<BukkitScriptProperties, TimeTag>registerTag(TimeTag.class, "step_expiration", (attribute, script) -> {
PlayerTag player = attribute.hasParam() ? attribute.paramAsType(PlayerTag.class) : ((BukkitScriptEntryData) attribute.getScriptEntry().entryData).getPlayer();
if (player != null && player.isValid()) {
return InteractScriptHelper.getStepExpiration(player, script.script.getContainer().getName());
} else {
return null;
}
});
// <--[tag]
// @attribute <ScriptTag.default_step>
// @returns ElementTag
// @description
// Returns the name of the default step of an interact script.
// -->
PropertyParser.<BukkitScriptProperties, ElementTag>registerStaticTag(ElementTag.class, "default_step", (attribute, script) -> {
String step = ((InteractScriptContainer) script.script.getContainer()).getDefaultStepName();
return new ElementTag(step);
});
}
use of com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class ClickableCommand method runClickable.
public static void runClickable(UUID id, Player player) {
Clickable clickable = clickables.get(id);
if (clickable == null) {
return;
}
if (clickable.until != 0 && System.currentTimeMillis() > clickable.until) {
clickables.remove(id);
return;
}
if (clickable.forPlayers != null && !clickable.forPlayers.contains(player.getUniqueId())) {
return;
}
if (clickable.remainingUsages > 0) {
clickable.remainingUsages--;
if (clickable.remainingUsages <= 0) {
clickables.remove(id);
}
}
Consumer<ScriptQueue> configure = (queue) -> {
if (clickable.defMap != null) {
for (Map.Entry<StringHolder, ObjectTag> val : clickable.defMap.map.entrySet()) {
queue.addDefinition(val.getKey().str, val.getValue());
}
}
};
ScriptUtilities.createAndStartQueue(clickable.script.getContainer(), clickable.path, new BukkitScriptEntryData(new PlayerTag(player), clickable.npc), null, configure, null, null, clickable.definitions, clickable.context);
}
use of com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData 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.denizen.utilities.implementation.BukkitScriptEntryData 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.denizen.utilities.implementation.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.
the class Debug method echoError.
public static void echoError(ScriptEntry source, String addedContext, String message, boolean reformat) {
message = cleanTextForDebugOutput(message);
if (errorDuplicatePrevention) {
if (!com.denizenscript.denizencore.utilities.debugging.Debug.verbose) {
finalOutputDebugText("Error within error (??!!!! SOMETHING WENT SUPER WRONG!): " + message, source, reformat);
}
return;
}
errorDuplicatePrevention = true;
ScriptQueue sourceQueue = CommandExecutor.currentQueue;
if (source != null && source.queue != null) {
sourceQueue = source.queue;
}
ScriptTag sourceScript = null;
if (source != null) {
sourceScript = source.getScript();
}
if (throwErrorEvent) {
throwErrorEvent = false;
boolean cancel = ScriptGeneratesErrorScriptEvent.instance.handle(message, sourceQueue, sourceScript, source == null ? -1 : source.internal.lineNumber);
throwErrorEvent = true;
if (cancel) {
errorDuplicatePrevention = false;
return;
}
}
if (!showDebug) {
errorDuplicatePrevention = false;
return;
}
StringBuilder headerBuilder = new StringBuilder();
headerBuilder.append(ERROR_HEADER_START);
if (sourceScript != null) {
headerBuilder.append(" in script '").append(ChatColor.AQUA).append(sourceScript.getName()).append(ChatColor.RED).append("'");
}
if (sourceQueue != null) {
headerBuilder.append(" in queue '").append(sourceQueue.debugId).append(ChatColor.RED).append("'");
}
if (source != null) {
headerBuilder.append(" while executing command '").append(ChatColor.AQUA).append(source.getCommandName()).append(ChatColor.RED).append("'");
if (sourceScript != null) {
headerBuilder.append(" in file '").append(ChatColor.AQUA).append(sourceScript.getContainer().getRelativeFileName()).append(ChatColor.RED).append("' on line '").append(ChatColor.AQUA).append(source.internal.lineNumber).append(ChatColor.RED).append("'");
}
BukkitScriptEntryData data = Utilities.getEntryData(source);
if (data.hasPlayer()) {
headerBuilder.append(" with player '").append(ChatColor.AQUA).append(data.getPlayer().getName()).append(ChatColor.RED).append("'");
}
if (data.hasNPC()) {
headerBuilder.append(" with NPC '").append(ChatColor.AQUA).append(data.getNPC().debuggable()).append(ChatColor.RED).append("'");
}
}
if (addedContext != null) {
headerBuilder.append("\n<FORCE_ALIGN>").append(addedContext);
}
headerBuilder.append(ERROR_HEADER_END);
String header = headerBuilder.toString();
boolean showDebugSuffix = sourceScript != null && !sourceScript.getContainer().shouldDebug();
String headerRef = header;
if (header.equals(lastErrorHeader)) {
header = ADDITIONAL_ERROR_HEADER;
showDebugSuffix = false;
}
finalOutputDebugText(header + message + (showDebugSuffix ? ENABLE_DEBUG_MESSAGE : ""), sourceQueue, reformat);
errorDuplicatePrevention = false;
if (com.denizenscript.denizencore.utilities.debugging.Debug.verbose && depthCorrectError == 0) {
depthCorrectError++;
try {
throw new RuntimeException("Verbose info for above error");
} catch (Throwable e) {
echoError(source, e);
}
depthCorrectError--;
}
lastErrorHeader = headerRef;
}
Aggregations