New access commands

This commit is contained in:
Magnus Ulf 2019-04-15 13:55:20 +02:00
parent d015f19181
commit ae442c677b
22 changed files with 589 additions and 231 deletions

View File

@ -12,8 +12,17 @@ permissions:
# THE REAL NODES
# -------------------------------------------- #
factions.access: {description: manage access, with the proper fperm, default: false}
factions.access.faction: {description: grant faction access, with the proper fperm, default: false}
factions.access.player: {description: grant player access, with the proper fperm, default: false}
factions.access.deny: {description: deny faction access, default: false}
factions.access.deny.one: {description: deny access in a single chunk, default: false}
factions.access.deny.fill: {description: deny access by filling, default: false}
factions.access.deny.square: {description: deny access by square and radius, default: false}
factions.access.deny.circle: {description: deny access by circle and radius, default: false}
factions.access.grant: {description: grant faction access, default: false}
factions.access.grant.one: {description: grant access in a single chunk, default: false}
factions.access.grant.fill: {description: grant access by filling, default: false}
factions.access.grant.square: {description: grant access by square and radius, default: false}
factions.access.grant.circle: {description: grant access by circle and radius, default: false}
factions.access.inspect: {description: inspect where someone has access, default: false}
factions.access.view: {description: view access, default: false}
factions.override: {description: enable override mode, default: false}
factions.basecommand: {description: use factions base command, default: false}
@ -134,8 +143,17 @@ permissions:
factions.*:
children:
factions.access: true
factions.access.faction: true
factions.access.player: true
factions.access.deny: true
factions.access.deny.one: true
factions.access.deny.fill: true
factions.access.deny.square: true
factions.access.deny.circle: true
factions.access.grant: true
factions.access.grant.one: true
factions.access.grant.fill: true
factions.access.grant.square: true
factions.access.grant.circle: true
factions.access.inspect: true
factions.access.view: true
factions.override: true
factions.basecommand: true
@ -301,8 +319,17 @@ permissions:
default: false
children:
factions.access: true
factions.access.faction: true
factions.access.player: true
factions.access.deny: true
factions.access.deny.one: true
factions.access.deny.fill: true
factions.access.deny.square: true
factions.access.deny.circle: true
factions.access.grant: true
factions.access.grant.one: true
factions.access.grant.fill: true
factions.access.grant.square: true
factions.access.grant.circle: true
factions.access.inspect: true
factions.access.view: true
factions.basecommand: true
factions.claim: true

View File

@ -11,6 +11,15 @@ public enum Perm implements Identified
// ENUM
// -------------------------------------------- //
ACCESS_GRANT_ONE,
ACCESS_GRANT_FILL,
ACCESS_GRANT_SQUARE,
ACCESS_GRANT_CIRCLE,
ACCESS_DENY_ONE,
ACCESS_DENY_FILL,
ACCESS_DENY_SQUARE,
ACCESS_DENY_CIRCLE,
CLAIM_ONE,
CLAIM_AUTO,
CLAIM_FILL,

View File

