TF-EssentialsX/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java

73 lines
3 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import com.earth2me.essentials.Teleport;
2011-06-13 13:05:11 +00:00
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import org.bukkit.Location;
2011-11-18 17:42:26 +00:00
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
2015-04-15 04:06:16 +00:00
import static com.earth2me.essentials.I18n.tl;
2015-04-15 04:06:16 +00:00
public class Commandtpaccept extends EssentialsCommand {
public Commandtpaccept() {
super("tpaccept");
}
2015-04-15 04:06:16 +00:00
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
final User requester;
try {
requester = ess.getUser(user.getTeleportRequest());
} catch (Exception ex) {
throw new Exception(tl("noPendingRequest"));
}
2015-04-15 04:06:16 +00:00
if (!requester.getBase().isOnline()) {
throw new Exception(tl("noPendingRequest"));
}
2012-03-20 14:32:11 +00:00
2015-04-15 04:06:16 +00:00
if (user.isTpRequestHere() && ((!requester.isAuthorized("essentials.tpahere") && !requester.isAuthorized("essentials.tpaall")) || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + user.getWorld().getName())))) {
throw new Exception(tl("noPendingRequest"));
}
2012-03-20 14:32:11 +00:00
2015-04-15 04:06:16 +00:00
if (!user.isTpRequestHere() && (!requester.isAuthorized("essentials.tpa") || (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + requester.getWorld().getName())))) {
throw new Exception(tl("noPendingRequest"));
}
2012-03-20 14:32:11 +00:00
2015-04-15 04:06:16 +00:00
if (args.length > 0 && !requester.getName().contains(args[0])) {
throw new Exception(tl("noPendingRequest"));
}
if (!user.hasOutstandingTeleportRequest()) {
2015-04-15 04:06:16 +00:00
user.requestTeleport(null, false);
throw new Exception(tl("requestTimedOut"));
}
2015-04-15 04:06:16 +00:00
final Trade charge = new Trade(this.getName(), ess);
user.sendMessage(tl("requestAccepted"));
requester.sendMessage(tl("requestAcceptedFrom", user.getDisplayName()));
2015-04-15 04:06:16 +00:00
try {
if (user.isTpRequestHere()) {
final Location loc = user.getTpRequestLocation();
Teleport teleport = requester.getTeleport();
teleport.setTpType(Teleport.TeleportType.TPA);
teleport.teleportPlayer(user, user.getTpRequestLocation(), charge, TeleportCause.COMMAND);
2015-04-15 04:06:16 +00:00
requester.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
} else {
Teleport teleport = requester.getTeleport();
teleport.setTpType(Teleport.TeleportType.TPA);
teleport.teleport(user.getBase(), charge, TeleportCause.COMMAND);
2015-04-15 04:06:16 +00:00
}
} catch (Exception ex) {
user.sendMessage(tl("pendingTeleportCancelled"));
ess.showError(requester.getSource(), ex, commandLabel);
}
user.requestTeleport(null, false);
throw new NoChargeException();
}
}