Implement #70 (untested), TODO assign default permissions

This commit is contained in:
vemacs 2015-07-03 13:07:25 -04:00
parent 500384abf3
commit 1d20184f0b
2 changed files with 42 additions and 3 deletions

View File

@ -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) {

View File

@ -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"));