2014-10-13 15:14:34 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.Perm;
|
2015-02-12 12:00:55 +01:00
|
|
|
import com.massivecraft.massivecore.MassiveException;
|
2015-11-06 02:10:29 +01:00
|
|
|
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
|
|
|
|
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
|
2014-10-13 15:14:34 +02:00
|
|
|
import com.massivecraft.massivecore.ps.PS;
|
|
|
|
|
|
|
|
|
|
|
|
public class CmdFactionsSetCircle extends CmdFactionsSetXRadius
|
|
|
|
{
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2014-11-19 10:30:44 +01:00
|
|
|
public CmdFactionsSetCircle(boolean claim)
|
2014-10-13 15:14:34 +02:00
|
|
|
{
|
2014-11-19 10:30:44 +01:00
|
|
|
// Super
|
|
|
|
super(claim);
|
|
|
|
|
2014-10-13 15:14:34 +02:00
|
|
|
// Aliases
|
2015-10-21 21:18:00 +02:00
|
|
|
this.addAliases("circle");
|
2014-10-13 15:14:34 +02:00
|
|
|
|
2014-10-14 08:56:07 +02:00
|
|
|
// Format
|
2014-10-14 09:41:20 +02:00
|
|
|
this.setFormatOne("<h>%s<i> %s <h>%d <i>chunk %s<i> using circle.");
|
|
|
|
this.setFormatMany("<h>%s<i> %s <h>%d <i>chunks near %s<i> using circle.");
|
2014-10-14 08:56:07 +02:00
|
|
|
|
2014-10-13 15:14:34 +02:00
|
|
|
// Requirements
|
2015-11-06 02:10:29 +01:00
|
|
|
this.addRequirements(RequirementIsPlayer.get());
|
2014-11-19 10:30:44 +01:00
|
|
|
String node = claim ? Perm.CLAIM_CIRCLE.node : Perm.UNCLAIM_CIRCLE.node;
|
2015-11-06 02:10:29 +01:00
|
|
|
this.addRequirements(RequirementHasPerm.get(node));
|
2014-10-13 15:14:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
|
|
|
@Override
|
2015-02-12 12:00:55 +01:00
|
|
|
public Set<PS> getChunks() throws MassiveException
|
2014-10-13 15:14:34 +02:00
|
|
|
{
|
|
|
|
// Common Startup
|
2014-11-18 10:00:15 +01:00
|
|
|
final PS chunk = PS.valueOf(me.getLocation()).getChunk(true);
|
2014-10-13 15:14:34 +02:00
|
|
|
final Set<PS> chunks = new LinkedHashSet<PS>();
|
|
|
|
|
2014-10-14 08:19:00 +02:00
|
|
|
chunks.add(chunk); // The center should come first for pretty messages
|
|
|
|
|
2014-10-13 15:14:34 +02:00
|
|
|
Integer radiusZero = this.getRadiusZero();
|
|
|
|
if (radiusZero == null) return null;
|
|
|
|
|
2014-10-14 08:19:00 +02:00
|
|
|
double radiusSquared = radiusZero * radiusZero;
|
2014-10-13 15:14:34 +02:00
|
|
|
|
2014-10-14 08:19:00 +02:00
|
|
|
for (int dx = -radiusZero; dx <= radiusZero; dx++)
|
2014-10-13 15:14:34 +02:00
|
|
|
{
|
2014-10-14 08:19:00 +02:00
|
|
|
for (int dz = -radiusZero; dz <= radiusZero; dz++)
|
2014-10-13 15:14:34 +02:00
|
|
|
{
|
|
|
|
if (dx*dx + dz*dz > radiusSquared) continue;
|
2014-10-14 08:19:00 +02:00
|
|
|
|
|
|
|
int x = chunk.getChunkX() + dx;
|
|
|
|
int z = chunk.getChunkZ() + dz;
|
|
|
|
|
2014-10-13 15:14:34 +02:00
|
|
|
chunks.add(chunk.withChunkX(x).withChunkZ(z));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return chunks;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|