Fixed player handle being reset on death or disconnection

This commit is contained in:
Dinnerbone 2010-12-30 05:35:30 +00:00
parent bd53a823d2
commit a063036210
4 changed files with 35 additions and 29 deletions

View File

@ -27,7 +27,10 @@ public class NetServerHandler extends NetHandler
private double i; private double i;
private boolean j; private boolean j;
private Map k; private Map k;
private final CraftServer server; // CraftBukkit
// CraftBukkit - next 2 lines
private final CraftServer server;
private final CraftPlayer player;
public NetServerHandler(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayerMP entityplayermp) { public NetServerHandler(MinecraftServer minecraftserver, NetworkManager networkmanager, EntityPlayerMP entityplayermp) {
c = false; c = false;
@ -39,9 +42,18 @@ public class NetServerHandler extends NetHandler
networkmanager.a(this); networkmanager.a(this);
e = entityplayermp; e = entityplayermp;
entityplayermp.a = this; entityplayermp.a = this;
server = minecraftserver.server; // CraftBukkit
// CraftBukkit - next 2 lines
server = minecraftserver.server;
player = new CraftPlayer(server, e);
} }
// CraftBukkit start
public CraftPlayer getPlayer() {
return player;
}
// CraftBukkit end
public void a() { public void a() {
b.a(); b.a();
if (f++ % 20 == 0) { if (f++ % 20 == 0) {
@ -67,7 +79,6 @@ public class NetServerHandler extends NetHandler
} }
// CraftBukkit start // CraftBukkit start
Player player = server.getPlayer(e);
Location from = new Location(player.getWorld(), g, h, i, e.v, e.w); Location from = new Location(player.getWorld(), g, h, i, e.v, e.w);
Location to = player.getLocation(); Location to = player.getLocation();
PlayerMoveEvent event = new PlayerMoveEvent(Type.PLAYER_MOVE, player, from, to); PlayerMoveEvent event = new PlayerMoveEvent(Type.PLAYER_MOVE, player, from, to);
@ -194,7 +205,6 @@ public class NetServerHandler extends NetHandler
float f2) { float f2) {
// CraftBukkit start // CraftBukkit start
Player player = server.getPlayer(e);
Location from = player.getLocation(); Location from = player.getLocation();
Location to = new Location(player.getWorld(), d1, d2, d3, f1, f2); Location to = new Location(player.getWorld(), d1, d2, d3, f1, f2);
PlayerMoveEvent event = new PlayerMoveEvent(Type.PLAYER_TELEPORT, player, from, to); PlayerMoveEvent event = new PlayerMoveEvent(Type.PLAYER_TELEPORT, player, from, to);
@ -378,7 +388,7 @@ public class NetServerHandler extends NetHandler
c(s); c(s);
} else { } else {
// CraftBukkit start // CraftBukkit start
PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_CHAT, server.getPlayer(e), s); PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_CHAT, player, s);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
s = (new StringBuilder()).append("<").append(event.getPlayer().getName()).append("> ").append(event.getMessage()).toString(); s = (new StringBuilder()).append("<").append(event.getPlayer().getName()).append("> ").append(event.getMessage()).toString();
// CraftBukkit stop // CraftBukkit stop
@ -390,7 +400,7 @@ public class NetServerHandler extends NetHandler
private void c(String s) { private void c(String s) {
// CraftBukkit start // CraftBukkit start
PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_COMMAND, server.getPlayer(e), s); PlayerChatEvent event = new PlayerChatEvent(Type.PLAYER_COMMAND, player, s);
server.getPluginManager().callEvent(event); server.getPluginManager().callEvent(event);
if (event.isCancelled()) return; if (event.isCancelled()) return;
s = event.getMessage(); s = event.getMessage();

View File

@ -3,6 +3,7 @@ package net.minecraft.server;
import java.io.*; import java.io.*;
import java.util.*; import java.util.*;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.bukkit.craftbukkit.CraftPlayer;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.event.Event.Type; import org.bukkit.event.Event.Type;
@ -90,7 +91,7 @@ public class ServerConfigurationManager {
// depending on the outcome. // depending on the outcome.
EntityPlayerMP entity = new EntityPlayerMP(c, c.e, s, new ItemInWorldManager(c.e)); EntityPlayerMP entity = new EntityPlayerMP(c, c.e, s, new ItemInWorldManager(c.e));
PlayerLoginEvent event = new PlayerLoginEvent(Type.PLAYER_LOGIN, server.getPlayer(entity)); PlayerLoginEvent event = new PlayerLoginEvent(Type.PLAYER_LOGIN, new CraftPlayer(server, entity));
String s2 = netloginhandler.b.b().toString(); String s2 = netloginhandler.b.b().toString();
s2 = s2.substring(s2.indexOf("/") + 1); s2 = s2.substring(s2.indexOf("/") + 1);

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() {