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

79 lines
2.6 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Relation;
2018-02-03 22:04:21 +01:00
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.util.LazyLocation;
2018-02-03 22:04:21 +01:00
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
public class CmdSetFWarp extends FCommand {
public CmdSetFWarp() {
super();
2018-02-03 22:04:21 +01:00
this.aliases.add("setwarp");
this.aliases.add("sw");
2018-02-03 22:04:21 +01:00
this.requiredArgs.add("warp name");
2017-12-19 11:10:52 +01:00
this.optionalArgs.put("password", "password");
2018-02-03 22:04:21 +01:00
this.senderMustBeMember = true;
2018-02-03 22:04:21 +01:00
this.senderMustBeModerator = false;
this.senderMustBePlayer = true;
2018-02-03 22:04:21 +01:00
this.permission = Permission.SETWARP.node;
}
@Override
public void perform() {
if (!(fme.getRelationToLocation() == Relation.MEMBER)) {
fme.msg(TL.COMMAND_SETFWARP_NOTCLAIMED);
return;
}
2018-02-03 22:04:21 +01:00
// This statement allows us to check if they've specifically denied it, or default to
// the old setting of allowing moderators to set warps.
if (!fme.isAdminBypassing()) {
Access access = myFaction.getAccess(fme, PermissableAction.SETWARP);
if (access != Access.ALLOW && fme.getRole() != Role.ADMIN) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set warps");
return;
}
2018-02-03 22:04:21 +01:00
}
int maxWarps = P.p.getConfig().getInt("max-warps", 5);
if (maxWarps <= myFaction.getWarps().size()) {
fme.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps);
return;
}
if (!transact(fme)) {
return;
}
String warp = argAsString(0);
2017-12-19 11:10:52 +01:00
String password = argAsString(1);
LazyLocation loc = new LazyLocation(fme.getPlayer().getLocation());
myFaction.setWarp(warp, loc);
2017-12-19 11:10:52 +01:00
if (password != null) {
myFaction.setWarpPassword(warp, password);
}
fme.msg(TL.COMMAND_SETFWARP_SET, warp, password != null ? password : "");
}
private boolean transact(FPlayer player) {
2014-12-11 17:05:04 +01:00
return !P.p.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || payForCommand(P.p.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;
}
}