Search in sources :

Example 16 with CommandExecutionException

use of net.aufdemrand.denizencore.exceptions.CommandExecutionException in project Denizen-For-Bukkit by DenizenScript.

the class PlaySoundCommand method execute.

@SuppressWarnings("unchecked")
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    List<dLocation> locations = (List<dLocation>) scriptEntry.getObject("locations");
    List<dPlayer> players = (List<dPlayer>) scriptEntry.getObject("entities");
    Element sound = scriptEntry.getElement("sound");
    Element volume = scriptEntry.getElement("volume");
    Element pitch = scriptEntry.getElement("pitch");
    Element custom = scriptEntry.getElement("custom");
    dB.report(scriptEntry, getName(), (locations != null ? aH.debugObj("locations", locations.toString()) : "") + (players != null ? aH.debugObj("entities", players.toString()) : "") + sound.debug() + volume.debug() + pitch.debug() + custom.debug());
    try {
        if (locations != null) {
            if (custom.asBoolean()) {
                for (dLocation location : locations) {
                    for (Player player : location.getWorld().getPlayers()) // Note: Randomly defining 100 blocks as maximum hearing distance.
                    {
                        if (player.getLocation().distanceSquared(location) < 100 * 100) {
                            player.playSound(location, sound.asString(), volume.asFloat(), pitch.asFloat());
                        }
                    }
                }
            } else {
                for (dLocation location : locations) {
                    location.getWorld().playSound(location, Sound.valueOf(sound.asString().toUpperCase()), volume.asFloat(), pitch.asFloat());
                }
            }
        } else {
            for (dPlayer player : players) {
                if (custom.asBoolean()) {
                    player.getPlayerEntity().playSound(player.getLocation(), sound.asString(), volume.asFloat(), pitch.asFloat());
                } else {
                    player.getPlayerEntity().playSound(player.getLocation(), Sound.valueOf(sound.asString().toUpperCase()), volume.asFloat(), pitch.asFloat());
                }
            }
        }
    } catch (Exception e) {
        dB.echoDebug(scriptEntry, "Unable to play sound.");
    }
}
Also used : net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Player(org.bukkit.entity.Player) net.aufdemrand.denizen.objects.dPlayer(net.aufdemrand.denizen.objects.dPlayer) Element(net.aufdemrand.denizencore.objects.Element) List(java.util.List) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException)

Example 17 with CommandExecutionException

use of net.aufdemrand.denizencore.exceptions.CommandExecutionException in project Denizen-For-Bukkit by DenizenScript.

