Skip to content

Commit

Permalink
Role updates.
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
drtshock committed Jan 5, 2018
1 parent 4852ac6 commit 4db185e
Show file tree
Hide file tree
Showing 15 changed files with 152 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/massivecraft/factions/Conf.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/massivecraft/factions/Faction.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/massivecraft/factions/cmd/CmdDemote.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.massivecraft.factions.cmd;

public class CmdDemote extends FPromoteCommand {

public CmdDemote() {
aliases.add("demote");
this.relative = -1;
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/massivecraft/factions/cmd/CmdHome.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public void perform() {

// 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();
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/massivecraft/factions/cmd/CmdPromote.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public CmdSetMaxVaults() {
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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/massivecraft/factions/cmd/CmdSethome.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public void perform() {

// 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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -156,6 +158,8 @@ public FCmdRoot() {
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());
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/com/massivecraft/factions/cmd/FPromoteCommand.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public static boolean playerCanBuildDestroyBlock(Player player, Location locatio
}
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ public static boolean playerCanUseItemHere(Player player, Location location, Mat
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;
Expand Down Expand Up @@ -422,7 +422,7 @@ public static boolean canPlayerUseBlock(Player player, Block block, boolean just
}
}

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;
Expand Down
33 changes: 30 additions & 3 deletions src/main/java/com/massivecraft/factions/struct/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
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;
Expand All @@ -26,6 +27,24 @@ public boolean isAtMost(Role 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;
Expand All @@ -44,6 +63,14 @@ public String getPrefix() {
return Conf.prefixMod;
}

if (this == Role.NORMAL) {
return Conf.prefixNormal;
}

if (this == Role.RECRUIT) {
return Conf.prefixRecruit;
}

return "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public enum Action {
TERRITORY("territory"),
ACCESS("access"),
DISBAND("disband"),
PROMOTE("promote"),
PERMS("perms");

private String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public int getDeaths() {
// -------------------------------------------- //


public Access hasPerm(FPlayer fPlayer, Action action) {
public Access getAccess(FPlayer fPlayer, Action action) {
Relation relation = fPlayer.getRelationTo(this);
Map<Action, Access> accessMap = permissions.get(relation);
if (accessMap != null && accessMap.containsKey(action)) {
Expand Down Expand Up @@ -569,12 +569,10 @@ public void refreshFPlayers() {

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() {
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/massivecraft/factions/zcore/util/TL.java
Original file line number Diff line number Diff line change
Expand Up @@ -375,13 +375,21 @@ public enum TL {
COMMAND_PERMANENT_REVOKE("removed permanent status from"),
COMMAND_PERMANENT_YOURS("%1$s has %2$s your faction"),
COMMAND_PERMANENT_OTHER("%s<i> has %s the faction '%s<i>'."),
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"),
COMMAND_PERMANENTPOWER_REVOKE("removed permanentpower status from"),
COMMAND_PERMANENTPOWER_SUCCESS("<i>You %s <h>%s<i>."),
COMMAND_PERMANENTPOWER_FACTION("%s<i> %s your faction"),

COMMAND_PROMOTE_DESCRIPTION("/f promote <name>"),
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<a> - Power / Maxpower: <i>%2$d / %3$d %4$s"),
Expand Down Expand Up @@ -657,6 +665,7 @@ public enum TL {
ROLE_ADMIN("admin"),
ROLE_MODERATOR("moderator"),
ROLE_NORMAL("normal member"),
ROLE_RECRUIT("recruit"),

/**
* Region types.
Expand Down

0 comments on commit 4db185e

Please sign in to comment.