Factions/src/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java

68 lines
1.8 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
2015-02-12 12:00:55 +01:00
import com.massivecraft.massivecore.MassiveException;
2018-01-19 20:51:07 +01:00
import com.massivecraft.massivecore.collections.MassiveSet;
2015-11-06 02:10:29 +01:00
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.ps.PS;
2017-03-24 13:05:58 +01:00
import java.util.LinkedHashSet;
import java.util.Set;
public class CmdFactionsSetSquare extends CmdFactionsSetXRadius
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
2014-11-19 10:30:44 +01:00
public CmdFactionsSetSquare(boolean claim)
{
2014-11-19 10:30:44 +01:00
// Super
super(claim);
// Aliases
2015-10-21 21:18:00 +02:00
this.addAliases("square");
// Format
2014-10-14 09:41:20 +02:00
this.setFormatOne("<h>%s<i> %s <h>%d <i>chunk %s<i> using square.");
this.setFormatMany("<h>%s<i> %s <h>%d <i>chunks near %s<i> using square.");
// Requirements
2015-11-06 02:10:29 +01:00
this.addRequirements(RequirementIsPlayer.get());
Perm perm = claim ? Perm.CLAIM_SQUARE : Perm.UNCLAIM_SQUARE;
this.addRequirements(RequirementHasPerm.get(perm));
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
2015-02-12 12:00:55 +01:00
public Set<PS> getChunks() throws MassiveException
{
// Common Startup
final PS chunk = PS.valueOf(me.getLocation()).getChunk(true);
2018-01-19 20:51:07 +01:00
final Set<PS> chunks = new MassiveSet<>();
chunks.add(chunk); // The center should come first for pretty messages
Integer radiusZero = this.getRadiusZero();
for (int dx = -radiusZero; dx <= radiusZero; dx++)
{
for (int dz = -radiusZero; dz <= radiusZero; dz++)
{
int x = chunk.getChunkX() + dx;
int z = chunk.getChunkZ() + dz;
chunks.add(chunk.withChunkX(x).withChunkZ(z));
}
}
return chunks;
}
}