From 4db185e3ee757be2bea410f6e3164737c612bfc1 Mon Sep 17 00:00:00 2001 From: Trent Hensler Date: Thu, 4 Jan 2018 17:17:26 -0800 Subject: [PATCH] Role updates. * Adds recruit role below the normal role. * Adds /f promote and demote. Access to this command defaults to moderator if not set in /f perm * Default role is still set to recruite. Will have to /f demote to set players to that rank. --- .../java/com/massivecraft/factions/Conf.java | 2 + .../com/massivecraft/factions/Faction.java | 2 +- .../massivecraft/factions/cmd/CmdDemote.java | 9 +++ .../massivecraft/factions/cmd/CmdHome.java | 4 +- .../massivecraft/factions/cmd/CmdPromote.java | 10 +++ .../factions/cmd/CmdSetMaxVaults.java | 4 +- .../massivecraft/factions/cmd/CmdSethome.java | 4 +- .../massivecraft/factions/cmd/FCmdRoot.java | 4 + .../factions/cmd/FPromoteCommand.java | 76 +++++++++++++++++++ .../listeners/FactionsBlockListener.java | 2 +- .../listeners/FactionsPlayerListener.java | 4 +- .../massivecraft/factions/struct/Role.java | 33 +++++++- .../factions/zcore/fperms/Action.java | 1 + .../factions/zcore/persist/MemoryFaction.java | 4 +- .../massivecraft/factions/zcore/util/TL.java | 9 +++ 15 files changed, 152 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdDemote.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdPromote.java create mode 100644 src/main/java/com/massivecraft/factions/cmd/FPromoteCommand.java diff --git a/src/main/java/com/massivecraft/factions/Conf.java b/src/main/java/com/massivecraft/factions/Conf.java index 359cad41..8eb6148f 100644 --- a/src/main/java/com/massivecraft/factions/Conf.java +++ b/src/main/java/com/massivecraft/factions/Conf.java @@ -36,6 +36,8 @@ public class Conf { public static String prefixAdmin = "**"; public static String prefixMod = "*"; + public static String prefixRecruit = "-"; + public static String prefixNormal = "+"; public static int factionTagLengthMin = 3; public static int factionTagLengthMax = 10; diff --git a/src/main/java/com/massivecraft/factions/Faction.java b/src/main/java/com/massivecraft/factions/Faction.java index 17588592..100b4d5e 100644 --- a/src/main/java/com/massivecraft/factions/Faction.java +++ b/src/main/java/com/massivecraft/factions/Faction.java @@ -138,7 +138,7 @@ public interface Faction extends EconomyParticipator { public int getDeaths(); - public Access hasPerm(FPlayer fPlayer, Action perm); + public Access getAccess(FPlayer fPlayer, Action perm); public void setPermission(Relation relation, Action action, Access access); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdDemote.java b/src/main/java/com/massivecraft/factions/cmd/CmdDemote.java new file mode 100644 index 00000000..2890d2f5 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdDemote.java @@ -0,0 +1,9 @@ +package com.massivecraft.factions.cmd; + +public class CmdDemote extends FPromoteCommand { + + public CmdDemote() { + aliases.add("demote"); + this.relative = -1; + } +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java index ee2ece1d..2891d529 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdHome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdHome.java @@ -68,8 +68,8 @@ public class CmdHome extends FCommand { // if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby if (Conf.homesTeleportAllowedEnemyDistance > 0 && - !faction.isSafeZone() && - (!fme.isInOwnTerritory() || (fme.isInOwnTerritory() && !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory))) { + !faction.isSafeZone() && + (!fme.isInOwnTerritory() || (fme.isInOwnTerritory() && !Conf.homesTeleportIgnoreEnemiesIfInOwnTerritory))) { World w = loc.getWorld(); double x = loc.getX(); double y = loc.getY(); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdPromote.java b/src/main/java/com/massivecraft/factions/cmd/CmdPromote.java new file mode 100644 index 00000000..699e740d --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdPromote.java @@ -0,0 +1,10 @@ +package com.massivecraft.factions.cmd; + +public class CmdPromote extends FPromoteCommand { + + public CmdPromote() { + aliases.add("promote"); + aliases.add("promo"); + this.relative = 1; + } +} diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSetMaxVaults.java b/src/main/java/com/massivecraft/factions/cmd/CmdSetMaxVaults.java index 564de0d8..ee1b9129 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSetMaxVaults.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSetMaxVaults.java @@ -27,12 +27,12 @@ public class CmdSetMaxVaults extends FCommand { public void perform() { Faction targetFaction = argAsFaction(0); int value = argAsInt(1, -1); - if(value < 0) { + if (value < 0) { sender.sendMessage(ChatColor.RED + "Number must be greater than 0."); return; } - if(targetFaction == null) { + if (targetFaction == null) { sender.sendMessage(ChatColor.RED + "Couldn't find Faction: " + ChatColor.YELLOW + argAsString(0)); return; } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java b/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java index 36f0a262..016e0ff1 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdSethome.java @@ -50,8 +50,8 @@ public class CmdSethome extends FCommand { // Can the player set the faction home HERE? if (!Permission.BYPASS.has(me) && - Conf.homesMustBeInClaimedTerritory && - Board.getInstance().getFactionAt(new FLocation(me)) != faction) { + Conf.homesMustBeInClaimedTerritory && + Board.getInstance().getFactionAt(new FLocation(me)) != faction) { fme.msg(TL.COMMAND_SETHOME_NOTCLAIMED); return; } diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index fcee1046..5a02ab4d 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -71,6 +71,8 @@ public class FCmdRoot extends FCommand { public CmdTop cmdTop = new CmdTop(); public CmdAHome cmdAHome = new CmdAHome(); public CmdPerm cmdPerm = new CmdPerm(); + public CmdPromote cmdPromote = new CmdPromote(); + public CmdDemote cmdDemote = new CmdDemote(); public FCmdRoot() { super(); @@ -156,6 +158,8 @@ public class FCmdRoot extends FCommand { this.addSubCommand(this.cmdTop); this.addSubCommand(this.cmdAHome); this.addSubCommand(this.cmdPerm); + this.addSubCommand(this.cmdPromote); + this.addSubCommand(this.cmdDemote); 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/cmd/FPromoteCommand.java b/src/main/java/com/massivecraft/factions/cmd/FPromoteCommand.java new file mode 100644 index 00000000..1112b0ec --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/FPromoteCommand.java @@ -0,0 +1,76 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.struct.Permission; +import com.massivecraft.factions.struct.Role; +import com.massivecraft.factions.zcore.fperms.Access; +import com.massivecraft.factions.zcore.fperms.Action; +import com.massivecraft.factions.zcore.util.TL; + +public class FPromoteCommand extends FCommand { + + public int relative = 0; + + public FPromoteCommand() { + super(); + + this.optionalArgs.put("player name", "name"); + //this.optionalArgs.put("", ""); + + this.permission = Permission.MOD.node; + this.disableOnLock = true; + + senderMustBePlayer = true; + senderMustBeMember = true; + senderMustBeModerator = false; + senderMustBeAdmin = false; + } + + @Override + public void perform() { + FPlayer target = this.argAsBestFPlayerMatch(0); + if (target == null) { + msg(TL.GENERIC_NOPLAYERFOUND, this.argAsString(0)); + return; + } + + if (!target.getFaction().equals(myFaction)) { + msg(TL.COMMAND_PROMOTE_WRONGFACTION, target.getName()); + return; + } + + Access access = myFaction.getAccess(fme, Action.PROMOTE); + + // Well this is messy. + if (access == null || access == Access.UNDEFINED) { + if (!assertMinRole(Role.MODERATOR)) { + msg(TL.COMMAND_NOACCESS); + return; + } + } else if (access == Access.DENY) { + msg(TL.COMMAND_NOACCESS); + return; + } + + Role current = target.getRole(); + Role promotion = Role.getRelative(current, +relative); + if (promotion == null) { + fme.msg(TL.COMMAND_PROMOTE_NOTTHATPLAYER); + return; + } + + // Success! + target.setRole(promotion); + if (target.isOnline()) { + target.msg(TL.COMMAND_PROMOTE_TARGET, promotion.nicename); + } + + target.msg(TL.COMMAND_PROMOTE_SUCCESS, target.getName(), promotion.nicename); + } + + @Override + public TL getUsageTranslation() { + return TL.COMMAND_PROMOTE_DESCRIPTION; + } + +} diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java index eca300a1..9b60b67a 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsBlockListener.java @@ -252,7 +252,7 @@ public class FactionsBlockListener implements Listener { } } - Access access = otherFaction.hasPerm(me, Action.valueOf(action)); + Access access = otherFaction.getAccess(me, Action.valueOf(action)); if (access != null && access != Access.UNDEFINED) { // TODO: Update this once new access values are added other than just allow / deny. return access == Access.ALLOW; diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java index 68b90e8e..ba53fc52 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java +++ b/src/main/java/com/massivecraft/factions/listeners/FactionsPlayerListener.java @@ -355,7 +355,7 @@ public class FactionsPlayerListener implements Listener { Relation rel = myFaction.getRelationTo(otherFaction); - Access access = otherFaction.hasPerm(me, com.massivecraft.factions.zcore.fperms.Action.valueOf("items")); + Access access = otherFaction.getAccess(me, com.massivecraft.factions.zcore.fperms.Action.valueOf("items")); if (access != null && access != Access.UNDEFINED) { // TODO: Update this once new access values are added other than just allow / deny. return access == Access.ALLOW; @@ -422,7 +422,7 @@ public class FactionsPlayerListener implements Listener { } } - Access access = otherFaction.hasPerm(me, com.massivecraft.factions.zcore.fperms.Action.BUILD); + Access access = otherFaction.getAccess(me, com.massivecraft.factions.zcore.fperms.Action.BUILD); if (access != null && access != Access.UNDEFINED) { // TODO: Update this once new access values are added other than just allow / deny. return access == Access.ALLOW; diff --git a/src/main/java/com/massivecraft/factions/struct/Role.java b/src/main/java/com/massivecraft/factions/struct/Role.java index 1cdd505a..426d739a 100644 --- a/src/main/java/com/massivecraft/factions/struct/Role.java +++ b/src/main/java/com/massivecraft/factions/struct/Role.java @@ -4,9 +4,10 @@ import com.massivecraft.factions.Conf; import com.massivecraft.factions.zcore.util.TL; public enum Role { - ADMIN(2, TL.ROLE_ADMIN), - MODERATOR(1, TL.ROLE_MODERATOR), - NORMAL(0, TL.ROLE_NORMAL); + ADMIN(3, TL.ROLE_ADMIN), + MODERATOR(2, TL.ROLE_MODERATOR), + NORMAL(1, TL.ROLE_NORMAL), + RECRUIT(0, TL.ROLE_RECRUIT); public final int value; public final String nicename; @@ -26,6 +27,24 @@ public enum Role { return this.value <= role.value; } + public static Role getRelative(Role role, int relative) { + return Role.getByValue(role.value + relative); + } + + public static Role getByValue(int value) { + switch (value) { + case 0: + return RECRUIT; + case 1: + return NORMAL; + case 2: + return MODERATOR; + case 3: return ADMIN; + } + + return null; + } + @Override public String toString() { return this.nicename; @@ -44,6 +63,14 @@ public enum Role { return Conf.prefixMod; } + if (this == Role.NORMAL) { + return Conf.prefixNormal; + } + + if (this == Role.RECRUIT) { + return Conf.prefixRecruit; + } + return ""; } } diff --git a/src/main/java/com/massivecraft/factions/zcore/fperms/Action.java b/src/main/java/com/massivecraft/factions/zcore/fperms/Action.java index 318f94ea..8b380b27 100644 --- a/src/main/java/com/massivecraft/factions/zcore/fperms/Action.java +++ b/src/main/java/com/massivecraft/factions/zcore/fperms/Action.java @@ -17,6 +17,7 @@ public enum Action { TERRITORY("territory"), ACCESS("access"), DISBAND("disband"), + PROMOTE("promote"), PERMS("perms"); private String name; 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 cb61688e..dc1eb6ed 100644 --- a/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java +++ b/src/main/java/com/massivecraft/factions/zcore/persist/MemoryFaction.java @@ -323,7 +323,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { // -------------------------------------------- // - public Access hasPerm(FPlayer fPlayer, Action action) { + public Access getAccess(FPlayer fPlayer, Action action) { Relation relation = fPlayer.getRelationTo(this); Map accessMap = permissions.get(relation); if (accessMap != null && accessMap.containsKey(action)) { @@ -569,12 +569,10 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator { public boolean addFPlayer(FPlayer fplayer) { return !this.isPlayerFreeType() && fplayers.add(fplayer); - } public boolean removeFPlayer(FPlayer fplayer) { return !this.isPlayerFreeType() && fplayers.remove(fplayer); - } public int getSize() { 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 47e1897a..535440da 100644 --- a/src/main/java/com/massivecraft/factions/zcore/util/TL.java +++ b/src/main/java/com/massivecraft/factions/zcore/util/TL.java @@ -375,6 +375,8 @@ public enum TL { COMMAND_PERMANENT_REVOKE("removed permanent status from"), COMMAND_PERMANENT_YOURS("%1$s has %2$s your faction"), COMMAND_PERMANENT_OTHER("%s has %s the faction '%s'."), + COMMAND_PROMOTE_TARGET("You've been promoted to %1$s"), + COMMAND_PROMOTE_SUCCESS("You successfully promoted %1$s to %2$s"), COMMAND_PERMANENTPOWER_DESCRIPTION("Toggle faction power permanence"), //TODO: This a real word? COMMAND_PERMANENTPOWER_GRANT("added permanentpower status to"), @@ -382,6 +384,12 @@ public enum TL { COMMAND_PERMANENTPOWER_SUCCESS("You %s %s."), COMMAND_PERMANENTPOWER_FACTION("%s %s your faction"), + COMMAND_PROMOTE_DESCRIPTION("/f promote "), + COMMAND_PROMOTE_WRONGFACTION("%1$s is not part of your faction."), + COMMAND_NOACCESS("You don't have access to that."), + COMMAND_PROMOTE_NOTTHATPLAYER("That player cannot be promoted."), + + COMMAND_POWER_TOSHOW("to show player power info"), COMMAND_POWER_FORSHOW("for showing player power info"), COMMAND_POWER_POWER("%1$s - Power / Maxpower: %2$d / %3$d %4$s"), @@ -657,6 +665,7 @@ public enum TL { ROLE_ADMIN("admin"), ROLE_MODERATOR("moderator"), ROLE_NORMAL("normal member"), + ROLE_RECRUIT("recruit"), /** * Region types.