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.
This commit is contained in:
parent
4852ac6be4
commit
4db185e3ee
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -0,0 +1,9 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
public class CmdDemote extends FPromoteCommand {
|
||||
|
||||
public CmdDemote() {
|
||||
aliases.add("demote");
|
||||
this.relative = -1;
|
||||
}
|
||||
}
|
10
src/main/java/com/massivecraft/factions/cmd/CmdPromote.java
Normal file
10
src/main/java/com/massivecraft/factions/cmd/CmdPromote.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 "";
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ public enum Action {
|
||||
TERRITORY("territory"),
|
||||
ACCESS("access"),
|
||||
DISBAND("disband"),
|
||||
PROMOTE("promote"),
|
||||
PERMS("perms");
|
||||
|
||||
private String name;
|
||||
|
@ -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<Action, Access> 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() {
|
||||
|
@ -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<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"),
|
||||
@ -382,6 +384,12 @@ public enum TL {
|
||||
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"),
|
||||
@ -657,6 +665,7 @@ public enum TL {
|
||||
ROLE_ADMIN("admin"),
|
||||
ROLE_MODERATOR("moderator"),
|
||||
ROLE_NORMAL("normal member"),
|
||||
ROLE_RECRUIT("recruit"),
|
||||
|
||||
/**
|
||||
* Region types.
|
||||
|
Loading…
Reference in New Issue
Block a user