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;
|
2018-10-23 01:42:57 +02:00
|
|
|
import com.massivecraft.factions.SavageFactions;
|
2014-11-07 18:49:54 +01:00
|
|
|
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;
|
2014-11-07 18:49:54 +01:00
|
|
|
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;
|
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 {
|
|
|
|
|
|
|
|
public CmdSetFWarp() {
|
|
|
|
super();
|
2018-02-03 22:04:21 +01:00
|
|
|
|
2014-11-07 18:49:54 +01:00
|
|
|
this.aliases.add("setwarp");
|
|
|
|
this.aliases.add("sw");
|
2018-02-03 22:04:21 +01:00
|
|
|
|
2014-11-07 18:49:54 +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
|
|
|
|
2014-11-07 18:49:54 +01:00
|
|
|
this.senderMustBeMember = true;
|
2018-02-03 22:04:21 +01:00
|
|
|
this.senderMustBeModerator = false;
|
2018-12-21 22:46:10 +01:00
|
|
|
|
2019-02-11 05:57:45 +01:00
|
|
|
this.senderMustBePlayer = true;
|
2018-02-03 22:04:21 +01:00
|
|
|
|
2014-11-07 18:49:54 +01:00
|
|
|
this.permission = Permission.SETWARP.node;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() {
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!(fme.getRelationToLocation() == Relation.MEMBER)) {
|
2014-12-08 00:12:52 +01:00
|
|
|
fme.msg(TL.COMMAND_SETFWARP_NOTCLAIMED);
|
2014-11-07 18:49:54 +01:00
|
|
|
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.
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!fme.isAdminBypassing()) {
|
2018-09-09 00:28:09 +02:00
|
|
|
Access access = myFaction.getAccess(fme, PermissableAction.SETWARP);
|
2018-11-07 06:38:43 +01:00
|
|
|
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
|
2018-09-09 00:28:09 +02:00
|
|
|
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "set warps");
|
|
|
|
return;
|
|
|
|
}
|
2018-02-03 22:04:21 +01:00
|
|
|
}
|
2019-02-11 05:57:45 +01:00
|
|
|
|
2019-01-18 17:08:51 +01:00
|
|
|
String warp = argAsString(0);
|
2018-02-03 22:04:21 +01:00
|
|
|
|
2019-01-18 17:08:51 +01:00
|
|
|
// Checks if warp with same name already exists and ignores maxWarp check if it does.
|
|
|
|
boolean warpExists = myFaction.isWarp(warp);
|
2018-08-02 19:55:21 +02:00
|
|
|
|
2018-11-07 06:38:43 +01:00
|
|
|
int maxWarps = SavageFactions.plugin.getConfig().getInt("max-warps", 5);
|
2019-01-18 17:08:51 +01:00
|
|
|
boolean tooManyWarps = maxWarps <= myFaction.getWarps().size();
|
|
|
|
if (tooManyWarps && !warpExists) {
|
2014-12-08 00:12:52 +01:00
|
|
|
fme.msg(TL.COMMAND_SETFWARP_LIMIT, maxWarps);
|
2014-11-07 18:49:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!transact(fme)) {
|
2014-11-11 16:28:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-12-19 11:10:52 +01:00
|
|
|
String password = argAsString(1);
|
|
|
|
|
2014-11-07 18:49:54 +01:00
|
|
|
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 : "");
|
2014-11-07 18:49:54 +01:00
|
|
|
}
|
2014-11-11 16:28:53 +01:00
|
|
|
|
|
|
|
private boolean transact(FPlayer player) {
|
2018-11-07 17:14:42 +01:00
|
|
|
return !SavageFactions.plugin.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || payForCommand(SavageFactions.plugin.getConfig().getDouble("warp-cost.setwarp", 5), TL.COMMAND_SETFWARP_TOSET.toString(), TL.COMMAND_SETFWARP_FORSET.toString());
|
2014-11-11 16:28:53 +01:00
|
|
|
}
|
2015-01-22 00:58:33 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_SETFWARP_DESCRIPTION;
|
|
|
|
}
|
2014-11-07 18:49:54 +01:00
|
|
|
}
|