From 03445e5b9b20e09583a17b2e08f2f64ec70e2f37 Mon Sep 17 00:00:00 2001 From: KHobbits Date: Sat, 29 Dec 2012 06:43:26 +0000 Subject: Fix home functionality bugs: /home not using bed when enabled /home not giving teleport warning --- .../src/com/earth2me/essentials/Teleport.java | 67 ++++++++++++---------- .../earth2me/essentials/commands/Commandhome.java | 2 +- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java index 241a8328d..fc1a2cc04 100644 --- a/Essentials/src/com/earth2me/essentials/Teleport.java +++ b/Essentials/src/com/earth2me/essentials/Teleport.java @@ -16,30 +16,30 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; public class Teleport implements Runnable, ITeleport { private static final double MOVE_CONSTANT = 0.3; - - + + private class Target { private final Location location; private final String name; - + Target(Location location) { this.location = location; this.name = null; } - + Target(Player entity) { this.name = entity.getName(); this.location = null; } - + public Location getLocation() { if (this.name != null) { - + return ess.getServer().getPlayerExact(name).getLocation(); } return location; @@ -63,12 +63,12 @@ public class Teleport implements Runnable, ITeleport private final IEssentials ess; private static final Logger logger = Logger.getLogger("Minecraft"); 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(); @@ -83,11 +83,11 @@ public class Teleport implements Runnable, ITeleport this.cause = cause; this.respawn = respawn; } - + @Override public void run() { - + if (user == null || !user.isOnline() || user.getLocation() == null) { cancel(false); @@ -98,7 +98,7 @@ public class Teleport implements Runnable, ITeleport cancel(false); return; } - + if (!user.isAuthorized("essentials.teleport.timer.move") && (Math.round(teleportUser.getLocation().getX() * MOVE_CONSTANT) != initX || Math.round(teleportUser.getLocation().getY() * MOVE_CONSTANT) != initY @@ -119,10 +119,12 @@ public class Teleport implements Runnable, ITeleport teleportUser.sendMessage(_("teleportationCommencing")); try { - if (respawn) { + if (respawn) + { teleportUser.getTeleport().respawn(cause); } - else { + else + { teleportUser.getTeleport().now(teleportTarget, cause); } cancel(false); @@ -146,13 +148,13 @@ public class Teleport implements Runnable, ITeleport } } } - + public Teleport(IUser user, IEssentials ess) { this.user = user; this.ess = ess; } - + public void cooldown(boolean check) throws Exception { final Calendar time = new GregorianCalendar(); @@ -168,7 +170,7 @@ public class Teleport implements Runnable, ITeleport // When was the last teleport used? final Long lastTime = user.getLastTeleportTimestamp(); - + if (lastTime > time.getTimeInMillis()) { // This is to make sure time didn't get messed up on last kit use. @@ -225,7 +227,7 @@ public class Teleport implements Runnable, ITeleport } now(new Target(loc), cause); } - + public void now(Player entity, boolean cooldown, TeleportCause cause) throws Exception { if (cooldown) @@ -234,7 +236,7 @@ public class Teleport implements Runnable, ITeleport } now(new Target(entity), cause); } - + private void now(Target target, TeleportCause cause) throws Exception { cancel(false); @@ -249,21 +251,21 @@ public class Teleport implements Runnable, ITeleport { teleport(loc, chargeFor, TeleportCause.PLUGIN); } - + public void teleport(Location loc, Trade chargeFor, TeleportCause cause) throws Exception { teleport(new Target(loc), chargeFor, cause); } - + public void teleport(Player entity, Trade chargeFor, TeleportCause cause) throws Exception { teleport(new Target(entity), chargeFor, cause); } - + private void teleport(Target target, Trade chargeFor, TeleportCause cause) throws Exception { double delay = ess.getSettings().getTeleportDelay(); - + if (chargeFor != null) { chargeFor.isAffordableFor(user); @@ -279,11 +281,11 @@ public class Teleport implements Runnable, ITeleport } return; } - + cancel(false); warnUser(user, delay); initTimer((long)(delay * 1000.0), target, chargeFor, cause); - + teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10); } @@ -292,7 +294,7 @@ public class Teleport implements Runnable, ITeleport { Target target = new Target(user); double delay = ess.getSettings().getTeleportDelay(); - + if (chargeFor != null) { chargeFor.isAffordableFor(user); @@ -308,13 +310,13 @@ public class Teleport implements Runnable, ITeleport } return; } - + cancel(false); warnUser(otherUser, delay); initTimer((long)(delay * 1000.0), otherUser, target, chargeFor, cause, false); teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10); } - + private void warnUser(final IUser user, final double delay) { Calendar c = new GregorianCalendar(); @@ -342,22 +344,27 @@ public class Teleport implements Runnable, ITeleport } return; } - + cancel(false); + warnUser(user, delay); initTimer((long)(delay * 1000.0), user, null, chargeFor, cause, true); teleTimer = ess.scheduleSyncRepeatingTask(this, 10, 10); } - + public void respawn(TeleportCause cause) throws Exception { final Player player = user.getBase(); Location bed = player.getBedSpawnLocation(); - if (bed != null && bed.getBlock().getType() != Material.BED_BLOCK) + if (bed != null && bed.getBlock().getType() == Material.BED_BLOCK) { now(new Target(bed), cause); } else { + if (ess.getSettings().isDebug()) + { + ess.getLogger().info("Could not find bed spawn, forcing respawn event."); + } final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false); ess.getServer().getPluginManager().callEvent(pre); now(new Target(pre.getRespawnLocation()), cause); diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java index 293dbfb6d..a5d355415 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java @@ -69,7 +69,7 @@ public class Commandhome extends EssentialsCommand } else if (homes.isEmpty()) { - throw new Exception(player == user ? _("noHomeSet") : _("noHomeSetPlayer")); + throw new Exception(_("noHomeSetPlayer")); } else if (homes.size() == 1 && player.equals(user)) { -- cgit v1.2.3