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

103 lines
2.9 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction;
2019-04-15 13:55:20 +02:00
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPerm.MPermable;
2015-11-06 02:10:29 +01:00
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
import com.massivecraft.massivecore.util.Txt;
2017-03-24 13:05:58 +01:00
import java.util.Collection;
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
2015-11-06 02:10:29 +01:00
this.addRequirements(RequirementIsPlayer.get());
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
2019-04-15 13:55:20 +02:00
@Override
2019-04-15 13:55:20 +02:00
public void senderFields(boolean set)
{
2019-04-15 13:55:20 +02:00
super.senderFields(set);
if (set)
{
chunk = PS.valueOf(me.getLocation()).getChunk(true);
ta = BoardColl.get().getTerritoryAccessAt(chunk);
hostFaction = ta.getHostFaction();
}
else
{
chunk = null;
ta = null;
hostFaction = null;
}
}
public void sendAccessInfo()
{
Object title = "Access at " + chunk.toString(PSFormatHumanSpace.get());
title = Txt.titleize(title);
message(title);
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"));
msg("<k>Granted to: %s", CmdFactionsPermShow.permablesToDisplayString(ta.getGranteds(), msender));
}
2019-04-15 13:55:20 +02:00
public void setAccess(Collection<PS> chunks, MPermable mpermable, boolean granted)
{
2019-04-15 13:55:20 +02:00
chunks.forEach(chunk -> setAccess(chunk, mpermable, granted));
}
public void setAccess(PS chunk, MPermable mpermable, boolean granted)
{
TerritoryAccess ta = BoardColl.get().getTerritoryAccessAt(chunk);
Faction faction = ta.getHostFaction();
String chunkDesc = chunk.toString(PSFormatHumanSpace.get());
String grantedDenied = granted ? "granted" : "denied";
String mpermableDesc = mpermable.getDisplayName(msender);
if ( ! MPerm.getPermAccess().has(msender, faction, false))
{
2019-04-15 13:55:20 +02:00
msg("<b>You do not have permission to edit access at %s<b>.", chunkDesc);
return;
}
2019-04-15 13:55:20 +02:00
if (ta.isGranted(mpermable) == granted)
{
msg("<b>Access at %s <b>is already %s to %s<b>.", chunkDesc, grantedDenied, mpermableDesc);
return;
}
ta = ta.withGranted(mpermable, granted);
BoardColl.get().setTerritoryAccessAt(chunk, ta);
msg("<i>Access at %s<i> is now %s to %s<i>.", chunkDesc, grantedDenied, mpermableDesc);
}
2019-04-15 13:55:20 +02:00
}