diff --git a/src/net/minecraft/server/NetServerHandler.java b/src/net/minecraft/server/NetServerHandler.java index a745b03030..02ac31d70e 100644 --- a/src/net/minecraft/server/NetServerHandler.java +++ b/src/net/minecraft/server/NetServerHandler.java @@ -27,7 +27,10 @@ public class NetServerHandler extends NetHandler private double i; private boolean j; 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) { c = false; @@ -39,9 +42,18 @@ public class NetServerHandler extends NetHandler networkmanager.a(this); e = entityplayermp; 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() { b.a(); if (f++ % 20 == 0) { @@ -67,7 +79,6 @@ public class NetServerHandler extends NetHandler } // CraftBukkit start - Player player = server.getPlayer(e); Location from = new Location(player.getWorld(), g, h, i, e.v, e.w); Location to = player.getLocation(); PlayerMoveEvent event = new PlayerMoveEvent(Type.PLAYER_MOVE, player, from, to); @@ -194,7 +205,6 @@ public class NetServerHandler extends NetHandler float f2) { // CraftBukkit start - Player player = server.getPlayer(e); Location from = player.getLocation(); Location to = new Location(player.getWorld(), d1, d2, d3, f1, f2); PlayerMoveEvent event = new PlayerMoveEvent(Type.PLAYER_TELEPORT, player, from, to); @@ -378,7 +388,7 @@ public class NetServerHandler extends NetHandler c(s); } else { // 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); s = (new StringBuilder()).append("<").append(event.getPlayer().getName()).append("> ").append(event.getMessage()).toString(); // CraftBukkit stop @@ -390,7 +400,7 @@ public class NetServerHandler extends NetHandler private void c(String s) { // 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); if (event.isCancelled()) return; s = event.getMessage(); diff --git a/src/net/minecraft/server/ServerConfigurationManager.java b/src/net/minecraft/server/ServerConfigurationManager.java index e841da9766..dac524b8e8 100644 --- a/src/net/minecraft/server/ServerConfigurationManager.java +++ b/src/net/minecraft/server/ServerConfigurationManager.java @@ -3,6 +3,7 @@ package net.minecraft.server; import java.io.*; import java.util.*; import java.util.logging.Logger; +import org.bukkit.craftbukkit.CraftPlayer; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.event.Event.Type; @@ -90,7 +91,7 @@ public class ServerConfigurationManager { // depending on the outcome. 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(); s2 = s2.substring(s2.indexOf("/") + 1); diff --git a/src/org/bukkit/craftbukkit/CraftPlayer.java b/src/org/bukkit/craftbukkit/CraftPlayer.java index 9e6d44fb67..f10d920c19 100644 --- a/src/org/bukkit/craftbukkit/CraftPlayer.java +++ b/src/org/bukkit/craftbukkit/CraftPlayer.java @@ -3,10 +3,11 @@ package org.bukkit.craftbukkit; import net.minecraft.server.EntityPlayerMP; import net.minecraft.server.Packet3Chat; +import org.bukkit.Location; import org.bukkit.Player; public class CraftPlayer extends CraftHumanEntity implements Player { - private final EntityPlayerMP entity; + private EntityPlayerMP entity; public CraftPlayer(CraftServer server, EntityPlayerMP entity) { super(server, entity); @@ -22,12 +23,21 @@ public class CraftPlayer extends CraftHumanEntity implements Player { return entity; } - @Override - public String toString() { - return "CraftPlayer{" + "name=" + getName() + '}'; + public void setHandle(final EntityPlayerMP entity) { + this.entity = entity; } public void sendMessage(String 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() + '}'; + } } diff --git a/src/org/bukkit/craftbukkit/CraftServer.java b/src/org/bukkit/craftbukkit/CraftServer.java index 9060d062ad..1fe1ee4473 100644 --- a/src/org/bukkit/craftbukkit/CraftServer.java +++ b/src/org/bukkit/craftbukkit/CraftServer.java @@ -18,7 +18,6 @@ import org.bukkit.plugin.java.JavaPluginLoader; public final class CraftServer implements Server { private final String serverName = "Craftbukkit"; private final String serverVersion; - private final HashMap playerCache = new HashMap(); private final PluginManager pluginManager = new SimplePluginManager(this); protected final MinecraftServer console; @@ -57,28 +56,14 @@ public final class CraftServer implements Server { Player[] players = new Player[online.size()]; for (int i = 0; i < players.length; i++) { - String name = online.get(i).aw; - - if (playerCache.containsKey(name)) { - players[i] = playerCache.get(name); - } else { - players[i] = new CraftPlayer(this, online.get(i)); - playerCache.put(name, players[i]); - } + players[i] = online.get(i).a.getPlayer(); } return players; } - public Player getPlayer(EntityPlayerMP entity) { - Player result = playerCache.get(entity.aw); - - if (result == null) { - result = new CraftPlayer(this, entity); - playerCache.put(entity.aw, result); - } - - return result; + public Player getPlayer(final EntityPlayerMP entity) { + return entity.a.getPlayer(); } public PluginManager getPluginManager() {