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:
Trent Hensler
2018-01-04 17:17:26 -08:00
parent 4852ac6be4
commit 4db185e3ee
15 changed files with 152 additions and 16 deletions

View File

@@ -0,0 +1,9 @@
package com.massivecraft.factions.cmd;
public class CmdDemote extends FPromoteCommand {
public CmdDemote() {
aliases.add("demote");
this.relative = -1;
}
}

View File

@@ -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();

View 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;
}
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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());

View File

@@ -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;
}
}