Search in sources :

Example 66 with Element

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

the class TimeCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    // Fetch objects
    Duration value = (Duration) scriptEntry.getObject("value");
    dWorld world = (dWorld) scriptEntry.getObject("world");
    Element type_element = scriptEntry.getElement("type");
    Type type = Type.valueOf(type_element.asString().toUpperCase());
    // Report to dB
    dB.report(scriptEntry, getName(), type_element.debug() + value.debug() + world.debug());
    if (type.equals(Type.GLOBAL)) {
        world.getWorld().setTime(value.getTicks());
    } else {
        if (!((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer()) {
            dB.echoError("Must have a valid player link!");
        } else {
            ((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getPlayerEntity().setPlayerTime(value.getTicks(), true);
        }
    }
}
Also used : BukkitScriptEntryData(net.aufdemrand.denizen.BukkitScriptEntryData) Element(net.aufdemrand.denizencore.objects.Element) Duration(net.aufdemrand.denizencore.objects.Duration) net.aufdemrand.denizen.objects.dWorld(net.aufdemrand.denizen.objects.dWorld)

Example 67 with Element

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

the class BukkitWorldScriptHelper method timeEvent.

// <--[event]
// @Events
// time changes (in <world>)
// time <0-23> in <world>
//
// @Regex ^on time [^\s]+( in [^\s]+)$
//
// @Triggers when the current time changes in a world (once per mine-hour).
//
// @Context
// <context.time> returns the current time.
// <context.world> returns the world.
//
// -->
public void timeEvent() {
    for (World world : Bukkit.getWorlds()) {
        // TODO: What is this conversion math
        int hour = Double.valueOf(world.getTime() / 1000).intValue();
        hour = hour + 6;
        // Get the hour
        if (hour >= 24) {
            hour = hour - 24;
        }
        dWorld currentWorld = new dWorld(world);
        if (!current_time.containsKey(currentWorld.identifySimple()) || current_time.get(currentWorld.identifySimple()) != hour) {
            Map<String, dObject> context = new HashMap<String, dObject>();
            context.put("time", new Element(hour));
            context.put("world", currentWorld);
            doEvents(Arrays.asList("time changes", "time changes in " + currentWorld.identifySimple(), // NOTE: Deprecated
            String.valueOf(hour) + ":00 in " + currentWorld.identifySimple(), "time " + String.valueOf(hour) + " in " + currentWorld.identifySimple()), null, null, context, true);
            current_time.put(currentWorld.identifySimple(), hour);
        }
    }
}
Also used : HashMap(java.util.HashMap) net.aufdemrand.denizencore.objects.dObject(net.aufdemrand.denizencore.objects.dObject) Element(net.aufdemrand.denizencore.objects.Element) World(org.bukkit.World)

Example 68 with Element

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

the class CopyBlockCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    dLocation copy_location = (dLocation) scriptEntry.getObject("location");
    dLocation destination = (dLocation) scriptEntry.getObject("destination");
    dCuboid copy_cuboid = (dCuboid) scriptEntry.getObject("cuboid");
    Element remove_original = (Element) scriptEntry.getObject("remove");
    dB.report(scriptEntry, getName(), (copy_location != null ? copy_location.debug() : "") + (copy_cuboid != null ? copy_cuboid.debug() : "") + destination.debug() + remove_original.debug());
    List<Location> locations = new ArrayList<Location>();
    if (copy_location != null) {
        locations.add(copy_location);
    } else if (copy_cuboid != null) {
        // TODO: make this work?...
        locations.addAll(copy_cuboid.getBlockLocations());
    }
    for (Location loc : locations) {
        Block source = loc.getBlock();
        BlockState sourceState = source.getState();
        Block update = destination.getBlock();
        update.setTypeIdAndData(source.getTypeId(), source.getData(), false);
        BlockState updateState = update.getState();
        // of InventoryHolder
        if (sourceState instanceof InventoryHolder) {
            ((InventoryHolder) updateState).getInventory().setContents(((InventoryHolder) sourceState).getInventory().getContents());
        } else if (sourceState instanceof Sign) {
            int n = 0;
            for (String line : ((Sign) sourceState).getLines()) {
                ((Sign) updateState).setLine(n, line);
                n++;
            }
        } else if (sourceState instanceof NoteBlock) {
            ((NoteBlock) updateState).setNote(((NoteBlock) sourceState).getNote());
        } else if (sourceState instanceof Skull) {
            ((Skull) updateState).setSkullType(((Skull) sourceState).getSkullType());
            ((Skull) updateState).setOwner(((Skull) sourceState).getOwner());
            ((Skull) updateState).setRotation(((Skull) sourceState).getRotation());
        } else if (sourceState instanceof Jukebox) {
            ((Jukebox) updateState).setPlaying(((Jukebox) sourceState).getPlaying());
        } else if (sourceState instanceof Banner) {
            ((Banner) updateState).setBaseColor(((Banner) sourceState).getBaseColor());
            ((Banner) updateState).setPatterns(((Banner) sourceState).getPatterns());
        } else if (sourceState instanceof CommandBlock) {
            ((CommandBlock) updateState).setName(((CommandBlock) sourceState).getName());
            ((CommandBlock) updateState).setCommand(((CommandBlock) sourceState).getCommand());
        } else if (sourceState instanceof CreatureSpawner) {
            ((CreatureSpawner) updateState).setCreatureTypeByName(((CreatureSpawner) sourceState).getCreatureTypeName());
            ((CreatureSpawner) updateState).setDelay(((CreatureSpawner) sourceState).getDelay());
        }
        updateState.update();
        if (remove_original.asBoolean()) {
            loc.getBlock().setType(Material.AIR);
        }
    }
}
Also used : Element(net.aufdemrand.denizencore.objects.Element) ArrayList(java.util.ArrayList) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) net.aufdemrand.denizen.objects.dCuboid(net.aufdemrand.denizen.objects.dCuboid) InventoryHolder(org.bukkit.inventory.InventoryHolder) Location(org.bukkit.Location) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation)

