Skip to content

Commit

Permalink
Fix events, fix 'in notable cuboid' for breaks block [experimental]
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 20, 2015
1 parent 0278c4b commit 47fdad6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 22 deletions.
58 changes: 58 additions & 0 deletions src/main/java/net/aufdemrand/denizen/events/BukkitScriptEvent.java
@@ -0,0 +1,58 @@
package net.aufdemrand.denizen.events;

import net.aufdemrand.denizen.objects.dCuboid;
import net.aufdemrand.denizen.objects.dEllipsoid;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.events.ScriptEvent;
import net.aufdemrand.denizencore.scripts.containers.ScriptContainer;
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.Location;

import java.util.List;

public abstract class BukkitScriptEvent extends ScriptEvent {

public boolean runInCheck(ScriptContainer scriptContainer, String s, String lower, Location location) {

List<String> data = CoreUtilities.split(lower, ' ');

int index;

for (index = 0; index < data.size(); index++) {
if (data.get(index).equals("in")) {
break;
}
}
if (index >= data.size()) {
// No 'in ...' specified
return true;
}

String it = CoreUtilities.getXthArg(index + 1, s);
if (it.equalsIgnoreCase("notable")) {
String subit = CoreUtilities.getXthArg(index + 2, lower);
if (subit.equalsIgnoreCase("cuboid")) {
return dCuboid.getNotableCuboidsContaining(location).size() > 0;
}
else if (subit.equalsIgnoreCase("ellipsoid")) {
return dEllipsoid.getNotableEllipsoidsContaining(location).size() > 0;
}
else {
dB.echoError("Invalid event 'IN ...' check [" + getName() + "] ('in notable ???'): '" + s + "' for " + scriptContainer.getName());
return false;
}
}
else if (dCuboid.matches(it)) {
dCuboid cuboid = dCuboid.valueOf(it);
return cuboid.isInsideCuboid(location);
}
else if (dEllipsoid.matches(it)) {
dEllipsoid ellipsoid = dEllipsoid.valueOf(it);
return ellipsoid.contains(location);
}
else {
dB.echoError("Invalid event 'IN ...' check [" + getName() + "] ('in ???'): '" + s + "' for " + scriptContainer.getName());
return false;
}
}
}
@@ -1,10 +1,9 @@
package net.aufdemrand.denizen.events.player;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.events.BukkitScriptEvent;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizencore.events.ScriptEvent;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.aH;
import net.aufdemrand.denizencore.objects.dList;
Expand All @@ -22,7 +21,7 @@

import java.util.HashMap;

public class PlayerBreaksBlockScriptEvent extends ScriptEvent implements Listener {
public class PlayerBreaksBlockScriptEvent extends BukkitScriptEvent implements Listener {

// <--[event]
// @Events
Expand Down Expand Up @@ -73,24 +72,9 @@ public boolean matches(ScriptContainer scriptContainer, String s) {
if (!mat.equals("block") && !mat.equals(material.identifyNoIdentifier())) {
return false;
}
if (CoreUtilities.xthArgEquals(3, lower, "in") || CoreUtilities.xthArgEquals(5, lower, "in")) {
String it = CoreUtilities.getXthArg(4, lower);
if (dCuboid.matches(it)) {
dCuboid cuboid = dCuboid.valueOf(it);
if (!cuboid.isInsideCuboid(location)) {
return false;
}
}
else if (dEllipsoid.matches(it)) {
dEllipsoid ellipsoid = dEllipsoid.valueOf(it);
if (!ellipsoid.contains(location)) {
return false;
}
}
else {
dB.echoError("Invalid event 'IN ...' check [" + getName() + "]: '" + s + "' for " + scriptContainer.getName());
return false;
}

if (!runInCheck(scriptContainer, s, lower, location)) {
return false;
}

if (CoreUtilities.xthArgEquals(3, lower, "with")) {
Expand Down
Expand Up @@ -54,7 +54,7 @@ public PlayerDamagesBlockScriptEvent() {
@Override
public boolean couldMatch(ScriptContainer scriptContainer, String s) {
String lower = CoreUtilities.toLowerCase(s);
String mat = CoreUtilities.getXthArg(3, lower);
String mat = CoreUtilities.getXthArg(2, lower);
return lower.startsWith("player damages")
&& (mat.equals("block") || dMaterial.matches(mat));
}
Expand Down

0 comments on commit 47fdad6

Please sign in to comment.