Skip to content

Commit

Permalink
Fix up the physics event
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 12, 2015
1 parent 0129934 commit 5cffab6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package net.aufdemrand.denizen.events.scriptevents;

import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dEllipsoid;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dMaterial;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.events.ScriptEvent;
import net.aufdemrand.denizencore.objects.dList;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
Expand All @@ -16,6 +17,7 @@
import org.bukkit.event.block.BlockPhysicsEvent;

import java.util.HashMap;
import java.util.List;

public class BlockPhysicsScriptEvent extends ScriptEvent implements Listener {

Expand All @@ -39,9 +41,11 @@ public class BlockPhysicsScriptEvent extends ScriptEvent implements Listener {
public BlockPhysicsScriptEvent() {
instance = this;
}

public static BlockPhysicsScriptEvent instance;
public dLocation location;
public dMaterial new_material;
public dMaterial old_material;
public BlockPhysicsEvent event;

@Override
Expand All @@ -58,29 +62,44 @@ public boolean matches(ScriptContainer scriptContainer, String s) {
return true;
}

Boolean blockvalid = true;
if (!lower.startsWith(new_material.identifySimple())) {
blockvalid = false;
if (!lower.startsWith("block")) {
dMaterial mat = dMaterial.valueOf(CoreUtilities.getXthArg(0, lower));
if (mat == null) {
dB.echoError("Invalid event material [BlockPhysics]: '" + s + "' for " + scriptContainer.getName());
return false;
}
if (!old_material.matchesMaterialData(mat.getMaterialData())) {
return false;
}
}

Boolean cuboidvalid = true;
if (lower.contains(" in ")) {
dList cuboids = new dList();
for (dCuboid cuboid: dCuboid.getNotableCuboidsContaining(location)) {
cuboids.add(cuboid.identify());
if (CoreUtilities.xthArgEquals(2, lower, "in")) {
String it = CoreUtilities.getXthArg(3, lower);
if (dCuboid.matches(it)) {
dCuboid cuboid = dCuboid.valueOf(it);
if (!cuboid.isInsideCuboid(location)) {
dB.log(location + " not in " + cuboid);
return false;
}
}

if (!cuboids.contains(lower.substring(lower.lastIndexOf("in ") + 3))) {
cuboidvalid = false;
else if (dEllipsoid.matches(it)) {
dEllipsoid ellipsoid = dEllipsoid.valueOf(it);
if (!ellipsoid.contains(location)) {
return false;
}
}
else {
dB.echoError("Invalid event 'IN ...' check [BlockPhysics]: '" + s + "' for " + scriptContainer.getName());
return false;
}
}

return blockvalid && cuboidvalid;
return true;
}

@Override
public String getName() {
return "ChunkLoads";
return "BlockPhysics";
}

@Override
Expand All @@ -102,14 +121,15 @@ public boolean applyDetermination(ScriptContainer container, String determinatio
public HashMap<String, dObject> getContext() {
HashMap<String, dObject> context = super.getContext();
context.put("location", location);
context.put("new_material", new_material); // Deprecated in favor of context.chunk.world
context.put("new_material", new_material);
return context;
}

@EventHandler
public void onBlockPhysics(BlockPhysicsEvent event) {
location = new dLocation(event.getBlock().getLocation());
new_material = dMaterial.getMaterialFrom(location.getBlock().getType(), location.getBlock().getData());
new_material = dMaterial.getMaterialFrom(event.getChangedType());
old_material = dMaterial.getMaterialFrom(location.getBlock().getType(), location.getBlock().getData());
cancelled = event.isCancelled();
this.event = event;
fire();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public String getAttribute(Attribute attribute) {
// @mechanism dItem.base_color
// @description
// Gets the base color of a banner.
// For the list of possible colors, see http://bit.ly/1dydq12
// For the list of possible colors, see <@link url http://bit.ly/1dydq12>.
// -->
if (attribute.startsWith("base_color")) {
Element baseColor = getBaseColor();
Expand Down Expand Up @@ -91,7 +91,7 @@ public void adjust(Mechanism mechanism) {
// @input Element
// @description
// Changes the base color of a banner.
// For the list of possible colors, see http://bit.ly/1dydq12
// For the list of possible colors, see <@link url http://bit.ly/1dydq12>.
// @tags
// <i@item.base_color>
// -->
Expand Down

0 comments on commit 5cffab6

Please sign in to comment.