Minor improvements to the rank commands
This commit is contained in:
parent
3827d2bf06
commit
c5a1bb4801
@ -16,7 +16,7 @@ public class CmdFactionsRankEdit extends FactionsCommand
|
||||
public CmdFactionsRankEditPrefix cmdFactionsRankEditPrefix = new CmdFactionsRankEditPrefix();
|
||||
public CmdFactionsRankEditPriority cmdFactionsRankEditPriority = new CmdFactionsRankEditPriority();
|
||||
|
||||
static void ensureAllowed(MPlayer msender, Faction faction) throws MassiveException
|
||||
static void ensureAllowed(MPlayer msender, Faction faction, String action) throws MassiveException
|
||||
{
|
||||
if (msender.isOverriding()) return;
|
||||
|
||||
@ -27,7 +27,7 @@ public class CmdFactionsRankEdit extends FactionsCommand
|
||||
|
||||
if (!msender.getRank().isLeader())
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>Only the leader can create, edit or delete ranks.");
|
||||
throw new MassiveException().addMsg("<b>Only the leader can %s ranks.", action);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,8 @@ import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeStringParsed;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class CmdFactionsRankEditCreate extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -36,9 +38,9 @@ public class CmdFactionsRankEditCreate extends FactionsCommand
|
||||
String prefix = this.readArg();
|
||||
Faction faction = this.readArg(msenderFaction);
|
||||
|
||||
CmdFactionsRankEdit.ensureAllowed(msender, faction);
|
||||
CmdFactionsRankEdit.ensureAllowed(msender, faction, "create");
|
||||
|
||||
var ranks = faction.getRanks().getAll();
|
||||
Collection<Rank> ranks = faction.getRanks().getAll();
|
||||
|
||||
if (ranks.stream().map(Rank::getName).anyMatch(s -> s.equalsIgnoreCase(name)))
|
||||
{
|
||||
|
@ -3,11 +3,14 @@ package com.massivecraft.factions.cmd;
|
||||
import com.massivecraft.factions.cmd.type.TypeFaction;
|
||||
import com.massivecraft.factions.cmd.type.TypeRank;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.Rank;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CmdFactionsRankEditDelete extends FactionsCommand
|
||||
@ -37,21 +40,22 @@ public class CmdFactionsRankEditDelete extends FactionsCommand
|
||||
TypeRank typeRank = new TypeRank(faction);
|
||||
Rank rank = typeRank.read(this.argAt(0), sender);
|
||||
|
||||
CmdFactionsRankEdit.ensureAllowed(msender, faction);
|
||||
CmdFactionsRankEdit.ensureAllowed(msender, faction, "delete");
|
||||
|
||||
var ranks = faction.getRanks().getAll();
|
||||
Collection<Rank> ranks = faction.getRanks().getAll();
|
||||
if (ranks.size() <= 2)
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>A faction must have at least two ranks.");
|
||||
}
|
||||
|
||||
var mplayers = faction.getMPlayersWhereRank(rank);
|
||||
List<MPlayer> mplayers = faction.getMPlayersWhereRank(rank);
|
||||
if (!mplayers.isEmpty())
|
||||
{
|
||||
var count = mplayers.size();
|
||||
var names = mplayers.stream().map(m -> m.getDisplayName(sender)).collect(Collectors.toList());
|
||||
var namesDesc = Txt.implodeCommaAnd(names, Txt.parse("<i>"));
|
||||
throw new MassiveException().addMsg("<b>This rank is held by <h>%s <b>change their ranks first.", namesDesc);
|
||||
int count = mplayers.size();
|
||||
List<String> names = mplayers.stream().map(m -> m.getDisplayName(sender)).collect(Collectors.toList());
|
||||
String namesDesc = Txt.implodeCommaAnd(names, Txt.parse("<i>"));
|
||||
String rankRanks = count == 1 ? "rank" : "ranks";
|
||||
throw new MassiveException().addMsg("<b>This rank is held by <h>%s <b>change their %s first.", namesDesc, rankRanks);
|
||||
}
|
||||
|
||||
String visual = rank.getVisual();
|
||||
|
@ -7,6 +7,8 @@ import com.massivecraft.factions.entity.Rank;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeString;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class CmdFactionsRankEditName extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -38,16 +40,16 @@ public class CmdFactionsRankEditName extends FactionsCommand
|
||||
|
||||
// Args
|
||||
|
||||
CmdFactionsRankEdit.ensureAllowed(msender, faction);
|
||||
CmdFactionsRankEdit.ensureAllowed(msender, faction, "rename");
|
||||
|
||||
var ranks = faction.getRanks().getAll();
|
||||
Collection<Rank> ranks = faction.getRanks().getAll();
|
||||
|
||||
if (ranks.stream().map(Rank::getName).anyMatch(s -> s.equalsIgnoreCase(name)))
|
||||
{
|
||||
throw new MassiveException().addMsg("<b>There is already a rank called <h>%s<b>.", name);
|
||||
}
|
||||
|
||||
var priorVisual = rank.getVisual();
|
||||
String priorVisual = rank.getVisual();
|
||||
rank.setName(name);
|
||||
|
||||
// Visual
|
||||
|
@ -38,9 +38,9 @@ public class CmdFactionsRankEditPrefix extends FactionsCommand
|
||||
|
||||
// Args
|
||||
|
||||
CmdFactionsRankEdit.ensureAllowed(msender, faction);
|
||||
CmdFactionsRankEdit.ensureAllowed(msender, faction, "edit");
|
||||
|
||||
var priorPrefix = rank.getPrefix();
|
||||
String priorPrefix = rank.getPrefix();
|
||||
rank.setPrefix(prefix);
|
||||
|
||||
// Visual
|
||||
|
@ -7,6 +7,8 @@ import com.massivecraft.factions.entity.Rank;
|
||||
import com.massivecraft.massivecore.MassiveException;
|
||||
import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class CmdFactionsRankEditPriority extends FactionsCommand
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
@ -36,9 +38,9 @@ public class CmdFactionsRankEditPriority extends FactionsCommand
|
||||
TypeRank typeRank = new TypeRank(faction);
|
||||
Rank rank = typeRank.read(this.argAt(0), sender);
|
||||
|
||||
CmdFactionsRankEdit.ensureAllowed(msender, faction);
|
||||
CmdFactionsRankEdit.ensureAllowed(msender, faction, "edit");
|
||||
|
||||
var ranks = faction.getRanks().getAll();
|
||||
Collection<Rank> ranks = faction.getRanks().getAll();
|
||||
|
||||
if (ranks.stream().map(Rank::getPriority).anyMatch(s -> s.equals(priority)))
|
||||
{
|
||||
|
@ -504,7 +504,6 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
|
||||
|
||||
// RAW
|
||||
|
||||
|
||||
public EntityInternalMap<Rank> getRanks() { return this.ranks; }
|
||||
|
||||
// FINER
|
||||
@ -522,17 +521,12 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
|
||||
|
||||
private EntityInternalMap<Rank> createRankMap()
|
||||
{
|
||||
var ret = new EntityInternalMap<>(this, Rank.class);
|
||||
EntityInternalMap<Rank> ret = new EntityInternalMap<>(this, Rank.class);
|
||||
Rank leader = new Rank("Leader", 400, "**");
|
||||
Rank officer = new Rank("Officer", 300, "*");
|
||||
Rank member = new Rank("Member", 200, "+");
|
||||
Rank recruit = new Rank("Recruit", 100, "-");
|
||||
|
||||
/*leader.setPermIds(new MassiveList<>(MConf.get().defaultPermsLeader));
|
||||
officer.setPermIds(new MassiveList<>(MConf.get().defaultPermsOfficer));
|
||||
member.setPermIds(new MassiveList<>(MConf.get().defaultPermsMember));
|
||||
recruit.setPermIds(new MassiveList<>(MConf.get().defaultPermsRecruit));*/
|
||||
|
||||
ret.attach(leader);
|
||||
ret.attach(officer);
|
||||
ret.attach(member);
|
||||
|
Loading…
Reference in New Issue
Block a user