@ -45,6 +45,11 @@ public class TerritoryAccess
public TerritoryAccess withGrantedIds(Collection<String> factionIds) { return valueOf(hostFactionId, hostFactionAllowed, grantedIds); }
// The intermediate ones
public TerritoryAccess withGranted(MPermable mpermable, boolean with)
{
return withGrantedId(mpermable.getId(), with);
}
public TerritoryAccess withGrantedId(String grantedId, boolean with)
{
if (this.getHostFactionId().equals(grantedId))

View File

@ -9,8 +9,9 @@ public class CmdFactionsAccess extends FactionsCommand
// -------------------------------------------- //
public CmdFactionsAccessView cmdFactionsAccessView = new CmdFactionsAccessView();
public CmdFactionsAccessPlayer cmdFactionsAccessPlayer = new CmdFactionsAccessPlayer();
public CmdFactionsAccessFaction cmdFactionsAccessFaction = new CmdFactionsAccessFaction();
public CmdFactionsAccessGrant cmdFactionsAccessGrant = new CmdFactionsAccessGrant();
public CmdFactionsAccessDeny cmdFactionsAccessDeny = new CmdFactionsAccessDeny();
public CmdFactionsAccessInspect cmdFactionsAccessInspect = new CmdFactionsAccessInspect();
// -------------------------------------------- //
// CONSTRUCT

View File

@ -1,18 +1,16 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.RelationParticipator;
import com.massivecraft.factions.TerritoryAccess;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.massivecore.MassiveException;
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.ArrayList;
import java.util.Collection;
import java.util.List;
public abstract class CmdFactionsAccessAbstract extends FactionsCommand
@ -40,17 +38,24 @@ public abstract class CmdFactionsAccessAbstract extends FactionsCommand
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
public void senderFields(boolean set)
{
chunk = PS.valueOf(me.getLocation()).getChunk(true);
ta = BoardColl.get().getTerritoryAccessAt(chunk);
hostFaction = ta.getHostFaction();
super.senderFields(set);
this.innerPerform();
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 abstract void innerPerform() throws MassiveException;
public void sendAccessInfo()
{
Object title = "Access at " + chunk.toString(PSFormatHumanSpace.get());
@ -62,15 +67,36 @@ public abstract class CmdFactionsAccessAbstract extends FactionsCommand
msg("<k>Granted to: %s", CmdFactionsPermShow.permablesToDisplayString(ta.getGranteds(), msender));
}
public static String describeRelationParticipators(Collection<? extends RelationParticipator> relationParticipators, RelationParticipator observer)
public void setAccess(Collection<PS> chunks, MPermable mpermable, boolean granted)
{
if (relationParticipators.size() == 0) return Txt.parse("<silver><em>none");
List<String> descriptions = new ArrayList<>();
for (RelationParticipator relationParticipator : relationParticipators)
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))
{
descriptions.add(relationParticipator.describeTo(observer));
msg("<b>You do not have permission to edit access at %s<b>.", chunkDesc);
return;
}
return Txt.implodeCommaAnd(descriptions, Txt.parse("<i>, "), Txt.parse(" <i>and "));
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);
}
}

View File

@ -0,0 +1,26 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
public class CmdFactionsAccessDeny extends CmdFactionsAccessAbstract
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
public CmdFactionsAccessSetOne cmdFactionsAccessDenyOne = new CmdFactionsAccessSetOne(false);
public CmdFactionsAccessSetSquare cmdFactionsAccessDenySquare = new CmdFactionsAccessSetSquare(false);
public CmdFactionsAccessSetCircle cmdFactionsAccessDenyCircle = new CmdFactionsAccessSetCircle(false);
public CmdFactionsAccessSetFill cmdFactionsAccessDenyFill = new CmdFactionsAccessSetFill(false);
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsAccessDeny()
{
// Requirements
this.addRequirements(RequirementIsPlayer.get());
}
}

View File

@ -1,45 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.type.TypeFaction;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes;
public class CmdFactionsAccessFaction extends CmdFactionsAccessAbstract
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsAccessFaction()
{
// Parameters
this.addParameter(TypeFaction.get(), "faction");
this.addParameter(TypeBooleanYes.get(), "yes/no", "toggle");
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void innerPerform() throws MassiveException
{
// Args
Faction faction = this.readArg();
boolean newValue = this.readArg(!ta.isGranted(faction));
// MPerm
if (!MPerm.getPermAccess().has(msender, hostFaction, true)) return;
// Apply
ta = ta.withGrantedId(faction.getId(), newValue);
BoardColl.get().setTerritoryAccessAt(chunk, ta);
// Inform
this.sendAccessInfo();
}
}

View File

