Search in sources :

Example 26 with BukkitScriptEntryData

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

the class CommandScriptContainer method runAllowedHelpProcedure.

public boolean runAllowedHelpProcedure(dPlayer player, dNPC npc, Map<String, dObject> context) {
    // Add the reqId to each of the entries for the determine command
    List<ScriptEntry> entries = getEntries(new BukkitScriptEntryData(player, npc), "ALLOWED HELP");
    long id = DetermineCommand.getNewId();
    ScriptBuilder.addObjectToEntries(entries, "ReqId", id);
    ScriptQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId(getName())).setReqId(id).addEntries(entries);
    if (context != null) {
        OldEventManager.OldEventContextSource oecs = new OldEventManager.OldEventContextSource();
        oecs.contexts = context;
        queue.setContextSource(oecs);
    }
    queue.start();
    return DetermineCommand.hasOutcome(id) && DetermineCommand.getOutcome(id).get(0).equalsIgnoreCase("true");
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) OldEventManager(net.aufdemrand.denizencore.events.OldEventManager) ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry) ScriptQueue(net.aufdemrand.denizencore.scripts.queues.ScriptQueue)

Example 27 with BukkitScriptEntryData

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

the class FireworkCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    final dLocation location = scriptEntry.hasObject("location") ? (dLocation) scriptEntry.getObject("location") : ((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getLocation();
    Element type = (Element) scriptEntry.getObject("type");
    Element power = (Element) scriptEntry.getObject("power");
    boolean flicker = scriptEntry.hasObject("flicker");
    boolean trail = scriptEntry.hasObject("trail");
    List<dColor> primary = (List<dColor>) scriptEntry.getObject("primary");
    List<dColor> fade = (List<dColor>) scriptEntry.getObject("fade");
    // Report to dB
    dB.report(scriptEntry, getName(), location.debug() + type.debug() + power.debug() + (flicker ? aH.debugObj("flicker", flicker) : "") + (trail ? aH.debugObj("trail", trail) : "") + aH.debugObj("primary colors", primary.toString()) + (fade != null ? aH.debugObj("fade colors", fade.toString()) : ""));
    Firework firework = location.getWorld().spawn(location, Firework.class);
    FireworkMeta fireworkMeta = firework.getFireworkMeta();
    fireworkMeta.setPower(power.asInt());
    Builder fireworkBuilder = FireworkEffect.builder();
    fireworkBuilder.with(FireworkEffect.Type.valueOf(type.asString().toUpperCase()));
    fireworkBuilder.withColor(Conversion.convertColors(primary));
    if (fade != null) {
        fireworkBuilder.withFade(Conversion.convertColors(fade));
    }
    if (flicker) {
        fireworkBuilder.withFlicker();
    }
    if (trail) {
        fireworkBuilder.withTrail();
    }
    fireworkMeta.addEffects(fireworkBuilder.build());
    firework.setFireworkMeta(fireworkMeta);
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dColor(net.aufdemrand.denizen.objects.dColor) Firework(org.bukkit.entity.Firework) Builder(org.bukkit.FireworkEffect.Builder) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 28 with BukkitScriptEntryData

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

the class OxygenCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element type = scriptEntry.getElement("type");
    Element mode = scriptEntry.getElement("mode");
    Element amount = scriptEntry.getElement("amount");
    dB.report(scriptEntry, getName(), type.debug() + mode.debug() + amount.debug());
    dPlayer player = ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer();
    switch(Type.valueOf(type.asString().toUpperCase())) {
        case MAXIMUM:
            switch(Mode.valueOf(mode.asString().toUpperCase())) {
                case SET:
                    player.setMaximumAir(amount.asInt());
                    break;
                case ADD:
                    player.setMaximumAir(player.getMaximumAir() + amount.asInt());
                    break;
                case REMOVE:
                    player.setMaximumAir(player.getMaximumAir() - amount.asInt());
                    break;
            }
            return;
        case REMAINING:
            switch(Mode.valueOf(mode.asString().toUpperCase())) {
                case SET:
                    player.setRemainingAir(amount.asInt());
                    break;
                case ADD:
                    player.setRemainingAir(player.getRemainingAir() + amount.asInt());
                    break;
                case REMOVE:
                    player.setRemainingAir(player.getRemainingAir() - amount.asInt());
                    break;
            }
            return;
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer)

Example 29 with BukkitScriptEntryData

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

the class PermissionCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element action = scriptEntry.getElement("action");
    Element permission = scriptEntry.getElement("permission");
    Element group = scriptEntry.getElement("group");
    dWorld world = (dWorld) scriptEntry.getObject("world");
    // Report to dB
    dB.report(scriptEntry, getName(), action.debug() + permission.debug() + (group != null ? group.debug() : "") + (world != null ? world.debug() : ""));
    World bukkitWorld = null;
    if (world != null) {
        bukkitWorld = world.getWorld();
    }
    OfflinePlayer player = ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getOfflinePlayer() : null;
    switch(Action.valueOf(action.asString().toUpperCase())) {
        case ADD:
            if (group != null) {
                if (Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString())) {
                    dB.echoDebug(scriptEntry, "Group " + group + " already has permission " + permission);
                } else {
                    Depends.permissions.groupAdd(bukkitWorld, group.asString(), permission.asString());
                }
            } else {
                if (Depends.permissions.playerHas(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString())) {
                    dB.echoDebug(scriptEntry, "Player " + player.getName() + " already has permission " + permission);
                } else {
                    Depends.permissions.playerAdd(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString());
                }
            }
            return;
        case REMOVE:
            if (group != null) {
                if (!Depends.permissions.groupHas(bukkitWorld, group.asString(), permission.asString())) {
                    dB.echoDebug(scriptEntry, "Group " + group + " does not have access to permission " + permission);
                } else {
                    Depends.permissions.groupRemove(bukkitWorld, group.asString(), permission.asString());
                }
            } else {
                if (!Depends.permissions.playerHas(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString())) {
                    dB.echoDebug(scriptEntry, "Player " + player.getName() + " does not have access to permission " + permission);
                } else {
                    Depends.permissions.playerRemove(bukkitWorld == null ? null : bukkitWorld.getName(), player, permission.asString());
                }
            }
            return;
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) OfflinePlayer(org.bukkit.OfflinePlayer) net.aufdemrand.denizen.objects.dWorld(net.aufdemrand.denizen.objects.dWorld) World(org.bukkit.World) net.aufdemrand.denizen.objects.dWorld(net.aufdemrand.denizen.objects.dWorld)

Example 30 with BukkitScriptEntryData

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

the class StatisticCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    boolean specified_players = false;
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("action") && arg.matchesEnum(Action.values())) {
            scriptEntry.addObject("action", arg.asElement());
        } else if (arg.matchesPrefix("players") && !scriptEntry.hasObject("players") && arg.matchesArgumentList(dPlayer.class)) {
            scriptEntry.addObject("players", arg.asType(dList.class));
            specified_players = true;
        } else if (!scriptEntry.hasObject("statistic") && arg.matchesEnum(Statistic.values())) {
            scriptEntry.addObject("statistic", arg.asElement());
        } else if (!scriptEntry.hasObject("amount") && arg.matchesPrimitive(aH.PrimitiveType.Integer)) {
            scriptEntry.addObject("amount", arg.asElement());
        } else if (arg.matchesPrefix("qualifier", "q") && !scriptEntry.hasObject("material") && !scriptEntry.hasObject("entity")) {
            if (arg.matchesArgumentType(dMaterial.class)) {
                scriptEntry.addObject("material", arg.asType(dMaterial.class));
            } else if (arg.matchesArgumentType(dEntity.class)) {
                scriptEntry.addObject("entity", arg.asType(dEntity.class));
            }
        }
    }
    if (!scriptEntry.hasObject("action")) {
        throw new InvalidArgumentsException("Must specify a valid action!");
    }
    if (!scriptEntry.hasObject("statistic")) {
        throw new InvalidArgumentsException("Must specify a valid Statistic!");
    }
    if (!scriptEntry.hasObject("amount")) {
        scriptEntry.addObject("amount", new Element(1));
    }
    Statistic.Type type = Statistic.valueOf(scriptEntry.getElement("statistic").asString().toUpperCase()).getType();
    if (type != Statistic.Type.UNTYPED) {
        if ((type == Statistic.Type.BLOCK || type == Statistic.Type.ITEM) && !scriptEntry.hasObject("material")) {
            throw new InvalidArgumentsException("Must specify a valid " + type.name() + " MATERIAL!");
        } else if (type == Statistic.Type.ENTITY && !scriptEntry.hasObject("entity")) {
            throw new InvalidArgumentsException("Must specify a valid ENTITY!");
        }
    }
    if (!scriptEntry.hasObject("players") && ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() && !specified_players) {
        scriptEntry.addObject("players", new dList(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().identify()));
    }
    if (!scriptEntry.hasObject("players")) {
        throw new InvalidArgumentsException("Must specify valid players!");
    }
}
Also used : net.aufdemrand.denizen.objects.dMaterial(net.aufdemrand.denizen.objects.dMaterial) Statistic(org.bukkit.Statistic) 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) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) 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