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

69 lines
2.4 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
import com.massivecraft.factions.*;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.WarmUpUtil;
import com.massivecraft.factions.zcore.util.TL;
public class CmdCheckpoint extends FCommand {
2019-12-02 19:55:38 +01:00
/**
* @author Illyria Team
*/
public CmdCheckpoint() {
super();
this.aliases.addAll(Aliases.checkpoint);
this.optionalArgs.put("set", "");
this.requirements = new CommandRequirements.Builder(Permission.CHECKPOINT)
.playerOnly()
.memberOnly()
.build();
}
@Override
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("checkpoints.Enabled")) {
context.msg(TL.COMMAND_CHECKPOINT_DISABLED);
return;
}
if (context.args.size() == 1) {
FLocation myLocation = new FLocation(context.player.getLocation());
Faction myLocFaction = Board.getInstance().getFactionAt(myLocation);
if (myLocFaction == Factions.getInstance().getWilderness() || myLocFaction == context.faction) {
context.faction.setCheckpoint(context.player.getLocation());
context.msg(TL.COMMAND_CHECKPOINT_SET);
return;
} else {
context.msg(TL.COMMAND_CHECKPOINT_INVALIDLOCATION);
return;
}
}
if (context.faction.getCheckpoint() == null) {
context.msg(TL.COMMAND_CHECKPOINT_NOT_SET);
return;
}
FLocation checkLocation = new FLocation(context.faction.getCheckpoint());
Faction checkfaction = Board.getInstance().getFactionAt(checkLocation);
if (checkfaction.getId().equals(Factions.getInstance().getWilderness().getId()) || checkfaction.getId().equals(context.faction.getId())) {
context.msg(TL.COMMAND_CHECKPOINT_GO);
context.doWarmUp(WarmUpUtil.Warmup.CHECKPOINT, TL.WARMUPS_NOTIFY_TELEPORT, "Checkpoint", () -> {
context.player.teleport(context.faction.getCheckpoint());
}, FactionsPlugin.getInstance().getConfig().getLong("warmups.f-checkpoint", 0));
} else {
context.msg(TL.COMMAND_CHECKPOINT_CLAIMED);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_CHECKPOINT_DESCRIPTION;
}
}