Search in sources :

Example 56 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class FlyCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("cancel") && arg.matches("cancel")) {
            scriptEntry.addObject("cancel", "");
        } else if (!scriptEntry.hasObject("destinations") && arg.matchesPrefix("destination", "destinations", "d")) {
            scriptEntry.addObject("destinations", arg.asType(dList.class).filter(dLocation.class));
        } else if (!scriptEntry.hasObject("controller") && arg.matchesArgumentType(dPlayer.class) && arg.matchesPrefix("controller", "c")) {
            // Check if it matches a dPlayer, but save it as a dEntity
            scriptEntry.addObject("controller", (arg.asType(dEntity.class)));
        } else if (!scriptEntry.hasObject("origin") && arg.matchesArgumentType(dLocation.class)) {
            scriptEntry.addObject("origin", arg.asType(dLocation.class));
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentList(dEntity.class)) {
            scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
        } else if (!scriptEntry.hasObject("rotationThreshold") && arg.matchesPrefix("rotationthreshold", "rotation", "r") && arg.matchesPrimitive(aH.PrimitiveType.Float)) {
            scriptEntry.addObject("rotationThreshold", arg.asElement());
        } else if (!scriptEntry.hasObject("speed") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
            scriptEntry.addObject("speed", arg.asElement());
        } else {
            arg.reportUnhandled();
        }
    }
    // Use the NPC or player's locations as the location if one is not specified
    scriptEntry.defaultObject("origin", ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getLocation() : null, ((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ? ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation() : null);
    // Use a default speed and rotation threshold if they are not specified
    scriptEntry.defaultObject("speed", new Element(1.2));
    scriptEntry.defaultObject("rotationThreshold", new Element(15));
    // Check to make sure required arguments have been filled
    if (!scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Must specify entity/entities!");
    }
    if (!scriptEntry.hasObject("origin")) {
        throw new InvalidArgumentsException("Must specify an origin!");
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 57 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class HealCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    boolean specified_targets = false;
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("amount") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
            scriptEntry.addObject("amount", arg.asElement());
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(dList.class)) {
            // Entity arg
            scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
            specified_targets = true;
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(dEntity.class)) {
            // Entity arg
            scriptEntry.addObject("entities", Arrays.asList(arg.asType(dEntity.class)));
            specified_targets = true;
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("amount")) {
        scriptEntry.addObject("amount", new Element(-1));
    }
    if (!specified_targets) {
        List<dEntity> entities = new ArrayList<dEntity>();
        if (((BukkitScriptEntryData) scriptEntry.entryData).getPlayer() != null) {
            entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity());
        } else if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC() != null) {
            entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity());
        } else {
            throw new InvalidArgumentsException("No valid target entities found.");
        }
        scriptEntry.addObject("entities", entities);
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) ArrayList(java.util.ArrayList) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 58 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class HurtCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    boolean specified_targets = false;
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("amount") && (arg.matchesPrimitive(aH.PrimitiveType.Double) || arg.matchesPrimitive(aH.PrimitiveType.Integer))) {
            scriptEntry.addObject("amount", arg.asElement());
        } else if (!scriptEntry.hasObject("source") && arg.matchesPrefix("source", "s") && arg.matchesArgumentType(dEntity.class)) {
            scriptEntry.addObject("source", arg.asType(dEntity.class));
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(dList.class)) {
            // Entity arg
            scriptEntry.addObject("entities", arg.asType(dList.class).filter(dEntity.class));
            specified_targets = true;
        } else if (!scriptEntry.hasObject("entities") && arg.matchesArgumentType(dEntity.class)) {
            // Entity arg
            scriptEntry.addObject("entities", Arrays.asList(arg.asType(dEntity.class)));
            specified_targets = true;
        } else if (!scriptEntry.hasObject("cause") && arg.matchesEnum(EntityDamageEvent.DamageCause.values())) {
            scriptEntry.addObject("cause", arg.asElement());
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("amount")) {
        scriptEntry.addObject("amount", new Element(1.0d));
    }
    if (!specified_targets) {
        List<dEntity> entities = new ArrayList<dEntity>();
        if (((BukkitScriptEntryData) scriptEntry.entryData).getPlayer() != null) {
            entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getDenizenEntity());
        } else if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC() != null) {
            entities.add(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity());
        } else {
            throw new InvalidArgumentsException("No valid target entities found.");
        }
        scriptEntry.addObject("entities", entities);
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizencore.objects.aH(net.aufdemrand.denizencore.objects.aH) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Element(net.aufdemrand.denizencore.objects.Element) ArrayList(java.util.ArrayList) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 59 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class GiveCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element engrave = scriptEntry.getElement("engrave");
    Element unlimit_stack_size = scriptEntry.getElement("unlimit_stack_size");
    dInventory inventory = (dInventory) scriptEntry.getObject("inventory");
    Element qty = scriptEntry.getElement("qty");
    Type type = (Type) scriptEntry.getObject("type");
    Element slot = scriptEntry.getElement("slot");
    Object items_object = scriptEntry.getObject("items");
    List<dItem> items = null;
    if (items_object != null) {
        items = (List<dItem>) items_object;
    }
    dB.report(scriptEntry, getName(), aH.debugObj("Type", type.name()) + (inventory != null ? inventory.debug() : "") + aH.debugObj("Quantity", qty.asDouble()) + engrave.debug() + unlimit_stack_size.debug() + (items != null ? aH.debugObj("Items", items) : "") + slot.debug());
    switch(type) {
        case MONEY:
            if (Depends.economy != null) {
                Depends.economy.depositPlayer(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getOfflinePlayer(), qty.asDouble());
            } else {
                dB.echoError("No economy loaded! Have you installed Vault and a compatible economy plugin?");
            }
            break;
        case EXP:
            ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().giveExp(qty.asInt());
            break;
        case ITEM:
            boolean set_quantity = scriptEntry.hasObject("set_quantity");
            boolean limited = !unlimit_stack_size.asBoolean();
            for (dItem item : items) {
                ItemStack is = item.getItemStack();
                if (is.getType() == Material.AIR) {
                    dB.echoError("Cannot give air!");
                    continue;
                }
                if (set_quantity) {
                    is.setAmount(qty.asInt());
                }
                // TODO: Should engrave be kept?
                if (engrave.asBoolean()) {
                    is = CustomNBT.addCustomNBT(item.getItemStack(), "owner", ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getName(), CustomNBT.KEY_DENIZEN);
                }
                List<ItemStack> leftovers = inventory.addWithLeftovers(slot.asInt() - 1, limited, is);
                if (!leftovers.isEmpty()) {
                    dB.echoDebug(scriptEntry, "The inventory didn't have enough space, the rest of the items have been placed on the floor.");
                    for (ItemStack leftoverItem : leftovers) {
                        inventory.getLocation().getWorld().dropItem(inventory.getLocation(), leftoverItem);
                    }
                }
            }
            break;
    }
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dInventory(net.aufdemrand.denizen.objects.dInventory) ItemStack(org.bukkit.inventory.ItemStack)

