From 1d20184f0b17e85561694814bebecb2d9bcf40a7 Mon Sep 17 00:00:00 2001 From: vemacs Date: Fri, 3 Jul 2015 13:07:25 -0400 Subject: [PATCH] Implement #70 (untested), TODO assign default permissions --- .../src/com/earth2me/essentials/Teleport.java | 36 ++++++++++++++++++- .../essentials/commands/Commandtpaccept.java | 9 +++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index cb7261e2f..4c04aaee8 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -21,9 +21,18 @@ public class Teleport implements net.ess3.api.ITeleport { private final IEssentials ess; private TimedTeleport timedTeleport; + private TeleportType tpType; + public Teleport(IUser user, IEssentials ess) { this.teleportOwner = user; this.ess = ess; + tpType = TeleportType.NORMAL; + } + + public enum TeleportType { + TPA, + BACK, + NORMAL } public void cooldown(boolean check) throws Exception { @@ -45,7 +54,8 @@ public class Teleport implements net.ess3.api.ITeleport { // If this happens, let's give the user the benifit of the doubt. teleportOwner.setLastTeleportTimestamp(time.getTimeInMillis()); return; - } else if (lastTime > earliestLong && !teleportOwner.isAuthorized("essentials.teleport.cooldown.bypass")) { + } else if (lastTime > earliestLong + && cooldownApplies()) { time.setTimeInMillis(lastTime); time.add(Calendar.SECOND, (int) cooldown); time.add(Calendar.MILLISECOND, (int) ((cooldown * 1000.0) % 1000.0)); @@ -58,6 +68,25 @@ public class Teleport implements net.ess3.api.ITeleport { } } + private boolean cooldownApplies() { + boolean applies = true; + String globalBypassPerm = "essentials.teleport.cooldown.bypass"; + switch (tpType) { + case NORMAL: + applies = !teleportOwner.isAuthorized(globalBypassPerm); + break; + case BACK: + applies = !(teleportOwner.isAuthorized(globalBypassPerm) && + teleportOwner.isAuthorized("essentials.teleport.cooldown.bypass.back")); + break; + case TPA: + applies = !(teleportOwner.isAuthorized(globalBypassPerm) && + teleportOwner.isAuthorized("essentials.teleport.cooldown.bypass.tpa")); + break; + } + return applies; + } + private void warnUser(final IUser user, final double delay) { Calendar c = new GregorianCalendar(); c.add(Calendar.SECOND, (int) delay); @@ -232,6 +261,7 @@ public class Teleport implements net.ess3.api.ITeleport { //The back function is a wrapper used to teleportPlayer a player /back to their previous location. @Override public void back(Trade chargeFor) throws Exception { + tpType = TeleportType.BACK; final Location loc = teleportOwner.getLastLocation(); teleportOwner.sendMessage(tl("backUsageMsg", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); teleport(teleportOwner, new LocationTarget(loc), chargeFor, TeleportCause.COMMAND); @@ -243,6 +273,10 @@ public class Teleport implements net.ess3.api.ITeleport { now(teleportOwner, new LocationTarget(teleportOwner.getLastLocation()), TeleportCause.COMMAND); } + public void setTpType(TeleportType tpType) { + this.tpType = tpType; + } + //If we need to cancelTimer a pending teleportPlayer call this method private void cancel(boolean notifyUser) { if (timedTeleport != null) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java index ff486f1c1..4a9bd2542 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandtpaccept.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.commands; +import com.earth2me.essentials.Teleport; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import org.bukkit.Location; @@ -52,10 +53,14 @@ public class Commandtpaccept extends EssentialsCommand { try { if (user.isTpRequestHere()) { final Location loc = user.getTpRequestLocation(); - requester.getTeleport().teleportPlayer(user, user.getTpRequestLocation(), charge, TeleportCause.COMMAND); + Teleport teleport = requester.getTeleport(); + teleport.setTpType(Teleport.TeleportType.TPA); + teleport.teleportPlayer(user, user.getTpRequestLocation(), charge, TeleportCause.COMMAND); requester.sendMessage(tl("teleporting", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())); } else { - requester.getTeleport().teleport(user.getBase(), charge, TeleportCause.COMMAND); + Teleport teleport = requester.getTeleport(); + teleport.setTpType(Teleport.TeleportType.TPA); + teleport.teleport(user.getBase(), charge, TeleportCause.COMMAND); } } catch (Exception ex) { user.sendMessage(tl("pendingTeleportCancelled"));