Search in sources :

Example 1 with LocationTag

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

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

the class BlockBuiltScriptEvent method onBlockBuilt.

@EventHandler
public void onBlockBuilt(BlockCanBuildEvent event) {
    location = new LocationTag(event.getBlock().getLocation());
    old_material = new MaterialTag(event.getBlock());
    new_material = new MaterialTag(event.getBlockData());
    cancelled = !event.isBuildable();
    this.event = event;
    fire(event);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MaterialTag(com.denizenscript.denizen.objects.MaterialTag) EventHandler(org.bukkit.event.EventHandler)

Example 3 with LocationTag

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

the class BlockDispensesScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    if (determinationObj.canBeType(LocationTag.class)) {
        LocationTag vel = determinationObj.asType(LocationTag.class, getTagContext(path));
        if (vel != null) {
            event.setVelocity(vel.toVector());
            return true;
        }
    }
    if (determinationObj.canBeType(ItemTag.class)) {
        ItemTag it = determinationObj.asType(ItemTag.class, getTagContext(path));
        if (it != null) {
            item = it;
            event.setItem(item.getItemStack());
            return true;
        }
    }
    if (ArgumentHelper.matchesDouble(determinationObj.toString())) {
        Deprecations.blockDispensesItemDetermination.warn();
        event.setVelocity(event.getVelocity().multiply(Double.parseDouble(determinationObj.toString())));
        return true;
    }
    return super.applyDetermination(path, determinationObj);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Example 4 with LocationTag

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

the class BlockDispensesScriptEvent method onBlockDispenses.

@EventHandler
public void onBlockDispenses(BlockDispenseEvent event) {
    location = new LocationTag(event.getBlock().getLocation());
    material = new MaterialTag(event.getBlock());
    item = new ItemTag(event.getItem());
    this.event = event;
    fire(event);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) MaterialTag(com.denizenscript.denizen.objects.MaterialTag) ItemTag(com.denizenscript.denizen.objects.ItemTag) EventHandler(org.bukkit.event.EventHandler)

Example 5 with LocationTag

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

the class PlayerJumpsScriptEventPaperImpl method onPlayerJumps.

@EventHandler
public void onPlayerJumps(PlayerJumpEvent event) {
    if (EntityTag.isNPC(event.getPlayer())) {
        return;
    }
    location = new LocationTag(event.getFrom());
    player = new PlayerTag(event.getPlayer());
    fire(event);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) PlayerTag(com.denizenscript.denizen.objects.PlayerTag) EventHandler(org.bukkit.event.EventHandler)

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