2018-01-05 02:17:26 +01:00
|
|
|
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;
|
2018-02-03 21:49:04 +01:00
|
|
|
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
2018-01-05 02:17:26 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2018-03-26 23:43:15 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2018-01-05 02:17:26 +01:00
|
|
|
|
|
|
|
public class FPromoteCommand extends FCommand {
|
|
|
|
|
|
|
|
public int relative = 0;
|
|
|
|
|
|
|
|
public FPromoteCommand() {
|
|
|
|
super();
|
|
|
|
|
2018-01-05 03:10:49 +01:00
|
|
|
this.requiredArgs.add("player");
|
2018-01-05 02:17:26 +01:00
|
|
|
|
2018-01-05 08:01:52 +01:00
|
|
|
this.permission = Permission.PROMOTE.node;
|
2018-01-05 02:17:26 +01:00
|
|
|
this.disableOnLock = true;
|
|
|
|
|
|
|
|
senderMustBePlayer = true;
|
|
|
|
senderMustBeMember = true;
|
|
|
|
senderMustBeModerator = false;
|
|
|
|
senderMustBeAdmin = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() {
|
2018-03-26 23:43:15 +02:00
|
|
|
|
2018-01-05 02:17:26 +01:00
|
|
|
FPlayer target = this.argAsBestFPlayerMatch(0);
|
|
|
|
if (target == null) {
|
|
|
|
msg(TL.GENERIC_NOPLAYERFOUND, this.argAsString(0));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
|
2018-01-05 02:17:26 +01:00
|
|
|
if (!target.getFaction().equals(myFaction)) {
|
|
|
|
msg(TL.COMMAND_PROMOTE_WRONGFACTION, target.getName());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
|
2018-02-03 21:49:04 +01:00
|
|
|
Access access = myFaction.getAccess(fme.getRole(), PermissableAction.PROMOTE);
|
2018-03-26 23:43:15 +02:00
|
|
|
if (fme.getRole() == Role.COLEADER && target.getRole() == Role.ADMIN){
|
|
|
|
fme.msg(TL.COMMAND_PROMOTE_COLEADER_ADMIN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-01-05 02:17:26 +01:00
|
|
|
|
|
|
|
// Well this is messy.
|
|
|
|
if (access == null || access == Access.UNDEFINED) {
|
2018-03-26 23:43:15 +02:00
|
|
|
if (!assertMinRole(Role.COLEADER)) {
|
2018-01-05 02:17:26 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else if (access == Access.DENY) {
|
|
|
|
msg(TL.COMMAND_NOACCESS);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
|
|
|
|
|
2018-01-05 02:17:26 +01:00
|
|
|
Role current = target.getRole();
|
|
|
|
Role promotion = Role.getRelative(current, +relative);
|
|
|
|
if (promotion == null) {
|
|
|
|
fme.msg(TL.COMMAND_PROMOTE_NOTTHATPLAYER);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
|
|
|
|
if (fme == target && fme.getRole() == Role.COLEADER){
|
|
|
|
fme.msg(TL.COMMAND_PROMOTE_COLEADER_ADMIN);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-05 03:10:49 +01:00
|
|
|
String action = relative > 0 ? TL.COMMAND_PROMOTE_PROMOTED.toString() : TL.COMMAND_PROMOTE_DEMOTED.toString();
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
|
2018-01-05 02:17:26 +01:00
|
|
|
// Success!
|
|
|
|
target.setRole(promotion);
|
|
|
|
if (target.isOnline()) {
|
2018-01-05 03:10:49 +01:00
|
|
|
target.msg(TL.COMMAND_PROMOTE_TARGET, action, promotion.nicename);
|
2018-01-05 02:17:26 +01:00
|
|
|
}
|
|
|
|
|
2018-01-05 03:10:49 +01:00
|
|
|
fme.msg(TL.COMMAND_PROMOTE_SUCCESS, action, target.getName(), promotion.nicename);
|
2018-01-05 02:17:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_PROMOTE_DESCRIPTION;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|