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

64 lines
1.9 KiB
Java
Raw Normal View History

package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n._;
2011-06-13 13:05:11 +00:00
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
2011-11-18 17:42:26 +00:00
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
public class Commandtpaccept extends EssentialsCommand
{
public Commandtpaccept()
{
super("tpaccept");
}
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
final User target = user.getTeleportRequest();
2012-03-20 13:26:49 +00:00
if (target == null || !target.isOnline()
|| (args.length > 0 && !target.getName().contains(args[0]))
|| (user.isTpRequestHere() && !target.isAuthorized("essentials.tpahere"))
|| (!user.isTpRequestHere() && ((!target.isAuthorized("essentials.tpa") && !target.isAuthorized("essentials.tpaall"))
|| (user.getWorld() != target.getWorld()
&& ess.getSettings().isWorldTeleportPermissions()
&& !user.isAuthorized("essentials.world." + target.getWorld().getName())))))
{
throw new Exception(_("noPendingRequest"));
}
long timeout = ess.getSettings().getTpaAcceptCancellation();
if (timeout != 0 && (System.currentTimeMillis() - user.getTeleportRequestTime()) / 1000 > timeout)
{
user.requestTeleport(null, false);
throw new Exception(_("requestTimedOut"));
}
final Trade charge = new Trade(this.getName(), ess);
2012-03-20 13:26:49 +00:00
if (user.isTpRequestHere())
{
charge.isAffordableFor(user);
}
else
{
charge.isAffordableFor(target);
}
user.sendMessage(_("requestAccepted"));
target.sendMessage(_("requestAcceptedFrom", user.getDisplayName()));
2012-03-20 13:26:49 +00:00
if (user.isTpRequestHere())
{
user.getTeleport().teleport(target, charge, TeleportCause.COMMAND);
}
else
{
target.getTeleport().teleport(user, charge, TeleportCause.COMMAND);
}
user.requestTeleport(null, false);
}
}