summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2012-12-09 17:10:12 +0000
committerKHobbits <rob@khobbits.co.uk>2012-12-09 17:10:12 +0000
commit4f21490ec8f4d522433f070ad17ef158bc79cd7c (patch)
tree8c619eee352057bb073788bd7ee98b94105b42e1
parenta9ace1163f7cb94a6aab1f18350a5ffa4f022530 (diff)
downloadEssentials-4f21490ec8f4d522433f070ad17ef158bc79cd7c.tar
Essentials-4f21490ec8f4d522433f070ad17ef158bc79cd7c.tar.gz
Essentials-4f21490ec8f4d522433f070ad17ef158bc79cd7c.tar.lz
Essentials-4f21490ec8f4d522433f070ad17ef158bc79cd7c.tar.xz
Essentials-4f21490ec8f4d522433f070ad17ef158bc79cd7c.zip
Move null bed check to teleport code
-rw-r--r--Essentials/src/com/earth2me/essentials/Teleport.java21
-rw-r--r--Essentials/src/com/earth2me/essentials/commands/Commandhome.java6
2 files changed, 15 insertions, 12 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Teleport.java b/Essentials/src/com/earth2me/essentials/Teleport.java
index 5eba636d5..dd39b98ed 100644
--- a/Essentials/src/com/earth2me/essentials/Teleport.java
+++ b/Essentials/src/com/earth2me/essentials/Teleport.java
@@ -2,10 +2,12 @@ package com.earth2me.essentials;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.api.ITeleport;
+import com.earth2me.essentials.commands.NoChargeException;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.logging.Logger;
import org.bukkit.Location;
+import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
@@ -241,7 +243,7 @@ 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);
@@ -321,10 +323,17 @@ public class Teleport implements Runnable, ITeleport
public void respawn(final Trade chargeFor, TeleportCause cause) throws Exception
{
final Player player = user.getBase();
- final Location bed = player.getBedSpawnLocation();
- final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, bed == null ? player.getWorld().getSpawnLocation() : bed, bed != null);
- ess.getServer().getPluginManager().callEvent(pre);
- teleport(new Target(pre.getRespawnLocation()), chargeFor, cause);
+ Location bed = player.getBedSpawnLocation();
+ if (bed != null && bed.getBlock().getType() != Material.BED_BLOCK)
+ {
+ teleport(bed, chargeFor, cause);
+ }
+ else
+ {
+ final PlayerRespawnEvent pre = new PlayerRespawnEvent(player, player.getWorld().getSpawnLocation(), false);
+ ess.getServer().getPluginManager().callEvent(pre);
+ teleport(new Target(pre.getRespawnLocation()), chargeFor, cause);
+ }
}
//The warp function is a wrapper used to teleport a player to a /warp
@@ -332,7 +341,7 @@ public class Teleport implements Runnable, ITeleport
{
Location loc = ess.getWarps().getWarp(warp);
user.sendMessage(_("warpingTo", warp));
- teleport(new Target(loc), chargeFor, cause);
+ teleport(new Target(loc), chargeFor, cause);
}
//The back function is a wrapper used to teleport a player /back to their previous location.
diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java
index de6e1ea9b..293dbfb6d 100644
--- a/Essentials/src/com/earth2me/essentials/commands/Commandhome.java
+++ b/Essentials/src/com/earth2me/essentials/commands/Commandhome.java
@@ -65,13 +65,7 @@ public class Commandhome extends EssentialsCommand
final List<String> homes = player.getHomes();
if (homes.isEmpty() && player.equals(user))
{
- if (bed != null)
- {
- user.getTeleport().teleport(bed, charge, TeleportCause.COMMAND);
- throw new NoChargeException();
- }
user.getTeleport().respawn(charge, TeleportCause.COMMAND);
-
}
else if (homes.isEmpty())
{