Search in sources :

Example 81 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class ExplodeCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    LocationTag location = scriptEntry.getObjectTag("location");
    ElementTag power = scriptEntry.getElement("power");
    ElementTag breakblocks = scriptEntry.getElement("breakblocks");
    ElementTag fire = scriptEntry.getElement("fire");
    EntityTag source = scriptEntry.getObjectTag("source");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), location, source, power, breakblocks, fire);
    }
    location.getWorld().createExplosion(location, power.asFloat(), fire.asBoolean(), breakblocks.asBoolean(), source == null ? null : source.getBukkitEntity());
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag)

Example 82 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class MidiCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) {
    boolean cancel = scriptEntry.hasObject("cancel");
    ElementTag filePath = scriptEntry.getElement("file");
    List<EntityTag> entities = (List<EntityTag>) scriptEntry.getObject("entities");
    LocationTag location = scriptEntry.getObjectTag("location");
    float tempo = scriptEntry.getElement("tempo").asFloat();
    float volume = scriptEntry.getElement("volume").asFloat();
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), (cancel ? db("cancel", true) : ""), filePath, db("entities", entities), location, db("tempo", tempo), db("volume", volume));
    }
    // Play the midi
    if (!cancel) {
        String fName = scriptEntry.getElement("file").asString();
        if (!fName.endsWith(".mid")) {
            fName += ".mid";
        }
        File file = new File(Denizen.getInstance().getDataFolder(), "/midi/" + fName);
        if (!Utilities.canReadFile(file)) {
            Debug.echoError("Cannot read from that file path due to security settings in Denizen/config.yml.");
            return;
        }
        if (!file.exists()) {
            Debug.echoError(scriptEntry, "Invalid file " + filePath.asString());
            return;
        }
        NoteBlockReceiver rec;
        if (location != null) {
            rec = MidiUtil.playMidi(file, tempo, volume, location);
        } else {
            rec = MidiUtil.playMidi(file, tempo, volume, entities);
        }
        if (rec == null) {
            Debug.echoError(scriptEntry, "Something went wrong playing a midi!");
            scriptEntry.setFinished(true);
        } else {
            rec.onFinish = () -> scriptEntry.setFinished(true);
        }
    } else {
        if (location != null) {
            MidiUtil.stopMidi(location.identify());
        } else {
            MidiUtil.stopMidi(entities);
        }
        scriptEntry.setFinished(true);
    }
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) List(java.util.List) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) File(java.io.File) NoteBlockReceiver(com.denizenscript.denizen.utilities.midi.NoteBlockReceiver)

Example 83 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class CopyBlockCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    LocationTag copy_location = scriptEntry.getObjectTag("location");
    LocationTag destination = scriptEntry.getObjectTag("destination");
    ElementTag remove_original = scriptEntry.getElement("remove");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), copy_location, destination, remove_original);
    }
    List<Location> locations = new ArrayList<>();
    if (copy_location != null) {
        locations.add(copy_location);
    }
    for (Location loc : locations) {
        Block source = loc.getBlock();
        BlockState sourceState = source.getState();
        Block update = destination.getBlock();
        FullBlockData block = new FullBlockData(source);
        block.set(update, 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()) {
                AdvancedTextImpl.instance.setSignLine(((Sign) updateState), n++, line);
            }
        } 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).setSpawnedType(((CreatureSpawner) sourceState).getSpawnedType());
            ((CreatureSpawner) updateState).setDelay(((CreatureSpawner) sourceState).getDelay());
        }
        updateState.update();
        if (remove_original.asBoolean()) {
            loc.getBlock().setType(Material.AIR);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) FullBlockData(com.denizenscript.denizen.utilities.blocks.FullBlockData) LocationTag(com.denizenscript.denizen.objects.LocationTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) InventoryHolder(org.bukkit.inventory.InventoryHolder) Location(org.bukkit.Location)

Example 84 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class DropCommand method execute.