Example 69 with Element

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

the class CreateWorldCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
    Element worldName = scriptEntry.getElement("world_name");
    Element generator = scriptEntry.getElement("generator");
    Element worldType = scriptEntry.getElement("worldtype");
    Element environment = scriptEntry.getElement("environment");
    Element copy_from = scriptEntry.getElement("copy_from");
    Element seed = scriptEntry.getElement("seed");
    dB.report(scriptEntry, getName(), worldName.debug() + (generator != null ? generator.debug() : "") + environment.debug() + (copy_from != null ? copy_from.debug() : "") + worldType.debug() + (seed != null ? seed.debug() : ""));
    if (copy_from != null) {
        try {
            if (copy_from.asString().contains("..")) {
                dB.echoError(scriptEntry.getResidingQueue(), "Invalid copy from world name!");
                return;
            }
            File newFolder = new File(worldName.asString());
            File folder = new File(copy_from.asString().replace("w@", ""));
            if (!folder.exists() || !folder.isDirectory()) {
                dB.echoError(scriptEntry.getResidingQueue(), "Invalid copy from world folder - does not exist!");
                return;
            }
            FileUtils.copyDirectory(folder, newFolder);
            File file = new File(worldName.asString() + "/uid.dat");
            if (file.exists()) {
                file.delete();
            }
            File file2 = new File(worldName.asString() + "/session.lock");
            if (file2.exists()) {
                file2.delete();
            }
        } catch (Exception ex) {
            dB.echoError(ex);
            return;
        }
    }
    World world;
    WorldCreator worldCreator = WorldCreator.name(worldName.asString()).environment(World.Environment.valueOf(environment.asString().toUpperCase())).type(WorldType.valueOf(worldType.asString().toUpperCase()));
    if (generator != null) {
        worldCreator.generator(generator.asString());
    }
    if (seed != null) {
        worldCreator.seed(seed.asLong());
    }
    world = Bukkit.getServer().createWorld(worldCreator);
    if (world == null) {
        dB.echoDebug(scriptEntry, "World is null, something went wrong in creation!");
    }
}
Also used : WorldCreator(org.bukkit.WorldCreator) Element(net.aufdemrand.denizencore.objects.Element) World(org.bukkit.World) File(java.io.File) InvalidArgumentsException(net.aufdemrand.denizencore.exceptions.InvalidArgumentsException) CommandExecutionException(net.aufdemrand.denizencore.exceptions.CommandExecutionException)

Example 70 with Element

use of net.aufdemrand.denizencore.objects.Element 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)

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