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-06-29 03:49:46 +02:00
|
|
|
import com.massivecraft.factions.SaberFactions;
|
2014-11-07 18:49:54 +01:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2018-08-05 03:32:36 +02:00
|
|
|
import com.massivecraft.factions.struct.Role;
|
2015-05-25 22:53:48 +02:00
|
|
|
import com.massivecraft.factions.util.WarmUpUtil;
|
2018-03-04 21:53:20 +01:00
|
|
|
import com.massivecraft.factions.util.WarpGUI;
|
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;
|
2015-09-07 16:00:58 +02:00
|
|
|
import org.bukkit.Bukkit;
|
2015-06-14 00:18:42 +02:00
|
|
|
import org.bukkit.entity.Player;
|
2014-11-07 18:49:54 +01:00
|
|
|
|
2015-09-07 16:00:58 +02:00
|
|
|
import java.util.UUID;
|
2014-12-08 04:59:59 +01:00
|
|
|
|
2014-11-07 18:49:54 +01:00
|
|
|
public class CmdFWarp extends FCommand {
|
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
public CmdFWarp() {
|
|
|
|
super();
|
|
|
|
this.aliases.add("warp");
|
|
|
|
this.aliases.add("warps");
|
|
|
|
this.optionalArgs.put("warpname", "warpname");
|
|
|
|
this.optionalArgs.put("password", "password");
|
2014-11-07 18:49:54 +01:00
|
|
|
|
2018-12-21 22:46:10 +01:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
this.permission = Permission.WARP.node;
|
|
|
|
this.senderMustBeMember = true;
|
|
|
|
this.senderMustBeModerator = false;
|
|
|
|
}
|
2014-11-07 18:49:54 +01:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
@Override
|
|
|
|
public void perform() {
|
|
|
|
//TODO: check if in combat.
|
|
|
|
if (!fme.isAdminBypassing()) {
|
|
|
|
Access access = myFaction.getAccess(fme, PermissableAction.WARP);
|
|
|
|
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
|
|
|
|
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use warps");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2018-02-03 22:04:21 +01:00
|
|
|
|
2018-08-02 19:55:21 +02:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
if (args.size() == 0) {
|
|
|
|
WarpGUI warpGUI = new WarpGUI(fme);
|
|
|
|
warpGUI.build();
|
2018-03-04 21:53:20 +01:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
me.openInventory(warpGUI.getInventory());
|
|
|
|
} else if (args.size() > 2) {
|
|
|
|
fme.msg(TL.COMMAND_FWARP_COMMANDFORMAT);
|
|
|
|
} else {
|
|
|
|
final String warpName = argAsString(0);
|
|
|
|
final String passwordAttempt = argAsString(1);
|
2017-12-19 11:10:52 +01:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
if (myFaction.isWarp(argAsString(0))) {
|
2017-12-19 11:10:52 +01:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
// Check if requires password and if so, check if valid. CASE SENSITIVE
|
|
|
|
if (myFaction.hasWarpPassword(warpName) && !myFaction.isWarpPassword(warpName, passwordAttempt)) {
|
|
|
|
fme.msg(TL.COMMAND_FWARP_INVALID_PASSWORD);
|
|
|
|
return;
|
|
|
|
}
|
2017-12-19 11:10:52 +01:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
// Check transaction AFTER password check.
|
|
|
|
if (!transact(fme)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
final FPlayer fPlayer = fme;
|
|
|
|
final UUID uuid = fme.getPlayer().getUniqueId();
|
2019-04-16 15:02:31 +02:00
|
|
|
this.doWarmUp(WarmUpUtil.Warmup.WARP, TL.WARMUPS_NOTIFY_TELEPORT, warpName, () -> {
|
|
|
|
Player player = Bukkit.getPlayer(uuid);
|
|
|
|
if (player != null) {
|
|
|
|
player.teleport(fPlayer.getFaction().getWarp(warpName).getLocation());
|
|
|
|
fPlayer.msg(TL.COMMAND_FWARP_WARPED, warpName);
|
2019-03-03 04:51:21 +01:00
|
|
|
}
|
|
|
|
}, this.p.getConfig().getLong("warmups.f-warp", 0));
|
|
|
|
} else {
|
|
|
|
fme.msg(TL.COMMAND_FWARP_INVALID_WARP, warpName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-11 16:28:53 +01:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
private boolean transact(FPlayer player) {
|
2019-06-29 03:49:46 +02:00
|
|
|
return !SaberFactions.plugin.getConfig().getBoolean("warp-cost.enabled", false) || player.isAdminBypassing() || payForCommand(SaberFactions.plugin.getConfig().getDouble("warp-cost.warp", 5), TL.COMMAND_FWARP_TOWARP.toString(), TL.COMMAND_FWARP_FORWARPING.toString());
|
2019-03-03 04:51:21 +01:00
|
|
|
}
|
2015-01-22 00:58:33 +01:00
|
|
|
|
2019-03-03 04:51:21 +01:00
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_FWARP_DESCRIPTION;
|
|
|
|
}
|
2014-11-07 18:49:54 +01:00
|
|
|
}
|