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

93 lines
3.4 KiB
Java
Raw Normal View History

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