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

74 lines
2.4 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
import com.massivecraft.massivecore.util.Txt;
2014-09-18 13:41:20 +02:00
public abstract class CmdFactionsAccessAbstract extends FactionsCommand
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
public PS chunk;
public TerritoryAccess ta;
public Faction hostFaction;
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsAccessAbstract()
{
2013-11-11 09:31:04 +01:00
// Requirements
this.addRequirements(ReqIsPlayer.get());
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform()
{
chunk = PS.valueOf(me.getLocation()).getChunk(true);
ta = BoardColl.get().getTerritoryAccessAt(chunk);
2014-09-17 13:29:58 +02:00
hostFaction = ta.getHostFaction();
this.innerPerform();
}
public abstract void innerPerform();
public void sendAccessInfo()
{
sendMessage(Txt.titleize("Access at " + chunk.toString(PSFormatHumanSpace.get())));
2014-09-18 13:41:20 +02:00
msg("<k>Host Faction: %s", hostFaction.describeTo(msender, true));
msg("<k>Host Faction Allowed: %s", ta.isHostFactionAllowed() ? Txt.parse("<lime>TRUE") : Txt.parse("<rose>FALSE"));
2014-09-18 13:41:20 +02:00
msg("<k>Granted Players: %s", describeRelationParticipators(ta.getGrantedMPlayers(), msender));
msg("<k>Granted Factions: %s", describeRelationParticipators(ta.getGrantedFactions(), msender));
}
public static String describeRelationParticipators(Collection<? extends RelationParticipator> relationParticipators, RelationParticipator observer)
{
if (relationParticipators.size() == 0) return Txt.parse("<silver><em>none");
List<String> descriptions = new ArrayList<String>();
for (RelationParticipator relationParticipator : relationParticipators)
{
descriptions.add(relationParticipator.describeTo(observer));
}
return Txt.implodeCommaAnd(descriptions, Txt.parse("<i>, "), Txt.parse(" <i>and "));
}
2013-11-11 09:31:04 +01:00
}