Search in sources :

Example 1 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag 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 ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemArmorStand method getDataMap.

public MapTag getDataMap() {
    ArmorStandMeta meta = (ArmorStandMeta) item.getItemMeta();
    if (meta == null) {
        return null;
    }
    MapTag result = new MapTag();
    result.putObject("base_plate", new ElementTag(!meta.hasNoBasePlate()));
    result.putObject("visible", new ElementTag(!meta.isInvisible()));
    result.putObject("marker", new ElementTag(meta.isMarker()));
    result.putObject("is_small", new ElementTag(meta.isSmall()));
    result.putObject("arms", new ElementTag(meta.shouldShowArms()));
    return result;
}
Also used : ArmorStandMeta(com.destroystokyo.paper.inventory.meta.ArmorStandMeta) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 3 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class ItemArmorStand method adjust.

@Override
public void adjust(Mechanism mechanism) {
    // -->
    if (mechanism.matches("armor_stand_data") && mechanism.requireObject(MapTag.class)) {
        MapTag map = mechanism.valueAsType(MapTag.class);
        ArmorStandMeta meta = (ArmorStandMeta) item.getItemMeta();
        ObjectTag base_plate = map.getObject("base_plate");
        ObjectTag visible = map.getObject("visible");
        ObjectTag marker = map.getObject("marker");
        ObjectTag is_small = map.getObject("is_small");
        ObjectTag arms = map.getObject("arms");
        if (base_plate != null) {
            meta.setNoBasePlate(!((ElementTag) base_plate).asBoolean());
        }
        if (visible != null) {
            meta.setInvisible(!((ElementTag) visible).asBoolean());
        }
        if (marker != null) {
            meta.setMarker(((ElementTag) marker).asBoolean());
        }
        if (is_small != null) {
            meta.setSmall(((ElementTag) is_small).asBoolean());
        }
        if (arms != null) {
            meta.setShowArms(((ElementTag) arms).asBoolean());
        }
        item.setItemMeta(meta);
    }
}
Also used : ObjectTag(com.denizenscript.denizencore.objects.ObjectTag) ArmorStandMeta(com.destroystokyo.paper.inventory.meta.ArmorStandMeta) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) MapTag(com.denizenscript.denizencore.objects.core.MapTag)

Example 4 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class BlockIgnitesScriptEvent method onBlockIgnites.

@EventHandler
public void onBlockIgnites(BlockIgniteEvent event) {
    location = new LocationTag(event.getBlock().getLocation());
    cause = new ElementTag(event.getCause().name());
    this.event = event;
    fire(event);
}
Also used : LocationTag(com.denizenscript.denizen.objects.LocationTag) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) EventHandler(org.bukkit.event.EventHandler)

Example 5 with ElementTag

use of com.denizenscript.denizencore.objects.core.ElementTag in project Denizen-For-Bukkit by DenizenScript.

the class EntityDeathScriptEvent method applyDetermination.

@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
    String determination = determinationObj.toString();
    String lower = CoreUtilities.toLowerCase(determination);
    if (lower.startsWith("drops ")) {
        // legacy drops determination format
        lower = lower.substring(6);
        determination = determination.substring(6);
    }
    if (lower.startsWith("no_drops")) {
        event.getDrops().clear();
        if (lower.endsWith("_or_xp")) {
            event.setDroppedExp(0);
        }
        return true;
    } else if (lower.equals("no_xp")) {
        event.setDroppedExp(0);
        return true;
    } else if (lower.equals("keep_inv") && event instanceof PlayerDeathEvent) {
        ((PlayerDeathEvent) event).setKeepInventory(true);
        return true;
    } else if (lower.equals("keep_level") && event instanceof PlayerDeathEvent) {
        ((PlayerDeathEvent) event).setKeepLevel(true);
        return true;
    } else if (lower.equals("no_message") && event instanceof PlayerDeathEvent) {
        ((PlayerDeathEvent) event).setDeathMessage(null);
        return true;
    } else if (determinationObj instanceof ElementTag && ((ElementTag) determinationObj).isInt()) {
        event.setDroppedExp(((ElementTag) determinationObj).asInt());
        return true;
    } else if (Argument.valueOf(lower).matchesArgumentList(ItemTag.class)) {
        List<ItemStack> drops = event.getDrops();
        drops.clear();
        for (ItemTag item : ListTag.getListFor(determinationObj, getTagContext(path)).filter(ItemTag.class, getTagContext(path), true)) {
            if (item != null) {
                drops.add(item.getItemStack());
            }
        }
        return true;
    } else if (event instanceof PlayerDeathEvent) {
        ((PlayerDeathEvent) event).setDeathMessage(determination);
        return true;
    } else {
        return super.applyDetermination(path, determinationObj);
    }
}
Also used : PlayerDeathEvent(org.bukkit.event.entity.PlayerDeathEvent) ElementTag(com.denizenscript.denizencore.objects.core.ElementTag) ItemStack(org.bukkit.inventory.ItemStack) ItemTag(com.denizenscript.denizen.objects.ItemTag)

Aggregations

ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)237 ListTag (com.denizenscript.denizencore.objects.core.ListTag)86 EntityTag (com.denizenscript.denizen.objects.EntityTag)66 LocationTag (com.denizenscript.denizen.objects.LocationTag)49 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)48 InvalidArgumentsException (com.denizenscript.denizencore.exceptions.InvalidArgumentsException)43 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)40 List (java.util.List)40 Argument (com.denizenscript.denizencore.objects.Argument)28 Player (org.bukkit.entity.Player)28 MapTag (com.denizenscript.denizencore.objects.core.MapTag)27 EventHandler (org.bukkit.event.EventHandler)26 NPCTag (com.denizenscript.denizen.objects.NPCTag)24 ObjectTag (com.denizenscript.denizencore.objects.ObjectTag)22 ItemTag (com.denizenscript.denizen.objects.ItemTag)19 ScriptTag (com.denizenscript.denizencore.objects.core.ScriptTag)18 ArrayList (java.util.ArrayList)16 Entity (org.bukkit.entity.Entity)16 MaterialTag (com.denizenscript.denizen.objects.MaterialTag)12 ScriptEntry (com.denizenscript.denizencore.scripts.ScriptEntry)12