Create teleport-to-center configuration option.

This option toggles whether essentials should rounds all teleportations off to the center of the block.
This commit is contained in:
Ali Moghnieh 2016-06-26 15:21:35 +01:00
parent 5cbcd7469b
commit 0a563b91a2
5 changed files with 34 additions and 4 deletions

View File

@ -245,4 +245,6 @@ public interface ISettings extends IConf {
boolean isWorldTimePermissions();
boolean isSpawnOnJoin();
boolean isTeleportToCenterLocation();
}

View File

@ -1168,4 +1168,9 @@ public class Settings implements net.ess3.api.ISettings {
public boolean isSpawnOnJoin() {
return config.getBoolean("spawn-on-join", false);
}
@Override
public boolean isTeleportToCenterLocation() {
return config.getBoolean("teleport-to-center", true);
}
}

View File

@ -117,7 +117,7 @@ public class Teleport implements net.ess3.api.ITeleport {
protected void now(IUser teleportee, ITarget target, TeleportCause cause) throws Exception {
cancel(false);
teleportee.setLastLocation();
final Location loc = target.getLocation();
Location loc = target.getLocation();
if (LocationUtil.isBlockUnsafeForUser(teleportee, loc.getWorld(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())) {
if (ess.getSettings().isTeleportSafetyEnabled()) {
@ -127,7 +127,7 @@ public class Teleport implements net.ess3.api.ITeleport {
if (ess.getSettings().isForceDisableTeleportSafety()) {
teleportee.getBase().teleport(loc, cause);
} else {
teleportee.getBase().teleport(LocationUtil.getSafeDestination(teleportee, loc), cause);
teleportee.getBase().teleport(LocationUtil.getSafeDestination(ess, teleportee, loc), cause);
}
} else {
throw new Exception(tl("unsafeTeleportDestination", loc.getWorld().getName(), loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
@ -139,7 +139,10 @@ public class Teleport implements net.ess3.api.ITeleport {
if (ess.getSettings().isForceDisableTeleportSafety()) {
teleportee.getBase().teleport(loc, cause);
} else {
teleportee.getBase().teleport(LocationUtil.getRoundedDestination(loc), cause);
if (ess.getSettings().isTeleportToCenterLocation()) {
loc = LocationUtil.getRoundedDestination(loc);
}
teleportee.getBase().teleport(loc, cause);
}
}
}

View File

@ -13,6 +13,9 @@ import java.util.*;
import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.Essentials;
import com.earth2me.essentials.IEssentials;
public class LocationUtil {
// The player can stand inside these materials
@ -261,12 +264,26 @@ public class LocationUtil {
return new Location(world, x + 0.5, y, z + 0.5, loc.getYaw(), loc.getPitch());
}
/**
* @deprecated Use {@link #getSafeDestination(IEssentials, IUser, Location)}
*/
@Deprecated
public static Location getSafeDestination(final IUser user, final Location loc) throws Exception {
return getSafeDestination(null, user, loc);
}
public static Location getSafeDestination(final IEssentials ess, final IUser user, final Location loc) throws Exception {
if (user.getBase().isOnline() && loc.getWorld().equals(user.getBase().getWorld()) && (user.getBase().getGameMode() == GameMode.CREATIVE || user.isGodModeEnabled()) && user.getBase().getAllowFlight()) {
if (shouldFly(loc)) {
user.getBase().setFlying(true);
}
return getRoundedDestination(loc);
// ess can be null if old deprecated method is calling it.
System.out.println((ess == null) + " " + ess.getSettings().isTeleportToCenterLocation());
if (ess == null || ess.getSettings().isTeleportToCenterLocation()) {
return getRoundedDestination(loc);
} else {
return loc;
}
}
return getSafeDestination(loc);
}

View File

@ -64,6 +64,9 @@ teleport-delay: 0
# This will also prevent the player attacking other players.
teleport-invulnerability: 4
# Whether to make all teleportations go to the center of the block; where the x and z coordinates decimal become .5
teleport-to-center: true
# The delay, in seconds, required between /heal or /feed attempts.
heal-cooldown: 60