From d24ed94cf83a9e985c046425bca68cb490f8cbd7 Mon Sep 17 00:00:00 2001 From: Magnus Ulf Date: Thu, 24 Jan 2019 19:04:42 +0100 Subject: [PATCH] Reimplement (sorta) dynamic command registration --- plugin.yml | 13 +++-- src/com/massivecraft/factions/Perm.java | 3 ++ .../factions/cmd/CmdFactions.java | 3 +- .../cmd/CmdFactionsDocumentation.java | 12 +++++ .../cmd/CmdFactionsDocumentationPower.java | 38 +++++++++++++ .../cmd/CmdFactionsDocumentationRanks.java | 54 +++++++++++++++++++ .../cmd/FactionsCommandDocumentation.java | 44 +++++++++++++++ 7 files changed, 162 insertions(+), 5 deletions(-) create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsDocumentationPower.java create mode 100644 src/com/massivecraft/factions/cmd/CmdFactionsDocumentationRanks.java create mode 100644 src/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java diff --git a/plugin.yml b/plugin.yml index c7824af2..1d96ae33 100644 --- a/plugin.yml +++ b/plugin.yml @@ -7,10 +7,6 @@ authors: [Madus, Cayorion, Ulumulu1510, MarkehMe, Brettflan] depend: [MassiveCore] softdepend: [PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, LocalAreaChat, LWC, ChatManager, AuthMe, Vault, WorldEdit, WorldGuard] api-version: 1.13 -commands: - f: - description: Factions basecommand - permission: factions.basecommand permissions: # -------------------------------------------- # # THE REAL NODES @@ -31,6 +27,9 @@ permissions: factions.create: {description: create new faction, default: false} factions.description: {description: change faction description, default: false} factions.disband: {description: disband faction, default: false} + factions.documentation: {description: show documentation, default: false} + factions.documentation.power: {description: show power documentation, default: false} + factions.documentation.ranks: {description: show rank documentation, default: false} factions.expansions: {description: list expansions, default: false} factions.faction: {description: show faction information, default: false} factions.flag: {description: manage faction flags, default: false} @@ -127,6 +126,9 @@ permissions: factions.demote: true factions.description: true factions.disband: true + factions.documentation: true + factions.documentation.power: true + factions.documentation.ranks: true factions.expansions: true factions.faction: true factions.flag: true @@ -254,6 +256,9 @@ permissions: factions.demote: true factions.description: true factions.disband: true + factions.documentation: true + factions.documentation.power: true + factions.documentation.ranks: true factions.expansions: true factions.faction: true factions.flag: true diff --git a/src/com/massivecraft/factions/Perm.java b/src/com/massivecraft/factions/Perm.java index f0cb183a..33a629d7 100644 --- a/src/com/massivecraft/factions/Perm.java +++ b/src/com/massivecraft/factions/Perm.java @@ -26,6 +26,9 @@ public enum Perm implements Identified CREATE, DESCRIPTION, DISBAND, + DOCUMENTATION, + DOCUMENTATION_POWER, + DOCUMENTATION_RANKS, EXPANSIONS, FACTION, FLAG, diff --git a/src/com/massivecraft/factions/cmd/CmdFactions.java b/src/com/massivecraft/factions/cmd/CmdFactions.java index 7fc1f4f5..24a99775 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactions.java +++ b/src/com/massivecraft/factions/cmd/CmdFactions.java @@ -21,7 +21,8 @@ public class CmdFactions extends FactionsCommand // -------------------------------------------- // // FIELDS // -------------------------------------------- // - + + public CmdFactionsDocumentation cmdFactionsDocumentation = new CmdFactionsDocumentation(); public CmdFactionsList cmdFactionsList = new CmdFactionsList(); public CmdFactionsFaction cmdFactionsFaction = new CmdFactionsFaction(); public CmdFactionsPlayer cmdFactionsPlayer = new CmdFactionsPlayer(); diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java new file mode 100644 index 00000000..afeb0595 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentation.java @@ -0,0 +1,12 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsDocumentation extends FactionsCommand +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public CmdFactionsDocumentationPower cmdFactionsDocumentationPower = new CmdFactionsDocumentationPower(); + public CmdFactionsDocumentationRanks cmdFactionsDocumentationRanks = new CmdFactionsDocumentationRanks(); + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationPower.java b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationPower.java new file mode 100644 index 00000000..dfb61926 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationPower.java @@ -0,0 +1,38 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.MConf; +import com.massivecraft.massivecore.MassiveException; + +public class CmdFactionsDocumentationPower extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsDocumentationPower() + { + + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException + { + msg("1) All players have an amount of power ranging from %.2f to %.2f.", MConf.get().powerMin, MConf.get().powerMax); + msg("2) The power of a faction is equal to the combined power of all it's members."); + msg("3) Your power is %.2f", msender.getPower()); + msg("4) Your faction's power is %.2f", msenderFaction.getPower()); + msg("5) The amount of chunks a faction can claim is the amount power it has."); + msg("6) For every hour you are online you gain %.2f power.", MConf.get().powerPerHour); + msg("7) Every time you die you power is decreased by %.2f .", MConf.get().powerPerDeath*-1); + if (!MConf.get().canLeaveWithNegativePower && MConf.get().powerMin < 0) + { + msg("8) You can't leave a faction if your power is negative."); + } + + } + +} diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationRanks.java b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationRanks.java new file mode 100644 index 00000000..e564a735 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/CmdFactionsDocumentationRanks.java @@ -0,0 +1,54 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.entity.Rank; +import com.massivecraft.massivecore.MassiveException; +import com.massivecraft.massivecore.mson.Mson; +import com.massivecraft.massivecore.util.Txt; + +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +public class CmdFactionsDocumentationRanks extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsDocumentationRanks() + { + + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() throws MassiveException + { + int i = 1; + msg("" + i++ + ") Ranks divide the faction into groups."); + + List ranks = msenderFaction.getRanks().getAll(Comparator.comparingInt(Rank::getPriority).reversed()); + List rankDesc = ranks.stream().map(r -> r.getDisplayName(msender)).collect(Collectors.toList()); + msg("" + i++ + ") Your faction has: %s", Txt.implodeCommaAndDot(rankDesc, Txt.parse(""))); + + msg("" + i++ + ") Ranks can have a prefix that will be prepended before any player name. Prefixes can be coloured."); + msg("" + i++ + ") All ranks have a priority showed in parentheses after the name."); + + Mson msonLeader = Mson.parse("" + i++ + ") The rank with the highest priority is deemed the “leader rank”" + + "(can be renamed) and only one person can have that rank"); + msonLeader = msonLeader.tooltip("For yor faction the leader rank is" + rankDesc.get(0)); + message(msonLeader); + msg("" + i++ + ") Whenever a new person joins the faction they will be assigned the rank with the lowest priority."); + msg("" + i++ + ") Priorities are important because they determine who can do what." + + "For example: you can’t kick someone with the same or higher rank than yourself." + + "So if you have both Officers, and Co-leaders, do not fear officers kicking co-leaders or the co-leaders kicking each other." + + "They can’t. The same goes for changing ranks, titles and other similar things."); + + msg("" + i++ + ") To show, set or edit ranks do:"); + message(CmdFactions.get().cmdFactionsRank.getTemplate(false, true, sender)); + } + +} diff --git a/src/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java b/src/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java new file mode 100644 index 00000000..4cdfa112 --- /dev/null +++ b/src/com/massivecraft/factions/cmd/FactionsCommandDocumentation.java @@ -0,0 +1,44 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.cmd.req.ReqFactionHomesEnabled; + +public class FactionsCommandDocumentation extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsCommandDocumentation() + { + this.addRequirements(ReqFactionHomesEnabled.get()); + } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public int num = 1; + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void senderFields(boolean set) + { + super.senderFields(set); + + num = 1; + } + + // -------------------------------------------- // + // MESSAGE + // -------------------------------------------- // + + public void msgDoc(String msg, String... args) + { + msg = "" + this.num++ + ") "; + msg(msg, args); + } + +}