@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())); } }
@Override public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { Element id = scriptEntry.getElement("map-id"); dWorld create = scriptEntry.getdObject("new"); Element reset = scriptEntry.getElement("reset"); dLocation resetLoc = scriptEntry.getdObject("reset-loc"); Element image = scriptEntry.getElement("image"); dScript script = scriptEntry.getdObject("script"); Element resize = scriptEntry.getElement("resize"); Element width = scriptEntry.getElement("width"); Element height = scriptEntry.getElement("height"); Element x = scriptEntry.getElement("x-value"); Element y = scriptEntry.getElement("y-value"); dB.report( scriptEntry, getName(), (id != null ? id.debug() : "") + (create != null ? create.debug() : "") + reset.debug() + (resetLoc != null ? resetLoc.debug() : "") + (image != null ? image.debug() : "") + (script != null ? script.debug() : "") + resize.debug() + (width != null ? width.debug() : "") + (height != null ? height.debug() : "") + x.debug() + y.debug()); MapView map = null; if (create != null) { map = Bukkit.getServer().createMap(create.getWorld()); scriptEntry.addObject("created_map", new Element(map.getId())); } else if (id != null) { map = Bukkit.getServer().getMap((short) id.asInt()); if (map == null) throw new CommandExecutionException("No map found for ID '" + id.asInt() + "'!"); } else { throw new CommandExecutionException( "The map command failed somehow! Report this to a developer!"); } if (reset.asBoolean()) { List<MapRenderer> oldRenderers = DenizenMapManager.removeDenizenRenderers(map); for (MapRenderer renderer : oldRenderers) { map.addRenderer(renderer); } if (resetLoc != null) { map.setCenterX(resetLoc.getBlockX()); map.setCenterZ(resetLoc.getBlockZ()); map.setWorld(resetLoc.getWorld()); } } else if (script != null) { DenizenMapManager.removeDenizenRenderers(map); ((MapScriptContainer) script.getContainer()).applyTo(map); } else { DenizenMapRenderer dmr = DenizenMapManager.getDenizenRenderer(map); if (image != null) { int wide = width != null ? width.asInt() : resize.asBoolean() ? 128 : 0; int high = height != null ? height.asInt() : resize.asBoolean() ? 128 : 0; if (CoreUtilities.toLowerCase(image.asString()).endsWith(".gif")) dmr.addObject( new MapAnimatedImage( x.asString(), y.asString(), "true", false, image.asString(), wide, high)); else dmr.addObject( new MapImage( x.asString(), y.asString(), "true", false, image.asString(), wide, high)); } } }
@Override public void execute(ScriptEntry scriptEntry) throws CommandExecutionException { // Extract objects from ScriptEntry List<dLocation> locations = (List<dLocation>) scriptEntry.getObject("location"); List<dPlayer> targets = (List<dPlayer>) scriptEntry.getObject("targets"); Effect effect = (Effect) scriptEntry.getObject("effect"); Particle particleEffect = (Particle) scriptEntry.getObject("particleeffect"); Element iconcrack = scriptEntry.getElement("iconcrack"); Element iconcrack_data = scriptEntry.getElement("iconcrack_data"); Element iconcrack_type = scriptEntry.getElement("iconcrack_type"); Element radius = scriptEntry.getElement("radius"); Element data = scriptEntry.getElement("data"); Element qty = scriptEntry.getElement("qty"); dLocation offset = scriptEntry.getdObject("offset"); // Report to dB dB.report( scriptEntry, getName(), (effect != null ? aH.debugObj("effect", effect.getName()) : particleEffect != null ? aH.debugObj("special effect", particleEffect.getName()) : iconcrack_type.debug() + iconcrack.debug() + (iconcrack_data != null ? iconcrack_data.debug() : "")) + aH.debugObj("locations", locations.toString()) + (targets != null ? aH.debugObj("targets", targets.toString()) : "") + radius.debug() + data.debug() + qty.debug() + offset.debug()); for (dLocation location : locations) { // Slightly increase the location's Y so effects don't seem to come out of the ground location.add(0, 1, 0); // Play the Bukkit effect the number of times specified if (effect != null) { for (int n = 0; n < qty.asInt(); n++) { if (targets != null) { for (dPlayer player : targets) { if (player.isValid() && player.isOnline()) { effect.playFor(player.getPlayerEntity(), location, data.asInt()); } } } else { effect.play(location, data.asInt(), radius.asInt()); } } } // Play a ParticleEffect else if (particleEffect != null) { float osX = (float) offset.getX(); float osY = (float) offset.getY(); float osZ = (float) offset.getZ(); List<Player> players = new ArrayList<Player>(); if (targets == null) { float rad = radius.asFloat(); for (Player player : location.getWorld().getPlayers()) { if (player.getLocation().distanceSquared(location) < rad * rad) { players.add(player); } } } else { for (dPlayer player : targets) { if (player.isValid() && player.isOnline()) { players.add(player.getPlayerEntity()); } } } for (Player player : players) { particleEffect.playFor(player, location, qty.asInt(), offset.toVector(), data.asFloat()); } } // Play an iconcrack (item break) effect else { float osX = (float) offset.getX(); float osY = (float) offset.getY(); float osZ = (float) offset.getZ(); List<Player> players = new ArrayList<Player>(); if (targets == null) { float rad = radius.asFloat(); for (Player player : location.getWorld().getPlayers()) { if (player.getLocation().distanceSquared(location) < rad * rad) { players.add(player); } } } else { for (dPlayer player : targets) { if (player.isValid() && player.isOnline()) { players.add(player.getPlayerEntity()); } } } // TODO: better this all if (iconcrack_type.asString().equalsIgnoreCase("iconcrack")) { ItemStack itemStack = new ItemStack(iconcrack.asInt(), iconcrack_data != null ? iconcrack_data.asInt() : 0); Particle particle = NMSHandler.getInstance().getParticleHelper().getParticle("ITEM_CRACK"); for (Player player : players) { particle.playFor( player, location, qty.asInt(), offset.toVector(), data.asFloat(), itemStack); } } else if (iconcrack_type.asString().equalsIgnoreCase("blockcrack")) { MaterialData materialData = new MaterialData( iconcrack.asInt(), (byte) (iconcrack_data != null ? iconcrack_data.asInt() : 0)); Particle particle = NMSHandler.getInstance().getParticleHelper().getParticle("BLOCK_CRACK"); for (Player player : players) { particle.playFor( player, location, qty.asInt(), offset.toVector(), data.asFloat(), materialData); } } else { // blockdust MaterialData materialData = new MaterialData( iconcrack.asInt(), (byte) (iconcrack_data != null ? iconcrack_data.asInt() : 0)); Particle particle = NMSHandler.getInstance().getParticleHelper().getParticle("BLOCK_DUST"); for (Player player : players) { particle.playFor( player, location, qty.asInt(), offset.toVector(), data.asFloat(), materialData); } } } } }