2013-04-29 10:23:39 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.TerritoryAccess;
|
2014-09-17 13:17:33 +02:00
|
|
|
import com.massivecraft.factions.entity.BoardColl;
|
2013-04-29 10:23:39 +02:00
|
|
|
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;
|
2019-10-12 13:25:33 +02:00
|
|
|
import com.massivecraft.factions.util.AsciiMap;
|
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;
|
2013-04-29 10:23:39 +02:00
|
|
|
|
2017-03-24 13:05:58 +01:00
|
|
|
import java.util.Collection;
|
|
|
|
|
2013-04-29 10:23:39 +02:00
|
|
|
|
2014-09-18 13:41:20 +02:00
|
|
|
public abstract class CmdFactionsAccessAbstract extends FactionsCommand
|
2013-04-29 10:23:39 +02:00
|
|
|
{
|
2013-11-11 09:31:04 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// FIELDS
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-04-29 10:23:39 +02:00
|
|
|
public PS chunk;
|
|
|
|
public TerritoryAccess ta;
|
|
|
|
public Faction hostFaction;
|
|
|
|
|
2013-11-11 09:31:04 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-04-29 10:23:39 +02:00
|
|
|
public CmdFactionsAccessAbstract()
|
|
|
|
{
|
2013-11-11 09:31:04 +01:00
|
|
|
// Requirements
|
2015-11-06 02:10:29 +01:00
|
|
|
this.addRequirements(RequirementIsPlayer.get());
|
2013-04-29 10:23:39 +02:00
|
|
|
}
|
|
|
|
|
2013-11-11 09:31:04 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE
|
|
|
|
// -------------------------------------------- //
|
2019-04-15 13:55:20 +02:00
|
|
|
|
2013-04-29 10:23:39 +02:00
|
|
|
@Override
|
2019-04-15 13:55:20 +02:00
|
|
|
public void senderFields(boolean set)
|
2013-04-29 10:23:39 +02:00
|
|
|
{
|
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;
|
|
|
|
}
|
2013-04-29 10:23:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void sendAccessInfo()
|
|
|
|
{
|
2019-10-12 13:25:33 +02:00
|
|
|
String chunkDesc = AsciiMap.showChunkCoords(chunk) ? " at " + chunk.toString(PSFormatHumanSpace.get()) : "";
|
|
|
|
Object title = "Access" + chunkDesc;
|
2016-03-15 20:43:54 +01:00
|
|
|
title = Txt.titleize(title);
|
|
|
|
message(title);
|
|
|
|
|
2014-09-18 13:41:20 +02:00
|
|
|
msg("<k>Host Faction: %s", hostFaction.describeTo(msender, true));
|
2013-04-29 10:23:39 +02:00
|
|
|
msg("<k>Host Faction Allowed: %s", ta.isHostFactionAllowed() ? Txt.parse("<lime>TRUE") : Txt.parse("<rose>FALSE"));
|
2019-04-14 23:18:10 +02:00
|
|
|
msg("<k>Granted to: %s", CmdFactionsPermShow.permablesToDisplayString(ta.getGranteds(), msender));
|
2013-04-29 10:23:39 +02:00
|
|
|
}
|
2019-04-15 13:55:20 +02:00
|
|
|
|
|
|
|
public void setAccess(Collection<PS> chunks, MPermable mpermable, boolean granted)
|
2013-04-29 10:23:39 +02:00
|
|
|
{
|
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();
|
|
|
|
|
2019-10-12 13:25:33 +02:00
|
|
|
|
|
|
|
String chunkDesc = AsciiMap.showChunkCoords(chunk) ? " at " + chunk.toString(PSFormatHumanSpace.get()) : "";
|
2019-04-15 13:55:20 +02:00
|
|
|
String grantedDenied = granted ? "granted" : "denied";
|
|
|
|
String mpermableDesc = mpermable.getDisplayName(msender);
|
|
|
|
|
|
|
|
if ( ! MPerm.getPermAccess().has(msender, faction, false))
|
2013-04-29 10:23:39 +02:00
|
|
|
{
|
2019-10-12 13:25:33 +02:00
|
|
|
msg("<b>You do not have permission to edit access%s<b>.", chunkDesc);
|
2019-04-15 13:55:20 +02:00
|
|
|
return;
|
2013-04-29 10:23:39 +02:00
|
|
|
}
|
2019-04-15 13:55:20 +02:00
|
|
|
|
|
|
|
if (ta.isGranted(mpermable) == granted)
|
|
|
|
{
|
2019-10-12 13:25:33 +02:00
|
|
|
msg("<b>Access%s <b>is already %s to %s<b>.", chunkDesc, grantedDenied, mpermableDesc);
|
2019-04-15 13:55:20 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ta = ta.withGranted(mpermable, granted);
|
|
|
|
BoardColl.get().setTerritoryAccessAt(chunk, ta);
|
|
|
|
|
2019-10-12 13:25:33 +02:00
|
|
|
msg("<i>Access%s<i> is now %s to %s<i>.", chunkDesc, grantedDenied, mpermableDesc);
|
2013-04-29 10:23:39 +02:00
|
|
|
}
|
2019-04-15 13:55:20 +02:00
|
|
|
|
2013-04-29 10:23:39 +02:00
|
|
|
}
|