Factions/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java

68 lines
1.7 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;
2013-04-16 11:27:03 +02:00
import com.massivecraft.factions.cmd.arg.ARFaction;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPerm;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
import com.massivecraft.massivecore.ps.PS;
public class CmdFactionsSetAuto extends FactionsCommand
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsSetAuto()
{
2013-11-11 09:31:04 +01:00
// Aliases
this.addAliases("a", "auto");
2013-11-11 09:31:04 +01:00
// Args
this.addOptionalArg("faction", "you");
2013-11-11 09:31:04 +01:00
// Requirements
this.addRequirements(ReqIsPlayer.get());
this.addRequirements(ReqHasPerm.get(Perm.SET_AUTO.node));
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
{
2013-04-25 13:25:15 +02:00
// Args
final Faction newFaction = this.arg(0, ARFaction.get(), msenderFaction);
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).getChunk(true);
Set<PS> chunks = Collections.singleton(chunk);
2014-10-13 11:42:40 +02:00
// Apply / Inform
msender.tryClaim(newFaction, chunks);
}
}