@ -0,0 +1,26 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
public class CmdFactionsAccessGrant extends CmdFactionsAccessAbstract
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
public CmdFactionsAccessSetOne cmdFactionsAccessGrantOne = new CmdFactionsAccessSetOne(true);
public CmdFactionsAccessSetSquare cmdFactionsAccessGrantSquare = new CmdFactionsAccessSetSquare(true);
public CmdFactionsAccessSetCircle cmdFactionsAccessGrantCircle = new CmdFactionsAccessSetCircle(true);
public CmdFactionsAccessSetFill cmdFactionsAccessGrantFill = new CmdFactionsAccessSetFill(true);
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsAccessGrant()
{
// Requirements
this.addRequirements(RequirementIsPlayer.get());
}
}

View File

@ -0,0 +1,96 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.type.TypeFaction;
import com.massivecraft.factions.cmd.type.TypeMPermable;
import com.massivecraft.factions.entity.Board;
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.MassiveException;
import com.massivecraft.massivecore.collections.MassiveMap;
import com.massivecraft.massivecore.mixin.MixinWorld;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.ps.PSFormatHumanSpace;
import com.massivecraft.massivecore.util.Txt;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;
public class CmdFactionsAccessInspect extends FactionsCommand
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsAccessInspect()
{
// Parameters
this.addParameter(TypeMPermable.get(), "rank/rel/player/faction");
this.addParameter(TypeFaction.get(), "faction", "your");
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
{
// Parameter
Faction faction = this.readArgAt(1, msenderFaction);
MPermable mpermable = TypeMPermable.get(faction).read(this.argAt(0), sender);
String factionId = faction.getId();
// Check if they have access perms, unless they are checking for their own access
if (mpermable != msender && mpermable != msenderFaction && mpermable != msender.getRank());
{
if ( ! MPerm.getPermAccess().has(msender, faction, true)) return;
}
// Turn into id->chunks
// And filter the ones that are empty
Map<String, Set<PS>> world2Chunks = new MassiveMap<>();
for (Board board : BoardColl.get().getAll())
{
String worldId = board.getId();
Set<PS> chunks = board.getMap().entrySet().stream()
.filter(e -> e.getValue().getHostFactionId().equals(factionId))
.filter(e -> e.getValue().isGranted(mpermable))
.map(Entry::getKey)
.collect(Collectors.toSet());
if ( ! chunks.isEmpty()) world2Chunks.put(worldId, chunks);
}
if (world2Chunks.isEmpty())
{
msg("%s <i>has no special access in <reset>%s <i>.", mpermable.getDisplayName(msender), faction.describeTo(msender));
return;
}
msg("%s <i>has special access in <reset>%s <i> in the following chunks:", mpermable.getDisplayName(msender), faction.describeTo(msender));
for (Entry<String, Set<PS>> entry : world2Chunks.entrySet())
{
String worldId = entry.getKey();
Set<PS> chunks = entry.getValue();
String worldName = MixinWorld.get().getWorldDisplayName(worldId);
// Remove world from chunks
List<String> chunkNames = chunks.stream()
.map(PS::getChunkCoords)
.map(PSFormatHumanSpace.get()::format)
.collect(Collectors.toList());
String chunkDesc = Txt.implodeCommaAnd(chunkNames, Txt.parse("<i>"));
msg("%s<i> (%d): <reset>%s", worldName, chunks.size(), chunkDesc);
}
}
}

View File

@ -1,45 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.type.TypeMPlayer;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.primitive.TypeBooleanYes;
public class CmdFactionsAccessPlayer extends CmdFactionsAccessAbstract
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsAccessPlayer()
{
// Parameters
this.addParameter(TypeMPlayer.get(), "player");
this.addParameter(TypeBooleanYes.get(), "yes/no", "toggle");
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void innerPerform() throws MassiveException
{
// Args
MPlayer mplayer = this.readArg();
boolean newValue = this.readArg(!ta.isGranted(mplayer));
// MPerm
if (!MPerm.getPermAccess().has(msender, hostFaction, true)) return;
// Apply
ta = ta.withGrantedId(mplayer.getId(), newValue);
BoardColl.get().setTerritoryAccessAt(chunk, ta);
// Inform
this.sendAccessInfo();
}
}

