use of net.aufdemrand.denizen.nms.interfaces.EntityHelper in project Denizen-For-Bukkit by DenizenScript.
the class dLocation method getAttribute.
@Override
public String getAttribute(Attribute attribute) {
if (attribute == null) {
return null;
}
// -->
if (attribute.startsWith("above")) {
return new dLocation(this.clone().add(0, 1, 0)).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("below")) {
return new dLocation(this.clone().add(0, -1, 0)).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("block")) {
return new dLocation(getWorld(), getBlockX(), getBlockY(), getBlockZ()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("center")) {
return new dLocation(getWorld(), getBlockX() + 0.5, getBlockY() + 0.5, getBlockZ() + 0.5).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("highest")) {
return new dLocation(getWorld().getHighestBlockAt(this).getLocation().add(0, -1, 0)).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("base_color")) {
DyeColor color = ((Banner) getBlock().getState()).getBaseColor();
return new Element(color != null ? color.name() : "BLACK").getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("has_inventory")) {
return new Element(getBlock().getState() instanceof InventoryHolder).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("inventory")) {
dObject obj = Element.handleNull(identify() + ".inventory", getInventory(), "dInventory", attribute.hasAlternative());
return obj == null ? null : obj.getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("material")) {
return dMaterial.getMaterialFrom(getBlock().getType(), getBlock().getData()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("patterns")) {
dList list = new dList();
for (org.bukkit.block.banner.Pattern pattern : ((Banner) getBlock().getState()).getPatterns()) {
list.add(pattern.getColor().name() + "/" + pattern.getPattern().name());
}
return list.getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("head_rotation")) {
return new Element(getSkullRotation(((Skull) getBlock().getState()).getRotation()) + 1).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("switched")) {
Material type = getBlock().getType();
if (type == Material.IRON_DOOR_BLOCK || type == Material.WOODEN_DOOR || type == Material.DARK_OAK_DOOR || type == Material.BIRCH_DOOR || type == Material.ACACIA_DOOR || type == Material.JUNGLE_DOOR || type == Material.SPRUCE_DOOR) {
Location location = this;
int data = getBlock().getData();
if (data >= 8) {
location = clone().add(0, -1, 0);
}
return new Element((location.getBlock().getData() & 0x4) > 0).getAttribute(attribute.fulfill(1));
} else if (type == Material.TRAP_DOOR || type == Material.IRON_TRAPDOOR) {
return new Element((getBlock().getData() & 0x4) > 0).getAttribute(attribute.fulfill(1));
} else {
return new Element((getBlock().getData() & 0x8) > 0).getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("sign_contents")) {
if (getBlock().getState() instanceof Sign) {
return new dList(Arrays.asList(((Sign) getBlock().getState()).getLines())).getAttribute(attribute.fulfill(1));
} else {
return null;
}
}
// -->
if (attribute.startsWith("spawner_type")) {
if (getBlock().getState() instanceof CreatureSpawner) {
return new dEntity(DenizenEntityType.getByName(((CreatureSpawner) getBlock().getState()).getSpawnedType().name())).getAttribute(attribute.fulfill(1));
} else {
return null;
}
}
// -->
if (attribute.startsWith("drops")) {
Collection<ItemStack> its = getBlock().getDrops();
dList list = new dList();
for (ItemStack it : its) {
list.add(new dItem(it).identify());
}
return list.getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("skull_type")) {
BlockState blockState = getBlock().getState();
if (blockState instanceof Skull) {
String t = ((Skull) blockState).getSkullType().name();
return new Element(t).getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("skull_name")) {
BlockState blockState = getBlock().getState();
if (blockState instanceof Skull) {
PlayerProfile profile = NMSHandler.getInstance().getBlockHelper().getPlayerProfile((Skull) blockState);
String n = profile.getName();
if (n == null) {
n = ((Skull) blockState).getOwningPlayer().getName();
}
return new Element(n).getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("skull_skin")) {
BlockState blockState = getBlock().getState();
if (blockState instanceof Skull) {
PlayerProfile profile = NMSHandler.getInstance().getBlockHelper().getPlayerProfile((Skull) blockState);
String name = profile.getName();
UUID uuid = profile.getUniqueId();
String texture = profile.getTexture();
attribute = attribute.fulfill(1);
// -->
if (attribute.startsWith("full")) {
return new Element((uuid != null ? uuid : name != null ? name : null) + (texture != null ? "|" + texture : "")).getAttribute(attribute.fulfill(1));
}
return new Element(uuid != null ? uuid.toString() : name != null ? name : null).getAttribute(attribute);
} else {
return null;
}
}
// -->
if (attribute.startsWith("simple.formatted")) {
return new Element("X '" + getBlockX() + "', Y '" + getBlockY() + "', Z '" + getBlockZ() + "', in world '" + getWorld().getName() + "'").getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("simple")) {
if (getWorld() == null) {
return new Element(getBlockX() + "," + getBlockY() + "," + getBlockZ()).getAttribute(attribute.fulfill(1));
} else {
return new Element(getBlockX() + "," + getBlockY() + "," + getBlockZ() + "," + getWorld().getName()).getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("precise_impact_normal")) {
int range = attribute.getIntContext(1);
if (range < 1) {
range = 200;
}
double xzLen = Math.cos((getPitch() % 360) * (Math.PI / 180));
double nx = xzLen * Math.sin(-getYaw() * (Math.PI / 180));
double ny = Math.sin(getPitch() * (Math.PI / 180));
double nz = xzLen * Math.cos(getYaw() * (Math.PI / 180));
Location location = NMSHandler.getInstance().getEntityHelper().getImpactNormal(this, new org.bukkit.util.Vector(nx, -ny, nz), range);
if (location != null) {
return new dLocation(location).getAttribute(attribute.fulfill(1));
} else {
return null;
}
}
// -->
if (attribute.startsWith("precise_cursor_on")) {
int range = attribute.getIntContext(1);
if (range < 1) {
range = 200;
}
double xzLen = Math.cos((getPitch() % 360) * (Math.PI / 180));
double nx = xzLen * Math.sin(-getYaw() * (Math.PI / 180));
double ny = Math.sin(getPitch() * (Math.PI / 180));
double nz = xzLen * Math.cos(getYaw() * (Math.PI / 180));
Location location = NMSHandler.getInstance().getEntityHelper().rayTrace(this, new org.bukkit.util.Vector(nx, -ny, nz), range);
if (location != null) {
return new dLocation(location).getAttribute(attribute.fulfill(1));
} else {
return null;
}
}
// -->
if (attribute.startsWith("points_between")) {
dLocation target = dLocation.valueOf(attribute.getContext(1));
if (target == null) {
return null;
}
attribute = attribute.fulfill(1);
// <--[tag]
// @attribute <l@location.points_between[<location>].distance[<#.#>]>
// @returns dList(dLocation)
// @description
// Finds all locations between this location and another, separated by the specified distance each.
// -->
double rad = 1d;
if (attribute.startsWith("distance")) {
rad = attribute.getDoubleContext(1);
attribute = attribute.fulfill(1);
}
dList list = new dList();
org.bukkit.util.Vector rel = target.toVector().subtract(this.toVector());
double len = rel.length();
rel = rel.multiply(1d / len);
for (double i = 0d; i < len; i += rad) {
list.add(new dLocation(this.clone().add(rel.clone().multiply(i))).identify());
}
return list.getAttribute(attribute);
}
// -->
if (attribute.startsWith("facing_blocks")) {
int range = attribute.getIntContext(1);
if (range < 1) {
range = 100;
}
dList list = new dList();
BlockIterator iterator = new BlockIterator(this, 0, range);
while (iterator.hasNext()) {
list.add(new dLocation(iterator.next().getLocation()).identify());
}
return list.getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("line_of_sight") && attribute.hasContext(1)) {
dLocation location = dLocation.valueOf(attribute.getContext(1));
if (location != null) {
return new Element(NMSHandler.getInstance().getEntityHelper().canTrace(getWorld(), toVector(), location.toVector())).getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("direction.vector")) {
double xzLen = Math.cos((getPitch() % 360) * (Math.PI / 180));
double nx = xzLen * Math.sin(-getYaw() * (Math.PI / 180));
double ny = Math.sin(getPitch() * (Math.PI / 180));
double nz = xzLen * Math.cos(getYaw() * (Math.PI / 180));
return new dLocation(getWorld(), nx, -ny, nz).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("direction")) {
// Get the cardinal direction from this location to another
if (attribute.hasContext(1) && dLocation.matches(attribute.getContext(1))) {
// Subtract this location's vector from the other location's vector,
// not the other way around
dLocation target = dLocation.valueOf(attribute.getContext(1));
attribute = attribute.fulfill(1);
EntityHelper entityHelper = NMSHandler.getInstance().getEntityHelper();
// -->
if (attribute.startsWith("yaw")) {
return new Element(entityHelper.normalizeYaw(entityHelper.getYaw(target.toVector().subtract(this.toVector()).normalize()))).getAttribute(attribute.fulfill(1));
} else {
return new Element(entityHelper.getCardinal(entityHelper.getYaw(target.toVector().subtract(this.toVector()).normalize()))).getAttribute(attribute);
}
} else // Get a cardinal direction from this location's yaw
{
return new Element(NMSHandler.getInstance().getEntityHelper().getCardinal(getYaw())).getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("face") && attribute.hasContext(1)) {
Location two = dLocation.valueOf(attribute.getContext(1));
return new dLocation(NMSHandler.getInstance().getEntityHelper().faceLocation(this, two)).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("facing")) {
if (attribute.hasContext(1)) {
// The default number of degrees if there is no degrees attribute
int degrees = 45;
// The attribute to fulfill from
int attributePos = 1;
// -->
if (attribute.getAttribute(2).startsWith("degrees") && attribute.hasContext(2) && aH.matchesInteger(attribute.getContext(2))) {
degrees = attribute.getIntContext(2);
attributePos++;
}
if (dLocation.matches(attribute.getContext(1))) {
return new Element(NMSHandler.getInstance().getEntityHelper().isFacingLocation(this, dLocation.valueOf(attribute.getContext(1)), degrees)).getAttribute(attribute.fulfill(attributePos));
} else if (dEntity.matches(attribute.getContext(1))) {
return new Element(NMSHandler.getInstance().getEntityHelper().isFacingLocation(this, dEntity.valueOf(attribute.getContext(1)).getBukkitEntity().getLocation(), degrees)).getAttribute(attribute.fulfill(attributePos));
}
}
}
// -->
if (attribute.startsWith("pitch")) {
return new Element(getPitch()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("with_pose")) {
String context = attribute.getContext(1);
Float pitch = 0f;
Float yaw = 0f;
if (dEntity.matches(context)) {
dEntity ent = dEntity.valueOf(context);
if (ent.isSpawned()) {
pitch = ent.getBukkitEntity().getLocation().getPitch();
yaw = ent.getBukkitEntity().getLocation().getYaw();
}
} else if (context.split(",").length == 2) {
String[] split = context.split(",");
pitch = Float.valueOf(split[0]);
yaw = Float.valueOf(split[1]);
}
dLocation loc = dLocation.valueOf(identify());
loc.setPitch(pitch);
loc.setYaw(yaw);
return loc.getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("yaw.simple")) {
float yaw = NMSHandler.getInstance().getEntityHelper().normalizeYaw(getYaw());
if (yaw < 45) {
return new Element("South").getAttribute(attribute.fulfill(2));
} else if (yaw < 135) {
return new Element("West").getAttribute(attribute.fulfill(2));
} else if (yaw < 225) {
return new Element("North").getAttribute(attribute.fulfill(2));
} else if (yaw < 315) {
return new Element("East").getAttribute(attribute.fulfill(2));
} else {
return new Element("South").getAttribute(attribute.fulfill(2));
}
}
// -->
if (attribute.startsWith("yaw.raw")) {
return new Element(getYaw()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("yaw")) {
return new Element(NMSHandler.getInstance().getEntityHelper().normalizeYaw(getYaw())).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("rotate_around_x") && attribute.hasContext(1)) {
double angle = attribute.getDoubleContext(1);
double cos = Math.cos(angle);
double sin = Math.sin(angle);
double y = (getY() * cos) - (getZ() * sin);
double z = (getY() * sin) + (getZ() * cos);
Location location = clone();
location.setY(y);
location.setZ(z);
return new dLocation(location).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("rotate_around_y") && attribute.hasContext(1)) {
double angle = attribute.getDoubleContext(1);
double cos = Math.cos(angle);
double sin = Math.sin(angle);
double x = (getX() * cos) + (getZ() * sin);
double z = (getX() * -sin) + (getZ() * cos);
Location location = clone();
location.setX(x);
location.setZ(z);
return new dLocation(location).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("rotate_around_z") && attribute.hasContext(1)) {
double angle = attribute.getDoubleContext(1);
double cos = Math.cos(angle);
double sin = Math.sin(angle);
double x = (getX() * cos) - (getY() * sin);
double y = (getZ() * sin) + (getY() * cos);
Location location = clone();
location.setX(x);
location.setY(y);
return new dLocation(location).getAttribute(attribute.fulfill(1));
}
if (attribute.matches("find") || attribute.startsWith("nearest")) {
attribute.fulfill(1);
// -->
if (attribute.startsWith("blocks") && attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2)) {
ArrayList<dLocation> found = new ArrayList<dLocation>();
int radius = aH.matchesInteger(attribute.getContext(2)) ? attribute.getIntContext(2) : 10;
List<dMaterial> materials = new ArrayList<dMaterial>();
if (attribute.hasContext(1)) {
materials = dList.valueOf(attribute.getContext(1)).filter(dMaterial.class);
}
// Avoid NPE from invalid materials
if (materials == null) {
return null;
}
int max = Settings.blockTagsMaxBlocks();
int index = 0;
attribute.fulfill(2);
Location tstart = getBlock().getLocation();
double tstartY = tstart.getY();
fullloop: for (int x = -(radius); x <= radius; x++) {
for (int y = -(radius); y <= radius; y++) {
double newY = y + tstartY;
if (newY < 0 || newY > 255) {
continue;
}
for (int z = -(radius); z <= radius; z++) {
index++;
if (index > max) {
break fullloop;
}
if (Utilities.checkLocation(this, tstart.clone().add(x + 0.5, y + 0.5, z + 0.5), radius)) {
if (!materials.isEmpty()) {
for (dMaterial material : materials) {
if (material.hasData() && material.getData() != 0) {
// TODO: less arbitrary matching
if (material.matchesMaterialData(tstart.clone().add(x, y, z).getBlock().getState().getData())) {
found.add(new dLocation(tstart.clone().add(x, y, z)));
}
} else if (material.getMaterial() == tstart.clone().add(x, y, z).getBlock().getType()) {
found.add(new dLocation(tstart.clone().add(x, y, z)));
}
}
} else {
found.add(new dLocation(tstart.clone().add(x, y, z)));
}
}
}
}
}
Collections.sort(found, new Comparator<dLocation>() {
@Override
public int compare(dLocation loc1, dLocation loc2) {
return dLocation.this.compare(loc1, loc2);
}
});
return new dList(found).getAttribute(attribute);
} else // -->
if (attribute.startsWith("surface_blocks") && attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2)) {
ArrayList<dLocation> found = new ArrayList<dLocation>();
double radius = aH.matchesDouble(attribute.getContext(2)) ? attribute.getDoubleContext(2) : 10;
List<dMaterial> materials = new ArrayList<dMaterial>();
if (attribute.hasContext(1)) {
materials = dList.valueOf(attribute.getContext(1)).filter(dMaterial.class);
}
// Avoid NPE from invalid materials
if (materials == null) {
return null;
}
int max = Settings.blockTagsMaxBlocks();
int index = 0;
attribute.fulfill(2);
Location loc = getBlock().getLocation().add(0.5f, 0.5f, 0.5f);
fullloop: for (double x = -(radius); x <= radius; x++) {
for (double y = -(radius); y <= radius; y++) {
for (double z = -(radius); z <= radius; z++) {
index++;
if (index > max) {
break fullloop;
}
if (Utilities.checkLocation(loc, getBlock().getLocation().add(x + 0.5, y + 0.5, z + 0.5), radius)) {
Location l = getBlock().getLocation().clone().add(x, y, z);
if (!materials.isEmpty()) {
for (dMaterial material : materials) {
if (material.matchesMaterialData(getBlock().getLocation().clone().add(x, y, z).getBlock().getType().getNewData(getBlock().getLocation().clone().add(x, y, z).getBlock().getData()))) {
if (l.clone().add(0, 1, 0).getBlock().getType() == Material.AIR && l.clone().add(0, 2, 0).getBlock().getType() == Material.AIR && l.getBlock().getType() != Material.AIR) {
found.add(new dLocation(getBlock().getLocation().clone().add(x + 0.5, y, z + 0.5)));
}
}
}
} else {
if (l.clone().add(0, 1, 0).getBlock().getType() == Material.AIR && l.clone().add(0, 2, 0).getBlock().getType() == Material.AIR && l.getBlock().getType() != Material.AIR) {
found.add(new dLocation(getBlock().getLocation().clone().add(x + 0.5, y, z + 0.5)));
}
}
}
}
}
}
Collections.sort(found, new Comparator<dLocation>() {
@Override
public int compare(dLocation loc1, dLocation loc2) {
return dLocation.this.compare(loc1, loc2);
}
});
return new dList(found).getAttribute(attribute);
} else // -->
if (attribute.startsWith("players") && attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2)) {
ArrayList<dPlayer> found = new ArrayList<dPlayer>();
double radius = aH.matchesDouble(attribute.getContext(2)) ? attribute.getDoubleContext(2) : 10;
attribute.fulfill(2);
for (Player player : Bukkit.getOnlinePlayers()) {
if (!player.isDead() && Utilities.checkLocation(this, player.getLocation(), radius)) {
found.add(new dPlayer(player));
}
}
Collections.sort(found, new Comparator<dPlayer>() {
@Override
public int compare(dPlayer pl1, dPlayer pl2) {
return dLocation.this.compare(pl1.getLocation(), pl2.getLocation());
}
});
return new dList(found).getAttribute(attribute);
} else // -->
if (attribute.startsWith("npcs") && attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2)) {
ArrayList<dNPC> found = new ArrayList<dNPC>();
double radius = aH.matchesDouble(attribute.getContext(2)) ? attribute.getDoubleContext(2) : 10;
attribute.fulfill(2);
for (dNPC npc : DenizenAPI.getSpawnedNPCs()) {
if (Utilities.checkLocation(this.getBlock().getLocation(), npc.getLocation(), radius)) {
found.add(npc);
}
}
Collections.sort(found, new Comparator<dNPC>() {
@Override
public int compare(dNPC npc1, dNPC npc2) {
return dLocation.this.compare(npc1.getLocation(), npc2.getLocation());
}
});
return new dList(found).getAttribute(attribute);
} else // -->
if (attribute.startsWith("entities") && attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2)) {
dList ent_list = new dList();
if (attribute.hasContext(1)) {
ent_list = dList.valueOf(attribute.getContext(1));
}
ArrayList<dEntity> found = new ArrayList<dEntity>();
double radius = aH.matchesDouble(attribute.getContext(2)) ? attribute.getDoubleContext(2) : 10;
attribute.fulfill(2);
for (Entity entity : getWorld().getEntities()) {
if (Utilities.checkLocation(this, entity.getLocation(), radius)) {
dEntity current = new dEntity(entity);
if (!ent_list.isEmpty()) {
for (String ent : ent_list) {
if (current.comparedTo(ent)) {
found.add(current);
break;
}
}
} else {
found.add(current);
}
}
}
Collections.sort(found, new Comparator<dEntity>() {
@Override
public int compare(dEntity ent1, dEntity ent2) {
return dLocation.this.compare(ent1.getLocation(), ent2.getLocation());
}
});
return new dList(found).getAttribute(attribute);
} else // -->
if (attribute.startsWith("living_entities") && attribute.getAttribute(2).startsWith("within") && attribute.hasContext(2)) {
ArrayList<dEntity> found = new ArrayList<dEntity>();
double radius = aH.matchesDouble(attribute.getContext(2)) ? attribute.getDoubleContext(2) : 10;
attribute.fulfill(2);
for (Entity entity : getWorld().getEntities()) {
if (entity instanceof LivingEntity && Utilities.checkLocation(this, entity.getLocation(), radius)) {
found.add(new dEntity(entity));
}
}
Collections.sort(found, new Comparator<dEntity>() {
@Override
public int compare(dEntity ent1, dEntity ent2) {
return dLocation.this.compare(ent1.getLocation(), ent2.getLocation());
}
});
return new dList(found).getAttribute(attribute);
}
}
// -->
if (attribute.startsWith("find_path") && attribute.hasContext(1)) {
dLocation two = dLocation.valueOf(attribute.getContext(1));
if (two == null) {
return null;
}
List<dLocation> locs = PathFinder.getPath(this, two);
dList list = new dList();
for (dLocation loc : locs) {
list.add(loc.identify());
}
return list.getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("formatted.citizens")) {
return new Element(getX() + ":" + getY() + ":" + getZ() + ":" + getWorld().getName()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("formatted")) {
return new Element("X '" + getX() + "', Y '" + getY() + "', Z '" + getZ() + "', in world '" + getWorld().getName() + "'").getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("chunk") || attribute.startsWith("get_chunk")) {
return new dChunk(this).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("raw")) {
dLocation rawLocation = new dLocation(this);
rawLocation.setRaw(true);
return rawLocation.getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("world")) {
return dWorld.mirrorBukkitWorld(getWorld()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("x")) {
return new Element(getX()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("y")) {
return new Element(getY()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("z")) {
return new Element(getZ()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("notable_name")) {
String notname = NotableManager.getSavedId(this);
if (notname == null) {
return null;
}
return new Element(notname).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("add") && attribute.hasContext(1)) {
// TODO: Just dLocation.valueOf?
String[] ints = attribute.getContext(1).replace("l@", "").split(",", 4);
if (ints.length >= 3) {
if ((aH.matchesDouble(ints[0]) || aH.matchesInteger(ints[0])) && (aH.matchesDouble(ints[1]) || aH.matchesInteger(ints[1])) && (aH.matchesDouble(ints[2]) || aH.matchesInteger(ints[2]))) {
return new dLocation(this.clone().add(Double.valueOf(ints[0]), Double.valueOf(ints[1]), Double.valueOf(ints[2]))).getAttribute(attribute.fulfill(1));
}
} else if (dLocation.matches(attribute.getContext(1))) {
return new dLocation(this.clone().add(dLocation.valueOf(attribute.getContext(1)))).getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("sub") && attribute.hasContext(1)) {
// TODO: Just dLocation.valueOf?
String[] ints = attribute.getContext(1).replace("l@", "").split(",", 4);
if (ints.length == 3 || ints.length == 4) {
if ((aH.matchesDouble(ints[0]) || aH.matchesInteger(ints[0])) && (aH.matchesDouble(ints[1]) || aH.matchesInteger(ints[1])) && (aH.matchesDouble(ints[2]) || aH.matchesInteger(ints[2]))) {
return new dLocation(this.clone().subtract(Double.valueOf(ints[0]), Double.valueOf(ints[1]), Double.valueOf(ints[2]))).getAttribute(attribute.fulfill(1));
}
} else if (dLocation.matches(attribute.getContext(1))) {
return new dLocation(this.clone().subtract(dLocation.valueOf(attribute.getContext(1)))).getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("mul") && attribute.hasContext(1)) {
return new dLocation(this.clone().multiply(Double.parseDouble(attribute.getContext(1)))).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("div") && attribute.hasContext(1)) {
return new dLocation(this.clone().multiply(1D / Double.parseDouble(attribute.getContext(1)))).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("normalize")) {
double len = Math.sqrt(Math.pow(getX(), 2) + Math.pow(getY(), 2) + Math.pow(getZ(), 2));
if (len == 0) {
return this.getAttribute(attribute.fulfill(1));
} else {
return new dLocation(this.clone().multiply(1D / len)).getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("vector_length")) {
return new Element(Math.sqrt(Math.pow(getX(), 2) + Math.pow(getY(), 2) + Math.pow(getZ(), 2))).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("distance_squared") && attribute.hasContext(1)) {
if (dLocation.matches(attribute.getContext(1))) {
dLocation toLocation = dLocation.valueOf(attribute.getContext(1));
if (!getWorld().getName().equalsIgnoreCase(toLocation.getWorld().getName())) {
if (!attribute.hasAlternative()) {
dB.echoError("Can't measure distance between two different worlds!");
}
return null;
}
return new Element(this.distanceSquared(toLocation)).getAttribute(attribute.fulfill(1));
}
}
// -->
if (attribute.startsWith("distance") && attribute.hasContext(1)) {
if (dLocation.matches(attribute.getContext(1))) {
dLocation toLocation = dLocation.valueOf(attribute.getContext(1));
// -->
if (attribute.getAttribute(2).startsWith("horizontal")) {
// -->
if (attribute.getAttribute(3).startsWith("multiworld")) {
return new Element(Math.sqrt(Math.pow(this.getX() - toLocation.getX(), 2) + Math.pow(this.getZ() - toLocation.getZ(), 2))).getAttribute(attribute.fulfill(3));
} else if (this.getWorld() == toLocation.getWorld()) {
return new Element(Math.sqrt(Math.pow(this.getX() - toLocation.getX(), 2) + Math.pow(this.getZ() - toLocation.getZ(), 2))).getAttribute(attribute.fulfill(2));
}
} else // -->
if (attribute.getAttribute(2).startsWith("vertical")) {
// -->
if (attribute.getAttribute(3).startsWith("multiworld")) {
return new Element(Math.abs(this.getY() - toLocation.getY())).getAttribute(attribute.fulfill(3));
} else if (this.getWorld() == toLocation.getWorld()) {
return new Element(Math.abs(this.getY() - toLocation.getY())).getAttribute(attribute.fulfill(2));
}
}
if (!getWorld().getName().equalsIgnoreCase(toLocation.getWorld().getName())) {
if (!attribute.hasAlternative()) {
dB.echoError("Can't measure distance between two different worlds!");
}
return null;
} else {
return new Element(this.distance(toLocation)).getAttribute(attribute.fulfill(1));
}
}
}
// -->
if (attribute.startsWith("is_within") && attribute.hasContext(1)) {
if (dEllipsoid.matches(attribute.getContext(1))) {
dEllipsoid ellipsoid = dEllipsoid.valueOf(attribute.getContext(1));
if (ellipsoid != null) {
return new Element(ellipsoid.contains(this)).getAttribute(attribute.fulfill(1));
}
} else {
dCuboid cuboid = dCuboid.valueOf(attribute.getContext(1));
if (cuboid != null) {
return new Element(cuboid.isInsideCuboid(this)).getAttribute(attribute.fulfill(1));
}
}
}
// -->
if (attribute.startsWith("biome.formatted")) {
return new Element(CoreUtilities.toLowerCase(getBlock().getBiome().name()).replace('_', ' ')).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("biome")) {
return new dBiome(getBlock().getBiome()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("cuboids")) {
List<dCuboid> cuboids = dCuboid.getNotableCuboidsContaining(this);
dList cuboid_list = new dList();
for (dCuboid cuboid : cuboids) {
cuboid_list.add(cuboid.identify());
}
return cuboid_list.getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("ellipsoids")) {
List<dEllipsoid> ellipsoids = dEllipsoid.getNotableEllipsoidsContaining(this);
dList ellipsoid_list = new dList();
for (dEllipsoid ellipsoid : ellipsoids) {
ellipsoid_list.add(ellipsoid.identify());
}
return ellipsoid_list.getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("is_liquid")) {
return new Element(getBlock().isLiquid()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("light.from_blocks") || attribute.startsWith("light.blocks")) {
return new Element(getBlock().getLightFromBlocks()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("light.from_sky") || attribute.startsWith("light.sky")) {
return new Element(getBlock().getLightFromSky()).getAttribute(attribute.fulfill(2));
}
// -->
if (attribute.startsWith("light")) {
return new Element(getBlock().getLightLevel()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("power")) {
return new Element(getBlock().getBlockPower()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("type")) {
return new Element("Location").getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("command_block_name") && getBlock().getType() == Material.COMMAND) {
return new Element(((CommandBlock) getBlock().getState()).getName()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("command_block") && getBlock().getType() == Material.COMMAND) {
return new Element(((CommandBlock) getBlock().getState()).getCommand()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("furnace_burn_time")) {
return new Element(((Furnace) getBlock().getState()).getBurnTime()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("furnace_cook_time")) {
return new Element(((Furnace) getBlock().getState()).getCookTime()).getAttribute(attribute.fulfill(1));
}
// -->
if (attribute.startsWith("attached_to")) {
BlockFace face = BlockFace.SELF;
MaterialData data = getBlock().getState().getData();
if (data instanceof Attachable) {
face = ((Attachable) data).getAttachedFace();
}
if (face != BlockFace.SELF) {
return new dLocation(getBlock().getRelative(face).getLocation()).getAttribute(attribute.fulfill(1));
}
}
// Iterate through this object's properties' attributes
for (Property property : PropertyParser.getProperties(this)) {
String returned = property.getAttribute(attribute);
if (returned != null) {
return returned;
}
}
return new Element(identify()).getAttribute(attribute);
}
Aggregations