BedLocationFix for CraftBukkit

This commit is contained in:
snowleo 2011-11-27 04:46:33 +01:00
parent 0234c55ce3
commit 65776d6ed2
4 changed files with 35 additions and 5 deletions

View File

@ -1,5 +1,6 @@
package com.earth2me.essentials;
import com.earth2me.essentials.craftbukkit.BedLocationFix;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.textreader.KeywordReplacer;
@ -233,7 +234,7 @@ public class EssentialsPlayerListener extends PlayerListener
{
Location loc = user.getHome(user.getLocation());
if (loc == null) {
loc = user.getBedSpawnLocation();
loc = BedLocationFix.getBedSpawnLocation(user);
}
if (loc != null) {
user.setCompassTarget(loc);

View File

@ -4,6 +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.craftbukkit.BedLocationFix;
import java.util.List;
import java.util.Locale;
import org.bukkit.Location;
@ -44,7 +45,7 @@ public class Commandhome extends EssentialsCommand
try
{
if ("bed".equalsIgnoreCase(homeName)) {
final Location bed = player.getBedSpawnLocation();
final Location bed = BedLocationFix.getBedSpawnLocation(player);
if (bed != null)
{
user.getTeleport().teleport(bed, charge);
@ -57,7 +58,7 @@ public class Commandhome extends EssentialsCommand
final List<String> homes = player.getHomes();
if (homes.isEmpty() && player.equals(user))
{
final Location loc = player.getBedSpawnLocation();
final Location loc = BedLocationFix.getBedSpawnLocation(player);
if (loc == null)
{
if (ess.getSettings().spawnIfNoHome())

View File

@ -0,0 +1,27 @@
package com.earth2me.essentials.craftbukkit;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.entity.Player;
public class BedLocationFix
{
/*
* Adds missing null pointer check to getHandle().getBed()
*/
public static Location getBedSpawnLocation(final Player player)
{
final CraftPlayer cplayer = (CraftPlayer)player;
final World world = player.getServer().getWorld(cplayer.getHandle().spawnWorld);
if (world != null && cplayer.getHandle().getBed() != null)
{
return new Location(world, cplayer.getHandle().getBed().x, cplayer.getHandle().getBed().y, cplayer.getHandle().getBed().z);
}
else
{
return null;
}
}
}

View File

@ -3,6 +3,7 @@ package com.earth2me.essentials.spawn;
import static com.earth2me.essentials.I18n._;
import com.earth2me.essentials.IEssentials;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.BedLocationFix;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.bukkit.Location;
@ -31,7 +32,7 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
Location home = user.getHome(user.getLocation());
if (home == null)
{
home = user.getBedSpawnLocation();
home = BedLocationFix.getBedSpawnLocation(user);
}
if (home != null)
{
@ -51,7 +52,7 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
{
final User user = ess.getUser(event.getPlayer());
if (!user.isNew() || user.getBedSpawnLocation() != null)
if (!user.isNew() || BedLocationFix.getBedSpawnLocation(user) != null)
{
return;
}