summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-08-11 16:37:21 +0100
committerKHobbits <rob@khobbits.co.uk>2013-08-11 16:37:21 +0100
commit7401608cc5f0d3e111159c7e07a1d5d6b2787645 (patch)
treec872b62c3d1d3745dc027bd1e303b21be5227c7a
parent4cfa3fc3a2e55b198308af5fb9b3bb82cc9ffa0d (diff)
downloadEssentials-7401608cc5f0d3e111159c7e07a1d5d6b2787645.tar
Essentials-7401608cc5f0d3e111159c7e07a1d5d6b2787645.tar.gz
Essentials-7401608cc5f0d3e111159c7e07a1d5d6b2787645.tar.lz
Essentials-7401608cc5f0d3e111159c7e07a1d5d6b2787645.tar.xz
Essentials-7401608cc5f0d3e111159c7e07a1d5d6b2787645.zip
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.
-rw-r--r--Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/PlayerTarget.java2
-rw-r--r--Essentials/src/com/earth2me/essentials/Teleport.java9
-rw-r--r--Essentials/src/com/earth2me/essentials/User.java13
-rw-r--r--Essentials/src/com/earth2me/essentials/api/ITeleport.java12
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java26
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandtphere.java2
7 files changed, 32 insertions, 34 deletions
diff --git a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
index 99e07f31c..366e0c059 100644
--- a/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
+++ b/Essentials/src/com/earth2me/essentials/EssentialsPlayerListener.java
@@ -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();
}
diff --git a/Essentials/src/com/earth2me/essentials/PlayerTarget.java b/Essentials/src/com/earth2me/essentials/PlayerTarget.java
index 867f832d9..6fd714ca1 100644
--- a/Essentials/src/com/earth2me/essentials/PlayerTarget.java
+++ b/Essentials/src/com/earth2me/essentials/PlayerTarget.java
@@ -9,7 +9,7 @@ public class PlayerTarget implements ITarget
{
private final String name;
- PlayerTarget(Player entity)
+ public PlayerTarget(Player entity)
{
this.name = entity.getName();
}
diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java
index 6b287fb8d..708016d69 100644
--- a/Essentials/src/com/earth2me/essentials/Teleport.java
+++ b/Essentials/src/com/earth2me/essentials/Teleport.java
@@ -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
diff --git a/Essentials/src/com/earth2me/essentials/User.java b/Essentials/src/com/earth2me/essentials/User.java
index 19f29bfef..7bd4ae0bf 100644
--- a/Essentials/src/com/earth2me/essentials/User.java
+++ b/Essentials/src/com/earth2me/essentials/User.java
@@ -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)
{
diff --git a/Essentials/src/com/earth2me/essentials/api/ITeleport.java b/Essentials/src/com/earth2me/essentials/api/ITeleport.java
index 798ecfdfb..392cd9fca 100644
--- a/Essentials/src/com/earth2me/essentials/api/ITeleport.java
+++ b/Essentials/src/com/earth2me/essentials/api/ITeleport.java
@@ -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
@@ -75,16 +75,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
*
* @param chargeFor - What the user will be charged if teleportPlayer is successful
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java
index 6086ee193..9dd60d2bc 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java
@@ -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();
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java
index c0372283b..bc5972218 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandtphere.java
@@ -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();