mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-24 11:54:35 +08:00
The /tpahere command now stores the location of 'here' rather than using the current players location.
Cleanup teleport logic - This also fixes exploiting /tpahere to get accesses to restricted areas.
This commit is contained in:
parent
4cfa3fc3a2
commit
7401608cc5
@ -92,7 +92,7 @@ public class EssentialsPlayerListener implements Listener
|
||||
ess.getLogger().info("Ignore could not block chat due to custom chat plugin event.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
user.updateActivity(true);
|
||||
user.setDisplayNick();
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ public class PlayerTarget implements ITarget
|
||||
{
|
||||
private final String name;
|
||||
|
||||
PlayerTarget(Player entity)
|
||||
public PlayerTarget(Player entity)
|
||||
{
|
||||
this.name = entity.getName();
|
||||
}
|
||||
|
@ -96,6 +96,7 @@ public class Teleport implements net.ess3.api.ITeleport
|
||||
{
|
||||
cancel(false);
|
||||
teleportee.setLastLocation();
|
||||
teleportee.requestTeleport(null, false);
|
||||
teleportee.getBase().teleport(LocationUtil.getSafeDestination(target.getLocation()), cause);
|
||||
}
|
||||
|
||||
@ -157,14 +158,6 @@ public class Teleport implements net.ess3.api.ITeleport
|
||||
initTimer((long)(delay * 1000.0), teleportee, target, chargeFor, cause, false);
|
||||
}
|
||||
|
||||
//The teleportToMe function is a wrapper used to handle teleporting players to them, like /tphere
|
||||
@Override
|
||||
public void teleportToMe(IUser otherUser, Trade chargeFor, TeleportCause cause) throws Exception
|
||||
{
|
||||
ITarget target = new PlayerTarget(teleportOwner.getBase());
|
||||
teleport(otherUser, target, chargeFor, cause);
|
||||
}
|
||||
|
||||
//The respawn function is a wrapper used to handle tp fallback, on /jail and /home
|
||||
@Override
|
||||
public void respawn(final Trade chargeFor, TeleportCause cause) throws Exception
|
||||
|
@ -26,6 +26,7 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
|
||||
private CommandSender replyTo = null;
|
||||
private transient String teleportRequester;
|
||||
private transient boolean teleportRequestHere;
|
||||
private transient Location teleportLocation;
|
||||
private transient boolean vanished;
|
||||
private transient final Teleport teleport;
|
||||
private transient long teleportRequestTime;
|
||||
@ -233,11 +234,18 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
|
||||
setLogoutLocation(getLocation());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void requestTeleport(final User player, final boolean here)
|
||||
{
|
||||
teleportRequestTime = System.currentTimeMillis();
|
||||
teleportRequester = player == null ? null : player.getName();
|
||||
teleportRequestHere = here;
|
||||
if (player == null) {
|
||||
teleportLocation = null;
|
||||
}
|
||||
else {
|
||||
teleportLocation = here ? player.getLocation() : this.getLocation();
|
||||
}
|
||||
}
|
||||
|
||||
public String getTeleportRequest()
|
||||
@ -249,6 +257,11 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
|
||||
{
|
||||
return teleportRequestHere;
|
||||
}
|
||||
|
||||
public Location getTpRequestLocation()
|
||||
{
|
||||
return teleportLocation;
|
||||
}
|
||||
|
||||
public String getNick(final boolean longnick)
|
||||
{
|
||||
|
@ -52,7 +52,7 @@ public interface ITeleport
|
||||
*/
|
||||
void teleport(Player entity, Trade chargeFor, PlayerTeleportEvent.TeleportCause cause) throws Exception;
|
||||
|
||||
/**
|
||||
/**
|
||||
* Teleport a player to a specific location
|
||||
*
|
||||
* @param otherUser - Which user will be teleported
|
||||
@ -74,16 +74,6 @@ public interface ITeleport
|
||||
*/
|
||||
void teleportPlayer(IUser otherUser, Player entity, Trade chargeFor, PlayerTeleportEvent.TeleportCause cause) throws Exception;
|
||||
|
||||
/**
|
||||
* Teleport wrapper used to handle teleporting players to them, like /tphere
|
||||
*
|
||||
* @param otherUser - Which user will be teleported
|
||||
* @param chargeFor - What the user will be charged if teleportPlayer is successful
|
||||
* @param cause - The reported teleportPlayer cause
|
||||
* @throws Exception
|
||||
*/
|
||||
public void teleportToMe(IUser otherUser, Trade chargeFor, PlayerTeleportEvent.TeleportCause cause) throws Exception;
|
||||
|
||||
/**
|
||||
* Teleport wrapper used to handle tp fallback on /jail and /home
|
||||
*
|
||||
|
@ -1,6 +1,8 @@
|
||||
package com.earth2me.essentials.commands;
|
||||
|
||||
import static com.earth2me.essentials.I18n._;
|
||||
import com.earth2me.essentials.ITarget;
|
||||
import com.earth2me.essentials.PlayerTarget;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import org.bukkit.Server;
|
||||
@ -18,28 +20,28 @@ public class Commandtpaccept extends EssentialsCommand
|
||||
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception
|
||||
{
|
||||
|
||||
final User target = ess.getUser(user.getTeleportRequest());
|
||||
final User requester = ess.getUser(user.getTeleportRequest());
|
||||
|
||||
if (target == null || !target.isOnline())
|
||||
if (requester == null || !requester.isOnline())
|
||||
{
|
||||
throw new Exception(_("noPendingRequest"));
|
||||
}
|
||||
|
||||
if (user.isTpRequestHere() && ((!target.isAuthorized("essentials.tpahere") && !target.isAuthorized("essentials.tpaall"))
|
||||
|| (user.getWorld() != target.getWorld() && ess.getSettings().isWorldTeleportPermissions()
|
||||
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(_("noPendingRequest"));
|
||||
}
|
||||
|
||||
if (!user.isTpRequestHere() && (!target.isAuthorized("essentials.tpa")
|
||||
|| (user.getWorld() != target.getWorld() && ess.getSettings().isWorldTeleportPermissions()
|
||||
&& !user.isAuthorized("essentials.worlds." + target.getWorld().getName()))))
|
||||
if (!user.isTpRequestHere() && (!requester.isAuthorized("essentials.tpa")
|
||||
|| (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions()
|
||||
&& !user.isAuthorized("essentials.worlds." + requester.getWorld().getName()))))
|
||||
{
|
||||
throw new Exception(_("noPendingRequest"));
|
||||
}
|
||||
|
||||
if (args.length > 0 && !target.getName().contains(args[0]))
|
||||
if (args.length > 0 && !requester.getName().contains(args[0]))
|
||||
{
|
||||
throw new Exception(_("noPendingRequest"));
|
||||
}
|
||||
@ -53,23 +55,23 @@ public class Commandtpaccept extends EssentialsCommand
|
||||
|
||||
final Trade charge = new Trade(this.getName(), ess);
|
||||
user.sendMessage(_("requestAccepted"));
|
||||
target.sendMessage(_("requestAcceptedFrom", user.getDisplayName()));
|
||||
requester.sendMessage(_("requestAcceptedFrom", user.getDisplayName()));
|
||||
|
||||
try
|
||||
{
|
||||
if (user.isTpRequestHere())
|
||||
{
|
||||
target.getTeleport().teleportToMe(user, charge, TeleportCause.COMMAND);
|
||||
requester.getTeleport().teleportPlayer(user, user.getTpRequestLocation(), charge, TeleportCause.COMMAND);
|
||||
}
|
||||
else
|
||||
{
|
||||
target.getTeleport().teleport(user.getBase(), charge, TeleportCause.COMMAND);
|
||||
requester.getTeleport().teleport(user.getBase(), charge, TeleportCause.COMMAND);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
user.sendMessage(_("pendingTeleportCancelled"));
|
||||
ess.showError(target.getBase(), ex, commandLabel);
|
||||
ess.showError(requester.getBase(), ex, commandLabel);
|
||||
}
|
||||
user.requestTeleport(null, false);
|
||||
throw new NoChargeException();
|
||||
|
@ -27,7 +27,7 @@ public class Commandtphere extends EssentialsCommand
|
||||
{
|
||||
throw new Exception(_("noPerm", "essentials.worlds." + user.getWorld().getName()));
|
||||
}
|
||||
user.getTeleport().teleportToMe(player, new Trade(this.getName(), ess), TeleportCause.COMMAND);
|
||||
user.getTeleport().teleportPlayer(player, user.getBase(), new Trade(this.getName(), ess), TeleportCause.COMMAND);
|
||||
user.sendMessage(_("teleporting"));
|
||||
player.sendMessage(_("teleporting"));
|
||||
throw new NoChargeException();
|
||||
|
Loading…
Reference in New Issue
Block a user