Skip to content

Commit

Permalink
Merge pull request #87 from jb-aero/pullable
Browse files Browse the repository at this point in the history
let all_entities take a location array
  • Loading branch information
LadyCailin committed Feb 18, 2013
2 parents 239de34 + ffda8d4 commit f6ae626
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/laytonsmith/abstraction/MCWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public interface MCWorld extends AbstractionObject{
public String getName();
public MCBlock getBlockAt(int x, int y, int z);
public MCChunk getChunkAt(int x, int z);
public MCChunk getChunkAt(MCBlock b);
public MCChunk getChunkAt(MCLocation l);

public boolean regenerateChunk(int x, int y);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,14 @@ public boolean regenerateChunk(int x, int z) {
public MCChunk getChunkAt(int x, int z) {
return new BukkitMCChunk(w.getChunkAt(x, z));
}

public MCChunk getChunkAt(MCBlock b) {
return new BukkitMCChunk(w.getChunkAt(((BukkitMCBlock) b).__Block()));
}

public MCChunk getChunkAt(MCLocation l) {
return new BukkitMCChunk(w.getChunkAt(((BukkitMCLocation) l).asLocation()));
}

public void setThundering(boolean b) {
w.setThundering(b);
Expand Down
50 changes: 36 additions & 14 deletions src/main/java/com/laytonsmith/core/functions/EntityManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static String docs(){
public static class all_entities extends AbstractFunction {

public ExceptionType[] thrown() {
return new ExceptionType[]{ExceptionType.InvalidWorldException};
return new ExceptionType[]{ExceptionType.InvalidWorldException, ExceptionType.FormatException};
}

public boolean isRestricted() {
Expand All @@ -48,16 +48,34 @@ public Construct exec(Target t, Environment environment,
}
}
} else {
MCWorld w = Static.getServer().getWorld(args[0].val());
MCWorld w;
MCChunk c;
if (args.length == 3) {
int x = Static.getInt32(args[1], t);
int z = Static.getInt32(args[2], t);
for (MCEntity e : w.getChunkAt(x, z).getEntities()) {
w = Static.getServer().getWorld(args[0].val());
try {
int x = Static.getInt32(args[1], t);
int z = Static.getInt32(args[2], t);
c = w.getChunkAt(x, z);
} catch (ConfigRuntimeException cre) {
CArray l = CArray.GetAssociativeArray(t);
l.set("x", args[1], t);
l.set("z", args[2], t);
c = w.getChunkAt(ObjectGenerator.GetGenerator().location(l, w, t));
}
for (MCEntity e : c.getEntities()) {
ret.push(new CInt(e.getEntityId(), t));
}
} else {
for (MCEntity e : w.getEntities()) {
ret.push(new CInt(e.getEntityId(), t));
if (args[0] instanceof CArray) {
c = ObjectGenerator.GetGenerator().location(args[0], null, t).getChunk();
for (MCEntity e : c.getEntities()) {
ret.push(new CInt(e.getEntityId(), t));
}
} else {
w = Static.getServer().getWorld(args[0].val());
for (MCEntity e : w.getEntities()) {
ret.push(new CInt(e.getEntityId(), t));
}
}
}
}
Expand All @@ -73,10 +91,12 @@ public Integer[] numArgs() {
}

public String docs() {
return "array {[world, [x, z]]} Returns an array of IDs for all entities in the given scope. With no args,"
+ " this will return all entities loaded on the entire server. If the first argument is given, only"
+ " entities in that world will be returned, and if all 3 arguments are given, only entities in the"
+ " chunk with those coords will be returned.";
return "array {[world, [x, z]] | [locationArray]} Returns an array of IDs for all entities in the given"
+ " scope. With no args, this will return all entities loaded on the entire server. If the first"
+ " argument is given and is a location, only entities in the chunk containin that location will"
+ " be returned, or if it is a world only entities in that world will be returned. If all 3"
+ "arguments are given, only entities in the chunk with those coords will be returned. This can"
+ " take chunk coords (ints) or location coords (doubles).";
}

public CHVersion since() {
Expand All @@ -86,10 +106,12 @@ public CHVersion since() {
@Override
public ExampleScript[] examples() throws ConfigCompileException {
return new ExampleScript[]{
new ExampleScript("Basic use", "msg(all_entities(pworld()))",
new ExampleScript("Getting all entities in a world", "msg(all_entities(pworld()))",
"Sends you an array of all entities in your world."),
new ExampleScript("Basic use", "msg(all_entities(pworld(), ploc()[0], ploc()[2]))",
"Sends you an array of all entities in the same chunk as you.")
new ExampleScript("Getting entities in a chunk", "msg(all_entities(pworld(), 5, -3))",
"Sends you an array of all entities in chunk (5,-3)."),
new ExampleScript("Getting entities in your chunk", "msg(all_entities(ploc()))",
"Sends you an array of all entities in the chunk you are in.")
};
}

Expand Down

0 comments on commit f6ae626

Please sign in to comment.