Skip to content

Commit

Permalink
Add dWorld.mirrorBukkitWorld to avoid unneccesary reconstruction of d…
Browse files Browse the repository at this point in the history
…Worlds. Add dLocation tags for block.x, block.y, block.z, x, y, z, and world.
  • Loading branch information
aufdemrand committed Jul 2, 2013
1 parent 7b48e7d commit b375d7c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
40 changes: 27 additions & 13 deletions src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,35 @@ else return new Element(String.valueOf(this.distance(toLocation)))
.getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("world")) {
return dWorld.mirrorBukkitWorld(getWorld())
.getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("block.x")) {
return new Element(getBlockX()).getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("block.y")) {
return new Element(getBlockY()).getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("block.z")) {
return new Element(getBlockZ()).getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("x")) {
return new Element(getX()).getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("y")) {
return new Element(getY()).getAttribute(attribute.fulfill(1));
}

if (attribute.startsWith("z")) {
return new Element(getZ()).getAttribute(attribute.fulfill(1));
}

//
// else if (type.equals("TIME"))
// {
// if (subType.equals("PERIOD"))
Expand All @@ -406,18 +432,6 @@ else return new Element(String.valueOf(this.distance(toLocation)))
// else if (fromLocation.getWorld().getTime() > 13500)
// event.setReplaced("night");
// }
//
// else if (type.equals("WORLD"))
// event.setReplaced(fromLocation.getWorld().getName());
//
// else if (type.equals("X"))
// event.setReplaced(String.valueOf(fromLocation.getX()));
//
// else if (type.equals("Y"))
// event.setReplaced(String.valueOf(fromLocation.getY()));
//
// else if (type.equals("Z"))
// event.setReplaced(String.valueOf(fromLocation.getZ()));

return new Element(identify()).getAttribute(attribute.fulfill(0));
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class dWorld implements dObject {

static Map<String, dWorld> worlds = new HashMap<String, dWorld>();

public static dWorld mirrorBukkitWorld(World world) {
if (worlds.containsKey(world.getName())) return worlds.get(world.getName());
else return new dWorld(world);
}

@ObjectFetcher("w")
public static dPlayer valueOf(String string) {
if (string == null) return null;
Expand Down Expand Up @@ -66,6 +75,8 @@ public dWorld(String prefix, World world) {
if (prefix == null) this.prefix = "World";
else this.prefix = prefix;
this.world_name = world.getName();
if (!worlds.containsKey(world.getName()))
worlds.put(world.getName(), this);
}

@Override
Expand Down

0 comments on commit b375d7c

Please sign in to comment.