2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-06-10 21:26:12 +02:00
|
|
|
|
2014-10-13 11:42:40 +02:00
|
|
|
import java.util.Collections;
|
2014-10-13 15:14:34 +02:00
|
|
|
import java.util.Set;
|
2014-10-13 11:42:40 +02:00
|
|
|
|
2013-04-09 12:56:29 +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;
|
2014-11-19 10:30:44 +01:00
|
|
|
import com.massivecraft.factions.entity.FactionColl;
|
2014-10-02 14:02:07 +02:00
|
|
|
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;
|
2011-10-09 14:53:38 +02:00
|
|
|
|
2014-10-13 15:14:34 +02:00
|
|
|
|
|
|
|
public class CmdFactionsSetAuto extends FactionsCommand
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
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)
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2014-11-19 10:30:44 +01:00
|
|
|
// Fields
|
|
|
|
this.setClaim(claim);
|
|
|
|
|
2013-11-11 09:31:04 +01:00
|
|
|
// Aliases
|
2014-10-13 15:14:34 +02:00
|
|
|
this.addAliases("a", "auto");
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// Args
|
2014-11-19 10:30:44 +01:00
|
|
|
if (claim)
|
|
|
|
{
|
|
|
|
this.addOptionalArg("faction", "you");
|
|
|
|
}
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// Requirements
|
2013-04-16 09:48:57 +02:00
|
|
|
this.addRequirements(ReqIsPlayer.get());
|
2014-11-19 10:30:44 +01:00
|
|
|
String node = claim ? Perm.CLAIM_AUTO.node : Perm.UNCLAIM_AUTO.node;
|
|
|
|
this.addRequirements(ReqHasPerm.get(node));
|
2011-06-10 21:26:12 +02:00
|
|
|
}
|
|
|
|
|
2013-11-11 09:31:04 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2011-06-10 21:26:12 +02:00
|
|
|
@Override
|
2011-10-09 14:53:38 +02:00
|
|
|
public void perform()
|
2014-09-17 13:17:33 +02:00
|
|
|
{
|
2013-04-25 13:25:15 +02:00
|
|
|
// Args
|
2014-11-19 10:30:44 +01:00
|
|
|
final Faction newFaction;
|
|
|
|
if (claim)
|
|
|
|
{
|
|
|
|
newFaction = this.arg(0, ARFaction.get(), msenderFaction);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newFaction = FactionColl.get().getNone();
|
|
|
|
}
|
2013-04-25 13:25:15 +02:00
|
|
|
|
2014-10-13 15:14:34 +02:00
|
|
|
// Disable?
|
|
|
|
if (newFaction == null || newFaction == msender.getAutoClaimFaction())
|
2011-10-09 14:53:38 +02:00
|
|
|
{
|
2014-09-18 13:41:20 +02:00
|
|
|
msender.setAutoClaimFaction(null);
|
2014-10-13 15:14:34 +02:00
|
|
|
msg("<i>Disabled auto-setting as you walk around.");
|
2011-06-10 21:26:12 +02:00
|
|
|
return;
|
|
|
|
}
|
2011-10-25 21:18:08 +02:00
|
|
|
|
2014-10-13 15:14:34 +02:00
|
|
|
// MPerm Preemptive Check
|
|
|
|
if (newFaction.isNormal() && ! MPerm.getPermTerritory().has(msender, newFaction, true)) return;
|
2011-10-22 17:03:49 +02:00
|
|
|
|
2014-10-13 15:14:34 +02:00
|
|
|
// Apply / Inform
|
|
|
|
msender.setAutoClaimFaction(newFaction);
|
|
|
|
msg("<i>Now auto-setting <h>%s<i> land.", newFaction.describeTo(msender));
|
2011-10-22 17:03:49 +02:00
|
|
|
|
2014-10-13 15:14:34 +02:00
|
|
|
// Chunks
|
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
|
|
|
Set<PS> chunks = Collections.singleton(chunk);
|
2014-10-13 11:42:40 +02:00
|
|
|
|
2014-10-13 15:14:34 +02:00
|
|
|
// Apply / Inform
|
|
|
|
msender.tryClaim(newFaction, chunks);
|
2011-06-10 21:26:12 +02:00
|
|
|
}
|
|
|
|
|
2014-10-13 15:14:34 +02:00
|
|
|
}
|