Search in sources :

Example 1 with EntityTag

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

the class PaperEntityProperties method registerTags.

public static void registerTags() {
    // <--[tag]
    // @attribute <EntityTag.spawn_reason>
    // @returns ElementTag
    // @group properties
    // @Plugin Paper
    // @description
    // Returns the entity's spawn reason.
    // Valid spawn reasons can be found at <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/CreatureSpawnEvent.SpawnReason.html>
    // -->
    PropertyParser.<PaperEntityProperties, ElementTag>registerTag(ElementTag.class, "spawn_reason", (attribute, entity) -> {
        return new ElementTag(entity.entity.getBukkitEntity().getEntitySpawnReason().name());
    });
    // <--[tag]
    // @attribute <EntityTag.xp_spawn_reason>
    // @returns ElementTag
    // @group properties
    // @Plugin Paper
    // @description
    // If the entity is an experience orb, returns its spawn reason.
    // Valid spawn reasons can be found at <@link url https://papermc.io/javadocs/paper/1.17/org/bukkit/entity/ExperienceOrb.SpawnReason.html>
    // -->
    PropertyParser.<PaperEntityProperties, ElementTag>registerTag(ElementTag.class, "xp_spawn_reason", (attribute, entity) -> {
        if (!(entity.entity.getBukkitEntity() instanceof ExperienceOrb)) {
            attribute.echoError("Entity " + entity.entity + " is not an experience orb.");
            return null;
        }
        return new ElementTag(((ExperienceOrb) entity.entity.getBukkitEntity()).getSpawnReason().name());
    });
    // <--[tag]
    // @attribute <EntityTag.xp_trigger>
    // @returns EntityTag
    // @group properties
    // @Plugin Paper
    // @description
    // If the entity is an experience orb, returns the entity that triggered it spawning (if any).
    // For example, if a player killed an entity this would return the player.
    // -->
    PropertyParser.<PaperEntityProperties, EntityTag>registerTag(EntityTag.class, "xp_trigger", (attribute, entity) -> {
        if (!(entity.entity.getBukkitEntity() instanceof ExperienceOrb)) {
            attribute.echoError("Entity " + entity.entity + " is not an experience orb.");
            return null;
        }
        UUID uuid = ((ExperienceOrb) entity.entity.getBukkitEntity()).getTriggerEntityId();
        if (uuid == null) {
            return null;
        }
        Entity e = EntityTag.getEntityForID(uuid);
        if (e == null) {
            return null;
        }
        return new EntityTag(e);
    });
    // <--[tag]
    // @attribute <EntityTag.xp_source>
    // @returns EntityTag
    // @group properties
    // @Plugin Paper
    // @description
    // If the entity is an experience orb, returns the entity that it was created from (if any).
    // For example, if the xp orb was spawned from breeding this would return the baby.
    // -->
    PropertyParser.<PaperEntityProperties, EntityTag>registerTag(EntityTag.class, "xp_source", (attribute, entity) -> {
        if (!(entity.entity.getBukkitEntity() instanceof ExperienceOrb)) {
            attribute.echoError("Entity " + entity.entity + " is not an experience orb.");
            return null;
        }
        UUID uuid = ((ExperienceOrb) entity.entity.getBukkitEntity()).getSourceEntityId();
        if (uuid == null) {
            return null;
        }
        Entity e = EntityTag.getEntityForID(uuid);
        if (e == null) {
            return null;
        }
        return new EntityTag(e);
    });
    // <--[tag]
    // @attribute <EntityTag.spawn_location>
    // @returns LocationTag
    // @group properties
    // @Plugin Paper
    // @description
    // Returns the initial spawn location of this entity.
    // -->
    PropertyParser.<PaperEntityProperties, LocationTag>registerTag(LocationTag.class, "spawn_location", (attribute, entity) -> {
        Location loc = entity.entity.getBukkitEntity().getOrigin();
        return loc != null ? new LocationTag(loc) : null;
    });
    // <--[tag]
    // @attribute <EntityTag.from_spawner>
    // @returns ElementTag(Boolean)
    // @group properties
    // @Plugin Paper
    // @description
    // Returns whether the entity was spawned from a spawner.
    // -->
    PropertyParser.<PaperEntityProperties, ElementTag>registerTag(ElementTag.class, "from_spawner", (attribute, entity) -> {
        return new ElementTag(entity.entity.getBukkitEntity().fromMobSpawner());
    });
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) Entity(org.bukkit.entity.Entity) ExperienceOrb(org.bukkit.entity.ExperienceOrb) EntityTag(com.denizenscript.denizen.objects.EntityTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) UUID(java.util.UUID) Location(org.bukkit.Location)

Example 2 with EntityTag

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

the class ProjectileCollideScriptEvent method projectileCollideEvent.

@EventHandler
public void projectileCollideEvent(ProjectileCollideEvent event) {
    this.event = event;
    collidedWith = new EntityTag(event.getCollidedWith());
    projectile = new EntityTag(event.getEntity());
    fire(event);
}
Also used : EntityTag(com.denizenscript.denizen.objects.EntityTag) EventHandler(org.bukkit.event.EventHandler)

Example 3 with EntityTag

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

the class PreEntitySpawnScriptEvent method onPreCreatureSpawn.

@EventHandler
public void onPreCreatureSpawn(PreCreatureSpawnEvent event) {
    this.entity = new EntityTag(event.getType());
    this.location = new LocationTag(event.getSpawnLocation());
    this.event = event;
    fire(event);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) EntityTag(com.denizenscript.denizen.objects.EntityTag) EventHandler(org.bukkit.event.EventHandler)

Example 4 with EntityTag

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

the class EntityLoadCrossbowScriptEvent method onLoadCrossbow.

@EventHandler
public void onLoadCrossbow(EntityLoadCrossbowEvent event) {
    this.event = event;
    this.entity = new EntityTag(event.getEntity());
    fire(event);
}
Also used : EntityTag(com.denizenscript.denizen.objects.EntityTag) EventHandler(org.bukkit.event.EventHandler)

Example 5 with EntityTag

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

the class CreeperIgnitesScriptEvent method onCreeperIgnites.

@EventHandler
public void onCreeperIgnites(CreeperIgniteEvent event) {
    entity = new EntityTag(event.getEntity());
    this.event = event;
    fire(event);
}
Also used : EntityTag(com.denizenscript.denizen.objects.EntityTag) EventHandler(org.bukkit.event.EventHandler)

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