View File

@ -0,0 +1,45 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.ChunkUtil;
import java.util.Set;
public class CmdFactionsAccessSetCircle extends CmdFactionsAccessSetXRadius
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsAccessSetCircle(boolean grant)
{
// Super
super(grant);
// Aliases
this.addAliases("circle");
// Requirements
this.addRequirements(RequirementIsPlayer.get());
Perm perm = grant ? Perm.ACCESS_GRANT_CIRCLE : Perm.ACCESS_DENY_CIRCLE;
this.addRequirements(RequirementHasPerm.get(perm));
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Set<PS> getChunks() throws MassiveException
{
// Common Startup
final PS chunk = PS.valueOf(me.getLocation()).getChunk(true);
return ChunkUtil.getChunksCircle(chunk, this.getRadius());
}
}

View File

@ -0,0 +1,57 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.predicate.Predicate;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.ChunkUtil;
import java.util.Set;
public class CmdFactionsAccessSetFill extends CmdFactionsAccessSetXSimple
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsAccessSetFill(boolean claim)
{
// Super
super(claim);
// Aliases
this.addAliases("fill");
// Requirements
this.addRequirements(RequirementIsPlayer.get());
Perm perm = claim ? Perm.ACCESS_GRANT_FILL : Perm.ACCESS_DENY_FILL;
this.addRequirements(RequirementHasPerm.get(perm));
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Set<PS> getChunks() throws MassiveException
{
// Common Startup
final PS chunk = PS.valueOf(me.getLocation()).getChunk(true);
// What faction (aka color) resides there?
// NOTE: Wilderness/None is valid.
final Faction color = BoardColl.get().getFactionAt(chunk);
// Calculate
int max = MConf.get().setFillMax;
Predicate<PS> matcher = ps -> BoardColl.get().getFactionAt(ps) == color;
return ChunkUtil.getChunkArea(chunk, matcher, max);
}
}

View File

@ -0,0 +1,44 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.ps.PS;
import java.util.Collections;
import java.util.Set;
public class CmdFactionsAccessSetOne extends CmdFactionsAccessSetXSimple
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsAccessSetOne(boolean claim)
{
// Super
super(claim);
// Aliases
this.addAliases("one");
// Requirements
this.addRequirements(RequirementIsPlayer.get());
Perm perm = claim ? Perm.ACCESS_GRANT_ONE : Perm.ACCESS_DENY_ONE;
this.addRequirements(RequirementHasPerm.get(perm));
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Set<PS> getChunks()
{
final PS chunk = PS.valueOf(me.getLocation()).getChunk(true);
final Set<PS> chunks = Collections.singleton(chunk);
return chunks;
}
}

View File

@ -0,0 +1,45 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.ChunkUtil;
import java.util.Set;
public class CmdFactionsAccessSetSquare extends CmdFactionsAccessSetXRadius
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsAccessSetSquare(boolean grant)
{
// Super
super(grant);
// Aliases
this.addAliases("square");
// Requirements
this.addRequirements(RequirementIsPlayer.get());
Perm perm = grant ? Perm.ACCESS_GRANT_SQUARE : Perm.ACCESS_DENY_SQUARE;
this.addRequirements(RequirementHasPerm.get(perm));
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public Set<PS> getChunks() throws MassiveException
{
// Common Startup
final PS chunk = PS.valueOf(me.getLocation()).getChunk(true);
return ChunkUtil.getChunksSquare(chunk, this.getRadius());
}
}

View File

