mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-12 18:31:36 +01:00
BedLocationFix for CraftBukkit
This commit is contained in:
parent
0234c55ce3
commit
65776d6ed2
@ -1,5 +1,6 @@
|
|||||||
package com.earth2me.essentials;
|
package com.earth2me.essentials;
|
||||||
|
|
||||||
|
import com.earth2me.essentials.craftbukkit.BedLocationFix;
|
||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.textreader.IText;
|
import com.earth2me.essentials.textreader.IText;
|
||||||
import com.earth2me.essentials.textreader.KeywordReplacer;
|
import com.earth2me.essentials.textreader.KeywordReplacer;
|
||||||
@ -233,7 +234,7 @@ public class EssentialsPlayerListener extends PlayerListener
|
|||||||
{
|
{
|
||||||
Location loc = user.getHome(user.getLocation());
|
Location loc = user.getHome(user.getLocation());
|
||||||
if (loc == null) {
|
if (loc == null) {
|
||||||
loc = user.getBedSpawnLocation();
|
loc = BedLocationFix.getBedSpawnLocation(user);
|
||||||
}
|
}
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
user.setCompassTarget(loc);
|
user.setCompassTarget(loc);
|
||||||
|
@ -4,6 +4,7 @@ import static com.earth2me.essentials.I18n._;
|
|||||||
import com.earth2me.essentials.Trade;
|
import com.earth2me.essentials.Trade;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
import com.earth2me.essentials.Util;
|
import com.earth2me.essentials.Util;
|
||||||
|
import com.earth2me.essentials.craftbukkit.BedLocationFix;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -44,7 +45,7 @@ public class Commandhome extends EssentialsCommand
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
if ("bed".equalsIgnoreCase(homeName)) {
|
if ("bed".equalsIgnoreCase(homeName)) {
|
||||||
final Location bed = player.getBedSpawnLocation();
|
final Location bed = BedLocationFix.getBedSpawnLocation(player);
|
||||||
if (bed != null)
|
if (bed != null)
|
||||||
{
|
{
|
||||||
user.getTeleport().teleport(bed, charge);
|
user.getTeleport().teleport(bed, charge);
|
||||||
@ -57,7 +58,7 @@ public class Commandhome extends EssentialsCommand
|
|||||||
final List<String> homes = player.getHomes();
|
final List<String> homes = player.getHomes();
|
||||||
if (homes.isEmpty() && player.equals(user))
|
if (homes.isEmpty() && player.equals(user))
|
||||||
{
|
{
|
||||||
final Location loc = player.getBedSpawnLocation();
|
final Location loc = BedLocationFix.getBedSpawnLocation(player);
|
||||||
if (loc == null)
|
if (loc == null)
|
||||||
{
|
{
|
||||||
if (ess.getSettings().spawnIfNoHome())
|
if (ess.getSettings().spawnIfNoHome())
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ package com.earth2me.essentials.spawn;
|
|||||||
import static com.earth2me.essentials.I18n._;
|
import static com.earth2me.essentials.I18n._;
|
||||||
import com.earth2me.essentials.IEssentials;
|
import com.earth2me.essentials.IEssentials;
|
||||||
import com.earth2me.essentials.User;
|
import com.earth2me.essentials.User;
|
||||||
|
import com.earth2me.essentials.craftbukkit.BedLocationFix;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -31,7 +32,7 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
|
|||||||
Location home = user.getHome(user.getLocation());
|
Location home = user.getHome(user.getLocation());
|
||||||
if (home == null)
|
if (home == null)
|
||||||
{
|
{
|
||||||
home = user.getBedSpawnLocation();
|
home = BedLocationFix.getBedSpawnLocation(user);
|
||||||
}
|
}
|
||||||
if (home != null)
|
if (home != null)
|
||||||
{
|
{
|
||||||
@ -51,7 +52,7 @@ public class EssentialsSpawnPlayerListener extends PlayerListener
|
|||||||
{
|
{
|
||||||
final User user = ess.getUser(event.getPlayer());
|
final User user = ess.getUser(event.getPlayer());
|
||||||
|
|
||||||
if (!user.isNew() || user.getBedSpawnLocation() != null)
|
if (!user.isNew() || BedLocationFix.getBedSpawnLocation(user) != null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user