From aa0edb28b725e49e2966123717f6e28f3202dd35 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 12 Nov 2014 11:34:43 +0100 Subject: [PATCH] Add Expansions command and placeholders. --- .../java/com/massivecraft/factions/Perm.java | 1 + .../factions/cmd/CmdFactions.java | 6 +++ .../factions/cmd/CmdFactionsExpansions.java | 53 +++++++++++++++++++ .../factions/cmd/CmdFactionsXPlaceholder.java | 42 +++++++++++++++ .../event/EventFactionsExpansions.java | 39 ++++++++++++++ src/main/resources/plugin.yml | 3 ++ 6 files changed, 144 insertions(+) create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsExpansions.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdFactionsXPlaceholder.java create mode 100644 src/main/java/com/massivecraft/factions/event/EventFactionsExpansions.java diff --git a/src/main/java/com/massivecraft/factions/Perm.java b/src/main/java/com/massivecraft/factions/Perm.java index 54dfadc0..c427ba30 100644 --- a/src/main/java/com/massivecraft/factions/Perm.java +++ b/src/main/java/com/massivecraft/factions/Perm.java @@ -19,6 +19,7 @@ public enum Perm DEMOTE("demote"), DESCRIPTION("description"), DISBAND("disband"), + EXPANSIONS("expansions"), FACTION("faction"), FLAG("flag"), HOME("home"), diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java index b1ff1976..5dc0644d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactions.java @@ -36,6 +36,7 @@ public class CmdFactions extends FactionsCommand public CmdFactionsOfficer cmdFactionsOfficer = new CmdFactionsOfficer(); public CmdFactionsLeader cmdFactionsLeader = new CmdFactionsLeader(); public CmdFactionsMoney cmdFactionsMoney = new CmdFactionsMoney(); + public CmdFactionsXPlaceholder cmdFactionsTax = new CmdFactionsXPlaceholder("FactionsTax", "tax"); public CmdFactionsSeeChunk cmdFactionsSeeChunk = new CmdFactionsSeeChunk(); public CmdFactionsSeeChunkOld cmdFactionsSeeChunkOld = new CmdFactionsSeeChunkOld(); public CmdFactionsAccess cmdFactionsAccess = new CmdFactionsAccess(); @@ -46,6 +47,8 @@ public class CmdFactions extends FactionsCommand public CmdFactionsPerm cmdFactionsPerm = new CmdFactionsPerm(); public CmdFactionsFlag cmdFactionsFlag = new CmdFactionsFlag(); public CmdFactionsDisband cmdFactionsDisband = new CmdFactionsDisband(); + public CmdFactionsExpansions cmdFactionsExpansions = new CmdFactionsExpansions(); + public CmdFactionsXPlaceholder cmdFactionsDynmap = new CmdFactionsXPlaceholder("FactionsDynmap", "dynmap"); public CmdFactionsAdmin cmdFactionsAdmin = new CmdFactionsAdmin(); public CmdFactionsPowerBoost cmdFactionsPowerBoost = new CmdFactionsPowerBoost(); public VersionCommand cmdFactionsVersion = new VersionCommand(Factions.get(), Perm.VERSION.node, "v", "version"); @@ -80,6 +83,7 @@ public class CmdFactions extends FactionsCommand this.addSubCommand(this.cmdFactionsOfficer); this.addSubCommand(this.cmdFactionsLeader); this.addSubCommand(this.cmdFactionsMoney); + this.addSubCommand(this.cmdFactionsTax); this.addSubCommand(this.cmdFactionsSeeChunk); this.addSubCommand(this.cmdFactionsSeeChunkOld); this.addSubCommand(this.cmdFactionsAccess); @@ -90,6 +94,8 @@ public class CmdFactions extends FactionsCommand this.addSubCommand(this.cmdFactionsPerm); this.addSubCommand(this.cmdFactionsFlag); this.addSubCommand(this.cmdFactionsDisband); + this.addSubCommand(this.cmdFactionsExpansions); + this.addSubCommand(this.cmdFactionsDynmap); this.addSubCommand(this.cmdFactionsAdmin); this.addSubCommand(this.cmdFactionsPowerBoost); this.addSubCommand(this.cmdFactionsVersion); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsExpansions.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsExpansions.java new file mode 100644 index 00000000..827cfc61 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsExpansions.java @@ -0,0 +1,53 @@ +package com.massivecraft.factions.cmd; + +import java.util.Map.Entry; + +import com.massivecraft.factions.event.EventFactionsExpansions; +import com.massivecraft.factions.Perm; +import com.massivecraft.massivecore.cmd.req.ReqHasPerm; +import com.massivecraft.massivecore.util.Txt; + +public class CmdFactionsExpansions extends FactionsCommand +{ + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsExpansions() + { + // Aliases + this.addAliases("e", "expansions"); + + // Requirements + this.addRequirements(ReqHasPerm.get(Perm.EXPANSIONS.node)); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() + { + // Event + EventFactionsExpansions event = new EventFactionsExpansions(sender); + event.run(); + + // Title + msg(Txt.titleize("Factions Expansions")); + + // Lines + for (Entry entry : event.getExpansions().entrySet()) + { + String name = entry.getKey(); + Boolean installed = entry.getValue(); + String format = (installed ? "[X] %s" : "[ ] %s"); + msg(format, name); + } + + // URL Suggestion + msg("Learn all about expansions in the online documentation:"); + msg("http://www.massivecraft.com/factions"); + } + +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsXPlaceholder.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsXPlaceholder.java new file mode 100644 index 00000000..b680c171 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsXPlaceholder.java @@ -0,0 +1,42 @@ +package com.massivecraft.factions.cmd; + +public class CmdFactionsXPlaceholder extends FactionsCommand +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + public String extensionName; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public CmdFactionsXPlaceholder(String extensionName, String... aliases) + { + // Fields + this.extensionName = extensionName; + + // Aliases + this.addAliases(aliases); + + // Desc + this.setDesc("Use " + extensionName); + + // Args + this.setErrorOnToManyArgs(false); + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void perform() + { + msg("The extension %s isn't installed.", this.extensionName); + msg("Learn more and download the extension here:"); + msg("http://www.massivecraft.com/%s", this.extensionName.toLowerCase()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/event/EventFactionsExpansions.java b/src/main/java/com/massivecraft/factions/event/EventFactionsExpansions.java new file mode 100644 index 00000000..55bcfea7 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/event/EventFactionsExpansions.java @@ -0,0 +1,39 @@ +package com.massivecraft.factions.event; + +import java.util.Map; + +import org.bukkit.command.CommandSender; +import org.bukkit.event.HandlerList; + +import com.massivecraft.massivecore.CaseInsensitiveComparator; +import com.massivecraft.massivecore.collections.MassiveTreeMap; + +public class EventFactionsExpansions extends EventFactionsAbstractSender +{ + // -------------------------------------------- // + // REQUIRED EVENT CODE + // -------------------------------------------- // + + private static final HandlerList handlers = new HandlerList(); + @Override public HandlerList getHandlers() { return handlers; } + public static HandlerList getHandlerList() { return handlers; } + + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + private final MassiveTreeMap expansions = new MassiveTreeMap(CaseInsensitiveComparator.get()); + public Map getExpansions() { return this.expansions; } + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public EventFactionsExpansions(CommandSender sender) + { + super(sender); + this.getExpansions().put("FactionsTax", false); + this.getExpansions().put("FactionsDynmap", false); + } + +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 66ec783b..3c7a1eff 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -19,6 +19,7 @@ permissions: factions.demote: {description: demote lesser members in your faction, default: false} factions.description: {description: change faction description, default: false} factions.disband: {description: disband faction, 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} factions.home: {description: teleport to faction home, default: false} @@ -78,6 +79,7 @@ permissions: factions.demote: true factions.description: true factions.disband: true + factions.expansions: true factions.faction: true factions.flag: true factions.home: true @@ -160,6 +162,7 @@ permissions: factions.demote: true factions.description: true factions.disband: true + factions.expansions: true factions.faction: true factions.flag: true factions.home: true