mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-02-12 04:20:41 +00: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
7 changed files with 32 additions and 34 deletions
|
@ -9,7 +9,7 @@ public class PlayerTarget implements ITarget
|
||||||
{
|
{
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
PlayerTarget(Player entity)
|
public PlayerTarget(Player entity)
|
||||||
{
|
{
|
||||||
this.name = entity.getName();
|
this.name = entity.getName();
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,7 @@ public class Teleport implements net.ess3.api.ITeleport
|
||||||
{
|
{
|
||||||
cancel(false);
|
cancel(false);
|
||||||
teleportee.setLastLocation();
|
teleportee.setLastLocation();
|
||||||
|
teleportee.requestTeleport(null, false);
|
||||||
teleportee.getBase().teleport(LocationUtil.getSafeDestination(target.getLocation()), cause);
|
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);
|
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
|
//The respawn function is a wrapper used to handle tp fallback, on /jail and /home
|
||||||
@Override
|
@Override
|
||||||
public void respawn(final Trade chargeFor, TeleportCause cause) throws Exception
|
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 CommandSender replyTo = null;
|
||||||
private transient String teleportRequester;
|
private transient String teleportRequester;
|
||||||
private transient boolean teleportRequestHere;
|
private transient boolean teleportRequestHere;
|
||||||
|
private transient Location teleportLocation;
|
||||||
private transient boolean vanished;
|
private transient boolean vanished;
|
||||||
private transient final Teleport teleport;
|
private transient final Teleport teleport;
|
||||||
private transient long teleportRequestTime;
|
private transient long teleportRequestTime;
|
||||||
|
@ -233,11 +234,18 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
|
||||||
setLogoutLocation(getLocation());
|
setLogoutLocation(getLocation());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void requestTeleport(final User player, final boolean here)
|
public void requestTeleport(final User player, final boolean here)
|
||||||
{
|
{
|
||||||
teleportRequestTime = System.currentTimeMillis();
|
teleportRequestTime = System.currentTimeMillis();
|
||||||
teleportRequester = player == null ? null : player.getName();
|
teleportRequester = player == null ? null : player.getName();
|
||||||
teleportRequestHere = here;
|
teleportRequestHere = here;
|
||||||
|
if (player == null) {
|
||||||
|
teleportLocation = null;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
teleportLocation = here ? player.getLocation() : this.getLocation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTeleportRequest()
|
public String getTeleportRequest()
|
||||||
|
@ -250,6 +258,11 @@ public class User extends UserData implements Comparable<User>, IReplyTo, net.es
|
||||||
return teleportRequestHere;
|
return teleportRequestHere;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Location getTpRequestLocation()
|
||||||
|
{
|
||||||
|
return teleportLocation;
|
||||||
|
}
|
||||||
|
|
||||||
public String getNick(final boolean longnick)
|
public String getNick(final boolean longnick)
|
||||||
{
|
{
|
||||||
final StringBuilder prefix = new StringBuilder();
|
final StringBuilder prefix = new StringBuilder();
|
||||||
|
|
|
@ -74,16 +74,6 @@ public interface ITeleport
|
||||||
*/
|
*/
|
||||||
void teleportPlayer(IUser otherUser, Player entity, Trade chargeFor, PlayerTeleportEvent.TeleportCause cause) throws Exception;
|
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
|
* Teleport wrapper used to handle tp fallback on /jail and /home
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package com.earth2me.essentials.commands;
|
package com.earth2me.essentials.commands;
|
||||||
|
|
||||||
import static com.earth2me.essentials.I18n._;
|
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.Trade;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import org.bukkit.Server;
|
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
|
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"));
|
throw new Exception(_("noPendingRequest"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.isTpRequestHere() && ((!target.isAuthorized("essentials.tpahere") && !target.isAuthorized("essentials.tpaall"))
|
if (user.isTpRequestHere() && ((!requester.isAuthorized("essentials.tpahere") && !requester.isAuthorized("essentials.tpaall"))
|
||||||
|| (user.getWorld() != target.getWorld() && ess.getSettings().isWorldTeleportPermissions()
|
|| (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions()
|
||||||
&& !user.isAuthorized("essentials.worlds." + user.getWorld().getName()))))
|
&& !user.isAuthorized("essentials.worlds." + user.getWorld().getName()))))
|
||||||
{
|
{
|
||||||
throw new Exception(_("noPendingRequest"));
|
throw new Exception(_("noPendingRequest"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!user.isTpRequestHere() && (!target.isAuthorized("essentials.tpa")
|
if (!user.isTpRequestHere() && (!requester.isAuthorized("essentials.tpa")
|
||||||
|| (user.getWorld() != target.getWorld() && ess.getSettings().isWorldTeleportPermissions()
|
|| (user.getWorld() != requester.getWorld() && ess.getSettings().isWorldTeleportPermissions()
|
||||||
&& !user.isAuthorized("essentials.worlds." + target.getWorld().getName()))))
|
&& !user.isAuthorized("essentials.worlds." + requester.getWorld().getName()))))
|
||||||
{
|
{
|
||||||
throw new Exception(_("noPendingRequest"));
|
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"));
|
throw new Exception(_("noPendingRequest"));
|
||||||
}
|
}
|
||||||
|
@ -53,23 +55,23 @@ public class Commandtpaccept extends EssentialsCommand
|
||||||
|
|
||||||
final Trade charge = new Trade(this.getName(), ess);
|
final Trade charge = new Trade(this.getName(), ess);
|
||||||
user.sendMessage(_("requestAccepted"));
|
user.sendMessage(_("requestAccepted"));
|
||||||
target.sendMessage(_("requestAcceptedFrom", user.getDisplayName()));
|
requester.sendMessage(_("requestAcceptedFrom", user.getDisplayName()));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (user.isTpRequestHere())
|
if (user.isTpRequestHere())
|
||||||
{
|
{
|
||||||
target.getTeleport().teleportToMe(user, charge, TeleportCause.COMMAND);
|
requester.getTeleport().teleportPlayer(user, user.getTpRequestLocation(), charge, TeleportCause.COMMAND);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
target.getTeleport().teleport(user.getBase(), charge, TeleportCause.COMMAND);
|
requester.getTeleport().teleport(user.getBase(), charge, TeleportCause.COMMAND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
user.sendMessage(_("pendingTeleportCancelled"));
|
user.sendMessage(_("pendingTeleportCancelled"));
|
||||||
ess.showError(target.getBase(), ex, commandLabel);
|
ess.showError(requester.getBase(), ex, commandLabel);
|
||||||
}
|
}
|
||||||
user.requestTeleport(null, false);
|
user.requestTeleport(null, false);
|
||||||
throw new NoChargeException();
|
throw new NoChargeException();
|
||||||
|
|
|
@ -27,7 +27,7 @@ public class Commandtphere extends EssentialsCommand
|
||||||
{
|
{
|
||||||
throw new Exception(_("noPerm", "essentials.worlds." + user.getWorld().getName()));
|
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"));
|
user.sendMessage(_("teleporting"));
|
||||||
player.sendMessage(_("teleporting"));
|
player.sendMessage(_("teleporting"));
|
||||||
throw new NoChargeException();
|
throw new NoChargeException();
|
||||||
|
|
Loading…
Reference in a new issue