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-09-15 11:08:00 +02:00
|
|
|
public CmdSetFWarp() {
|
|
|
|
super();
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
this.aliases.add("setwarp");
|
|
|
|
this.aliases.add("sw");
|
|
|
|
this.requiredArgs.add("warp name");
|
|
|
|
this.optionalArgs.put("password", "password");
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
this.requirements = new CommandRequirements.Builder(Permission.SETWARP)
|
|
|
|
.playerOnly()
|
|
|
|
.memberOnly()
|
|
|
|
.withAction(PermissableAction.SETWARP)
|
|
|
|
.build();
|
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
@Override
|
|
|
|
public void perform(CommandContext context) {
|
|
|
|
if (!(context.fPlayer.getRelationToLocation() == Relation.MEMBER)) {
|
|
|
|
context.msg(TL.COMMAND_SETFWARP_NOTCLAIMED);
|
|
|
|
return;
|
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
String warp = context.argAsString(0);
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
// Checks if warp with same name already exists and ignores maxWarp check if it does.
|
|
|
|
boolean warpExists = context.faction.isWarp(warp);
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
int maxWarps = FactionsPlugin.getInstance().getConfig().getInt("max-warps", 5);
|
|
|
|
boolean tooManyWarps = maxWarps <= context.faction.getWarps().size();
|
|
|
|
if (tooManyWarps && !warpExists) {
|
|
|
|
context.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps);
|
|
|
|
return;
|
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
if (!transact(context.fPlayer, context)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
String password = context.argAsString(1);
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
LazyLocation loc = new LazyLocation(context.player.getLocation());
|
|
|
|
context.faction.setWarp(warp, loc);
|
|
|
|
if (password != null) {
|
|
|
|
context.faction.setWarpPassword(warp, password);
|
|
|
|
}
|
|
|
|
context.msg(TL.COMMAND_SETFWARP_SET, warp, password != null ? password : "");
|
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:08:00 +02:00
|
|
|
private boolean transact(FPlayer player, CommandContext context) {
|
|
|
|
return !FactionsPlugin.getInstance().getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || context.payForCommand(FactionsPlugin.getInstance().getConfig().getDouble("warp-cost.setwarp", 5), TL.COMMAND_SETFWARP_TOSET.toString(), TL.COMMAND_SETFWARP_FORSET.toString());
|
|
|
|
}
|
2019-08-24 19:18:50 +02:00
|
|
|
|
2019-09-15 11:08:00 +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
|
|
|
|