use of com.denizenscript.denizen.utilities.blocks.SpawnableHelper in project Denizen-For-Bukkit by DenizenScript.
the class AreaContainmentObject method registerTags.
static <T extends AreaContainmentObject> void registerTags(Class<T> type, ObjectTagProcessor<T> processor) {
// <--[tag]
// @attribute <AreaObject.bounding_box>
// @returns CuboidTag
// @description
// Returns a cuboid approximately representing the maximal bounding box of the area (anything this cuboid does not contain, is also not contained by the area, but not vice versa).
// For single-member CuboidTags, this tag returns a copy of the cuboid.
// -->
processor.registerTag(CuboidTag.class, "bounding_box", (attribute, area) -> {
return area.getCuboidBoundary();
});
// <--[tag]
// @attribute <AreaObject.world>
// @returns WorldTag
// @description
// Returns the area's world.
// -->
processor.registerTag(WorldTag.class, "world", (attribute, area) -> {
return area.getWorld();
});
// <--[tag]
// @attribute <AreaObject.players>
// @returns ListTag(PlayerTag)
// @description
// Gets a list of all players currently within the area.
// -->
processor.registerTag(ListTag.class, "players", (attribute, area) -> {
ListTag result = new ListTag();
for (Player player : Bukkit.getOnlinePlayers()) {
if (area.doesContainLocation(player.getLocation())) {
result.addObject(PlayerTag.mirrorBukkitPlayer(player));
}
}
return result;
});
// -->
if (Depends.citizens != null) {
processor.registerTag(ListTag.class, "npcs", (attribute, area) -> {
ListTag result = new ListTag();
for (NPC npc : CitizensAPI.getNPCRegistry()) {
NPCTag dnpc = new NPCTag(npc);
if (area.doesContainLocation(dnpc.getLocation())) {
result.addObject(dnpc);
}
}
return result;
});
}
// <--[tag]
// @attribute <AreaObject.entities[(<matcher>)]>
// @returns ListTag(EntityTag)
// @description
// Gets a list of all entities currently within the area, with an optional search parameter for the entity.
// -->
processor.registerTag(ListTag.class, "entities", (attribute, area) -> {
String matcher = attribute.hasParam() ? attribute.getParam() : null;
ListTag entities = new ListTag();
for (Entity ent : area.getCuboidBoundary().getEntitiesPossiblyWithinForTag()) {
if (area.doesContainLocation(ent.getLocation())) {
EntityTag current = new EntityTag(ent);
if (matcher == null || BukkitScriptEvent.tryEntity(current, matcher)) {
entities.addObject(current.getDenizenObject());
}
}
}
return entities;
});
// <--[tag]
// @attribute <AreaObject.living_entities>
// @returns ListTag(EntityTag)
// @description
// Gets a list of all living entities currently within the area.
// This includes Players, mobs, NPCs, etc., but excludes dropped items, experience orbs, etc.
// -->
processor.registerTag(ListTag.class, "living_entities", (attribute, area) -> {
ListTag result = new ListTag();
for (Entity ent : area.getCuboidBoundary().getEntitiesPossiblyWithinForTag()) {
if (ent instanceof LivingEntity && area.doesContainLocation(ent.getLocation()) && !EntityTag.isCitizensNPC(ent)) {
result.addObject(new EntityTag(ent).getDenizenObject());
}
}
return result;
});
// <--[tag]
// @attribute <AreaObject.contains[<location>]>
// @returns ElementTag(Boolean)
// @description
// Returns a boolean indicating whether the specified location is inside this area.
// -->
processor.registerTag(ElementTag.class, "contains", (attribute, area) -> {
if (!attribute.hasParam()) {
return null;
}
LocationTag loc = attribute.paramAsType(LocationTag.class);
if (loc == null) {
return null;
}
return new ElementTag(area.doesContainLocation(loc));
}, "contains_location");
// <--[tag]
// @attribute <AreaObject.blocks[(<matcher>)]>
// @returns ListTag(LocationTag)
// @description
// Returns each block location within the area.
// Optionally, specify a material match to only return locations with that block type.
// -->
processor.registerTag(ListTag.class, "blocks", (attribute, area) -> {
if (attribute.hasParam()) {
NMSHandler.getChunkHelper().changeChunkServerThread(area.getWorld().getWorld());
try {
String matcher = attribute.getParam();
Predicate<Location> predicate = (l) -> BukkitScriptEvent.tryMaterial(l.getBlock().getType(), matcher);
return area.getBlocks(predicate);
} finally {
NMSHandler.getChunkHelper().restoreServerThread(area.getWorld().getWorld());
}
}
return area.getBlocks(null);
}, "get_blocks");
// <--[tag]
// @attribute <AreaObject.spawnable_blocks[(<matcher>)]>
// @returns ListTag(LocationTag)
// @description
// Returns each LocationTag within the area that is safe for players or similar entities to spawn in.
// Optionally, specify a material matcher to only return locations with that block type.
// Uses the same spawnable check as <@link tag LocationTag.is_spawnable>
// -->
processor.registerTag(ListTag.class, "spawnable_blocks", (attribute, area) -> {
NMSHandler.getChunkHelper().changeChunkServerThread(area.getWorld().getWorld());
try {
if (attribute.hasParam()) {
String matcher = attribute.getParam();
Predicate<Location> predicate = (l) -> SpawnableHelper.isSpawnable(l) && BukkitScriptEvent.tryMaterial(l.getBlock().getRelative(0, -1, 0).getType(), matcher);
return area.getBlocks(predicate);
}
return area.getBlocks(SpawnableHelper::isSpawnable);
} finally {
NMSHandler.getChunkHelper().restoreServerThread(area.getWorld().getWorld());
}
}, "get_spawnable_blocks");
// <--[tag]
// @attribute <AreaObject.blocks_flagged[<flag_name>]>
// @returns ListTag(LocationTag)
// @description
// Gets a list of all block locations with a specified flag within the area.
// Searches the internal flag lists, rather than through all possible blocks.
// -->
processor.registerTag(ListTag.class, "blocks_flagged", (attribute, area) -> {
if (!attribute.hasParam()) {
return null;
}
return area.getBlocksFlagged(CoreUtilities.toLowerCase(attribute.getParam()), attribute);
});
// <--[tag]
// @attribute <AreaObject.shell>
// @returns ListTag(LocationTag)
// @description
// Returns each block location on the 3D outer shell of the area.
// This tag is useful for displaying particles or blocks to mark the boundary of the area.
// -->
processor.registerTag(ListTag.class, "shell", (attribute, area) -> {
return area.getShell();
});
// <--[tag]
// @attribute <AreaObject.is_within[<cuboid>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether this area is fully inside another cuboid.
// -->
processor.registerTag(ElementTag.class, "is_within", (attribute, area) -> {
if (!attribute.hasParam()) {
return null;
}
CuboidTag cub2 = attribute.paramAsType(CuboidTag.class);
if (cub2 == null) {
return null;
}
CuboidTag cuboid = area instanceof CuboidTag ? (CuboidTag) area : area.getCuboidBoundary();
if (cub2 != null) {
boolean contains = true;
for (CuboidTag.LocationPair pair2 : cuboid.pairs) {
boolean contained = false;
for (CuboidTag.LocationPair pair : cub2.pairs) {
if (!pair.low.getWorld().getName().equalsIgnoreCase(pair2.low.getWorld().getName())) {
return new ElementTag(false);
}
if (pair2.low.getX() >= pair.low.getX() && pair2.low.getY() >= pair.low.getY() && pair2.low.getZ() >= pair.low.getZ() && pair2.high.getX() <= pair.high.getX() && pair2.high.getY() <= pair.high.getY() && pair2.high.getZ() <= pair.high.getZ()) {
contained = true;
break;
}
}
if (!contained) {
contains = false;
break;
}
}
return new ElementTag(contains);
}
return null;
});
// <--[tag]
// @attribute <AreaObject.with_world[<world>]>
// @returns AreaObject
// @description
// Returns a copy of the area, with the specified world.
// -->
processor.registerTag(type, "with_world", (attribute, area) -> {
if (!attribute.hasParam()) {
return null;
}
WorldTag world = attribute.paramAsType(WorldTag.class);
if (world == null) {
return null;
}
return (T) area.withWorld(world);
});
}
Aggregations