2019-03-03 04:51:21 +01:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.FPlayer;
|
|
|
|
import com.massivecraft.factions.Faction;
|
2019-09-14 21:13:01 +02:00
|
|
|
import com.massivecraft.factions.FactionsPlugin;
|
2019-03-03 04:51:21 +01:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2019-09-14 21:13:01 +02:00
|
|
|
import org.bukkit.command.ConsoleCommandSender;
|
2019-03-03 04:51:21 +01:00
|
|
|
|
|
|
|
public class CmdPowerBoost extends FCommand {
|
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
public CmdPowerBoost() {
|
|
|
|
super();
|
|
|
|
this.aliases.add("powerboost");
|
|
|
|
this.requiredArgs.add("plugin|f|player|faction");
|
|
|
|
this.requiredArgs.add("name");
|
|
|
|
this.requiredArgs.add("# or reset");
|
2019-03-03 04:51:21 +01:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
this.requirements = new CommandRequirements.Builder(Permission.POWERBOOST)
|
|
|
|
.build();
|
|
|
|
}
|
2019-03-03 04:51:21 +01:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
@Override
|
|
|
|
public void perform(CommandContext context) {
|
|
|
|
String type = context.argAsString(0).toLowerCase();
|
|
|
|
boolean doPlayer = true;
|
|
|
|
if (type.equals("f") || type.equals("faction")) {
|
|
|
|
doPlayer = false;
|
|
|
|
} else if (!type.equals("plugin") && !type.equals("player")) {
|
|
|
|
context.msg(TL.COMMAND_POWERBOOST_HELP_1);
|
|
|
|
context.msg(TL.COMMAND_POWERBOOST_HELP_2);
|
|
|
|
return;
|
|
|
|
}
|
2019-03-03 04:51:21 +01:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
Double targetPower = context.argAsDouble(2);
|
|
|
|
if (targetPower == null) {
|
|
|
|
if (context.argAsString(2).equalsIgnoreCase("reset")) {
|
|
|
|
targetPower = 0D;
|
|
|
|
} else {
|
|
|
|
context.msg(TL.COMMAND_POWERBOOST_INVALIDNUM);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-03-03 04:51:21 +01:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
String target;
|
2019-03-03 04:51:21 +01:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
if (doPlayer) {
|
|
|
|
FPlayer targetPlayer = context.argAsBestFPlayerMatch(1);
|
|
|
|
if (targetPlayer == null) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-03 04:51:21 +01:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
if (targetPower != 0) {
|
|
|
|
targetPower += targetPlayer.getPowerBoost();
|
|
|
|
}
|
|
|
|
targetPlayer.setPowerBoost(targetPower);
|
|
|
|
target = TL.COMMAND_POWERBOOST_PLAYER.format(targetPlayer.getName());
|
|
|
|
} else {
|
|
|
|
Faction targetFaction = context.argAsFaction(1);
|
|
|
|
if (targetFaction == null) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-03 04:51:21 +01:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
if (targetPower != 0) {
|
|
|
|
targetPower += targetFaction.getPowerBoost();
|
|
|
|
}
|
|
|
|
targetFaction.setPowerBoost(targetPower);
|
|
|
|
target = TL.COMMAND_POWERBOOST_FACTION.format(targetFaction.getTag());
|
|
|
|
}
|
2019-03-03 04:51:21 +01:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
int roundedPower = (int) Math.round(targetPower);
|
|
|
|
context.msg(TL.COMMAND_POWERBOOST_BOOST, target, roundedPower);
|
|
|
|
if (!(context.sender instanceof ConsoleCommandSender)) {
|
|
|
|
FactionsPlugin.getInstance().log(TL.COMMAND_POWERBOOST_BOOSTLOG.toString(), context.fPlayer.getName(), target, roundedPower);
|
|
|
|
}
|
|
|
|
}
|
2019-03-03 04:51:21 +01:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_POWERBOOST_DESCRIPTION;
|
|
|
|
}
|
2019-03-03 04:51:21 +01:00
|
|
|
}
|