the class SchematicCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    Element angle = scriptEntry.getElement("angle");
    Element type = scriptEntry.getElement("type");
    Element name = scriptEntry.getElement("name");
    Element filename = scriptEntry.getElement("filename");
    Element noair = scriptEntry.getElement("noair");
    Element delayed = scriptEntry.getElement("delayed");
    dLocation location = scriptEntry.getdObject("location");
    dCuboid cuboid = scriptEntry.getdObject("cuboid");
    dB.report(scriptEntry, getName(), type.debug() + name.debug() + (location != null ? location.debug() : "") + (filename != null ? filename.debug() : "") + (cuboid != null ? cuboid.debug() : "") + (angle != null ? angle.debug() : "") + (noair != null ? noair.debug() : "") + (delayed != null ? delayed.debug() : ""));
    CuboidBlockSet set;
    Type ttype = Type.valueOf(type.asString());
    if (scriptEntry.shouldWaitFor() && ttype != Type.PASTE) {
        dB.echoError("Tried to wait for a non-paste schematic command.");
        scriptEntry.setFinished(true);
    }
    String fname = filename != null ? filename.asString() : name.asString();
    switch(ttype) {
        case CREATE:
            if (schematics.containsKey(name.asString().toUpperCase())) {
                dB.echoError(scriptEntry.getResidingQueue(), "Schematic file " + name.asString() + " is already loaded.");
                return;
            }
            if (cuboid == null) {
                dB.echoError(scriptEntry.getResidingQueue(), "Missing cuboid argument!");
                return;
            }
            if (location == null) {
                dB.echoError(scriptEntry.getResidingQueue(), "Missing origin location argument!");
                return;
            }
            try {
                // TODO: Make me waitable!
                set = new CuboidBlockSet(cuboid, location);
                schematics.put(name.asString().toUpperCase(), set);
            } catch (Exception ex) {
                dB.echoError(scriptEntry.getResidingQueue(), "Error creating schematic object " + name.asString() + ".");
                dB.echoError(scriptEntry.getResidingQueue(), ex);
                return;
            }
            break;
        case LOAD:
            if (schematics.containsKey(name.asString().toUpperCase())) {
                dB.echoError(scriptEntry.getResidingQueue(), "Schematic file " + name.asString() + " is already loaded.");
                return;
            }
            try {
                String directory = URLDecoder.decode(System.getProperty("user.dir"));
                File f = new File(directory + "/plugins/Denizen/schematics/" + fname + ".schematic");
                if (!f.exists()) {
                    dB.echoError("Schematic file " + fname + " does not exist. Are you sure it's in " + directory + "/plugins/Denizen/schematics/?");
                    return;
                }
                InputStream fs = new FileInputStream(f);
                // TODO: Make me waitable!
                set = CuboidBlockSet.fromMCEditStream(fs);
                fs.close();
                schematics.put(name.asString().toUpperCase(), set);
            } catch (Exception ex) {
                dB.echoError(scriptEntry.getResidingQueue(), "Error loading schematic file " + name.asString() + ".");
                dB.echoError(scriptEntry.getResidingQueue(), ex);
                return;
            }
            break;
        case UNLOAD:
            if (!schematics.containsKey(name.asString().toUpperCase())) {
                dB.echoError(scriptEntry.getResidingQueue(), "Schematic file " + name.asString() + " is not loaded.");
                return;
            }
            schematics.remove(name.asString().toUpperCase());
            break;
        case ROTATE:
            if (!schematics.containsKey(name.asString().toUpperCase())) {
                dB.echoError(scriptEntry.getResidingQueue(), "Schematic file " + name.asString() + " is not loaded.");
                return;
            }
            if (angle == null) {
                dB.echoError(scriptEntry.getResidingQueue(), "Missing angle argument!");
                return;
            }
            // TODO: Make me waitable!
            int ang = angle.asInt();
            if (ang < 0) {
                ang = 360 + ang;
            }
            while (ang > 0) {
                ang -= 90;
                schematics.get(name.asString().toUpperCase()).rotateOne();
            }
            break;
        case FLIP_X:
            if (!schematics.containsKey(name.asString().toUpperCase())) {
                dB.echoError(scriptEntry.getResidingQueue(), "Schematic file " + name.asString() + " is not loaded.");
                return;
            }
            schematics.get(name.asString().toUpperCase()).flipX();
            break;
        case FLIP_Y:
            if (!schematics.containsKey(name.asString().toUpperCase())) {
                dB.echoError(scriptEntry.getResidingQueue(), "Schematic file " + name.asString() + " is not loaded.");
                return;
            }
            schematics.get(name.asString().toUpperCase()).flipY();
            break;
        case FLIP_Z:
            if (!schematics.containsKey(name.asString().toUpperCase())) {
                dB.echoError(scriptEntry.getResidingQueue(), "Schematic file " + name.asString() + " is not loaded.");
                return;
            }
            schematics.get(name.asString().toUpperCase()).flipZ();
            break;
        case PASTE:
            if (!schematics.containsKey(name.asString().toUpperCase())) {
                dB.echoError(scriptEntry.getResidingQueue(), "Schematic file " + name.asString() + " is not loaded.");
                return;
            }
            if (location == null) {
                dB.echoError(scriptEntry.getResidingQueue(), "Missing location argument!");
                return;
            }
            try {
                if (delayed != null && delayed.asBoolean()) {
                    schematics.get(name.asString().toUpperCase()).setBlocksDelayed(location, new Runnable() {

                        @Override
                        public void run() {
                            scriptEntry.setFinished(true);
                        }
                    }, noair != null && noair.asBoolean());
                } else {
                    scriptEntry.setFinished(true);
                    schematics.get(name.asString().toUpperCase()).setBlocks(location, noair != null && noair.asBoolean());
                }
            } catch (Exception ex) {
                dB.echoError(scriptEntry.getResidingQueue(), "Exception pasting schematic file " + name.asString() + ".");
                dB.echoError(scriptEntry.getResidingQueue(), ex);
                return;
            }
            break;
        case SAVE:
            if (!schematics.containsKey(name.asString().toUpperCase())) {
                dB.echoError(scriptEntry.getResidingQueue(), "Schematic file " + name.asString() + " is not loaded.");
                return;
            }
            try {
                set = schematics.get(name.asString().toUpperCase());
                String directory = URLDecoder.decode(System.getProperty("user.dir"));
                File f = new File(directory + "/plugins/Denizen/schematics/" + fname + ".schematic");
                f.getParentFile().mkdirs();
                // TODO: Make me waitable!
                FileOutputStream fs = new FileOutputStream(f);
                set.saveMCEditFormatToStream(fs);
                fs.flush();
                fs.close();
            } catch (Exception ex) {
                dB.echoError(scriptEntry.getResidingQueue(), "Error saving schematic file " + fname + ".");
                dB.echoError(scriptEntry.getResidingQueue(), ex);
                return;
            }
            break;
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Element(net.aufdemrand.denizencore.objects.Element) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException) FileInputStream(java.io.FileInputStream) FileOutputStream(java.io.FileOutputStream) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) net.aufdemrand.denizen.objects.dCuboid(net.aufdemrand.denizen.objects.dCuboid) File(java.io.File) CuboidBlockSet(net.aufdemrand.denizen.utilities.blocks.CuboidBlockSet)

Example 18 with CommandExecutionException

use of net.aufdemrand.denizencore.exceptions.CommandExecutionException in project Denizen-For-Bukkit by DenizenScript.