@Override
public void execute(ScriptEntry scriptEntry) {
    LocationTag location = scriptEntry.getObjectTag("location");
    ElementTag quantity = scriptEntry.getElement("quantity");
    ElementTag action = scriptEntry.getElement("action");
    ElementTag speed = scriptEntry.getElement("speed");
    List<ItemTag> items = (List<ItemTag>) scriptEntry.getObject("item");
    EntityTag entity = scriptEntry.getObjectTag("entity");
    DurationTag delay = scriptEntry.getObjectTag("delay");
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), action, location, quantity, db("items", items), entity, speed, delay);
    }
    ListTag entityList = new ListTag();
    switch(Action.valueOf(action.asString())) {
        case DROP_EXP:
            EntityTag orb = new EntityTag(location.getWorld().spawnEntity(location, EntityType.EXPERIENCE_ORB));
            ((ExperienceOrb) orb.getBukkitEntity()).setExperience(quantity.asInt());
            entityList.addObject(orb);
            break;
        case DROP_ITEM:
            for (ItemTag item : items) {
                if (item.getMaterial().getMaterial() == Material.AIR) {
                    continue;
                }
                if (quantity.asInt() > 1 && item.isUnique()) {
                    Debug.echoDebug(scriptEntry, "Cannot drop multiples of this item because it is Unique!");
                }
                for (int x = 0; x < quantity.asInt(); x++) {
                    EntityTag e = new EntityTag(location.getWorld().dropItem(location, item.getItemStack()));
                    if (e.isValid()) {
                        e.setVelocity(e.getVelocity().multiply(speed != null ? speed.asDouble() : 1d));
                        if (delay != null) {
                            ((Item) e.getBukkitEntity()).setPickupDelay(delay.getTicksAsInt());
                        }
                    }
                    entityList.addObject(e);
                }
            }
            break;
        case DROP_ENTITY:
            if (quantity.asInt() > 1 && entity.isUnique()) {
                Debug.echoDebug(scriptEntry, "Cannot drop multiples of this entity because it is Unique!");
                entity.spawnAt(location);
                entityList.addObject(entity);
                break;
            }
            for (int x = 0; x < quantity.asInt(); x++) {
                ArrayList<Mechanism> mechanisms = new ArrayList<>();
                for (Mechanism mechanism : entity.getWaitingMechanisms()) {
                    mechanisms.add(new Mechanism(mechanism.getName(), mechanism.value, scriptEntry.context));
                }
                EntityTag ent = new EntityTag(entity.getEntityType(), mechanisms);
                ent.spawnAt(location);
                entityList.addObject(ent);
            }
            break;
    }
    scriptEntry.addObject("dropped_entities", entityList);
    if (entityList.size() == 1) {
        scriptEntry.addObject("dropped_entity", entityList.getObject(0));
    }
}
Also used : ArrayList(java.util.ArrayList) ExperienceOrb(org.bukkit.entity.ExperienceOrb) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag) ListTag(com.denizenscript.denizencore.objects.core.ListTag) LocationTag(com.denizenscript.denizen.objects.LocationTag) Item(org.bukkit.entity.Item) ArrayList(java.util.ArrayList) List(java.util.List) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Example 85 with LocationTag

use of com.denizenscript.denizen.objects.LocationTag in project Denizen-For-Bukkit by DenizenScript.

the class FireworkCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) {
    final LocationTag location = (LocationTag) scriptEntry.getObject("location");
    ElementTag type = scriptEntry.getElement("type");
    List<ColorTag> primary = scriptEntry.argForPrefixList("primary", ColorTag.class, true);
    if (primary == null) {
        primary = Collections.singletonList(new ColorTag(Color.YELLOW));
    }
    List<ColorTag> fade = scriptEntry.argForPrefixList("fade", ColorTag.class, true);
    boolean flicker = scriptEntry.argAsBoolean("flicker");
    boolean trail = scriptEntry.argAsBoolean("trail");
    ElementTag power = scriptEntry.argForPrefixAsElement("power", "1");
    DurationTag life = scriptEntry.argForPrefix("life", DurationTag.class, true);
    if (scriptEntry.dbCallShouldDebug()) {
        Debug.report(scriptEntry, getName(), location, type, power, life, db("flicker", flicker), db("trail", trail), db("primary colors", primary), db("fade colors", fade));
    }
    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);
    if (life != null) {
        NMSHandler.getEntityHelper().setFireworkLifetime(firework, life.getTicksAsInt());
    }
    scriptEntry.addObject("launched_firework", new EntityTag(firework));
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Firework(org.bukkit.entity.Firework) Builder(org.bukkit.FireworkEffect.Builder) ColorTag(com.denizenscript.denizen.objects.ColorTag) FireworkMeta(org.bukkit.inventory.meta.FireworkMeta) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) DurationTag(com.denizenscript.denizencore.objects.core.DurationTag)

Aggregations

LocationTag (com.denizenscript.denizen.objects.LocationTag)133 EventHandler (org.bukkit.event.EventHandler)69 EntityTag (com.denizenscript.denizen.objects.EntityTag)45 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)40 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)33 List (java.util.List)21 ItemTag (com.denizenscript.denizen.objects.ItemTag)18 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)15 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)14 ListTag (com.denizenscript.denizencore.objects.core.ListTag)13 NPCTag (com.denizenscript.denizen.objects.NPCTag)12 Location (org.bukkit.Location)11 ArrayList (java.util.ArrayList)8 Entity (org.bukkit.entity.Entity)8 FakeBlock (com.denizenscript.denizen.utilities.blocks.FakeBlock)6 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)6 Player (org.bukkit.entity.Player)6 Vector (org.bukkit.util.Vector)6 UUID (java.util.UUID)5 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)5