package com.massivecraft.factions.cmd; import com.massivecraft.factions.TerritoryAccess; import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPerm.MPermable; import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer; import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PSFormatHumanSpace; import com.massivecraft.massivecore.util.Txt; import java.util.Collection; public abstract class CmdFactionsAccessAbstract extends FactionsCommand { // -------------------------------------------- // // FIELDS // -------------------------------------------- // public PS chunk; public TerritoryAccess ta; public Faction hostFaction; // -------------------------------------------- // // CONSTRUCT // -------------------------------------------- // public CmdFactionsAccessAbstract() { // Requirements this.addRequirements(RequirementIsPlayer.get()); } // -------------------------------------------- // // OVERRIDE // -------------------------------------------- // @Override public void senderFields(boolean set) { 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); msg("Host Faction: %s", hostFaction.describeTo(msender, true)); msg("Host Faction Allowed: %s", ta.isHostFactionAllowed() ? Txt.parse("TRUE") : Txt.parse("FALSE")); msg("Granted to: %s", CmdFactionsPermShow.permablesToDisplayString(ta.getGranteds(), msender)); } public void setAccess(Collection chunks, MPermable mpermable, boolean granted) { 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)) { msg("You do not have permission to edit access at %s.", chunkDesc); return; } if (ta.isGranted(mpermable) == granted) { msg("Access at %s is already %s to %s.", chunkDesc, grantedDenied, mpermableDesc); return; } ta = ta.withGranted(mpermable, granted); BoardColl.get().setTerritoryAccessAt(chunk, ta); msg("Access at %s is now %s to %s.", chunkDesc, grantedDenied, mpermableDesc); } }