Prevent that players are teleported to offline players using /tpa and players that lost their tpahere permission

This commit is contained in:
snowleo 2011-11-15 22:47:02 +01:00
parent b619a54105
commit d2f3bf94ae

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.OfflinePlayer;
import com.earth2me.essentials.Trade;
import org.bukkit.Server;
import com.earth2me.essentials.User;
@ -14,34 +15,36 @@ public class Commandtpaccept extends EssentialsCommand
}
@Override
public void run(Server server, User user, String commandLabel, String[] args) throws Exception
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
{
User p = user.getTeleportRequest();
if (p == null)
final User target = user.getTeleportRequest();
if (target == null
|| target.getBase() instanceof OfflinePlayer
|| (user.isTeleportRequestHere() && !target.isAuthorized("essentials.tpahere")))
{
throw new Exception(Util.i18n("noPendingRequest"));
}
Trade charge = new Trade(this.getName(), ess);
final Trade charge = new Trade(this.getName(), ess);
if (user.isTeleportRequestHere())
{
charge.isAffordableFor(user);
}
else
{
charge.isAffordableFor(p);
charge.isAffordableFor(target);
}
user.sendMessage(Util.i18n("requestAccepted"));
p.sendMessage(Util.format("requestAcceptedFrom", user.getDisplayName()));
target.sendMessage(Util.format("requestAcceptedFrom", user.getDisplayName()));
if (user.isTeleportRequestHere())
{
user.getTeleport().teleport(p, charge);
user.getTeleport().teleport(target, charge);
}
else
{
p.getTeleport().teleport(user, charge);
target.getTeleport().teleport(user, charge);
}
user.requestTeleport(null, false);
}