Search in sources :

Example 36 with BukkitScriptEntryData

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

the class SitCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dLocation location = (dLocation) scriptEntry.getObject("location");
    if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntityType() != EntityType.PLAYER && ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntityType() != EntityType.OCELOT && ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntityType() != EntityType.WOLF) {
        dB.echoError(scriptEntry.getResidingQueue(), "...only Player, ocelot, or wolf type NPCs can sit!");
        return;
    }
    dB.report(scriptEntry, getName(), aH.debugObj("npc", ((BukkitScriptEntryData) scriptEntry.entryData).getNPC()) + (location != null ? location.debug() : ""));
    if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntityType() == EntityType.OCELOT) {
        ((Ocelot) ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntity()).setSitting(true);
    } else if (((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntityType() == EntityType.WOLF) {
        ((Wolf) ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getEntity()).setSitting(true);
    } else {
        SittingTrait trait = ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getCitizen().getTrait(SittingTrait.class);
        if (!((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getCitizen().hasTrait(SittingTrait.class)) {
            ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getCitizen().addTrait(SittingTrait.class);
            dB.echoDebug(scriptEntry, "...added sitting trait");
        }
        if (location != null) {
            trait.sit(location);
        } else {
            trait.sit();
        }
    }
}
Also used : Ocelot(org.bukkit.entity.Ocelot) SittingTrait(net.aufdemrand.denizen.npc.traits.SittingTrait) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 37 with BukkitScriptEntryData

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

the class TakeCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("type") && arg.matches("money", "coins")) {
            scriptEntry.addObject("type", Type.MONEY);
        } else if (!scriptEntry.hasObject("type") && arg.matches("item_in_hand", "iteminhand")) {
            scriptEntry.addObject("type", Type.ITEMINHAND);
        } else if (!scriptEntry.hasObject("qty") && arg.matchesPrefix("q", "qty", "quantity") && arg.matchesPrimitive(aH.PrimitiveType.Double)) {
            scriptEntry.addObject("qty", arg.asElement());
        } else if (!scriptEntry.hasObject("items") && arg.matchesPrefix("bydisplay") && !scriptEntry.hasObject("type")) {
            scriptEntry.addObject("type", Type.BYDISPLAY);
            scriptEntry.addObject("displayname", arg.asElement());
        } else if (!scriptEntry.hasObject("type") && !scriptEntry.hasObject("items") && arg.matchesPrefix("bycover")) {
            scriptEntry.addObject("type", Type.BYCOVER);
            scriptEntry.addObject("cover", arg.asType(dList.class));
        } else if (!scriptEntry.hasObject("slot") && !scriptEntry.hasObject("type") && arg.matchesPrefix("slot") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
            scriptEntry.addObject("type", Type.SLOT);
            scriptEntry.addObject("slot", arg.asElement());
        } else if (!scriptEntry.hasObject("items") && !scriptEntry.hasObject("type") && arg.matchesArgumentList(dItem.class)) {
            scriptEntry.addObject("items", dList.valueOf(arg.raw_value.replace("item:", "")).filter(dItem.class, scriptEntry));
        } else if (!scriptEntry.hasObject("inventory") && arg.matchesPrefix("f", "from") && arg.matchesArgumentType(dInventory.class)) {
            scriptEntry.addObject("inventory", arg.asType(dInventory.class));
        } else if (!scriptEntry.hasObject("type") && arg.matches("inventory")) {
            scriptEntry.addObject("type", Type.INVENTORY);
        } else if (!scriptEntry.hasObject("inventory") && arg.matches("npc")) {
            scriptEntry.addObject("inventory", ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getDenizenEntity().getInventory());
        }
    }
    scriptEntry.defaultObject("type", Type.ITEM).defaultObject("qty", 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 take from!");
    }
    if (type == Type.ITEM && scriptEntry.getObject("items") == null) {
        throw new InvalidArgumentsException("Must specify item/items!");
    }
}
Also used : net.aufdemrand.denizen.objects.dItem(net.aufdemrand.denizen.objects.dItem) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) 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 38 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 39 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 40 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)

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