Example 60 with BukkitScriptEntryData

use of net.aufdemrand.denizen.BukkitScriptEntryData in project Denizen-For-Bukkit by DenizenScript.

the class ActionHandler method doAction.

public String doAction(String actionName, dNPC npc, dPlayer player, AssignmentScriptContainer assignment, Map<String, dObject> context) {
    if (context == null) {
        context = new HashMap<String, dObject>();
    }
    String determination = "none";
    if (assignment == null) {
        // dB.echoDebug("Tried to do 'on " + actionName + ":' but couldn't find a matching script.");
        return determination;
    }
    if (!assignment.contains("actions.on " + actionName)) {
        return determination;
    }
    dB.report(assignment, "Action", aH.debugObj("Type", "On " + actionName) + aH.debugObj("NPC", npc.toString()) + assignment.getAsScriptArg().debug() + (player != null ? aH.debugObj("Player", player.getName()) : ""));
    // Fetch script from Actions
    List<ScriptEntry> script = assignment.getEntries(new BukkitScriptEntryData(player, npc), "actions.on " + actionName);
    if (script.isEmpty()) {
        return determination;
    }
    // Create new ID -- this is what we will look for when determining an outcome
    long id = DetermineCommand.getNewId();
    // Add the reqId to each of the entries for the determine command
    ScriptBuilder.addObjectToEntries(script, "ReqId", id);
    dB.echoDebug(assignment, DebugElement.Header, "Building action 'On " + actionName.toUpperCase() + "' for " + npc.toString());
    // Add entries and context to the queue
    ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(assignment.getName())).addEntries(script);
    OldEventManager.OldEventContextSource oecs = new OldEventManager.OldEventContextSource();
    oecs.contexts = context;
    oecs.contexts.put("event_header", new Element(actionName));
    queue.setContextSource(oecs);
    // Start the queue!
    queue.start();
    // Check the determination by asking the DetermineCommand
    if (DetermineCommand.hasOutcome(id)) {
        determination = DetermineCommand.getOutcome(id).get(0);
    }
    // TODO: Multiple determination system
    return determination;
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) OldEventManager(net.aufdemrand.denizencore.events.OldEventManager) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) DebugElement(net.aufdemrand.denizencore.utilities.debugging.dB.DebugElement) Element(net.aufdemrand.denizencore.objects.Element) ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry) ScriptQueue(net.aufdemrand.denizencore.scripts.queues.ScriptQueue)

Aggregations

BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)61 Element (net.aufdemrand.denizencore.objects.Element)38 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)19 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)18 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)18 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)13 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)13 Duration (net.aufdemrand.denizencore.objects.Duration)9 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)8 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)8 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)6 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)6 Player (org.bukkit.entity.Player)6 ArrayList (java.util.ArrayList)5 AssignmentTrait (net.aufdemrand.denizen.npc.traits.AssignmentTrait)5 net.aufdemrand.denizen.objects.dInventory (net.aufdemrand.denizen.objects.dInventory)5 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)5 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)5 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)5 EventHandler (org.bukkit.event.EventHandler)5