the class SwitchCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    final dList interactLocations = scriptEntry.getdObject("locations");
    long duration = ((Duration) scriptEntry.getObject("duration")).getTicks();
    final SwitchState switchState = SwitchState.valueOf(scriptEntry.getElement("switchstate").asString());
    final Player player = ((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ? ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity() : null;
    // Switch the Block
    dB.report(scriptEntry, getName(), interactLocations.debug() + aH.debugObj("duration", duration + "t") + aH.debugObj("switchstate", switchState.name()));
    for (final dLocation interactLocation : interactLocations.filter(dLocation.class)) {
        switchBlock(scriptEntry, interactLocation, switchState, player);
        // If duration set, schedule a delayed task.
        if (duration > 0) {
            // If this block already had a delayed task, cancel it.
            if (taskMap.containsKey(interactLocation)) {
                try {
                    DenizenAPI.getCurrentInstance().getServer().getScheduler().cancelTask(taskMap.get(interactLocation));
                } catch (Exception e) {
                }
            }
            dB.log("Setting delayed task 'SWITCH' for " + interactLocation.identify());
            // Store new delayed task ID, for checking against, then schedule new delayed task.
            taskMap.put(interactLocation, DenizenAPI.getCurrentInstance().getServer().getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(), new Runnable() {

                public void run() {
                    switchBlock(scriptEntry, interactLocation, SwitchState.TOGGLE, player);
                }
            }, duration));
        }
    }
}
Also used : Player(org.bukkit.entity.Player) BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException)

Example 19 with CommandExecutionException

use of net.aufdemrand.denizencore.exceptions.CommandExecutionException in project Denizen-For-Bukkit by DenizenScript.

the class LightCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dLocation location = scriptEntry.getdObject("location");
    Element light = scriptEntry.getElement("light");
    Element reset = scriptEntry.getElement("reset");
    Duration duration = scriptEntry.getdObject("duration");
    dB.report(scriptEntry, getName(), location.debug() + reset.debug() + (light != null ? light.debug() : "") + (duration != null ? duration.debug() : ""));
    if (location.getY() < 0 || location.getY() > 255) {
        dB.echoError(scriptEntry.getResidingQueue(), "Invalid light location!");
        return;
    }
    for (int x = -1; x <= 1; x++) {
        for (int z = -1; z <= 1; z++) {
            location.clone().add(x * 16, 0, z * 16).getChunk().load();
        }
    }
    if (!reset.asBoolean()) {
        int brightness = light.asInt();
        if (brightness < 0 || brightness > 15) {
            throw new CommandExecutionException("Light brightness must be between 0 and 15, inclusive!");
        }
        NMSHandler.getInstance().createBlockLight(location, brightness, duration == null ? 0 : duration.getTicks());
    } else {
        BlockLight.removeLight(location);
    }
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 20 with CommandExecutionException

use of net.aufdemrand.denizencore.exceptions.CommandExecutionException in project Denizen-For-Bukkit by DenizenScript.

the class PauseCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    pause(dNPC, pauseType, !scriptEntry.getCommandName().equalsIgnoreCase("RESUME"));
    // If duration...
    if (duration > 0) {
        if (durations.containsKey(dNPC.getCitizen().getId() + pauseType.name())) {
            try {
                DenizenAPI.getCurrentInstance().getServer().getScheduler().cancelTask(durations.get(dNPC.getCitizen().getId() + pauseType.name()));
            } catch (Exception e) {
                dB.echoError(scriptEntry.getResidingQueue(), "There was an error pausing that!");
                dB.echoError(scriptEntry.getResidingQueue(), e);
            }
        }
        dB.echoDebug(scriptEntry, "Running delayed task: Unpause " + pauseType.toString());
        final ScriptEntry se = scriptEntry;
        durations.put(dNPC.getId() + pauseType.name(), DenizenAPI.getCurrentInstance().getServer().getScheduler().scheduleSyncDelayedTask(DenizenAPI.getCurrentInstance(), new Runnable() {

            @Override
            public void run() {
                dB.echoDebug(se, "Running delayed task: Pausing " + pauseType.toString());
                pause(dNPC, pauseType, false);
            }
        }, duration * 20));
    }
}
Also used : ScriptEntry(net.aufdemrand.denizencore.scripts.ScriptEntry) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException)

Aggregations

CommandExecutionException (net.aufdemrand.denizencore.exceptions.CommandExecutionException)21 InvalidArgumentsException (net.aufdemrand.denizencore.exceptions.InvalidArgumentsException)17 Element (net.aufdemrand.denizencore.objects.Element)16 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)8 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)8 Duration (net.aufdemrand.denizencore.objects.Duration)6 BukkitScriptEntryData (net.aufdemrand.denizen.BukkitScriptEntryData)5 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)5 List (java.util.List)4 net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)4 ScriptEntry (net.aufdemrand.denizencore.scripts.ScriptEntry)4 Player (org.bukkit.entity.Player)4 File (java.io.File)3 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)3 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)3 net.aufdemrand.denizencore.objects.dObject (net.aufdemrand.denizencore.objects.dObject)3 ScriptQueue (net.aufdemrand.denizencore.scripts.queues.ScriptQueue)3 Location (org.bukkit.Location)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 Vector (org.bukkit.util.Vector)2