Add in checks for potential NPEs. Fixes BUKKIT-1706 and BUKKIT-1590.

This commit is contained in:
Travis Watkins 2012-05-24 19:11:05 -05:00
parent 2f16b8ffa3
commit c1bc0df718
4 changed files with 13 additions and 1 deletions

View File

@ -443,6 +443,8 @@ public class CraftWorld implements World {
// Forces the client to update to the new time immediately
for (Player p : getPlayers()) {
CraftPlayer cp = (CraftPlayer) p;
if (cp.getHandle().netServerHandler == null) continue;
cp.getHandle().netServerHandler.sendPacket(new Packet4UpdateTime(cp.getHandle().getPlayerTime()));
}
}
@ -767,6 +769,8 @@ public class CraftWorld implements World {
radius *= radius;
for (Player player : getPlayers()) {
if (((CraftPlayer) player).getHandle().netServerHandler == null) continue;
distance = (int) player.getLocation().distanceSquared(location);
if (distance <= radius) {
((CraftPlayer) player).getHandle().netServerHandler.sendPacket(packet);

View File

@ -221,6 +221,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
}
private void openCustomInventory(Inventory inventory, EntityPlayer player, int windowType) {
if (player.netServerHandler == null) return;
Container container = new CraftContainer(inventory, this, player.nextContainerCounter());
container = CraftEventFactory.callInventoryOpenEvent(player, container);
@ -270,6 +271,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
public void openInventory(InventoryView inventory) {
if (!(getHandle() instanceof EntityPlayer)) return; // TODO: NPC support?
if (((EntityPlayer) getHandle()).netServerHandler == null) return;
if (getHandle().activeContainer != getHandle().defaultContainer) {
// fire INVENTORY_CLOSE if one already open
((EntityPlayer)getHandle()).netServerHandler.handleContainerClose(new Packet101CloseWindow(getHandle().activeContainer.windowId));

View File

@ -240,6 +240,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
getHandle().effects.remove(type.getId());
getHandle().e = true; // Should be called updateEffects
if (getHandle() instanceof EntityPlayer) {
if (((EntityPlayer) getHandle()).netServerHandler == null) return;
((EntityPlayer) getHandle()).netServerHandler.sendPacket(new Packet42RemoveMobEffect(getHandle().id, new MobEffect(type.getId(), 0, 0)));
}
}

View File

@ -178,6 +178,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
Packet201PlayerInfo packet = new Packet201PlayerInfo(name, true, getHandle().ping);
for (int i = 0; i < server.getHandle().players.size(); ++i) {
EntityPlayer entityplayer = (EntityPlayer) server.getHandle().players.get(i);
if (entityplayer.netServerHandler == null) continue;
if (entityplayer.getBukkitEntity().canSee(this)) {
entityplayer.netServerHandler.sendPacket(oldpacket);
@ -587,6 +588,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
public void hidePlayer(Player player) {
Validate.notNull(player, "hidden player cannot be null");
if (getHandle().netServerHandler == null) return;
if (equals(player)) return;
if (hiddenPlayers.containsKey(player.getName())) return;
hiddenPlayers.put(player.getName(), player);
@ -605,6 +607,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
public void showPlayer(Player player) {
Validate.notNull(player, "shown player cannot be null");
if (getHandle().netServerHandler == null) return;
if (equals(player)) return;
if (!hiddenPlayers.containsKey(player.getName())) return;
hiddenPlayers.remove(player.getName());
@ -732,6 +735,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
public void sendPluginMessage(Plugin source, String channel, byte[] message) {
StandardMessenger.validatePluginMessage(server.getMessenger(), source, channel, message);
if (getHandle().netServerHandler == null) return;
if (channels.contains(channel)) {
Packet250CustomPayload packet = new Packet250CustomPayload();
@ -755,6 +759,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
public void sendSupportedChannels() {
if (getHandle().netServerHandler == null) return;
Set<String> listening = server.getMessenger().getIncomingChannels();
if (!listening.isEmpty()) {