Minor improvements to the rank commands

This commit is contained in:
Magnus Ulf 2019-01-03 15:23:06 +01:00
parent 3827d2bf06
commit c5a1bb4801
7 changed files with 29 additions and 25 deletions

View File

@ -16,7 +16,7 @@ public class CmdFactionsRankEdit extends FactionsCommand
public CmdFactionsRankEditPrefix cmdFactionsRankEditPrefix = new CmdFactionsRankEditPrefix(); public CmdFactionsRankEditPrefix cmdFactionsRankEditPrefix = new CmdFactionsRankEditPrefix();
public CmdFactionsRankEditPriority cmdFactionsRankEditPriority = new CmdFactionsRankEditPriority(); 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; if (msender.isOverriding()) return;
@ -27,7 +27,7 @@ public class CmdFactionsRankEdit extends FactionsCommand
if (!msender.getRank().isLeader()) 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);
} }
} }

View File

@ -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.TypeString;
import com.massivecraft.massivecore.command.type.primitive.TypeStringParsed; import com.massivecraft.massivecore.command.type.primitive.TypeStringParsed;
import java.util.Collection;
public class CmdFactionsRankEditCreate extends FactionsCommand public class CmdFactionsRankEditCreate extends FactionsCommand
{ {
// -------------------------------------------- // // -------------------------------------------- //
@ -36,9 +38,9 @@ public class CmdFactionsRankEditCreate extends FactionsCommand
String prefix = this.readArg(); String prefix = this.readArg();
Faction faction = this.readArg(msenderFaction); 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))) if (ranks.stream().map(Rank::getName).anyMatch(s -> s.equalsIgnoreCase(name)))
{ {

View File

@ -3,11 +3,14 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.cmd.type.TypeFaction; import com.massivecraft.factions.cmd.type.TypeFaction;
import com.massivecraft.factions.cmd.type.TypeRank; import com.massivecraft.factions.cmd.type.TypeRank;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.entity.Rank; import com.massivecraft.factions.entity.Rank;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.primitive.TypeString; import com.massivecraft.massivecore.command.type.primitive.TypeString;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
public class CmdFactionsRankEditDelete extends FactionsCommand public class CmdFactionsRankEditDelete extends FactionsCommand
@ -37,21 +40,22 @@ public class CmdFactionsRankEditDelete extends FactionsCommand
TypeRank typeRank = new TypeRank(faction); TypeRank typeRank = new TypeRank(faction);
Rank rank = typeRank.read(this.argAt(0), sender); 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) if (ranks.size() <= 2)
{ {
throw new MassiveException().addMsg("<b>A faction must have at least two ranks."); 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()) if (!mplayers.isEmpty())
{ {
var count = mplayers.size(); int count = mplayers.size();
var names = mplayers.stream().map(m -> m.getDisplayName(sender)).collect(Collectors.toList()); List<String> names = mplayers.stream().map(m -> m.getDisplayName(sender)).collect(Collectors.toList());
var namesDesc = Txt.implodeCommaAnd(names, Txt.parse("<i>")); String 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); 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(); String visual = rank.getVisual();

View File

@ -7,6 +7,8 @@ import com.massivecraft.factions.entity.Rank;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.primitive.TypeString; import com.massivecraft.massivecore.command.type.primitive.TypeString;
import java.util.Collection;
public class CmdFactionsRankEditName extends FactionsCommand public class CmdFactionsRankEditName extends FactionsCommand
{ {
// -------------------------------------------- // // -------------------------------------------- //
@ -38,16 +40,16 @@ public class CmdFactionsRankEditName extends FactionsCommand
// Args // 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))) 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); 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); rank.setName(name);
// Visual // Visual

View File

@ -38,9 +38,9 @@ public class CmdFactionsRankEditPrefix extends FactionsCommand
// Args // Args
CmdFactionsRankEdit.ensureAllowed(msender, faction); CmdFactionsRankEdit.ensureAllowed(msender, faction, "edit");
var priorPrefix = rank.getPrefix(); String priorPrefix = rank.getPrefix();
rank.setPrefix(prefix); rank.setPrefix(prefix);
// Visual // Visual

View File

@ -7,6 +7,8 @@ import com.massivecraft.factions.entity.Rank;
import com.massivecraft.massivecore.MassiveException; import com.massivecraft.massivecore.MassiveException;
import com.massivecraft.massivecore.command.type.primitive.TypeInteger; import com.massivecraft.massivecore.command.type.primitive.TypeInteger;
import java.util.Collection;
public class CmdFactionsRankEditPriority extends FactionsCommand public class CmdFactionsRankEditPriority extends FactionsCommand
{ {
// -------------------------------------------- // // -------------------------------------------- //
@ -36,9 +38,9 @@ public class CmdFactionsRankEditPriority extends FactionsCommand
TypeRank typeRank = new TypeRank(faction); TypeRank typeRank = new TypeRank(faction);
Rank rank = typeRank.read(this.argAt(0), sender); 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))) if (ranks.stream().map(Rank::getPriority).anyMatch(s -> s.equals(priority)))
{ {

View File

@ -504,7 +504,6 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
// RAW // RAW
public EntityInternalMap<Rank> getRanks() { return this.ranks; } public EntityInternalMap<Rank> getRanks() { return this.ranks; }
// FINER // FINER
@ -522,17 +521,12 @@ public class Faction extends Entity<Faction> implements FactionsParticipator, MP
private EntityInternalMap<Rank> createRankMap() 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 leader = new Rank("Leader", 400, "**");
Rank officer = new Rank("Officer", 300, "*"); Rank officer = new Rank("Officer", 300, "*");
Rank member = new Rank("Member", 200, "+"); Rank member = new Rank("Member", 200, "+");
Rank recruit = new Rank("Recruit", 100, "-"); 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(leader);
ret.attach(officer); ret.attach(officer);
ret.attach(member); ret.attach(member);