Factions3/src/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java

93 lines
2.4 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
2014-10-13 11:42:40 +02:00
import java.util.Collections;
import java.util.Set;
2014-10-13 11:42:40 +02:00
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.type.TypeFaction;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
2014-11-19 10:30:44 +01:00
import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.MPerm;
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-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.ps.PS;
public class CmdFactionsSetAuto extends FactionsCommand
{
2014-11-19 10:30:44 +01:00
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private boolean claim = true;
public boolean isClaim() { return this.claim; }
public void setClaim(boolean claim) { this.claim = claim; }
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
2014-11-19 10:30:44 +01:00
public CmdFactionsSetAuto(boolean claim)
{
2014-11-19 10:30:44 +01:00
// Fields
this.setClaim(claim);
2013-11-11 09:31:04 +01:00
// Aliases
2015-10-21 21:18:00 +02:00
this.addAliases("auto");
2013-11-11 09:31:04 +01:00
// Parameters
2014-11-19 10:30:44 +01:00
if (claim)
{
this.addParameter(TypeFaction.get(), "faction", "you");
2014-11-19 10:30:44 +01:00
}
2013-11-11 09:31:04 +01: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_AUTO.node : Perm.UNCLAIM_AUTO.node;
2015-11-06 02:10:29 +01:00
this.addRequirements(RequirementHasPerm.get(node));
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
2015-02-12 12:00:55 +01:00
public void perform() throws MassiveException
{
2013-04-25 13:25:15 +02:00
// Args
2014-11-19 10:30:44 +01:00
final Faction newFaction;
if (claim)
{
2015-05-06 17:04:35 +02:00
newFaction = this.readArg(msenderFaction);
2014-11-19 10:30:44 +01:00
}
else
{
newFaction = FactionColl.get().getNone();
}
2013-04-25 13:25:15 +02:00
// Disable?
if (newFaction == null || newFaction == msender.getAutoClaimFaction())
{
2014-09-18 13:41:20 +02:00
msender.setAutoClaimFaction(null);
msg("<i>Disabled auto-setting as you walk around.");
return;
}
// MPerm Preemptive Check
if (newFaction.isNormal() && ! MPerm.getPermTerritory().has(msender, newFaction, true)) return;
// Apply / Inform
msender.setAutoClaimFaction(newFaction);
msg("<i>Now auto-setting <h>%s<i> land.", newFaction.describeTo(msender));
// Chunks
final PS chunk = PS.valueOf(me.getLocation()).getChunk(true);
Set<PS> chunks = Collections.singleton(chunk);
2014-10-13 11:42:40 +02:00
// Apply / Inform
msender.tryClaim(newFaction, chunks);
}
}