diff --git a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java index c72b08aa80..55b2f1ef66 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftOfflinePlayer.java @@ -2,11 +2,13 @@ package org.bukkit.craftbukkit; import java.util.LinkedHashMap; import java.util.Map; +import net.minecraft.server.EntityPlayer; import org.bukkit.Bukkit; import org.bukkit.OfflinePlayer; import org.bukkit.Server; import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.SerializableAs; +import org.bukkit.entity.Player; @SerializableAs("Player") public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializable { @@ -19,7 +21,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa } public boolean isOnline() { - return false; + return getPlayer() != null; } public String getName() { @@ -84,4 +86,15 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa public String toString() { return getClass().getSimpleName() + "[name=" + name + "]"; } + + public Player getPlayer() { + for (Object obj: server.getHandle().players) { + EntityPlayer player = (EntityPlayer)obj; + if (player.name.equalsIgnoreCase(getName())) { + return (player.netServerHandler != null) ? player.netServerHandler.getPlayer() : null; + } + } + + return null; + } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index e43f4f0eb5..305d72a76e 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -548,4 +548,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player { return result; } + + public Player getPlayer() { + return this; + } }