Skip to content

Commit

Permalink
Hanging breaks - entity -> breaker
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jul 14, 2015
1 parent f393941 commit b719b5b
Showing 1 changed file with 10 additions and 9 deletions.
Expand Up @@ -33,12 +33,11 @@ public class EntityBreaksHangingScriptEvent extends BukkitScriptEvent implements
// @Triggers when a hanging entity (painting, item_frame, or leash_hitch) is broken.
//
// @Context
// <context.cause> returns the cause of the entity breaking.
// <context.entity> returns the dEntity that broke the hanging entity, if any.
// <context.cause> returns the cause of the entity breaking. Causes list: <@link url http://bit.ly/1BeqxPX>
// <context.breaker> returns the dEntity that broke the hanging entity, if any.
// <context.hanging> returns the dEntity of the hanging.
// <context.cuboids> DEPRECATED.
// <context.location> DEPRECATED.
// Causes list: <@link url http://bit.ly/1BeqxPX>
//
// -->

Expand All @@ -48,7 +47,7 @@ public EntityBreaksHangingScriptEvent() {

public static EntityBreaksHangingScriptEvent instance;
public Element cause;
public dEntity entity;
public dEntity breaker;
public dEntity hanging;
public dList cuboids;
public dLocation location;
Expand All @@ -66,7 +65,7 @@ public boolean matches(ScriptContainer scriptContainer, String s) {
String lower = CoreUtilities.toLowerCase(s);
String entName = CoreUtilities.getXthArg(0, lower);
String hang = CoreUtilities.getXthArg(2, lower);
if (!entity.matchesEntity(entName)) {
if (!breaker.matchesEntity(entName)) {
return false;
}
if (!hang.equals("hanging") && !hanging.matchesEntity(hang)) {
Expand Down Expand Up @@ -106,15 +105,17 @@ public boolean applyDetermination(ScriptContainer container, String determinatio

@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(entity.isPlayer() ? entity.getDenizenPlayer() : null,
entity.isCitizensNPC() ? entity.getDenizenNPC() : null);
// TODO: What if the hanging is an NPC?
return new BukkitScriptEntryData(breaker.isPlayer() ? breaker.getDenizenPlayer() : null,
breaker.isCitizensNPC() ? breaker.getDenizenNPC() : null);
}

@Override
public HashMap<String, dObject> getContext() {
HashMap<String, dObject> context = super.getContext();
context.put("cause", cause);
context.put("entity", entity);
context.put("entity", breaker); // NOTE: Deprecated
context.put("breaker", breaker);
context.put("hanging", hanging);
context.put("cuboids", cuboids);
context.put("location", location);
Expand All @@ -126,7 +127,7 @@ public void onHangingBreaks(HangingBreakByEntityEvent event) {
hanging = new dEntity(event.getEntity());
cause = new Element(event.getCause().name());
location = new dLocation(hanging.getLocation());
entity = new dEntity(event.getRemover());
breaker = new dEntity(event.getRemover());
cuboids = new dList();
for (dCuboid cuboid : dCuboid.getNotableCuboidsContaining(location)) {
cuboids.add(cuboid.identifySimple());
Expand Down

0 comments on commit b719b5b

Please sign in to comment.