Add command to set default rank. Only used by admins.

/f defaultrole <role>
This commit is contained in:
Trent Hensler 2018-01-04 17:37:21 -08:00
parent 4db185e3ee
commit f6bd156f89
7 changed files with 88 additions and 1 deletions

View File

@ -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
// ----------------------------------------------//

View File

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

View File

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

View File

@ -21,6 +21,7 @@ public enum Permission {
CLAIM_RADIUS("claim.radius"),
CONFIG("config"),
CREATE("create"),
DEFAULTRANK("defaultrank"),
DEINVITE("deinvite"),
DESCRIPTION("description"),
DISBAND("disband"),

View File

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

View File

@ -48,6 +48,7 @@ public abstract class MemoryFaction implements Faction, EconomyParticipator {
private long lastDeath;
protected int maxVaults;
protected Map<Relation, Map<Action, Access>> permissions = new HashMap<>();
protected Role defaultRole;
public HashMap<String, List<String>> 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) {

View File

@ -434,6 +434,11 @@ public enum TL {
COMMAND_SCOREBOARD_DESCRIPTION("Scoreboardy things"),
COMMAND_SETDEFAULTROLE_DESCRIPTION("/f defaultrole <role> - 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("<i>You can only set warps in your faction territory."),
COMMAND_SETFWARP_LIMIT("<i>Your Faction already has the max amount of warps set <a>(%1$d)."),
COMMAND_SETFWARP_SET("<i>Set warp <a>%1$s and password <c>'%2$s' <i>to your location."),