From c5a1bb48018ff9375d1445bc0ca6f5b6fd120088 Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Thu, 3 Jan 2019 15:23:06 +0100 Subject: [PATCH] Minor improvements to the rank commands --- .../factions/cmd/CmdFactionsRankEdit.java | 4 ++-- .../cmd/CmdFactionsRankEditCreate.java | 6 ++++-- .../cmd/CmdFactionsRankEditDelete.java | 18 +++++++++++------- .../factions/cmd/CmdFactionsRankEditName.java | 8 +++++--- .../cmd/CmdFactionsRankEditPrefix.java | 4 ++-- .../cmd/CmdFactionsRankEditPriority.java | 6 ++++-- .../massivecraft/factions/entity/Faction.java | 8 +------- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankEdit.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankEdit.java index 66af160c..35a74c50 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankEdit.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRankEdit.java @@ -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("Only the leader can create, edit or delete ranks."); + throw new MassiveException().addMsg("Only the leader can %s ranks.", action); } } diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditCreate.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditCreate.java index 5123a246..2e7fe969 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditCreate.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditCreate.java @@ -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 ranks = faction.getRanks().getAll(); if (ranks.stream().map(Rank::getName).anyMatch(s -> s.equalsIgnoreCase(name))) { diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditDelete.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditDelete.java index 1b4a4cd2..f0a43faf 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditDelete.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditDelete.java @@ -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 ranks = faction.getRanks().getAll(); if (ranks.size() <= 2) { throw new MassiveException().addMsg("A faction must have at least two ranks."); } - var mplayers = faction.getMPlayersWhereRank(rank); + List 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("")); - throw new MassiveException().addMsg("This rank is held by %s change their ranks first.", namesDesc); + int count = mplayers.size(); + List names = mplayers.stream().map(m -> m.getDisplayName(sender)).collect(Collectors.toList()); + String namesDesc = Txt.implodeCommaAnd(names, Txt.parse("")); + String rankRanks = count == 1 ? "rank" : "ranks"; + throw new MassiveException().addMsg("This rank is held by %s change their %s first.", namesDesc, rankRanks); } String visual = rank.getVisual(); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditName.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditName.java index aeac7784..a9327fd3 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditName.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditName.java @@ -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 ranks = faction.getRanks().getAll(); if (ranks.stream().map(Rank::getName).anyMatch(s -> s.equalsIgnoreCase(name))) { throw new MassiveException().addMsg("There is already a rank called %s.", name); } - var priorVisual = rank.getVisual(); + String priorVisual = rank.getVisual(); rank.setName(name); // Visual diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPrefix.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPrefix.java index 6bc52829..7470b1da 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPrefix.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPrefix.java @@ -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 diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java index 14cccada..4b4ef063 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsRankEditPriority.java @@ -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 ranks = faction.getRanks().getAll(); if (ranks.stream().map(Rank::getPriority).anyMatch(s -> s.equals(priority))) { diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index 5f81374f..9733e201 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -504,7 +504,6 @@ public class Faction extends Entity implements FactionsParticipator, MP // RAW - public EntityInternalMap getRanks() { return this.ranks; } // FINER @@ -522,17 +521,12 @@ public class Faction extends Entity implements FactionsParticipator, MP private EntityInternalMap createRankMap() { - var ret = new EntityInternalMap<>(this, Rank.class); + EntityInternalMap 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);