use of net.aufdemrand.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.
the class BreakCommand method execute.
// <--[action]
// @Actions
// dig
//
// @Triggers when the NPC breaks a block with the Break Command
//
// @Context
// <context.location> returns the location the NPC Dug
// <context.material> Returns the Block dug
//
// -->
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
final dLocation location = (dLocation) scriptEntry.getObject("location");
final dNPC npc = (dNPC) scriptEntry.getObject("entity");
Element radius = scriptEntry.getElement("radius");
final HashMap<String, dObject> context = new HashMap<String, dObject>();
dMaterial material = dMaterial.getMaterialFrom(location.getBlock().getType(), location.getBlock().getData());
context.put("location", location);
context.put("material", material);
dB.report(scriptEntry, getName(), location.debug() + npc.debug() + radius.debug());
final ScriptEntry se = scriptEntry;
BlockBreaker.BlockBreakerConfiguration config = new BlockBreaker.BlockBreakerConfiguration();
config.item(npc.getLivingEntity().getEquipment().getItemInHand());
config.radius(radius.asDouble());
config.callback(new Runnable() {
@Override
public void run() {
npc.action("dig", null, context);
se.setFinished(true);
}
});
BlockBreaker breaker = npc.getCitizen().getBlockBreaker(location.getBlock(), config);
if (breaker.shouldExecute()) {
TaskRunnable run = new TaskRunnable(breaker);
run.taskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(DenizenAPI.getCurrentInstance(), run, 0, 1);
}
}
use of net.aufdemrand.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.
the class AbstractTrigger method parse.
public boolean parse(dNPC npc, dPlayer player, InteractScriptContainer script, String id, Map<String, dObject> 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;
}
dB.echoDebug(script, DebugElement.Header, "Parsing " + name + " trigger: n@" + npc.getName() + "/p@" + player.getName());
// Create Queue
TimedQueue queue = TimedQueue.getQueue(ScriptQueue.getNextId(script.getName()));
// Add all entries to set it up
queue.addEntries(entries);
// Add context
if (context != null) {
OldEventManager.OldEventContextSource oecs = new OldEventManager.OldEventContextSource();
oecs.contexts = context;
queue.setContextSource(oecs);
}
// Start it
queue.start();
return true;
}
use of net.aufdemrand.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.
the class dB method echoError.
public static void echoError(ScriptQueue source, Throwable ex) {
if (ThrowErrorEvent) {
ThrowErrorEvent = false;
Map<String, dObject> context = new HashMap<String, dObject>();
Throwable thrown = ex;
if (ex.getCause() != null) {
thrown = ex.getCause();
}
context.put("message", new Element(thrown.getMessage()));
context.put("type", new Element(thrown.getClass().getSimpleName()));
context.put("queue", source);
ScriptEntry entry = (source != null ? source.getLastEntryExecuted() : null);
List<String> Determinations = OldEventManager.doEvents(Arrays.asList("server generates exception"), entry == null ? new BukkitScriptEntryData(null, null) : entry.entryData, context);
ThrowErrorEvent = true;
for (String Determination : Determinations) {
if (Determination.equalsIgnoreCase("CANCELLED")) {
return;
}
}
}
if (!showDebug) {
return;
}
if (!showStackTraces) {
dB.echoError(source, "Exception! Enable '/denizen debug -s' for the nitty-gritty.");
} else {
dB.echoError(source, "Internal exception was thrown!");
ex.printStackTrace();
if (dB.record) {
String prefix = ConsoleSender.dateFormat.format(new Date()) + " [SEVERE] ";
boolean first = true;
while (ex != null) {
dB.Recording.append(URLEncoder.encode(prefix + (first ? "" : "Caused by: ") + ex.toString() + "\n"));
for (StackTraceElement ste : ex.getStackTrace()) {
dB.Recording.append(URLEncoder.encode(prefix + ste.toString() + "\n"));
}
if (ex.getCause() == ex) {
return;
}
ex = ex.getCause();
first = false;
}
}
}
}
use of net.aufdemrand.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.
the class dB method echoError.
public static void echoError(ScriptQueue source, String message) {
dScript script = null;
if (source != null && source.getEntries().size() > 0 && source.getEntries().get(0).getScript() != null) {
script = source.getEntries().get(0).getScript();
} else if (source != null && source.getLastEntryExecuted() != null && source.getLastEntryExecuted().getScript() != null) {
script = source.getLastEntryExecuted().getScript();
}
if (ThrowErrorEvent) {
ThrowErrorEvent = false;
Map<String, dObject> context = new HashMap<String, dObject>();
context.put("message", new Element(message));
if (source != null) {
context.put("queue", source);
}
if (script != null) {
context.put("script", script);
}
List<String> events = new ArrayList<String>();
events.add("script generates error");
if (script != null) {
events.add(script.identifySimple() + " generates error");
}
ScriptEntry entry = (source != null ? source.getLastEntryExecuted() : null);
List<String> Determinations = OldEventManager.doEvents(events, entry != null ? entry.entryData : new BukkitScriptEntryData(null, null), context, true);
ThrowErrorEvent = true;
for (String Determination : Determinations) {
if (Determination.equalsIgnoreCase("CANCELLED")) {
return;
}
}
}
if (!showDebug) {
return;
}
ConsoleSender.sendMessage(ChatColor.LIGHT_PURPLE + " " + ChatColor.RED + "ERROR" + (script != null ? " in script '" + script.getName() + "'" : "") + "! " + ChatColor.WHITE + trimMessage(message));
}
use of net.aufdemrand.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.
the class PauseCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
pause(dNPC, pauseType, !scriptEntry.getCommandName().equalsIgnoreCase("RESUME"));
// If duration...
if (duration > 0) {
if (durations.containsKey(dNPC.getCitizen().getId() + pauseType.name())) {
try {
DenizenAPI.getCurrentInstance().getServer().getScheduler().cancelTask(durations.get(dNPC.getCitizen().getId() + pauseType.name()));
} catch (Exception e) {
dB.echoError(scriptEntry.getResidingQueue(), "There was an error pausing that!");
dB.echoError(scriptEntry.getResidingQueue(), e);
}
}
dB.echoDebug(scriptEntry, "Running delayed task: Unpause " + pauseType.toString());
final ScriptEntry se = scriptEntry;
durations.put(dNPC.getId() + pauseType.name(), DenizenAPI.getCurrentInstance().getServer().getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(), new Runnable() {
@Override
public void run() {
dB.echoDebug(se, "Running delayed task: Pausing " + pauseType.toString());
pause(dNPC, pauseType, false);
}
}, duration * 20));
}
}
Aggregations