mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-04 11:36:24 +00:00
Properly handle tphere requests so the right user is in control/charged.
This commit is contained in:
parent
aa7f49cb85
commit
fbc0f13b2b
3 changed files with 63 additions and 18 deletions
|
@ -37,7 +37,7 @@ public class Teleport implements Runnable, ITeleport
|
||||||
{
|
{
|
||||||
if (this.name != null)
|
if (this.name != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
return ess.getServer().getPlayerExact(name).getLocation();
|
return ess.getServer().getPlayerExact(name).getLocation();
|
||||||
}
|
}
|
||||||
return location;
|
return location;
|
||||||
|
@ -62,13 +62,19 @@ public class Teleport implements Runnable, ITeleport
|
||||||
private TeleportCause cause;
|
private TeleportCause cause;
|
||||||
|
|
||||||
private void initTimer(long delay, Target target, Trade chargeFor, TeleportCause cause)
|
private void initTimer(long delay, Target target, Trade chargeFor, TeleportCause cause)
|
||||||
|
{
|
||||||
|
initTimer(delay, user, target, chargeFor, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initTimer(long delay, IUser teleportUser, Target target, Trade chargeFor, TeleportCause cause)
|
||||||
{
|
{
|
||||||
this.started = System.currentTimeMillis();
|
this.started = System.currentTimeMillis();
|
||||||
this.delay = delay;
|
this.delay = delay;
|
||||||
this.health = user.getHealth();
|
this.health = teleportUser.getHealth();
|
||||||
this.initX = Math.round(user.getLocation().getX() * MOVE_CONSTANT);
|
this.initX = Math.round(teleportUser.getLocation().getX() * MOVE_CONSTANT);
|
||||||
this.initY = Math.round(user.getLocation().getY() * MOVE_CONSTANT);
|
this.initY = Math.round(teleportUser.getLocation().getY() * MOVE_CONSTANT);
|
||||||
this.initZ = Math.round(user.getLocation().getZ() * MOVE_CONSTANT);
|
this.initZ = Math.round(teleportUser.getLocation().getZ() * MOVE_CONSTANT);
|
||||||
|
this.teleportUser = teleportUser;
|
||||||
this.teleportTarget = target;
|
this.teleportTarget = target;
|
||||||
this.chargeFor = chargeFor;
|
this.chargeFor = chargeFor;
|
||||||
this.cause = cause;
|
this.cause = cause;
|
||||||
|
@ -80,19 +86,25 @@ public class Teleport implements Runnable, ITeleport
|
||||||
|
|
||||||
if (user == null || !user.isOnline() || user.getLocation() == null)
|
if (user == null || !user.isOnline() || user.getLocation() == null)
|
||||||
{
|
{
|
||||||
cancel();
|
cancel(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (Math.round(user.getLocation().getX() * MOVE_CONSTANT) != initX
|
if (teleportUser == null || !teleportUser.isOnline() || teleportUser.getLocation() == null)
|
||||||
|| Math.round(user.getLocation().getY() * MOVE_CONSTANT) != initY
|
{
|
||||||
|| Math.round(user.getLocation().getZ() * MOVE_CONSTANT) != initZ
|
cancel(false);
|
||||||
|| user.getHealth() < health)
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Math.round(teleportUser.getLocation().getX() * MOVE_CONSTANT) != initX
|
||||||
|
|| Math.round(teleportUser.getLocation().getY() * MOVE_CONSTANT) != initY
|
||||||
|
|| Math.round(teleportUser.getLocation().getZ() * MOVE_CONSTANT) != initZ
|
||||||
|
|| teleportUser.getHealth() < health)
|
||||||
{ // user moved, cancel teleport
|
{ // user moved, cancel teleport
|
||||||
cancel(true);
|
cancel(true);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
health = user.getHealth(); // in case user healed, then later gets injured
|
health = teleportUser.getHealth(); // in case user healed, then later gets injured
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
if (now > started + delay)
|
if (now > started + delay)
|
||||||
|
@ -100,11 +112,12 @@ public class Teleport implements Runnable, ITeleport
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
cooldown(false);
|
cooldown(false);
|
||||||
user.sendMessage(_("teleportationCommencing"));
|
teleportUser.sendMessage(_("teleportationCommencing"));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
now(teleportTarget, cause);
|
teleportUser.getTeleport().now(teleportTarget, cause);
|
||||||
|
cancel(false);
|
||||||
if (chargeFor != null)
|
if (chargeFor != null)
|
||||||
{
|
{
|
||||||
chargeFor.charge(user);
|
chargeFor.charge(user);
|
||||||
|
@ -118,6 +131,10 @@ public class Teleport implements Runnable, ITeleport
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
user.sendMessage(_("cooldownWithMessage", ex.getMessage()));
|
user.sendMessage(_("cooldownWithMessage", ex.getMessage()));
|
||||||
|
if (user != teleportUser)
|
||||||
|
{
|
||||||
|
teleportUser.sendMessage(_("cooldownWithMessage", ex.getMessage()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,6 +196,10 @@ public class Teleport implements Runnable, ITeleport
|
||||||
if (notifyUser)
|
if (notifyUser)
|
||||||
{
|
{
|
||||||
user.sendMessage(_("pendingTeleportCancelled"));
|
user.sendMessage(_("pendingTeleportCancelled"));
|
||||||
|
if (teleportUser != user)
|
||||||
|
{
|
||||||
|
teleportUser.sendMessage(_("pendingTeleportCancelled"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
@ -254,13 +275,37 @@ public class Teleport implements Runnable, ITeleport
|
||||||
user.getBase().teleport(Util.getSafeDestination(target.getLocation()), cause);
|
user.getBase().teleport(Util.getSafeDestination(target.getLocation()), cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void now(Player entity, boolean cooldown, TeleportCause cause) throws Exception
|
//The teleportToMe function is a wrapper used to handle teleporting players to them, like /tphere
|
||||||
|
public void teleportToMe(User otherUser, Trade chargeFor, TeleportCause cause) throws Exception
|
||||||
{
|
{
|
||||||
if (cooldown)
|
Target target = new Target(user);
|
||||||
|
|
||||||
|
double delay = ess.getSettings().getTeleportDelay();
|
||||||
|
|
||||||
|
if (chargeFor != null)
|
||||||
|
{
|
||||||
|
chargeFor.isAffordableFor(user);
|
||||||
|
}
|
||||||
|
cooldown(true);
|
||||||
|
if (delay <= 0 || user.isAuthorized("essentials.teleport.timer.bypass"))
|
||||||
{
|
{
|
||||||
cooldown(false);
|
cooldown(false);
|
||||||
|
otherUser.getTeleport().now(target, cause);
|
||||||
|
if (chargeFor != null)
|
||||||
|
{
|
||||||
|
chargeFor.charge(user);
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
now(new Target(entity), cause);
|
|
||||||
|
cancel(false);
|
||||||
|
Calendar c = new GregorianCalendar();
|
||||||
|
c.add(Calendar.SECOND, (int)delay);
|
||||||
|
c.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0));
|
||||||
|
otherUser.sendMessage(_("dontMoveMessage", Util.formatDateDiff(c.getTimeInMillis())));
|
||||||
|
initTimer((long)(delay * 1000.0), otherUser, target, chargeFor, cause);
|
||||||
|
|
||||||
|
teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
//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
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class Commandtpaccept extends EssentialsCommand
|
||||||
|
|
||||||
if (user.isTpRequestHere())
|
if (user.isTpRequestHere())
|
||||||
{
|
{
|
||||||
user.getTeleport().teleport(target, charge, TeleportCause.COMMAND);
|
target.getTeleport().teleportToMe(user, charge, TeleportCause.COMMAND);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -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()));
|
||||||
}
|
}
|
||||||
player.getTeleport().teleport(user, new Trade(this.getName(), ess), TeleportCause.COMMAND);
|
user.getTeleport().teleportToMe(player, 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…
Add table
Add a link
Reference in a new issue