Search in sources :

Example 86 with EntityTag

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

the class EntityScriptHelper method onChunkUnload.

@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
    if (event instanceof Cancellable && ((Cancellable) event).isCancelled()) {
        return;
    }
    // CraftBukkit: https://github.com/Bukkit/CraftBukkit/pull/1386
    for (Entity ent : event.getChunk().getEntities()) {
        if (!(ent instanceof LivingEntity) || ((LivingEntity) ent).getRemoveWhenFarAway()) {
            EntityTag.rememberEntity(ent);
            EntityDespawnScriptEvent.instance.entity = new EntityTag(ent);
            EntityDespawnScriptEvent.instance.cause = new ElementTag("CHUNK_UNLOAD");
            EntityDespawnScriptEvent.instance.cancelled = false;
            EntityDespawnScriptEvent.instance.fire();
            EntityTag.forgetEntity(ent);
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Cancellable(org.bukkit.event.Cancellable) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) EventHandler(org.bukkit.event.EventHandler)

Example 87 with EntityTag

use of com.denizenscript.denizen.objects.EntityTag 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 88 with EntityTag

use of com.denizenscript.denizen.objects.EntityTag 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 89 with EntityTag

use of com.denizenscript.denizen.objects.EntityTag 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 90 with EntityTag

use of com.denizenscript.denizen.objects.EntityTag 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

EntityTag (com.denizenscript.denizen.objects.EntityTag)142 EventHandler (org.bukkit.event.EventHandler)81 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)56 LocationTag (com.denizenscript.denizen.objects.LocationTag)45 List (java.util.List)27 Entity (org.bukkit.entity.Entity)25 ItemTag (com.denizenscript.denizen.objects.ItemTag)17 ListTag (com.denizenscript.denizencore.objects.core.ListTag)17 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)15 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)12 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)11 NPCTag (com.denizenscript.denizen.objects.NPCTag)10 ArrayList (java.util.ArrayList)10 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)10 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)9 Player (org.bukkit.entity.Player)9 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)8 Argument (com.denizenscript.denizencore.objects.Argument)8 LivingEntity (org.bukkit.entity.LivingEntity)8 Item (org.bukkit.entity.Item)7