@Override public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { Element message = scriptEntry.getElement("message"); Element fileName = scriptEntry.getElement("file"); Element typeElement = scriptEntry.getElement("type"); dB.report(scriptEntry, getName(), message.debug() + fileName.debug() + typeElement.debug()); Type type = Type.valueOf(typeElement.asString().toUpperCase()); String directory = URLDecoder.decode(System.getProperty("user.dir")); File file = new File(directory, fileName.asString()); if (type == Type.NONE) { try { file.getParentFile().mkdirs(); FileWriter fw = new FileWriter(file, true); fw.write(message + "\n"); fw.close(); } catch (IOException e) { dB.echoError("Error logging to file..."); dB.echoError(e); } return; } DebugLog log = new DebugLog("Denizen-ScriptLog-" + fileName, file.getAbsolutePath()); switch (type) { case SEVERE: log.severe(message.asString()); break; case INFO: log.info(message.asString()); break; case WARNING: log.warning(message.asString()); break; case FINE: log.fine(message.asString()); break; case FINER: log.finer(message.asString()); break; case FINEST: log.finest(message.asString()); } log.close(); }
@Override public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { // Get objects Action action = (Action) scriptEntry.getObject("action"); dLocation location = (dLocation) scriptEntry.getObject("location"); Element range = (Element) scriptEntry.getObject("range"); Element id = (Element) scriptEntry.getObject("id"); // Report to dB dB.report( scriptEntry, getName(), aH.debugObj("NPC", scriptEntry.getNPC().toString()) + action.name() + id.debug() + (location != null ? location.debug() : "") + (range != null ? range.debug() : "")); dNPC npc = scriptEntry.getNPC(); switch (action) { case ADD: npc.getCitizen().getTrait(Anchors.class).addAnchor(id.asString(), location); return; case ASSUME: npc.getEntity() .teleport( npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString()).getLocation()); return; case WALKNEAR: npc.getNavigator() .setTarget( Utilities.getWalkableLocationNear( npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString()).getLocation(), range.asInt())); return; case WALKTO: npc.getNavigator() .setTarget( npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString()).getLocation()); return; case REMOVE: npc.getCitizen() .getTrait(Anchors.class) .removeAnchor(npc.getCitizen().getTrait(Anchors.class).getAnchor(id.asString())); } }