package com.massivecraft.factions.cmd; import java.util.LinkedHashSet; import java.util.Set; import com.massivecraft.factions.Perm; import com.massivecraft.massivecore.cmd.req.ReqHasPerm; import com.massivecraft.massivecore.cmd.req.ReqIsPlayer; import com.massivecraft.massivecore.ps.PS; public class CmdFactionsSetCircle extends CmdFactionsSetXRadius { // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // public CmdFactionsSetCircle() { // Aliases this.addAliases("c", "circle"); // Format this.setFormatOne("%s %s %d chunk %s using circle."); this.setFormatMany("%s %s %d chunks near %s using circle."); // Requirements this.addRequirements(ReqIsPlayer.get()); this.addRequirements(ReqHasPerm.get(Perm.SET_CIRCLE.node)); } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @Override public Set getChunks() { // Common Startup final PS chunk = PS.valueOf(me).getChunk(true); final Set chunks = new LinkedHashSet(); chunks.add(chunk); // The center should come first for pretty messages Integer radiusZero = this.getRadiusZero(); if (radiusZero == null) return null; double radiusSquared = radiusZero * radiusZero; for (int dx = -radiusZero; dx <= radiusZero; dx++) { for (int dz = -radiusZero; dz <= radiusZero; dz++) { if (dx*dx + dz*dz > radiusSquared) continue; int x = chunk.getChunkX() + dx; int z = chunk.getChunkZ() + dz; chunks.add(chunk.withChunkX(x).withChunkZ(z)); } } return chunks; } }