@ -0,0 +1,68 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.type.TypeMPermable;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPerm.MPermable;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.ps.PS;
import java.util.Set;
public abstract class CmdFactionsAccessSetX extends CmdFactionsAccessAbstract
{
// -------------------------------------------- //
// FIELDS
// -------------------------------------------- //
private boolean grant = true;
public boolean isGranting() { return this.grant; }
public void setGranting(boolean grant) { this.grant = grant; }
private int mpermableArgIndex = 0;
public int getMPermableArgIndex() { return this.mpermableArgIndex; }
public void setMPermableArgIndex(int mpermableArgIndex) { this.mpermableArgIndex = mpermableArgIndex; }
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsAccessSetX(boolean grant)
{
this.setGranting(grant);
this.setSetupEnabled(false);
}
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@Override
public void perform() throws MassiveException
{
// Args
final MPermable mpermable = this.getMPermable(hostFaction);
final Set<PS> chunks = this.getChunks();
if (chunks == null) throw new NullPointerException("chunks");
// Apply / Inform
setAccess(chunks, mpermable, this.isGranting());
}
// -------------------------------------------- //
// ABSTRACT
// -------------------------------------------- //
public abstract Set<PS> getChunks() throws MassiveException;
// -------------------------------------------- //
// EXTRAS
// -------------------------------------------- //
public MPermable getMPermable(Faction faction) throws MassiveException
{
String arg = this.argAt(this.getMPermableArgIndex());
return TypeMPermable.get(faction).read(arg, sender);
}
}

View File

@ -0,0 +1,51 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.type.TypeMPermable;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
public abstract class CmdFactionsAccessSetXRadius extends CmdFactionsAccessSetX
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsAccessSetXRadius(boolean claim)
{
// Super
super(claim);
// Parameters
this.addParameter(TypeInteger.get(), "radius");
this.addParameter(TypeMPermable.get(), "rank/rel/faction/player");
this.setMPermableArgIndex(1);
}
// -------------------------------------------- //
// EXTRAS
// -------------------------------------------- //
public Integer getRadius() throws MassiveException
{
int radius = this.readArgAt(0);
// Radius Claim Min
if (radius < 1)
{
throw new MassiveException().setMsg("<b>If you specify a radius, it must be at least 1.");
}
// Radius Claim Max
if (radius > MConf.get().setRadiusMax && ! msender.isOverriding())
{
throw new MassiveException().setMsg("<b>The maximum radius allowed is <h>%s<b>.", MConf.get().setRadiusMax);
}
return radius;
}
}

View File

@ -0,0 +1,21 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.type.TypeMPermable;
public abstract class CmdFactionsAccessSetXSimple extends CmdFactionsAccessSetX
{
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsAccessSetXSimple(boolean claim)
{
// Super
super(claim);
// Parameters
this.addParameter(TypeMPermable.get(), "rank/rel/player/faction");
this.setMPermableArgIndex(0);
}
}

View File

@ -7,7 +7,7 @@ public class CmdFactionsAccessView extends CmdFactionsAccessAbstract
// -------------------------------------------- //
@Override
public void innerPerform()
public void perform()
{
this.sendAccessInfo();
}

View File

@ -2,12 +2,11 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.ChunkUtil;
import java.util.LinkedHashSet;
import java.util.Set;
@ -44,27 +43,7 @@ public class CmdFactionsSetCircle extends CmdFactionsSetXRadius
{
// Common Startup
final PS chunk = PS.valueOf(me.getLocation()).getChunk(true);
final Set<PS> chunks = new MassiveSet<>();
chunks.add(chunk); // The center should come first for pretty messages
Integer radiusZero = this.getRadiusZero();
double radiusSquared = radiusZero * radiusZero;
for (int dx = -radiusZero; dx <= radiusZero; dx++)
{
for (int dz = -radiusZero; dz <= radiusZero; dz++)
{
if (dx*dx + dz*dz > radiusSquared) continue;
int x = chunk.getChunkX() + dx;
int z = chunk.getChunkZ() + dz;
chunks.add(chunk.withChunkX(x).withChunkZ(z));
}
}
return chunks;
return ChunkUtil.getChunksCircle(chunk, this.getRadius());
}
}

