2011-03-19 23:39:51 +01:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2020-06-24 10:52:25 +02:00
|
|
|
import com.earth2me.essentials.AsyncTeleport;
|
2018-12-19 11:50:30 +01:00
|
|
|
import com.earth2me.essentials.Trade;
|
2011-03-19 23:39:51 +01:00
|
|
|
import com.earth2me.essentials.User;
|
2019-05-30 20:17:58 +02:00
|
|
|
import net.ess3.api.events.TPARequestEvent;
|
2011-11-18 18:42:26 +01:00
|
|
|
import org.bukkit.Server;
|
2018-12-19 11:50:30 +01:00
|
|
|
import org.bukkit.event.player.PlayerTeleportEvent;
|
2011-03-19 23:39:51 +01:00
|
|
|
|
2017-06-11 02:17:43 +02:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
2020-06-24 10:52:25 +02:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2017-06-11 02:17:43 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
|
|
|
public class Commandtpa extends EssentialsCommand {
|
|
|
|
public Commandtpa() {
|
|
|
|
super("tpa");
|
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
@Override
|
2020-10-03 19:46:05 +02:00
|
|
|
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
2015-04-15 06:06:16 +02:00
|
|
|
if (args.length < 1) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
|
2020-10-03 19:46:05 +02:00
|
|
|
final User player = getPlayer(server, user, args, 0);
|
2015-04-15 06:06:16 +02:00
|
|
|
if (user.getName().equalsIgnoreCase(player.getName())) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
2020-06-15 14:36:13 +02:00
|
|
|
if (!player.isAuthorized("essentials.tpaccept")) {
|
|
|
|
throw new Exception(tl("teleportNoAcceptPermission", player.getDisplayName()));
|
|
|
|
}
|
2015-04-15 06:06:16 +02:00
|
|
|
if (!player.isTeleportEnabled()) {
|
|
|
|
throw new Exception(tl("teleportDisabled", player.getDisplayName()));
|
|
|
|
}
|
|
|
|
if (user.getWorld() != player.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + player.getWorld().getName())) {
|
|
|
|
throw new Exception(tl("noPerm", "essentials.worlds." + player.getWorld().getName()));
|
|
|
|
}
|
2016-07-22 21:51:47 +02:00
|
|
|
// Don't let sender request teleport twice to the same player.
|
2016-11-22 21:39:31 +01:00
|
|
|
if (user.getConfigUUID().equals(player.getTeleportRequest()) && player.hasOutstandingTeleportRequest() // Check timeout
|
2019-05-30 20:17:58 +02:00
|
|
|
&& !player.isTpRequestHere()) { // Make sure the last teleport request was actually tpa and not tpahere
|
2016-07-22 21:51:47 +02:00
|
|
|
throw new Exception(tl("requestSentAlready", player.getDisplayName()));
|
|
|
|
}
|
2018-12-21 10:58:44 +01:00
|
|
|
if (player.isAutoTeleportEnabled() && !player.isIgnoredPlayer(user)) {
|
2018-12-19 11:50:30 +01:00
|
|
|
final Trade charge = new Trade(this.getName(), ess);
|
2020-10-03 19:46:05 +02:00
|
|
|
final AsyncTeleport teleport = user.getAsyncTeleport();
|
2020-06-24 10:52:25 +02:00
|
|
|
teleport.setTpType(AsyncTeleport.TeleportType.TPA);
|
2020-10-03 19:46:05 +02:00
|
|
|
final CompletableFuture<Boolean> future = getNewExceptionFuture(user.getSource(), commandLabel);
|
2020-06-24 10:52:25 +02:00
|
|
|
teleport.teleport(player.getBase(), charge, PlayerTeleportEvent.TeleportCause.COMMAND, future);
|
|
|
|
future.thenAccept(success -> {
|
|
|
|
if (success) {
|
|
|
|
player.sendMessage(tl("requestAcceptedAuto", user.getDisplayName()));
|
|
|
|
user.sendMessage(tl("requestAcceptedFromAuto", player.getDisplayName()));
|
|
|
|
}
|
|
|
|
});
|
2018-12-19 11:50:30 +01:00
|
|
|
return;
|
|
|
|
}
|
2016-07-22 21:51:47 +02:00
|
|
|
|
2015-04-15 06:06:16 +02:00
|
|
|
if (!player.isIgnoredPlayer(user)) {
|
2020-10-03 19:46:05 +02:00
|
|
|
final TPARequestEvent tpaEvent = new TPARequestEvent(user.getSource(), player, false);
|
2019-05-30 20:17:58 +02:00
|
|
|
ess.getServer().getPluginManager().callEvent(tpaEvent);
|
|
|
|
if (tpaEvent.isCancelled()) {
|
|
|
|
throw new Exception(tl("teleportRequestCancelled", player.getDisplayName()));
|
|
|
|
}
|
2015-04-15 06:06:16 +02:00
|
|
|
player.requestTeleport(user, false);
|
|
|
|
player.sendMessage(tl("teleportRequest", user.getDisplayName()));
|
|
|
|
player.sendMessage(tl("typeTpaccept"));
|
|
|
|
player.sendMessage(tl("typeTpdeny"));
|
|
|
|
if (ess.getSettings().getTpaAcceptCancellation() != 0) {
|
|
|
|
player.sendMessage(tl("teleportRequestTimeoutInfo", ess.getSettings().getTpaAcceptCancellation()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
user.sendMessage(tl("requestSent", player.getDisplayName()));
|
2019-04-23 10:22:50 +02:00
|
|
|
if (user.isAuthorized("essentials.tpacancel")) {
|
|
|
|
user.sendMessage(tl("typeTpacancel"));
|
|
|
|
}
|
2015-04-15 06:06:16 +02:00
|
|
|
}
|
2017-06-11 02:17:43 +02:00
|
|
|
|
|
|
|
@Override
|
2020-10-03 19:46:05 +02:00
|
|
|
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
|
2017-06-11 02:17:43 +02:00
|
|
|
if (args.length == 1) {
|
|
|
|
return getPlayers(server, user);
|
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
2011-03-19 23:39:51 +01:00
|
|
|
}
|