Skip to content

Commit

Permalink
AreaObject.entities - use matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed May 5, 2021
1 parent 03236de commit f916680
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 56 deletions.
@@ -1,5 +1,6 @@
package com.denizenscript.denizen.objects;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.notable.NotableManager;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.depends.Depends;
Expand Down Expand Up @@ -1487,35 +1488,23 @@ public static void registerTags() {
}

// <--[tag]
// @attribute <CuboidTag.entities[(<entity>|...)]>
// @attribute <CuboidTag.entities[(<matcher>)]>
// @returns ListTag(EntityTag)
// @description
// Gets a list of all entities currently within the CuboidTag, with
// an optional search parameter for the entity type.
// Gets a list of all entities currently within the CuboidTag, with an optional search parameter for the entity.
// -->
registerTag("entities", (attribute, cuboid) -> {
ArrayList<EntityTag> entities = new ArrayList<>();
ListTag types = new ListTag();
if (attribute.hasContext(1)) {
types = attribute.contextAsType(1, ListTag.class);
}
String matcher = attribute.hasContext(1) ? attribute.getContext(1) : null;
ListTag entities = new ListTag();
for (Entity ent : new WorldTag(cuboid.getWorld()).getEntitiesForTag()) {
EntityTag current = new EntityTag(ent);
if (cuboid.isInsideCuboid(ent.getLocation())) {
if (!types.isEmpty()) {
for (String type : types) {
if (current.identifySimpleType().equalsIgnoreCase(type)) {
entities.add(current);
break;
}
}
}
else {
entities.add(new EntityTag(ent));
if (matcher == null || BukkitScriptEvent.tryEntity(current, matcher)) {
entities.addObject(new EntityTag(ent).getDenizenObject());
}
}
}
return new ListTag(entities);
return entities;
}, "list_entities");

// <--[tag]
Expand Down
@@ -1,5 +1,6 @@
package com.denizenscript.denizen.objects;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.notable.NotableManager;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.depends.Depends;
Expand Down Expand Up @@ -671,34 +672,23 @@ else if (projZ >= projX && projZ >= projY) {
}

// <--[tag]
// @attribute <EllipsoidTag.entities[(<entity>|...)]>
// @attribute <EllipsoidTag.entities[(<matcher>)]>
// @returns ListTag(EntityTag)
// @description
// Gets a list of all entities currently within the EllipsoidTag, with an optional search parameter for the entity type.
// Gets a list of all entities currently within the EllipsoidTag, with an optional search parameter for the entity.
// -->
registerTag("entities", (attribute, object) -> {
ArrayList<EntityTag> entities = new ArrayList<>();
ListTag types = new ListTag();
if (attribute.hasContext(1)) {
types = attribute.contextAsType(1, ListTag.class);
}
String matcher = attribute.hasContext(1) ? attribute.getContext(1) : null;
ListTag entities = new ListTag();
for (Entity ent : new WorldTag(object.center.getWorld()).getEntitiesForTag()) {
EntityTag current = new EntityTag(ent);
if (object.contains(ent.getLocation())) {
if (!types.isEmpty()) {
for (String type : types) {
if (current.identifySimpleType().equalsIgnoreCase(type)) {
entities.add(current);
break;
}
}
}
else {
entities.add(new EntityTag(ent));
if (matcher == null || BukkitScriptEvent.tryEntity(current, matcher)) {
entities.addObject(new EntityTag(ent).getDenizenObject());
}
}
}
return new ListTag(entities);
return entities;
});

// <--[tag]
Expand Down
Expand Up @@ -3298,6 +3298,7 @@ else if (getPlayerEntity().getGameMode() == GameMode.SPECTATOR) {
// @input ItemTag
// @description
// Displays a book to a player. Must be a WRITTEN_BOOK item.
// For simple usage, consider specifying a book script name as the input.
// -->
if (mechanism.matches("show_book")
&& mechanism.requireObject(ItemTag.class)) {
Expand Down
@@ -1,5 +1,6 @@
package com.denizenscript.denizen.objects;

import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.notable.NotableManager;
import com.denizenscript.denizen.utilities.Settings;
import com.denizenscript.denizen.utilities.debugging.Debug;
Expand Down Expand Up @@ -610,35 +611,23 @@ public static void registerTags() {
}

// <--[tag]
// @attribute <PolygonTag.entities[(<entity>|...)]>
// @attribute <PolygonTag.entities[(<matcher>)]>
// @returns ListTag(EntityTag)
// @description
// Gets a list of all entities currently within the PolygonTag, with
// an optional search parameter for the entity type.
// Gets a list of all entities currently within the PolygonTag, with an optional search parameter for the entity.
// -->
registerTag("entities", (attribute, polygon) -> {
ArrayList<EntityTag> entities = new ArrayList<>();
ListTag types = new ListTag();
if (attribute.hasContext(1)) {
types = attribute.contextAsType(1, ListTag.class);
}
String matcher = attribute.hasContext(1) ? attribute.getContext(1) : null;
ListTag entities = new ListTag();
for (Entity ent : polygon.world.getEntitiesForTag()) {
EntityTag current = new EntityTag(ent);
if (polygon.doesContainLocation(ent.getLocation())) {
if (!types.isEmpty()) {
for (String type : types) {
if (current.identifySimpleType().equalsIgnoreCase(type)) {
entities.add(current);
break;
}
}
}
else {
entities.add(new EntityTag(ent));
if (matcher == null || BukkitScriptEvent.tryEntity(current, matcher)) {
entities.addObject(new EntityTag(ent).getDenizenObject());
}
}
}
return new ListTag(entities);
return entities;
});

// <--[tag]
Expand Down

0 comments on commit f916680

Please sign in to comment.