Search in sources :

Example 71 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class GameRuleCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Fetch objects
    dWorld world = scriptEntry.getdObject("world");
    Element gamerule = scriptEntry.getElement("gamerule");
    Element value = scriptEntry.getElement("value");
    // Report to dB
    dB.report(scriptEntry, getName(), world.debug() + gamerule.debug() + value.debug());
    // Execute
    if (!world.getWorld().setGameRuleValue(gamerule.asString(), value.asString())) {
        dB.echoError(scriptEntry.getResidingQueue(), "Invalid gamerule!");
    }
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizen.objects.dWorld(net.aufdemrand.denizen.objects.dWorld)

Example 72 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class PlayEffectCommand method execute.

@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());
                }
            }
        } else // Play a ParticleEffect
        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());
            }
        } else // Play an iconcrack (item break) effect
        {
            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(), 1, (short) (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);
                }
            }
        }
    }
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) Element(net.aufdemrand.denizencore.objects.Element) Particle(net.aufdemrand.denizen.nms.interfaces.Particle) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) ArrayList(java.util.ArrayList) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Effect(net.aufdemrand.denizen.nms.interfaces.Effect) MaterialData(org.bukkit.material.MaterialData) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) ItemStack(org.bukkit.inventory.ItemStack)

Example 73 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class PlaySoundCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    // Iterate through arguments
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("entities") && arg.matchesArgumentList(dLocation.class)) {
            scriptEntry.addObject("locations", arg.asType(dList.class).filter(dLocation.class));
        } else if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("entities") && arg.matchesArgumentList(dPlayer.class)) {
            scriptEntry.addObject("entities", arg.asType(dList.class).filter(dPlayer.class));
        } else if (!scriptEntry.hasObject("volume") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("volume, v")) {
            scriptEntry.addObject("volume", arg.asElement());
        } else if (!scriptEntry.hasObject("pitch") && arg.matchesPrimitive(aH.PrimitiveType.Double) && arg.matchesPrefix("pitch, p")) {
            scriptEntry.addObject("pitch", arg.asElement());
        } else if (!scriptEntry.hasObject("sound") && arg.matchesPrimitive(aH.PrimitiveType.String)) {
            scriptEntry.addObject("sound", arg.asElement());
        } else if (!scriptEntry.hasObject("custom") && arg.matches("custom")) {
            scriptEntry.addObject("custom", Element.TRUE);
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("sound")) {
        throw new InvalidArgumentsException("Missing sound argument!");
    }
    if (!scriptEntry.hasObject("locations") && !scriptEntry.hasObject("entities")) {
        throw new InvalidArgumentsException("Missing location argument!");
    }
    scriptEntry.defaultObject("volume", new Element(1));
    scriptEntry.defaultObject("pitch", new Element(1));
    scriptEntry.defaultObject("custom", Element.FALSE);
}
Also used : 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) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Example 74 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class SignCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    // Get objects
    String direction = scriptEntry.hasObject("direction") ? ((Element) scriptEntry.getObject("direction")).asString() : null;
    Element typeElement = scriptEntry.getElement("type");
    dList text = (dList) scriptEntry.getObject("text");
    dLocation location = (dLocation) scriptEntry.getObject("location");
    // Report to dB
    dB.report(scriptEntry, getName(), typeElement.debug() + location.debug() + text.debug());
    Type type = Type.valueOf(typeElement.asString().toUpperCase());
    Block sign = location.getBlock();
    if (type != Type.AUTOMATIC || (sign.getType() != Material.WALL_SIGN && sign.getType() != Material.SIGN_POST)) {
        sign.setType(type == Type.WALL_SIGN ? Material.WALL_SIGN : Material.SIGN_POST, false);
    }
    BlockState signState = sign.getState();
    Utilities.setSignLines((Sign) signState, text.toArray(4));
    if (direction != null) {
        Utilities.setSignRotation(signState, direction);
    } else if (type == Type.WALL_SIGN) {
        Utilities.setSignRotation(signState);
    }
}
Also used : BlockState(org.bukkit.block.BlockState) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Block(org.bukkit.block.Block) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 75 with Element

use of net.aufdemrand.denizencore.objects.Element in project Denizen-For-Bukkit by DenizenScript.

the class SwitchCommand method parseArgs.

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
    for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
        if (!scriptEntry.hasObject("locations") && arg.matchesArgumentList(dLocation.class)) {
            scriptEntry.addObject("locations", arg.asType(dList.class));
        } else if (!scriptEntry.hasObject("duration") && arg.matchesArgumentType(Duration.class)) {
            scriptEntry.addObject("duration", arg.asType(Duration.class));
        } else if (!scriptEntry.hasObject("state") && arg.matchesEnum(SwitchState.values())) {
            scriptEntry.addObject("switchstate", new Element(arg.getValue().toUpperCase()));
        } else {
            arg.reportUnhandled();
        }
    }
    if (!scriptEntry.hasObject("locations")) {
        throw new InvalidArgumentsException("Must specify a location!");
    }
    scriptEntry.defaultObject("duration", new Duration(0));
    scriptEntry.defaultObject("switchstate", new Element("TOGGLE"));
}
Also used : 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) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)

Aggregations

Element (net.aufdemrand.denizencore.objects.Element)166 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)74 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)49 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)46 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)38 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)38 EventHandler (org.bukkit.event.EventHandler)38 List (java.util.List)29 net.aufdemrand.denizencore.objects.aH (net.aufdemrand.denizencore.objects.aH)28 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)27 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)21 Duration (net.aufdemrand.denizencore.objects.Duration)20 CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)16 ArrayList (java.util.ArrayList)14 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)14 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)14 Player (org.bukkit.entity.Player)11 net.aufdemrand.denizen.objects.dWorld (net.aufdemrand.denizen.objects.dWorld)10 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)10 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)9