Fixed player handle being reset on death or disconnection

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
CraftBukkit/Spigot 2010-12-30 05:35:30 +00:00
parent 19dcaeeb01
commit 2250c18a63
2 changed files with 17 additions and 22 deletions

View file

@ -3,10 +3,11 @@ package org.bukkit.craftbukkit;
import net.minecraft.server.EntityPlayerMP; import net.minecraft.server.EntityPlayerMP;
import net.minecraft.server.Packet3Chat; import net.minecraft.server.Packet3Chat;
import org.bukkit.Location;
import org.bukkit.Player; import org.bukkit.Player;
public class CraftPlayer extends CraftHumanEntity implements Player { public class CraftPlayer extends CraftHumanEntity implements Player {
private final EntityPlayerMP entity; private EntityPlayerMP entity;
public CraftPlayer(CraftServer server, EntityPlayerMP entity) { public CraftPlayer(CraftServer server, EntityPlayerMP entity) {
super(server, entity); super(server, entity);
@ -22,12 +23,21 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return entity; return entity;
} }
@Override public void setHandle(final EntityPlayerMP entity) {
public String toString() { this.entity = entity;
return "CraftPlayer{" + "name=" + getName() + '}';
} }
public void sendMessage(String message) { public void sendMessage(String message) {
entity.a.b(new Packet3Chat(message)); entity.a.b(new Packet3Chat(message));
} }
@Override
public void teleportTo(Location location) {
entity.a.a(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
}
@Override
public String toString() {
return "CraftPlayer{" + "name=" + getName() + '}';
}
} }

View file

@ -18,7 +18,6 @@ import org.bukkit.plugin.java.JavaPluginLoader;
public final class CraftServer implements Server { public final class CraftServer implements Server {
private final String serverName = "Craftbukkit"; private final String serverName = "Craftbukkit";
private final String serverVersion; private final String serverVersion;
private final HashMap<String, Player> playerCache = new HashMap<String, Player>();
private final PluginManager pluginManager = new SimplePluginManager(this); private final PluginManager pluginManager = new SimplePluginManager(this);
protected final MinecraftServer console; protected final MinecraftServer console;
@ -57,28 +56,14 @@ public final class CraftServer implements Server {
Player[] players = new Player[online.size()]; Player[] players = new Player[online.size()];
for (int i = 0; i < players.length; i++) { for (int i = 0; i < players.length; i++) {
String name = online.get(i).aw; players[i] = online.get(i).a.getPlayer();
if (playerCache.containsKey(name)) {
players[i] = playerCache.get(name);
} else {
players[i] = new CraftPlayer(this, online.get(i));
playerCache.put(name, players[i]);
}
} }
return players; return players;
} }
public Player getPlayer(EntityPlayerMP entity) { public Player getPlayer(final EntityPlayerMP entity) {
Player result = playerCache.get(entity.aw); return entity.a.getPlayer();
if (result == null) {
result = new CraftPlayer(this, entity);
playerCache.put(entity.aw, result);
}
return result;
} }
public PluginManager getPluginManager() { public PluginManager getPluginManager() {