diff options
13 files changed, 427 insertions, 280 deletions
diff --git a/Essentials/src/com/earth2me/essentials/IEssentials.java b/Essentials/src/com/earth2me/essentials/IEssentials.java index f04c37803..fd5e39bcd 100644 --- a/Essentials/src/com/earth2me/essentials/IEssentials.java +++ b/Essentials/src/com/earth2me/essentials/IEssentials.java @@ -1,6 +1,7 @@ package com.earth2me.essentials; import com.earth2me.essentials.api.IJails; +import com.earth2me.essentials.api.IWarps; import com.earth2me.essentials.metrics.Metrics; import com.earth2me.essentials.perm.PermissionsHandler; import com.earth2me.essentials.register.payment.Methods; @@ -39,7 +40,7 @@ public interface IEssentials extends Plugin IJails getJails(); - Warps getWarps(); + IWarps getWarps(); Worth getWorth(); diff --git a/Essentials/src/com/earth2me/essentials/IUser.java b/Essentials/src/com/earth2me/essentials/IUser.java index 88ff78532..7f46032f8 100644 --- a/Essentials/src/com/earth2me/essentials/IUser.java +++ b/Essentials/src/com/earth2me/essentials/IUser.java @@ -1,5 +1,6 @@ package com.earth2me.essentials; +import com.earth2me.essentials.api.ITeleport; import com.earth2me.essentials.commands.IEssentialsCommand; import java.math.BigDecimal; import java.util.Map; @@ -29,7 +30,7 @@ public interface IUser extends Player void takeMoney(BigDecimal value); void giveMoney(BigDecimal value); - + boolean canAfford(BigDecimal value); String getGroup(); @@ -41,50 +42,47 @@ public interface IUser extends Player Location getHome(Location loc) throws Exception; /** - * 'Hidden' Represents when a player is hidden from others. - * This status includes when the player is hidden via other supported plugins. - * Use isVanished() if you want to check if a user is vanished by Essentials. - * + * 'Hidden' Represents when a player is hidden from others. This status includes when the player is hidden via other + * supported plugins. Use isVanished() if you want to check if a user is vanished by Essentials. + * * @return If the user is hidden or not * @see isVanished */ - boolean isHidden(); - + void setHidden(boolean vanish); - + /** - * 'Vanished' Represents when a player is hidden from others by Essentials. - * This status does NOT include when the player is hidden via other plugins. - * Use isHidden() if you want to check if a user is vanished by any supported plugin. - * + * 'Vanished' Represents when a player is hidden from others by Essentials. This status does NOT include when the + * player is hidden via other plugins. Use isHidden() if you want to check if a user is vanished by any supported + * plugin. + * * @return If the user is vanished or not * @see isHidden */ - boolean isVanished(); - + void setVanished(boolean vanish); - Teleport getTeleport(); + ITeleport getTeleport(); void setJail(String jail); - + boolean isIgnoreExempt(); boolean isAfk(); void setAfk(final boolean set); - + void setLogoutLocation(); - + Location getLogoutLocation(); - + void setConfigProperty(String node, Object object); - + Set<String> getConfigKeys(); - + Map<String, Object> getConfigMap(); - + Map<String, Object> getConfigMap(String node); } diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index e4cb25bdf..792a815d2 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -10,12 +10,9 @@ import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; -public class Teleport implements Runnable, ITeleport +public class Teleport implements ITeleport { - private static final double MOVE_CONSTANT = 0.3; - - - private class Target + public class Target { private final Location location; private final String name; @@ -42,155 +39,40 @@ public class Teleport implements Runnable, ITeleport return location; } } - private final IUser user; - private String teleportUserName; - private int teleTimer = -1; - private long started; // time this task was initiated - private long tpdelay; // how long to delay the teleport - private int health; - // note that I initially stored a clone of the location for reference, but... - // when comparing locations, I got incorrect mismatches (rounding errors, looked like) - // so, the X/Y/Z values are stored instead and rounded off - private long initX; - private long initY; - private long initZ; - private Target teleportTarget; - private boolean respawn; - private boolean canMove; - private Trade chargeFor; + private final IUser teleportOwner; private final IEssentials ess; - private TeleportCause cause; - - private void initTimer(long delay, Target target, Trade chargeFor, TeleportCause cause) - { - initTimer(delay, user, target, chargeFor, cause, false); - } - - private void initTimer(long delay, IUser teleportUser, Target target, Trade chargeFor, TeleportCause cause, boolean respawn) - { - this.started = System.currentTimeMillis(); - this.tpdelay = delay; - this.health = teleportUser.getHealth(); - this.initX = Math.round(teleportUser.getLocation().getX() * MOVE_CONSTANT); - this.initY = Math.round(teleportUser.getLocation().getY() * MOVE_CONSTANT); - this.initZ = Math.round(teleportUser.getLocation().getZ() * MOVE_CONSTANT); - this.teleportUserName = teleportUser.getName(); - this.teleportTarget = target; - this.chargeFor = chargeFor; - this.cause = cause; - this.respawn = respawn; - - this.canMove = user.isAuthorized("essentials.teleport.timer.move"); - - teleTimer = ess.scheduleSyncRepeatingTask(this, 20, 20); - } - - @Override - public void run() - { - - if (user == null || !user.isOnline() || user.getLocation() == null) - { - cancel(false); - return; - } - - IUser teleportUser = ess.getUser(this.teleportUserName); - - if (teleportUser == null || !teleportUser.isOnline()) - { - cancel(false); - return; - } - - final Location currLocation = teleportUser.getLocation(); - if (currLocation == null) - { - cancel(false); - return; - } - - if (!canMove - && (Math.round(currLocation.getX() * MOVE_CONSTANT) != initX - || Math.round(currLocation.getY() * MOVE_CONSTANT) != initY - || Math.round(currLocation.getZ() * MOVE_CONSTANT) != initZ - || teleportUser.getHealth() < health)) - { - // user moved, cancel teleport - cancel(true); - return; - } - - health = teleportUser.getHealth(); // in case user healed, then later gets injured - final long now = System.currentTimeMillis(); - if (now > started + tpdelay) - { - try - { - cooldown(false); - teleportUser.sendMessage(_("teleportationCommencing")); - try - { - if (respawn) - { - teleportUser.getTeleport().respawn(cause); - } - else - { - teleportUser.getTeleport().now(teleportTarget, cause); - } - cancel(false); - if (chargeFor != null) - { - chargeFor.charge(user); - } - } - catch (Throwable ex) - { - ess.showError(user.getBase(), ex, "teleport"); - } - } - catch (Exception ex) - { - user.sendMessage(_("cooldownWithMessage", ex.getMessage())); - if (user != teleportUser) - { - teleportUser.sendMessage(_("cooldownWithMessage", ex.getMessage())); - } - } - } - } + private TimedTeleport timedTeleport; public Teleport(IUser user, IEssentials ess) { - this.user = user; + this.teleportOwner = user; this.ess = ess; } public void cooldown(boolean check) throws Exception { final Calendar time = new GregorianCalendar(); - if (user.getLastTeleportTimestamp() > 0) + if (teleportOwner.getLastTeleportTimestamp() > 0) { // Take the current time, and remove the delay from it. final double cooldown = ess.getSettings().getTeleportCooldown(); final Calendar earliestTime = new GregorianCalendar(); earliestTime.add(Calendar.SECOND, -(int)cooldown); earliestTime.add(Calendar.MILLISECOND, -(int)((cooldown * 1000.0) % 1000.0)); - // This value contains the most recent time a teleport could have been used that would allow another use. + // This value contains the most recent time a teleportPlayer could have been used that would allow another use. final long earliestLong = earliestTime.getTimeInMillis(); - // When was the last teleport used? - final Long lastTime = user.getLastTeleportTimestamp(); + // When was the last teleportPlayer used? + final Long lastTime = teleportOwner.getLastTeleportTimestamp(); if (lastTime > time.getTimeInMillis()) { - // This is to make sure time didn't get messed up on last kit use. + // This is to make sure time didn't get messed up on last teleportPlayer use. // If this happens, let's give the user the benifit of the doubt. - user.setLastTeleportTimestamp(time.getTimeInMillis()); + teleportOwner.setLastTeleportTimestamp(time.getTimeInMillis()); return; } - else if (lastTime > earliestLong && !user.isAuthorized("essentials.teleport.cooldown.bypass")) + else if (lastTime > earliestLong && !teleportOwner.isAuthorized("essentials.teleport.cooldown.bypass")) { time.setTimeInMillis(lastTime); time.add(Calendar.SECOND, (int)cooldown); @@ -201,33 +83,16 @@ public class Teleport implements Runnable, ITeleport // if justCheck is set, don't update lastTeleport; we're just checking if (!check) { - user.setLastTeleportTimestamp(time.getTimeInMillis()); + teleportOwner.setLastTeleportTimestamp(time.getTimeInMillis()); } } - //If we need to cancel a pending teleport call this method - public void cancel(boolean notifyUser) + private void warnUser(final IUser user, final double delay) { - if (teleTimer == -1) - { - return; - } - try - { - ess.getServer().getScheduler().cancelTask(teleTimer); - if (notifyUser) - { - user.sendMessage(_("pendingTeleportCancelled")); - if (teleportUserName != null && !teleportUserName.equals(user.getName())) - { - ess.getUser(teleportUserName).sendMessage(_("pendingTeleportCancelled")); - } - } - } - finally - { - teleTimer = -1; - } + Calendar c = new GregorianCalendar(); + c.add(Calendar.SECOND, (int)delay); + c.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0)); + user.sendMessage(_("dontMoveMessage", Util.formatDateDiff(c.getTimeInMillis()))); } //The now function is used when you want to skip tp delay when teleporting someone to a location or player. @@ -238,26 +103,27 @@ public class Teleport implements Runnable, ITeleport { cooldown(false); } - now(new Target(loc), cause); + now(teleportOwner, new Target(loc), cause); } + @Override public void now(Player entity, boolean cooldown, TeleportCause cause) throws Exception { if (cooldown) { cooldown(false); } - now(new Target(entity), cause); + now(teleportOwner, new Target(entity), cause); } - private void now(Target target, TeleportCause cause) throws Exception + protected void now(IUser teleportee, Target target, TeleportCause cause) throws Exception { cancel(false); - user.setLastLocation(); - user.getBase().teleport(Util.getSafeDestination(target.getLocation()), cause); + teleportee.setLastLocation(); + teleportee.getBase().teleport(Util.getSafeDestination(target.getLocation()), cause); } - //The teleport function is used when you want to normally teleport someone to a location or player. + //The teleportPlayer function is used when you want to normally teleportPlayer someone to a location or player. //This method is nolonger used internally and will be removed. @Deprecated public void teleport(Location loc, Trade chargeFor) throws Exception @@ -265,108 +131,97 @@ public class Teleport implements Runnable, ITeleport teleport(loc, chargeFor, TeleportCause.PLUGIN); } + @Override public void teleport(Location loc, Trade chargeFor, TeleportCause cause) throws Exception { - teleport(new Target(loc), chargeFor, cause); + teleport(teleportOwner, new Target(loc), chargeFor, cause); } + @Override public void teleport(Player entity, Trade chargeFor, TeleportCause cause) throws Exception { - teleport(new Target(entity), chargeFor, cause); + teleport(teleportOwner, new Target(entity), chargeFor, cause); } - private void teleport(Target target, Trade chargeFor, TeleportCause cause) throws Exception + @Override + public void teleportPlayer(IUser teleportee, Location loc, Trade chargeFor, TeleportCause cause) throws Exception { - double delay = ess.getSettings().getTeleportDelay(); - - if (chargeFor != null) - { - chargeFor.isAffordableFor(user); - } - cooldown(true); - if (delay <= 0 || user.isAuthorized("essentials.teleport.timer.bypass")) - { - cooldown(false); - now(target, cause); - if (chargeFor != null) - { - chargeFor.charge(user); - } - return; - } + teleport(teleportee, new Target(loc), chargeFor, cause); + } - cancel(false); - warnUser(user, delay); - initTimer((long)(delay * 1000.0), target, chargeFor, cause); + @Override + public void teleportPlayer(IUser teleportee, Player entity, Trade chargeFor, TeleportCause cause) throws Exception + { + teleport(teleportee, new Target(entity), chargeFor, cause); } - //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 + private void teleport(IUser teleportee, Target target, Trade chargeFor, TeleportCause cause) throws Exception { - Target target = new Target(user); double delay = ess.getSettings().getTeleportDelay(); if (chargeFor != null) { - chargeFor.isAffordableFor(user); + chargeFor.isAffordableFor(teleportOwner); } cooldown(true); - if (delay <= 0 || user.isAuthorized("essentials.teleport.timer.bypass")) + if (delay <= 0 || teleportOwner.isAuthorized("essentials.teleport.timer.bypass") + || teleportee.isAuthorized("essentials.teleport.timer.bypass")) { cooldown(false); - otherUser.getTeleport().now(target, cause); + now(teleportee, target, cause); if (chargeFor != null) { - chargeFor.charge(user); + chargeFor.charge(teleportOwner); } return; } cancel(false); - warnUser(otherUser, delay); - initTimer((long)(delay * 1000.0), otherUser, target, chargeFor, cause, false); + warnUser(teleportee, delay); + initTimer((long)(delay * 1000.0), teleportee, target, chargeFor, cause, false); } - private void warnUser(final IUser user, final double delay) + //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 { - Calendar c = new GregorianCalendar(); - c.add(Calendar.SECOND, (int)delay); - c.add(Calendar.MILLISECOND, (int)((delay * 1000.0) % 1000.0)); - user.sendMessage(_("dontMoveMessage", Util.formatDateDiff(c.getTimeInMillis()))); + Target target = new Target(teleportOwner); + 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 { double delay = ess.getSettings().getTeleportDelay(); if (chargeFor != null) { - chargeFor.isAffordableFor(user); + chargeFor.isAffordableFor(teleportOwner); } cooldown(true); - if (delay <= 0 || user.isAuthorized("essentials.teleport.timer.bypass")) + if (delay <= 0 || teleportOwner.isAuthorized("essentials.teleport.timer.bypass")) { cooldown(false); - respawn(cause); + respawnNow(teleportOwner, cause); if (chargeFor != null) { - chargeFor.charge(user); + chargeFor.charge(teleportOwner); } return; } cancel(false); - warnUser(user, delay); - initTimer((long)(delay * 1000.0), user, null, chargeFor, cause, true); + warnUser(teleportOwner, delay); + initTimer((long)(delay * 1000.0), teleportOwner, null, chargeFor, cause, true); } - public void respawn(TeleportCause cause) throws Exception + protected void respawnNow(IUser teleportee, TeleportCause cause) throws Exception { - final Player player = user.getBase(); + final Player player = teleportee.getBase(); Location bed = player.getBedSpawnLocation(); if (bed != null) { - now(new Target(bed), cause); + now(teleportee, new Target(bed), cause); } else { @@ -376,33 +231,52 @@ public class Teleport implements Runnable, ITeleport } final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false); ess.getServer().getPluginManager().callEvent(pre); - now(new Target(pre.getRespawnLocation()), cause); + now(teleportee, new Target(pre.getRespawnLocation()), cause); } } - //The warp function is a wrapper used to teleport a player to a /warp - public void warp(String warp, Trade chargeFor, TeleportCause cause) throws Exception + //The warp function is a wrapper used to teleportPlayer a player to a /warp + @Override + public void warp(IUser teleportee, String warp, Trade chargeFor, TeleportCause cause) throws Exception { Location loc = ess.getWarps().getWarp(warp); - user.sendMessage(_("warpingTo", warp)); - teleport(new Target(loc), chargeFor, cause); + teleportee.sendMessage(_("warpingTo", warp)); + teleport(teleportee, new Target(loc), chargeFor, cause); } - //The back function is a wrapper used to teleport a player /back to their previous location. + //The back function is a wrapper used to teleportPlayer a player /back to their previous location. + @Override public void back(Trade chargeFor) throws Exception { - teleport(new Target(user.getLastLocation()), chargeFor, TeleportCause.COMMAND); + teleport(teleportOwner, new Target(teleportOwner.getLastLocation()), chargeFor, TeleportCause.COMMAND); } //This function is used to throw a user back after a jail sentence + @Override public void back() throws Exception { - now(new Target(user.getLastLocation()), TeleportCause.COMMAND); + now(teleportOwner, new Target(teleportOwner.getLastLocation()), TeleportCause.COMMAND); } //This function handles teleporting to /home + @Override public void home(Location loc, Trade chargeFor) throws Exception { - teleport(new Target(loc), chargeFor, TeleportCause.COMMAND); + teleport(teleportOwner, new Target(loc), chargeFor, TeleportCause.COMMAND); + } + + //If we need to cancelTimer a pending teleportPlayer call this method + private void cancel(boolean notifyUser) + { + if (timedTeleport != null) + { + timedTeleport.cancelTimer(notifyUser); + timedTeleport = null; + } + } + + private void initTimer(long delay, IUser teleportUser, Target target, Trade chargeFor, TeleportCause cause, boolean respawn) + { + timedTeleport = new TimedTeleport(teleportOwner, ess, this, delay, teleportUser, target, chargeFor, cause, respawn); } } diff --git a/Essentials/src/com/earth2me/essentials/TimedTeleport.java b/Essentials/src/com/earth2me/essentials/TimedTeleport.java new file mode 100644 index 000000000..8946ce3ae --- /dev/null +++ b/Essentials/src/com/earth2me/essentials/TimedTeleport.java @@ -0,0 +1,155 @@ +package com.earth2me.essentials; + +import static com.earth2me.essentials.I18n._; +import com.earth2me.essentials.Teleport.Target; +import org.bukkit.Location; +import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; + + +public class TimedTeleport implements Runnable +{ + private static final double MOVE_CONSTANT = 0.3; + private final IUser teleportOwner; + private final IEssentials ess; + private final Teleport teleport; + private String timer_teleportee; + private int timer_task = -1; + private long timer_started; // time this task was initiated + private long timer_delay; // how long to delay the teleportPlayer + private int timer_health; + // note that I initially stored a clone of the location for reference, but... + // when comparing locations, I got incorrect mismatches (rounding errors, looked like) + // so, the X/Y/Z values are stored instead and rounded off + private long timer_initX; + private long timer_initY; + private long timer_initZ; + private Target timer_teleportTarget; + private boolean timer_respawn; + private boolean timer_canMove; + private Trade timer_chargeFor; + + private TeleportCause timer_cause; + + public TimedTeleport(IUser user, IEssentials ess, Teleport teleport, long delay, IUser teleportUser, Target target, Trade chargeFor, TeleportCause cause, boolean respawn) + { + + this.teleportOwner = user; + this.ess = ess; + this.teleport = teleport; + this.timer_started = System.currentTimeMillis(); + this.timer_delay = delay; + this.timer_health = teleportUser.getHealth(); + this.timer_initX = Math.round(teleportUser.getLocation().getX() * MOVE_CONSTANT); + this.timer_initY = Math.round(teleportUser.getLocation().getY() * MOVE_CONSTANT); + this.timer_initZ = Math.round(teleportUser.getLocation().getZ() * MOVE_CONSTANT); + this.timer_teleportee = teleportUser.getName(); + this.timer_teleportTarget = target; + this.timer_chargeFor = chargeFor; + this.timer_cause = cause; + this.timer_respawn = respawn; + this.timer_canMove = user.isAuthorized("essentials.teleport.timer.move"); + + timer_task = ess.scheduleSyncRepeatingTask(this, 20, 20); + } + + @Override + public void run() + { + + if (teleportOwner == null || !teleportOwner.isOnline() || teleportOwner.getLocation() == null) + { + cancelTimer(false); + return; + } + + IUser teleportUser = ess.getUser(this.timer_teleportee); + + if (teleportUser == null || !teleportUser.isOnline()) + { + cancelTimer(false); + return; + } + + final Location currLocation = teleportUser.getLocation(); + if (currLocation == null) + { + cancelTimer(false); + return; + } + + if (!timer_canMove + && (Math.round(currLocation.getX() * MOVE_CONSTANT) != timer_initX + || Math.round(currLocation.getY() * MOVE_CONSTANT) != timer_initY + || Math.round(currLocation.getZ() * MOVE_CONSTANT) != timer_initZ + || teleportUser.getHealth() < timer_health)) + { + // user moved, cancelTimer teleportPlayer + cancelTimer(true); + return; + } + + timer_health = teleportUser.getHealth(); // in case user healed, then later gets injured + final long now = System.currentTimeMillis(); + if (now > timer_started + timer_delay) + { + try + { + teleport.cooldown(false); + teleportUser.sendMessage(_("teleportationCommencing")); + try + { + if (timer_respawn) + { + teleport.respawnNow(teleportUser, timer_cause); + } + else + { + teleport.now(teleportUser, timer_teleportTarget, timer_cause); + } + cancelTimer(false); + if (timer_chargeFor != null) + { + timer_chargeFor.charge(teleportOwner); + } + } + catch (Throwable ex) + { + ess.showError(teleportOwner.getBase(), ex, "teleport"); + } + } + catch (Exception ex) + { + teleportOwner.sendMessage(_("cooldownWithMessage", ex.getMessage())); + if (teleportOwner != teleportUser) + { + teleportUser.sendMessage(_("cooldownWithMessage", ex.getMessage())); + } + } + } + } + + //If we need to cancelTimer a pending teleportPlayer call this method + public void cancelTimer(boolean notifyUser) + { + if (timer_task == -1) + { + return; + } + try + { + ess.getServer().getScheduler().cancelTask(timer_task); + if (notifyUser) + { + teleportOwner.sendMessage(_("pendingTeleportCancelled")); + if (timer_teleportee != null && !timer_teleportee.equals(teleportOwner.getName())) + { + ess.getUser(timer_teleportee).sendMessage(_("pendingTeleportCancelled")); + } + } + } + finally + { + timer_task = -1; + } + } +} diff --git a/Essentials/src/com/earth2me/essentials/Warps.java b/Essentials/src/com/earth2me/essentials/Warps.java index c5cfb12df..4ee883b06 100644 --- a/Essentials/src/com/earth2me/essentials/Warps.java +++ b/Essentials/src/com/earth2me/essentials/Warps.java @@ -38,7 +38,8 @@ public class Warps implements IConf, IWarps return warpPoints.isEmpty(); } - public Collection<String> getWarpNames() + @Override + public Collection<String> getList() { final List<String> keys = new ArrayList<String>(); for (StringIgnoreCase stringIgnoreCase : warpPoints.keySet()) @@ -87,7 +88,8 @@ public class Warps implements IConf, IWarps } } - public void delWarp(String name) throws Exception + @Override + public void removeWarp(String name) throws Exception { EssentialsConf conf = warpPoints.get(new StringIgnoreCase(name)); if (conf == null) @@ -132,25 +134,17 @@ public class Warps implements IConf, IWarps } } - // This is for api support, and so 3.x will not break this api - @Override - public Collection<String> getList() - { - return getWarpNames(); - } - - // This is for api support, and so 3.x will not break this api + //This is here for future 3.x api support. Not implemented here becasue storage is handled differently @Override - public void removeWarp(String name) throws Exception + public File getWarpFile(String name) throws InvalidNameException { - delWarp(name); + throw new UnsupportedOperationException("Not supported yet."); } - //This is here for future 3.x api support. Not implemented here becasue storage is handled differently @Override - public File getWarpFile(String name) throws InvalidNameException + public int getCount() { - throw new UnsupportedOperationException("Not supported yet."); + return getList().size(); } private static class StringIgnoreCase diff --git a/Essentials/src/com/earth2me/essentials/api/ITeleport.java b/Essentials/src/com/earth2me/essentials/api/ITeleport.java index 8fb1778ac..a7f296572 100644 --- a/Essentials/src/com/earth2me/essentials/api/ITeleport.java +++ b/Essentials/src/com/earth2me/essentials/api/ITeleport.java @@ -1,17 +1,128 @@ package com.earth2me.essentials.api; +import com.earth2me.essentials.IUser; +import com.earth2me.essentials.Teleport.Target; +import com.earth2me.essentials.Trade; import org.bukkit.Location; +import org.bukkit.entity.Player; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public interface ITeleport { /** - * Used to skip teleport delay when teleporting someone to a location or player. - * @param loc - * @param cooldown - * @param cause + * Used to skip teleportPlayer delay when teleporting someone to a location or player. + * + * @param loc - Where should the player end up + * @param cooldown - If cooldown should be enforced + * @param cause - The reported teleportPlayer cause * @throws Exception */ void now(Location loc, boolean cooldown, TeleportCause cause) throws Exception; + + /** + * Used to skip teleportPlayer delay when teleporting someone to a location or player. + * + * @param entity - Where should the player end up + * @param cooldown - If cooldown should be enforced + * @param cause - The reported teleportPlayer cause + * @throws Exception + */ + void now(Player entity, boolean cooldown, TeleportCause cause) throws Exception; + + /** + * Teleport a player to a specific location + * + * @param loc - Where should the player end up + * @param chargeFor - What the user will be charged if teleportPlayer is successful + * @param cause - The reported teleportPlayer cause + * @throws Exception + */ + void teleport(Location loc, Trade chargeFor, TeleportCause cause) throws Exception; + + /** + * Teleport a player to a specific player + * + * @param entity - Where should the player end up + * @param chargeFor - What the user will be charged if teleportPlayer is successful + * @param cause - The reported teleportPlayer cause + * @throws Exception + */ + void teleport(Player entity, Trade chargeFor, TeleportCause cause) throws Exception; + + /** + * Teleport a player to a specific location + * + * @param otherUser - Which user will be teleported + * @param loc - Where should the player end up + * @param chargeFor - What the user will be charged if teleportPlayer is successful + * @param cause - The reported teleportPlayer cause + * @throws Exception + */ + void teleportPlayer(IUser otherUser, Location loc, Trade chargeFor, TeleportCause cause) throws Exception; + + /** + * Teleport a player to a specific player + * + * @param otherUser - Which user will be teleported + * @param entity - Where should the player end up + * @param chargeFor - What the user will be charged if teleportPlayer is successful + * @param cause - The reported teleportPlayer cause + * @throws Exception + */ + void teleportPlayer(IUser otherUser, Player entity, Trade chargeFor, 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, 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 + * @param cause - The reported teleportPlayer cause + * @throws Exception + */ + public void respawn(final Trade chargeFor, TeleportCause cause) throws Exception; + + /** + * Teleport wrapper used to handle /warp teleports + * + * @param otherUser - Which user will be teleported + * @param warp - The name of the warp the user will be teleported too. + * @param chargeFor - What the user will be charged if teleportPlayer is successful + * @param cause - The reported teleportPlayer cause + * @throws Exception + */ + public void warp(IUser otherUser, String warp, Trade chargeFor, TeleportCause cause) throws Exception; + + /** + * Teleport wrapper used to handle /back teleports + * + * @param chargeFor - What the user will be charged if teleportPlayer is successful + * @throws Exception + */ + public void back(Trade chargeFor) throws Exception; + + /** + * Teleport wrapper used to handle throwing user home after a jail sentence + * + * @throws Exception + */ + public void back() throws Exception; + + /** + * Teleport wrapper used to handle /home teleports + * + * @param loc - Location where player will be teleported too + * @param chargeFor - What the user will be charged if teleportPlayer is successful + * @throws Exception + */ + public void home(Location loc, Trade chargeFor) throws Exception; } diff --git a/Essentials/src/com/earth2me/essentials/api/IWarps.java b/Essentials/src/com/earth2me/essentials/api/IWarps.java index 1866083a5..e1f7a85d0 100644 --- a/Essentials/src/com/earth2me/essentials/api/IWarps.java +++ b/Essentials/src/com/earth2me/essentials/api/IWarps.java @@ -1,5 +1,6 @@ package com.earth2me.essentials.api; +import com.earth2me.essentials.IConf; import java.io.File; import java.util.Collection; @@ -7,7 +8,7 @@ import com.earth2me.essentials.commands.WarpNotFoundException; import org.bukkit.Location; -public interface IWarps +public interface IWarps extends IConf { /** * Get a warp by name @@ -27,6 +28,13 @@ public interface IWarps Collection<String> getList(); /** + * Gets the number of warps + * + * @return the size of the list of warps + */ + int getCount(); + + /** * Delete a warp from the warp DB * * @param name - Name of warp @@ -51,13 +59,11 @@ public interface IWarps boolean isEmpty(); /** - * Get a warp file - * note: this is not yet implemented, as 3.x uses different storage methods + * Get a warp file note: this is not yet implemented, as 3.x uses different storage methods * * @param name - name of file * @return - an instance of the file * @throws InvalidNameException - When the file is not found */ File getWarpFile(String name) throws InvalidNameException; - } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java index 5eab72b33..3b7c42b4c 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanddelwarp.java @@ -19,7 +19,7 @@ public class Commanddelwarp extends EssentialsCommand { throw new NotEnoughArgumentsException(); } - ess.getWarps().delWarp(args[0]); + ess.getWarps().removeWarp(args[0]); sender.sendMessage(_("deleteWarp", args[0])); } } diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java index 542299c13..279d069aa 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandsetwarp.java @@ -3,7 +3,7 @@ package com.earth2me.essentials.commands; import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; -import com.earth2me.essentials.Warps; +import com.earth2me.essentials.api.IWarps; import org.bukkit.Location; import org.bukkit.Server; @@ -29,7 +29,7 @@ public class Commandsetwarp extends EssentialsCommand } final Location loc = user.getLocation(); - final Warps warps = ess.getWarps(); + final IWarps warps = ess.getWarps(); Location warpLoc = null; try diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java index 4ab9b3596..5984a29fe 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandwarp.java @@ -4,7 +4,7 @@ import static com.earth2me.essentials.I18n._; import com.earth2me.essentials.Trade; import com.earth2me.essentials.User; import com.earth2me.essentials.Util; -import com.earth2me.essentials.Warps; +import com.earth2me.essentials.api.IWarps; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Iterator; @@ -60,7 +60,7 @@ public class Commandwarp extends EssentialsCommand throw new NoChargeException(); } User otherUser = getPlayer(server, args, 1, true, false); - otherUser.getTeleport().warp(args[0], null, TeleportCause.COMMAND); + otherUser.getTeleport().warp(otherUser, args[0], null, TeleportCause.COMMAND); throw new NoChargeException(); } @@ -68,12 +68,12 @@ public class Commandwarp extends EssentialsCommand //TODO: Use one of the new text classes, like /help ? private void warpList(final CommandSender sender, final String[] args) throws Exception { - final Warps warps = ess.getWarps(); + final IWarps warps = ess.getWarps(); if (warps.isEmpty()) { throw new Exception(_("noWarpsDefined")); } - final List<String> warpNameList = new ArrayList<String>(warps.getWarpNames()); + final List<String> warpNameList = new ArrayList<String>(warps.getList()); if (sender instanceof User) { @@ -118,6 +118,6 @@ public class Commandwarp extends EssentialsCommand { throw new Exception(_("warpUsePermission")); } - user.getTeleport().warp(name, charge, TeleportCause.COMMAND); + owner.getTeleport().warp(user, name, charge, TeleportCause.COMMAND); } } diff --git a/Essentials/src/com/earth2me/essentials/metrics/MetricsStarter.java b/Essentials/src/com/earth2me/essentials/metrics/MetricsStarter.java index b22e8470d..f3da96675 100644 --- a/Essentials/src/com/earth2me/essentials/metrics/MetricsStarter.java +++ b/Essentials/src/com/earth2me/essentials/metrics/MetricsStarter.java @@ -115,7 +115,7 @@ public class MetricsStarter implements Runnable @Override public int getValue() { - return ess.getWarps().getWarpNames().size(); + return ess.getWarps().getCount(); } }); @@ -134,7 +134,7 @@ public class MetricsStarter implements Runnable { enabledGraph.addPlotter(new SimplePlotter("Kits")); } - if (ess.getWarps().getWarpNames().size() > 0) + if (ess.getWarps().getCount() > 0) { enabledGraph.addPlotter(new SimplePlotter("Warps")); } diff --git a/Essentials/src/com/earth2me/essentials/signs/SignWarp.java b/Essentials/src/com/earth2me/essentials/signs/SignWarp.java index ef52ceb60..5f4be8f09 100644 --- a/Essentials/src/com/earth2me/essentials/signs/SignWarp.java +++ b/Essentials/src/com/earth2me/essentials/signs/SignWarp.java @@ -58,7 +58,7 @@ public class SignWarp extends EssentialsSign final Trade charge = getTrade(sign, 3, ess); try { - player.getTeleport().warp(warpName, charge, TeleportCause.PLUGIN); + player.getTeleport().warp(player, warpName, charge, TeleportCause.PLUGIN); Trade.log("Sign", "Warp", "Interact", username, null, username, charge, sign.getBlock().getLocation(), ess); } catch (Exception ex) diff --git a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java index b59f0a0fe..35edd172c 100644 --- a/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java +++ b/EssentialsSpawn/src/com/earth2me/essentials/spawn/Commandspawn.java @@ -22,13 +22,13 @@ public class Commandspawn extends EssentialsCommand @Override public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception - { + { final Trade charge = new Trade(this.getName(), ess); charge.isAffordableFor(user); if (args.length > 0 && user.isAuthorized("essentials.spawn.others")) { final User otherUser = getPlayer(server, user, args, 0); - respawn(otherUser, charge); + respawn(user, otherUser, charge); if (!otherUser.equals(user)) { otherUser.sendMessage(_("teleportAtoB", user.getDisplayName(), "spawn")); @@ -36,8 +36,8 @@ public class Commandspawn extends EssentialsCommand } } else - { - respawn(user, charge); + { + respawn(user, user, charge); } throw new NoChargeException(); } @@ -50,14 +50,22 @@ public class Commandspawn extends EssentialsCommand throw new NotEnoughArgumentsException(); } final User user = getPlayer(server, args, 0, true, false); - respawn(user, null); + respawn(null, user, null); user.sendMessage(_("teleportAtoB", Console.NAME, "spawn")); sender.sendMessage(_("teleporting")); } - - private void respawn (final User user, final Trade charge) throws Exception { + + private void respawn(final User teleportOwner, final User teleportee, final Trade charge) throws Exception + { final SpawnStorage spawns = (SpawnStorage)this.module; - final Location spawn = spawns.getSpawn(user.getGroup()); - user.getTeleport().teleport(spawn, charge, TeleportCause.COMMAND); + final Location spawn = spawns.getSpawn(teleportee.getGroup()); + if (teleportOwner == null) + { + teleportee.getTeleport().now(spawn, false, TeleportCause.COMMAND); + } + else + { + teleportOwner.getTeleport().teleportPlayer(teleportee, spawn, charge, TeleportCause.COMMAND); + } } } |