2014-11-07 18:49:54 +01:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2014-11-11 16:28:53 +01:00
|
|
|
import com.massivecraft.factions.FPlayer;
|
2019-09-14 21:13:01 +02:00
|
|
|
import com.massivecraft.factions.FactionsPlugin;
|
2014-11-07 18:49:54 +01:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
|
|
|
import com.massivecraft.factions.struct.Relation;
|
|
|
|
import com.massivecraft.factions.util.LazyLocation;
|
2018-02-03 22:04:21 +01:00
|
|
|
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
2014-12-08 00:12:52 +01:00
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
2014-11-07 18:49:54 +01:00
|
|
|
|
|
|
|
public class CmdSetFWarp extends FCommand {
|
2019-12-02 19:55:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @author FactionsUUID Team
|
|
|
|
*/
|
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
public CmdSetFWarp() {
|
2020-01-02 02:59:31 +01:00
|
|
|
this.aliases.addAll(Aliases.setWarp);
|
2019-09-15 11:19:06 +02:00
|
|
|
this.requiredArgs.add("warp name");
|
|
|
|
this.optionalArgs.put("password", "password");
|
2019-09-15 13:51:12 +02:00
|
|
|
this.requirements = new CommandRequirements.Builder(Permission.SETWARP).playerOnly().memberOnly().withAction(PermissableAction.SETWARP).build();
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
@Override
|
|
|
|
public void perform(CommandContext context) {
|
2019-09-15 13:51:12 +02:00
|
|
|
if (context.fPlayer.getRelationToLocation() != Relation.MEMBER) {
|
2019-09-15 11:19:06 +02:00
|
|
|
context.msg(TL.COMMAND_SETFWARP_NOTCLAIMED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String warp = context.argAsString(0);
|
|
|
|
boolean warpExists = context.faction.isWarp(warp);
|
2019-09-15 13:51:12 +02:00
|
|
|
int maxWarps = context.faction.getWarpsLimit();
|
2019-09-15 11:19:06 +02:00
|
|
|
boolean tooManyWarps = maxWarps <= context.faction.getWarps().size();
|
|
|
|
if (tooManyWarps && !warpExists) {
|
|
|
|
context.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps);
|
|
|
|
return;
|
|
|
|
}
|
2019-09-15 13:51:12 +02:00
|
|
|
if (!this.transact(context.fPlayer, context)) {
|
2019-09-15 11:19:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
String password = context.argAsString(1);
|
|
|
|
LazyLocation loc = new LazyLocation(context.player.getLocation());
|
|
|
|
context.faction.setWarp(warp, loc);
|
|
|
|
if (password != null) {
|
|
|
|
context.faction.setWarpPassword(warp, password);
|
|
|
|
}
|
2019-09-15 13:51:12 +02:00
|
|
|
context.msg(TL.COMMAND_SETFWARP_SET, warp, (password != null) ? password : "");
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
private boolean transact(FPlayer player, CommandContext context) {
|
2019-09-15 13:51:12 +02:00
|
|
|
return !FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || context.payForCommand(FactionsPlugin.getInstance().getConfig().getDouble("warp-cost.setwarp", 5.0), TL.COMMAND_SETFWARP_TOSET.toString(), TL.COMMAND_SETFWARP_FORSET.toString());
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_SETFWARP_DESCRIPTION;
|
|
|
|
}
|
2014-11-07 18:49:54 +01:00
|
|
|
}
|
2019-09-14 21:13:01 +02:00
|
|
|
|