Skip to content

Commit

Permalink
in:<area> advanced matching support
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 28, 2020
1 parent 9b87d3c commit 56b358d
Showing 1 changed file with 30 additions and 11 deletions.
Expand Up @@ -13,6 +13,7 @@
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.*;
import org.bukkit.event.*;
import org.bukkit.plugin.EventExecutor;
Expand All @@ -33,7 +34,6 @@ public boolean couldMatchInArea(String lower) {
if (index == -1) {
return true;
}

String in = CoreUtilities.getXthArg(index + 1, lower);
if (InventoryTag.matches(in) || CoreUtilities.equalsIgnoreCase(in, "inventory") || isAdvancedMatchable(in)) {
return false;
Expand Down Expand Up @@ -358,8 +358,8 @@ public boolean runInCheck(ScriptPath path, Location location) {
}

public boolean runInCheck(ScriptPath path, Location location, String innote) {
String it = path.switches.get(innote);
if (it == null) {
String inputText = path.switches.get(innote);
if (inputText == null) {
int index;
for (index = 0; index < path.eventArgsLower.length; index++) {
if (path.eventArgsLower[index].equals(innote)) {
Expand All @@ -374,8 +374,8 @@ public boolean runInCheck(ScriptPath path, Location location, String innote) {
return false;
}
Deprecations.inAreaSwitchFormat.warn();
it = path.eventArgLowerAt(index + 1);
if (it.equals("notable")) {
inputText = path.eventArgLowerAt(index + 1);
if (inputText.equals("notable")) {
String subit = path.eventArgLowerAt(index + 2);
if (subit.equals("cuboid")) {
return CuboidTag.getNotableCuboidsContaining(location).size() > 0;
Expand All @@ -392,32 +392,51 @@ else if (subit.equals("ellipsoid")) {
if (location == null) {
return false;
}
String lower = CoreUtilities.toLowerCase(it);
String lower = CoreUtilities.toLowerCase(inputText);
if (lower.equals("cuboid")) {
return CuboidTag.getNotableCuboidsContaining(location).size() > 0;
}
else if (lower.equals("ellipsoid")) {
return EllipsoidTag.getNotableEllipsoidsContaining(location).size() > 0;
}
else if (WorldTag.matches(it)) {
else if (WorldTag.matches(inputText)) {
return CoreUtilities.equalsIgnoreCase(location.getWorld().getName(), lower);
}
else if (CuboidTag.matches(it)) {
CuboidTag cuboid = CuboidTag.valueOf(it, getTagContext(path));
else if (CuboidTag.matches(inputText)) {
CuboidTag cuboid = CuboidTag.valueOf(inputText, getTagContext(path));
if (cuboid == null || !cuboid.isUnique()) {
Debug.echoError("Invalid event 'in:<area>' switch [" + getName() + "] (invalid cuboid): '" + path.event + "' for " + path.container.getName());
return false;
}
return cuboid.isInsideCuboid(location);
}
else if (EllipsoidTag.matches(it)) {
EllipsoidTag ellipsoid = EllipsoidTag.valueOf(it, getTagContext(path));
else if (EllipsoidTag.matches(inputText)) {
EllipsoidTag ellipsoid = EllipsoidTag.valueOf(inputText, getTagContext(path));
if (ellipsoid == null || !ellipsoid.isUnique()) {
Debug.echoError("Invalid event 'in:<area>' switch [" + getName() + "] (invalid ellipsoid): '" + path.event + "' for " + path.container.getName());
return false;
}
return ellipsoid.contains(location);
}
else if (isAdvancedMatchable(lower)) {
MatchHelper matcher = createMatcher(lower);
for (CuboidTag cuboid : NotableManager.getAllType(CuboidTag.class)) {
if (cuboid.isInsideCuboid(location) && matcher.doesMatch(cuboid.noteName)) {
return true;
}
}
for (EllipsoidTag ellipsoid : NotableManager.getAllType(EllipsoidTag.class)) {
if (ellipsoid.contains(location) && matcher.doesMatch(ellipsoid.noteName)) {
return true;
}
}
for (World world : Bukkit.getWorlds()) {
if (matcher.doesMatch(CoreUtilities.toLowerCase(world.getName()))) {
return true;
}
}
return false;
}
else {
Debug.echoError("Invalid event 'in:<area>' switch [" + getName() + "] ('in:???') (did you make a typo, or forget to make a notable by that name?): '" + path.event + "' for " + path.container.getName());
return false;
Expand Down

0 comments on commit 56b358d

Please sign in to comment.