Implemented getPlayer of OfflinePlayer

This commit is contained in:
Nathan Adams 2011-10-11 14:52:07 +01:00
parent fd57c7111c
commit f4229fcadd
2 changed files with 18 additions and 1 deletions

View File

@ -2,11 +2,13 @@ package org.bukkit.craftbukkit;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import net.minecraft.server.EntityPlayer;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.configuration.serialization.ConfigurationSerializable; import org.bukkit.configuration.serialization.ConfigurationSerializable;
import org.bukkit.configuration.serialization.SerializableAs; import org.bukkit.configuration.serialization.SerializableAs;
import org.bukkit.entity.Player;
@SerializableAs("Player") @SerializableAs("Player")
public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializable { public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializable {
@ -19,7 +21,7 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
} }
public boolean isOnline() { public boolean isOnline() {
return false; return getPlayer() != null;
} }
public String getName() { public String getName() {
@ -84,4 +86,15 @@ public class CraftOfflinePlayer implements OfflinePlayer, ConfigurationSerializa
public String toString() { public String toString() {
return getClass().getSimpleName() + "[name=" + name + "]"; 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;
}
} }

View File

@ -548,4 +548,8 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return result; return result;
} }
public Player getPlayer() {
return this;
}
} }