Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Override
- public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
- Player p = (Player) sender;
- List<Chunk> chunks = getChunks(p.getLocation().getChunk(), 10);
- Chunk slimeChunk = getNearestChunk(p.getLocation().getChunk(), chunks);
- p.sendMessage(String.valueOf(slimeChunk.getX()*16) + " " + String.valueOf(slimeChunk.getZ()*16));
- return true;
- }
- public ArrayList<Chunk> getChunks(Chunk centerChunk, int radius) {
- ArrayList<Chunk> chunks = new ArrayList<>();
- chunks.add(centerChunk);
- for (int x = centerChunk.getX() - radius; x < centerChunk.getX() + radius; x++) {
- for (int z = centerChunk.getZ() - radius; z < centerChunk.getZ() + radius; z++) {
- Chunk chunk = centerChunk.getWorld().getChunkAt(x, z);
- if (chunk.isSlimeChunk()) {
- chunks.add(chunk);
- }
- }
- }
- return chunks;
- }
- public Chunk getNearestChunk(Chunk origin, List<Chunk> chunks) {
- Chunk nearestChunk = null;
- for (Chunk chunk : chunks) {
- if (nearestChunk == null) {
- nearestChunk = chunk;
- continue;
- }
- if (distance(origin, chunk) > distance(origin, nearestChunk))
- continue;
- nearestChunk = chunk;
- }
- return nearestChunk;
- }
- public double distance(Chunk firstChunk, Chunk secondChunk) {
- double ac = Math.abs(secondChunk.getZ() - firstChunk.getZ());
- double cb = Math.abs(secondChunk.getX() - firstChunk.getX());
- return Math.hypot(ac, cb);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement