Created
November 11, 2017 15:19
-
-
Save Cryptite/dcb32ef766f54d7225aea641ea70a1e0 to your computer and use it in GitHub Desktop.
StringChunk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.bukkit.Bukkit; | |
import org.bukkit.Chunk; | |
import java.util.Objects; | |
public class StringChunk { | |
public String world; | |
public int x, z; | |
public StringChunk(Chunk c) { | |
this.world = c.getWorld().getName(); | |
this.x = c.getX(); | |
this.z = c.getZ(); | |
} | |
public StringChunk(String args) { | |
String[] argsSplit = args.split(","); | |
this.world = argsSplit[0]; | |
this.x = Integer.parseInt(argsSplit[1]); | |
this.z = Integer.parseInt(argsSplit[2]); | |
} | |
public Chunk getChunk() { | |
return Bukkit.getWorld(world).getChunkAt(x, z); | |
} | |
public boolean isLoaded() { | |
return Bukkit.getWorld(world).isChunkLoaded(x, z); | |
} | |
@Override | |
public int hashCode() { | |
return Objects.hash(world, x, z); | |
} | |
@Override | |
public boolean equals(Object other) { | |
if (other instanceof Chunk) { | |
Chunk o = (Chunk) other; | |
return x == o.getX() && z == o.getZ() && world.equals(o.getWorld().getName()); | |
} else if (other instanceof StringChunk) { | |
StringChunk o = (StringChunk) other; | |
return x == o.x && z == o.z && world.equals(o.world); | |
} | |
return false; | |
} | |
@Override | |
public String toString() { | |
return world + "," + x + "," + z; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment