Skip to content

Commit

Permalink
Add tag location.attached_to, fixes #1296
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 29, 2016
1 parent b3e4d48 commit 7412af3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Expand Up @@ -47,7 +47,6 @@ public EntityInteractScriptEvent() {
public dEntity entity;
public dLocation location;
private dMaterial material;
public dList cuboids;
public EntityInteractEvent event;

@Override
Expand Down Expand Up @@ -110,6 +109,10 @@ else if (name.equals("location")) {
return location;
}
else if (name.equals("cuboids")) { // NOTE: Deprecated in favour of context.location.cuboids
dList cuboids = new dList();
for (dCuboid cuboid : dCuboid.getNotableCuboidsContaining(location)) {
cuboids.add(cuboid.identifySimple());
}
return cuboids;
}
return super.getContext(name);
Expand All @@ -120,9 +123,6 @@ public void onEntityInteract(EntityInteractEvent event) {
entity = new dEntity(event.getEntity());
location = new dLocation(event.getBlock().getLocation());
material = dMaterial.getMaterialFrom(event.getBlock().getType(), event.getBlock().getData());
for (dCuboid cuboid : dCuboid.getNotableCuboidsContaining(location)) {
cuboids.add(cuboid.identifySimple());
}
cancelled = event.isCancelled();
this.event = event;
fire();
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -32,6 +32,8 @@
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.material.Button;
import org.bukkit.material.Lever;
import org.bukkit.util.*;

import java.util.*;
Expand Down Expand Up @@ -1884,6 +1886,27 @@ && getBlock().getType() == Material.COMMAND) {
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <l@location.attached_to>
// @returns dLocation
// @description
// Returns the block this block is attached to.
// (Only if it is a lever or button!)
// -->
if (attribute.startsWith("attached_to")) {
BlockFace face = BlockFace.SELF;
BlockState state = getBlock().getState();
if (state instanceof Lever) {
face = ((Lever)state).getAttachedFace();
}
else if (state instanceof Button) {
face = ((Button)state).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);
Expand Down

0 comments on commit 7412af3

Please sign in to comment.