From f6bd156f8966424b6b2f4cad5b68f791c8741a95 Mon Sep 17 00:00:00 2001 From: Trent Hensler Date: Thu, 4 Jan 2018 17:37:21 -0800 Subject: [PATCH] Add command to set default rank. Only used by admins. /f defaultrole --- .../com/massivecraft/factions/Faction.java | 4 ++ .../factions/cmd/CmdSetDefaultRole.java | 41 +++++++++++++++++++ .../massivecraft/factions/cmd/FCmdRoot.java | 2 + .../factions/struct/Permission.java | 1 + .../massivecraft/factions/struct/Role.java | 18 ++++++++ .../factions/zcore/persist/MemoryFaction.java | 18 +++++++- .../massivecraft/factions/zcore/util/TL.java | 5 +++ 7 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdSetDefaultRole.java diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index 100b4d5e..0c9aa59d 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -219,6 +219,10 @@ public interface Faction extends EconomyParticipator { // promotes new leader, or disbands faction if no other members left public void promoteNewLeader(); + public Role getDefaultRole(); + + public void setDefaultRole(Role role); + // ----------------------------------------------// // Messages // ----------------------------------------------// diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSetDefaultRole.java b/src/main/java/com/massivecraft/factions/cmd/CmdSetDefaultRole.java new file mode 100644 index 00000000..8dfa36a7 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSetDefaultRole.java @@ -0,0 +1,41 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.struct.Role; +import com.massivecraft.factions.zcore.util.TL; + +public class CmdSetDefaultRole extends FCommand { + + public CmdSetDefaultRole() { + super(); + + this.aliases.add("defaultrole"); + this.aliases.add("defaultrank"); + this.aliases.add("default"); + this.aliases.add("def"); + this.requiredArgs.add("role"); + + this.senderMustBeMember = true; + this.senderMustBeAdmin = true; + this.senderMustBePlayer = true; + + this.permission = Permission.DEFAULTRANK.node; + } + + @Override + public void perform() { + Role target = Role.fromString(argAsString(0).toUpperCase()); + if (target == null) { + msg(TL.COMMAND_SETDEFAULTROLE_INVALIDROLE, argAsString(0)); + return; + } + + myFaction.setDefaultRole(target); + msg(TL.COMMAND_SETDEFAULTROLE_SUCCESS, target.nicename); + } + + @Override + public TL getUsageTranslation() { + return TL.COMMAND_SETDEFAULTROLE_DESCRIPTION; + } +} diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index 5a02ab4d..b8dfdfa9 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -73,6 +73,7 @@ public class FCmdRoot extends FCommand { public CmdPerm cmdPerm = new CmdPerm(); public CmdPromote cmdPromote = new CmdPromote(); public CmdDemote cmdDemote = new CmdDemote(); + public CmdSetDefaultRole cmdSetDefaultRole = new CmdSetDefaultRole(); public FCmdRoot() { super(); @@ -160,6 +161,7 @@ public class FCmdRoot extends FCommand { this.addSubCommand(this.cmdPerm); this.addSubCommand(this.cmdPromote); this.addSubCommand(this.cmdDemote); + this.addSubCommand(this.cmdSetDefaultRole); if (P.p.isHookedPlayervaults()) { P.p.log("Found playervaults hook, adding /f vault and /f setmaxvault commands."); this.addSubCommand(new CmdSetMaxVaults()); diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index ce1e8263..913818c6 100644 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -21,6 +21,7 @@ public enum Permission { CLAIM_RADIUS("claim.radius"), CONFIG("config"), CREATE("create"), + DEFAULTRANK("defaultrank"), DEINVITE("deinvite"), DESCRIPTION("description"), DISBAND("disband"), diff --git a/src/main/java/com/massivecraft/factions/struct/Role.java b/src/main/java/com/massivecraft/factions/struct/Role.java index 426d739a..fb48e2b9 100644 --- a/src/main/java/com/massivecraft/factions/struct/Role.java +++ b/src/main/java/com/massivecraft/factions/struct/Role.java @@ -45,6 +45,24 @@ public enum Role { return null; } + public static Role fromString(String check) { + switch (check.toLowerCase()) { + case "admin": + return ADMIN; + case "mod": + case "moderator": + return MODERATOR; + case "normal": + case "member": + return NORMAL; + case "recruit": + case "rec": + return RECRUIT; + } + + return null; + } + @Override public String toString() { return this.nicename; diff --git a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java index dc1eb6ed..17fcf2cd 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -48,6 +48,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { private long lastDeath; protected int maxVaults; protected Map> permissions = new HashMap<>(); + protected Role defaultRole; public HashMap> getAnnouncements() { return this.announcements; @@ -357,6 +358,14 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { } } + public Role getDefaultRole() { + return this.defaultRole; + } + + public void setDefaultRole(Role role) { + this.defaultRole = role; + } + // -------------------------------------------- // // Construct // -------------------------------------------- // @@ -376,6 +385,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { this.powerBoost = 0.0; this.foundedDate = System.currentTimeMillis(); this.maxVaults = Conf.defaultMaxVaults; + this.defaultRole = Role.NORMAL; resetPerms(); // Reset on new Faction so it has default values. } @@ -399,6 +409,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { fplayers = new HashSet<>(); invites = old.invites; announcements = old.announcements; + this.defaultRole = Role.NORMAL; resetPerms(); // Reset on new Faction so it has default values. } @@ -568,7 +579,12 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { } public boolean addFPlayer(FPlayer fplayer) { - return !this.isPlayerFreeType() && fplayers.add(fplayer); + if (!this.isPlayerFreeType() && fplayers.add(fplayer)) { + fplayer.setRole(defaultRole); // set default role on join. + return true; + } + + return false; } public boolean removeFPlayer(FPlayer fplayer) { diff --git a/src/main/java/com/massivecraft/factions/zcore/util/TL.java b/src/main/java/com/massivecraft/factions/zcore/util/TL.java index 535440da..021566b5 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -434,6 +434,11 @@ public enum TL { COMMAND_SCOREBOARD_DESCRIPTION("Scoreboardy things"), + COMMAND_SETDEFAULTROLE_DESCRIPTION("/f defaultrole - set your Faction's default role."), + COMMAND_SETDEFAULTROLE_NOTTHATROLE("You cannot set the default to admin."), + COMMAND_SETDEFAULTROLE_SUCCESS("Set default role of your faction to %1$s"), + COMMAND_SETDEFAULTROLE_INVALIDROLE("Couldn't find matching role for %1$s"), + COMMAND_SETFWARP_NOTCLAIMED("You can only set warps in your faction territory."), COMMAND_SETFWARP_LIMIT("Your Faction already has the max amount of warps set (%1$d)."), COMMAND_SETFWARP_SET("Set warp %1$s and password '%2$s' to your location."),