Skip to content

Commit

Permalink
Add <l@location.line_of_sight>
Browse files Browse the repository at this point in the history
For example, <player.eye_location.line_of_sight[l@CanYouSeeMe]>
Fixes #1105
  • Loading branch information
Morphan1 committed Aug 3, 2015
1 parent 43a732e commit 2aca5a5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -32,8 +32,10 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.util.*;

import java.util.*;
import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -678,6 +680,21 @@ else if (type == Material.TRAP_DOOR
return null;
}

// <--[tag]
// @attribute <l@location.line_of_sight[<location>]>
// @returns Element(Boolean)
// @description
// Returns whether the specified location is within this location's
// line of sight.
// -->
if (attribute.startsWith("line_of_sight") && attribute.hasContext(1)) {
dLocation location = dLocation.valueOf(attribute.getContext(1));
if (location != null) {
return new Element(Rotation.rayTrace(getWorld(), toVector(), location.toVector()) == null)
.getAttribute(attribute.fulfill(1));
}
}

// <--[tag]
// @attribute <l@location.direction.vector>
// @returns dLocation
Expand Down
Expand Up @@ -84,7 +84,7 @@ private static void look(Entity entity, float yaw, float pitch) {
}
}

private static MovingObjectPosition rayTrace(World world, Vector start, Vector end) {
public static MovingObjectPosition rayTrace(World world, Vector start, Vector end) {
return ((CraftWorld) world).getHandle().rayTrace(new Vec3D(start.getX(), start.getY(), start.getZ()),
new Vec3D(end.getX(), end.getY(), end.getZ()));
}
Expand Down

0 comments on commit 2aca5a5

Please sign in to comment.