use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class WalkCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Fetch required objects
dLocation loc = (dLocation) scriptEntry.getObject("location");
Element speed = scriptEntry.getElement("speed");
Element auto_range = scriptEntry.getElement("auto_range");
Element radius = scriptEntry.getElement("radius");
Element stop = scriptEntry.getElement("stop");
List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
final dLocation lookat = scriptEntry.getdObject("lookat");
// Debug the execution
dB.report(scriptEntry, getName(), (loc != null ? loc.debug() : "") + (speed != null ? speed.debug() : "") + (auto_range != null ? auto_range.debug() : "") + (radius != null ? radius.debug() : "") + (lookat != null ? lookat.debug() : "") + stop.debug() + (aH.debugObj("entities", entities)));
// Do the execution
boolean shouldStop = stop.asBoolean();
List<dNPC> npcs = new ArrayList<dNPC>();
final List<dEntity> waitForEntities = new ArrayList<dEntity>();
for (final dEntity entity : entities) {
if (entity.isCitizensNPC()) {
dNPC npc = entity.getDenizenNPC();
npcs.add(npc);
if (!npc.isSpawned()) {
dB.echoError(scriptEntry.getResidingQueue(), "NPC " + npc.identify() + " is not spawned!");
continue;
}
if (shouldStop) {
npc.getNavigator().cancelNavigation();
continue;
}
if (auto_range != null && auto_range == Element.TRUE) {
double distance = npc.getLocation().distance(loc);
if (npc.getNavigator().getLocalParameters().range() < distance + 10) {
npc.getNavigator().getLocalParameters().range((float) distance + 10);
}
}
npc.getNavigator().setTarget(loc);
if (lookat != null) {
npc.getNavigator().getLocalParameters().lookAtFunction(new Function<Navigator, Location>() {
@Override
public Location apply(Navigator nav) {
return lookat;
}
});
}
if (speed != null) {
npc.getNavigator().getLocalParameters().speedModifier(speed.asFloat());
}
if (radius != null) {
npc.getNavigator().getLocalParameters().addRunCallback(WalkCommandCitizensEvents.generateNewFlocker(npc.getCitizen(), radius.asDouble()));
}
} else if (shouldStop) {
NMSHandler.getInstance().getEntityHelper().stopWalking(entity.getBukkitEntity());
} else {
waitForEntities.add(entity);
NMSHandler.getInstance().getEntityHelper().walkTo(entity.getBukkitEntity(), loc, speed != null ? speed.asDouble() : 0.2, new Runnable() {
@Override
public void run() {
checkHeld(entity);
}
});
}
}
if (scriptEntry.shouldWaitFor()) {
held.add(scriptEntry);
if (!npcs.isEmpty()) {
scriptEntry.addObject("tally", npcs);
}
if (!waitForEntities.isEmpty()) {
scriptEntry.addObject("entities", waitForEntities);
}
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class FakeItemCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
List<dItem> items = (List<dItem>) scriptEntry.getObject("item");
final Element elSlot = scriptEntry.getElement("slot");
Duration duration = scriptEntry.getdObject("duration");
final List<dPlayer> players = (List<dPlayer>) scriptEntry.getObject("players");
final Element player_only = scriptEntry.getElement("player_only");
dB.report(scriptEntry, getName(), aH.debugList("items", items) + elSlot.debug() + duration.debug() + aH.debugList("players", players) + player_only.debug());
int slot = elSlot.asInt() - 1;
final boolean playerOnly = player_only.asBoolean();
final PacketHelper packetHelper = NMSHandler.getInstance().getPacketHelper();
for (dItem item : items) {
if (item == null) {
slot++;
continue;
}
for (dPlayer player : players) {
Player ent = player.getPlayerEntity();
packetHelper.setSlot(ent, translateSlot(ent, slot, playerOnly), item.getItemStack(), playerOnly);
}
final int slotSnapshot = slot;
slot++;
if (duration.getSeconds() > 0) {
DenizenCore.schedule(new OneTimeSchedulable(new Runnable() {
@Override
public void run() {
for (dPlayer player : players) {
Player ent = player.getPlayerEntity();
ItemStack original = ent.getOpenInventory().getItem(translateSlot(ent, slotSnapshot, playerOnly));
packetHelper.setSlot(ent, slotSnapshot, original, playerOnly);
}
}
}, (float) duration.getSeconds()));
}
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class GiveCommand method parseArgs.
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
/* Match arguments to expected variables */
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (!scriptEntry.hasObject("qty") && arg.matchesPrefix("q", "qty", "quantity") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
scriptEntry.addObject("qty", arg.asElement());
scriptEntry.addObject("set_quantity", new Element(true));
} else if (!scriptEntry.hasObject("type") && arg.matches("money", "coins")) {
scriptEntry.addObject("type", Type.MONEY);
} else if (!scriptEntry.hasObject("type") && arg.matches("xp", "exp", "experience")) {
scriptEntry.addObject("type", Type.EXP);
} else if (!scriptEntry.hasObject("engrave") && arg.matches("engrave")) {
scriptEntry.addObject("engrave", new Element(true));
} else if (!scriptEntry.hasObject("unlimit_stack_size") && arg.matches("unlimit_stack_size")) {
scriptEntry.addObject("unlimit_stack_size", new Element(true));
} else if (!scriptEntry.hasObject("items") && !scriptEntry.hasObject("type")) {
scriptEntry.addObject("items", dList.valueOf(arg.raw_value.startsWith("item:") ? arg.raw_value.substring("item:".length()) : arg.raw_value).filter(dItem.class, scriptEntry));
} else if (!scriptEntry.hasObject("inventory") && arg.matchesPrefix("t", "to") && arg.matchesArgumentType(dInventory.class)) {
scriptEntry.addObject("inventory", arg.asType(dInventory.class));
} else if (!scriptEntry.hasObject("slot") && arg.matchesPrefix("slot") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
scriptEntry.addObject("slot", arg.asElement());
} else {
arg.reportUnhandled();
}
}
scriptEntry.defaultObject("type", Type.ITEM).defaultObject("engrave", new Element(false)).defaultObject("unlimit_stack_size", new Element(false)).defaultObject("qty", new Element(1)).defaultObject("slot", new Element(1));
Type type = (Type) scriptEntry.getObject("type");
if (type != Type.MONEY && scriptEntry.getObject("inventory") == null) {
scriptEntry.addObject("inventory", ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getInventory() : null);
}
if (!scriptEntry.hasObject("inventory") && type != Type.MONEY) {
throw new InvalidArgumentsException("Must specify an inventory to give to!");
}
if (type == Type.ITEM && scriptEntry.getObject("items") == null) {
throw new InvalidArgumentsException("Must specify item/items!");
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class InventoryCommand method execute.
@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
// Get objects
List<String> actions = (List<String>) scriptEntry.getObject("actions");
AbstractMap.SimpleEntry<Integer, dInventory> originentry = (AbstractMap.SimpleEntry<Integer, dInventory>) scriptEntry.getObject("origin");
dInventory origin = originentry != null ? originentry.getValue() : null;
AbstractMap.SimpleEntry<Integer, dInventory> destinationentry = (AbstractMap.SimpleEntry<Integer, dInventory>) scriptEntry.getObject("destination");
dInventory destination = destinationentry.getValue();
Element slot = scriptEntry.getElement("slot");
dB.report(scriptEntry, getName(), aH.debugObj("actions", actions.toString()) + (destination.debug()) + (origin != null ? origin.debug() : "") + slot.debug());
for (String action : actions) {
switch(Action.valueOf(action.toUpperCase())) {
// Make the attached player open the destination inventory
case OPEN:
// Use special method to make opening workbenches work properly
if (destination.getIdType().equals("workbench") || destination.getIdHolder().equalsIgnoreCase("workbench")) {
((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().openWorkbench(null, true);
} else // Otherwise, open inventory as usual
{
((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().openInventory(destination.getInventory());
}
break;
// Make the attached player close any open inventory
case CLOSE:
((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().closeInventory();
break;
// Turn destination's contents into a copy of origin's
case COPY:
if (origin == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Missing origin argument!");
return;
}
origin.replace(destination);
break;
// Copy origin's contents to destination, then empty origin
case MOVE:
if (origin == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Missing origin argument!");
return;
}
origin.replace(destination);
origin.clear();
break;
// Swap the contents of the two inventories
case SWAP:
if (origin == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Missing origin argument!");
return;
}
dInventory temp = new dInventory(destination.getInventory());
origin.replace(destination);
temp.replace(origin);
break;
// Add origin's contents to destination
case ADD:
if (origin == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Missing origin argument!");
return;
}
destination.add(slot.asInt() - 1, origin.getContents());
break;
// Remove origin's contents from destination
case REMOVE:
if (origin == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Missing origin argument!");
return;
}
destination.remove(origin.getContents());
break;
// Set items by slot
case SET:
if (origin == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Missing origin argument!");
return;
}
destination.setSlots(slot.asInt() - 1, origin.getContents(), originentry.getKey());
break;
// destination
case KEEP:
if (origin == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Missing origin argument!");
return;
}
destination.keep(origin.getContents());
break;
// destination
case EXCLUDE:
if (origin == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Missing origin argument!");
return;
}
destination.exclude(origin.getContents());
break;
// until it is full
case FILL:
if (origin == null) {
dB.echoError(scriptEntry.getResidingQueue(), "Missing origin argument!");
return;
}
destination.fill(origin.getContents());
break;
// Clear the content of the destination inventory
case CLEAR:
destination.clear();
break;
// If this is a player inventory, update it
case UPDATE:
if (!destination.update()) {
dB.echoError("Only player inventories can be force-updated!");
}
break;
}
}
}
use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.
the class MapCommand method execute.
@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));
}
}
}
}
Aggregations