Skip to content

Commit

Permalink
cleanups to world/location handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 23, 2020
1 parent c78ebfa commit f385578
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 28 deletions.
Expand Up @@ -77,11 +77,14 @@ public class LocationTag extends org.bukkit.Location implements ObjectTag, Notab
public String backupWorld;

public String getWorldName() {
if (backupWorld != null) {
return backupWorld;
}
World w = super.getWorld();
if (w != null) {
return w.getName();
}
return backupWorld;
return null;
}

@Override
Expand Down Expand Up @@ -339,19 +342,15 @@ public ObjectTag duplicate() {
* @param location the Bukkit Location to reference
*/
public LocationTag(Location location) {
// Just save the yaw and pitch as they are; don't check if they are
// higher than 0, because Minecraft yaws are weird and can have
// negative values
super(location.getWorld(), location.getX(), location.getY(), location.getZ(),
location.getYaw(), location.getPitch());
this(location.getWorld(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
}

public LocationTag(Vector vector) {
super(null, vector.getX(), vector.getY(), vector.getZ());
this((World) null, vector.getX(), vector.getY(), vector.getZ(), 0, 0);
}

public LocationTag(World world, Vector vector) {
super(world, vector.getX(), vector.getY(), vector.getZ());
this(world, vector.getX(), vector.getY(), vector.getZ(), 0, 0);
}

public LocationTag(World world, double x, double y) {
Expand All @@ -369,7 +368,7 @@ public LocationTag(World world, double x, double y) {
* @param z z-coordinate of the location
*/
public LocationTag(World world, double x, double y, double z) {
super(world, x, y, z);
this(world, x, y, z, 0, 0);
}

public LocationTag(double x, double y, double z, String worldName) {
Expand All @@ -379,6 +378,9 @@ public LocationTag(double x, double y, double z, String worldName) {

public LocationTag(World world, double x, double y, double z, float pitch, float yaw) {
super(world, x, y, z, yaw, pitch);
if (world != null) {
backupWorld = world.getName();
}
}

public LocationTag(String worldName, double x, double y, double z, float pitch, float yaw) {
Expand Down
Expand Up @@ -22,28 +22,19 @@

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

public class WorldTag implements ObjectTag, Adjustable {

/////////////////////
// STATIC METHODS
/////////////////

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

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

/////////////////////
Expand Down Expand Up @@ -92,12 +83,7 @@ public static WorldTag valueOf(String string, boolean announce) {
}

if (returnable != null) {
if (worlds.containsKey(returnable.getName())) {
return worlds.get(returnable.getName());
}
else {
return new WorldTag(returnable);
}
return new WorldTag(returnable);
}
else if (announce) {
Debug.echoError("Invalid World! '" + string
Expand Down Expand Up @@ -169,9 +155,6 @@ public WorldTag(String prefix, World world) {
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 f385578

Please sign in to comment.