View File

@ -5,11 +5,11 @@ import com.massivecraft.factions.entity.BoardColl;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.predicate.Predicate;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.ChunkUtil;
import java.util.Set;
@ -47,69 +47,15 @@ public class CmdFactionsSetFill extends CmdFactionsSetXSimple
{
// Common Startup
final PS chunk = PS.valueOf(me.getLocation()).getChunk(true);
final Set<PS> chunks = new MassiveSet<>();
// What faction (aka color) resides there?
// NOTE: Wilderness/None is valid.
final Faction color = BoardColl.get().getFactionAt(chunk);
// We start where we are!
chunks.add(chunk);
// Flood!
// Calculate
int max = MConf.get().setFillMax;
floodSearch(chunks, color, max);
// Limit Reached?
if (chunks.size() >= max)
{
throw new MassiveException().addMsg("<b>Fill limit of <h>%d <b>reached.", max);
}
// OK!
return chunks;
}
// -------------------------------------------- //
// FLOOD FILL
// -------------------------------------------- //
public static void floodSearch(Set<PS> set, Faction color, int max)
{
// Clean
if (set == null) throw new NullPointerException("set");
if (color == null) throw new NullPointerException("color");
// Expand
Set<PS> expansion = new MassiveSet<>();
for (PS chunk : set)
{
Set<PS> neighbours = MUtil.set(
chunk.withChunkX(chunk.getChunkX() + 1),
chunk.withChunkX(chunk.getChunkX() - 1),
chunk.withChunkZ(chunk.getChunkZ() + 1),
chunk.withChunkZ(chunk.getChunkZ() - 1)
);
for (PS neighbour : neighbours)
{
if (set.contains(neighbour)) continue;
Faction faction = BoardColl.get().getFactionAt(neighbour);
if (faction == null) continue;
if (faction != color) continue;
expansion.add(neighbour);
}
}
set.addAll(expansion);
// No Expansion?
if (expansion.isEmpty()) return;
// Reached Max?
if (set.size() >= max) return;
// Recurse
floodSearch(set, color, max);
Predicate<PS> matcher = ps -> BoardColl.get().getFactionAt(ps) == color;
return ChunkUtil.getChunkArea(chunk, matcher, max);
}
}

View File

@ -2,12 +2,11 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Perm;
import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.collections.MassiveSet;
import com.massivecraft.massivecore.command.requirement.RequirementHasPerm;
import com.massivecraft.massivecore.command.requirement.RequirementIsPlayer;
import com.massivecraft.massivecore.ps.PS;
import com.massivecraft.massivecore.util.ChunkUtil;
import java.util.LinkedHashSet;
import java.util.Set;
@ -44,24 +43,7 @@ public class CmdFactionsSetSquare extends CmdFactionsSetXRadius
{
// Common Startup
final PS chunk = PS.valueOf(me.getLocation()).getChunk(true);
final Set<PS> chunks = new MassiveSet<>();
chunks.add(chunk); // The center should come first for pretty messages
Integer radiusZero = this.getRadiusZero();
for (int dx = -radiusZero; dx <= radiusZero; dx++)
{
for (int dz = -radiusZero; dz <= radiusZero; dz++)
{
int x = chunk.getChunkX() + dx;
int z = chunk.getChunkZ() + dz;
chunks.add(chunk.withChunkX(x).withChunkZ(z));
}
}
return chunks;
return ChunkUtil.getChunksSquare(chunk, this.getRadius());
}
}

View File

@ -49,10 +49,4 @@ public abstract class CmdFactionsSetXRadius extends CmdFactionsSetX
return radius;
}
public Integer getRadiusZero() throws MassiveException
{
Integer ret = this.getRadius();
return ret - 1;
}
}