Skip to content

Commit

Permalink
Merge pull request #909 from mcmonkey4eva/master
Browse files Browse the repository at this point in the history
Pull request for some minor things
  • Loading branch information
mcmonkey4eva committed Dec 29, 2014
2 parents 5993b02 + c7bbe74 commit 7ddce28
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
1 change: 0 additions & 1 deletion src/main/java/net/aufdemrand/denizen/npc/dNPCRegistry.java
Expand Up @@ -225,7 +225,6 @@ public void onRemove(NPCRemoveEvent event) {
denizenNPCs.remove(npc.getId());
npcInventories.remove(npc.getId());
}
dB.log(ChatColor.RED + "Deconstructing Denizen NPC " + npc.getName() + "/" + npc.getId());
FlagManager.clearNPCFlags(npc.getId());
}

Expand Down
12 changes: 5 additions & 7 deletions src/main/java/net/aufdemrand/denizen/objects/dCuboid.java
Expand Up @@ -54,7 +54,7 @@ public static List<dCuboid> getNotableCuboidsContaining(Location location) {
// OBJECT FETCHER
////////////////

final static Pattern item_by_saved = Pattern.compile("(cu@)(.+)");
final static Pattern cuboid_by_saved = Pattern.compile("(cu@)?(.+)");
/**
* Gets a Location Object from a string form of id,x,y,z,world
* or a dScript argument (location:)x,y,z,world. If including an Id,
Expand Down Expand Up @@ -108,7 +108,7 @@ public static dCuboid valueOf(String string) {
// Match @object format for Notable dCuboids
Matcher m;

m = item_by_saved.matcher(string);
m = cuboid_by_saved.matcher(string);

if (m.matches() && NotableManager.isType(m.group(2), dCuboid.class))
return (dCuboid) NotableManager.getSavedObject(m.group(2));
Expand All @@ -118,10 +118,8 @@ public static dCuboid valueOf(String string) {
return null;
}

// regex patterns used for matching
final static Pattern location_by_saved = Pattern.compile("(cu@)?(.+)");
// The regex below: optional-"|" + "<#.#>," x3 + <text> + "|" + "<#.#>," x3 + <text> -- repeating
final static Pattern location =
final static Pattern cuboidLocations =
Pattern.compile("(\\|?([\\d\\.]+,){3}[\\w\\s]+\\|([\\d\\.]+,){3}[\\w\\s]+)+",
Pattern.CASE_INSENSITIVE);

Expand All @@ -133,11 +131,11 @@ public static boolean matches(String string) {
Matcher m;

// Check for named cuboid: cu@notable_cuboid
m = location_by_saved.matcher(string);
m = cuboid_by_saved.matcher(string);
if (m.matches() && NotableManager.isType(m.group(2), dCuboid.class)) return true;

// Check for standard cuboid format: cu@x,y,z,world|x,y,z,world|...
m = location.matcher(string.replace("cu@", ""));
m = cuboidLocations.matcher(string.replace("cu@", ""));
return m.matches();
}

Expand Down
19 changes: 18 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dEllipsoid.java
Expand Up @@ -9,6 +9,7 @@
import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.Location;

import java.util.ArrayList;
import java.util.List;


Expand Down Expand Up @@ -83,12 +84,28 @@ public dList getBlocks(List<dMaterial> materials) {
.getBlocks_internal(materials);
dList list = new dList();
for (dLocation loc: initial) {
if (contains(loc))
if (contains(loc)) {
list.add(loc.identify());
}
}
return list;
}

public List<dLocation> getBlockLocations() {
List<dLocation> initial = new dCuboid(new Location(loc.getWorld(),
loc.getX() - size.getX(), loc.getY() - size.getY(), loc.getZ() - size.getZ()),
new Location(loc.getWorld(),
loc.getX() + size.getX(), loc.getY() + size.getY(), loc.getZ() + size.getZ()))
.getBlocks_internal(null);
List<dLocation> locations = new ArrayList<dLocation>();
for (dLocation loc: initial) {
if (contains(loc)) {
locations.add(loc);
}
}
return locations;
}

public boolean contains(dLocation test) {
double xbase = test.getX() - loc.getX();
double ybase = test.getY() - loc.getY();
Expand Down
Expand Up @@ -43,10 +43,18 @@ public void parseArgs(ScriptEntry scriptEntry)throws InvalidArgumentsException {
// Parse arguments
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (arg.matchesArgumentList(dLocation.class)){
if (arg.matchesArgumentList(dLocation.class)) {
scriptEntry.addObject("locations", arg.asType(dList.class).filter(dLocation.class));
}

else if (arg.matchesArgumentType(dCuboid.class)) {
scriptEntry.addObject("locations", arg.asType(dCuboid.class).getBlockLocations());
}

else if (arg.matchesArgumentType(dEllipsoid.class)) {
scriptEntry.addObject("locations", arg.asType(dEllipsoid.class).getBlockLocations());
}

else if (!scriptEntry.hasObject("materials")
&& arg.matchesArgumentList(dMaterial.class)) {
scriptEntry.addObject("materials", arg.asType(dList.class));
Expand Down

0 comments on commit 7ddce28

Please sign in to comment.