mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 02:55:47 +01:00
Fixed player handle being reset on death or disconnection
This commit is contained in:
parent
bd53a823d2
commit
a063036210
@ -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();
|
||||
|
@ -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);
|
||||
|
@ -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() + '}';
|
||||
}
|
||||
}
|
||||
|
@ -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<String, Player> playerCache = new HashMap<String, Player>();
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user