Skip to content

Commit

Permalink
minor cleanup of chunktag
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 19, 2023
1 parent f684697 commit 4b87d8c
Showing 1 changed file with 11 additions and 34 deletions.
Expand Up @@ -73,55 +73,32 @@ public static ChunkTag valueOf(String string) {
return valueOf(string, null);
}

/**
* Gets a Chunk Object from a string form of x,z,world.
* This is not to be confused with the 'x,y,z,world' of a
* location, which is a finer grain of unit in a WorldTags.
*
* @param string the string or dScript argument String
* @return a ChunkTag, or null if incorrectly formatted
*/
@Fetchable("ch")
public static ChunkTag valueOf(String string, TagContext context) {
if (string == null) {
return null;
}

string = CoreUtilities.toLowerCase(string).replace("ch@", "");

////////
// Match location formats

// Get a location to fetch its chunk, return if null
String[] parts = string.split(",");
if (parts.length == 3) {
try {
return new ChunkTag(new WorldTag(parts[2]), Integer.parseInt(parts[0]), Integer.parseInt(parts[1]));
}
catch (Exception e) {
if (context == null || context.showErrors()) {
Debug.log("Minor: valueOf ChunkTag returning null: " + "ch@" + string);
}
return null;
if (parts.length != 3) {
if (context == null || context.showErrors()) {
Debug.log("Minor: valueOf ChunkTag unable to handle malformed format: " + "ch@" + string);
}

return null;
}
else {
try {
return new ChunkTag(new WorldTag(parts[2]), Integer.parseInt(parts[0]), Integer.parseInt(parts[1]));
}
catch (Exception e) {
if (context == null || context.showErrors()) {
Debug.log("Minor: valueOf ChunkTag unable to handle malformed format: " + "ch@" + string);
Debug.log("Minor: valueOf ChunkTag returning null: " + "ch@" + string);
}
return null;
}

return null;
}

public static boolean matches(String string) {
if (CoreUtilities.toLowerCase(string).startsWith("ch@")) {
return true;
}
else {
return false;
}
return valueOf(string, CoreUtilities.noDebugContext) != null;
}

int chunkX, chunkZ;
Expand Down

0 comments on commit 4b87d8c

Please sign in to comment.