Saber-Factions/src/main/java/com/massivecraft/factions/cmd/CmdSetFWarp.java

71 lines
2.6 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
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;
import com.massivecraft.factions.zcore.util.TL;
public class CmdSetFWarp extends FCommand {
public CmdSetFWarp() {
super();
this.aliases.add("setwarp");
this.aliases.add("sw");
this.requiredArgs.add("warp name");
this.optionalArgs.put("password", "password");
this.requirements = new CommandRequirements.Builder(Permission.SETWARP)
.playerOnly()
.memberOnly()
.withAction(PermissableAction.SETWARP)
.build();
}
@Override
public void perform(CommandContext context) {
if (!(context.fPlayer.getRelationToLocation() == Relation.MEMBER)) {
context.msg(TL.COMMAND_SETFWARP_NOTCLAIMED);
return;
}
String warp = context.argAsString(0);
// Checks if warp with same name already exists and ignores maxWarp check if it does.
boolean warpExists = context.faction.isWarp(warp);
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;
}
if (!transact(context.fPlayer, context)) {
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);
}
context.msg(TL.COMMAND_SETFWARP_SET, warp, password != null ? password : "");
}
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());
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SETFWARP_DESCRIPTION;
}
}