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());
});
}
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;
}
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);
}
}
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);
}
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);
}
}
Aggregations