Remove Player cache and edit CraftPlayer.equals to account for EntityID. Fixes BUKKIT-1541 and Addresses BUKKIT-761

Dieser Commit ist enthalten in:
feildmaster 2012-04-21 18:02:25 -05:00
Ursprung 53ed0dad48
Commit 99aeb32d0d
2 geänderte Dateien mit 20 neuen und 42 gelöschten Zeilen

Datei anzeigen

@ -1,28 +1,23 @@
package org.bukkit.craftbukkit.entity; package org.bukkit.craftbukkit.entity;
import com.google.common.collect.MapMaker; import java.util.List;
import java.util.UUID;
import net.minecraft.server.*; import net.minecraft.server.*;
import org.bukkit.Location;
import org.bukkit.EntityEffect; import org.bukkit.EntityEffect;
import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.entity.Vehicle;
import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.metadata.MetadataValue; import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
public abstract class CraftEntity implements org.bukkit.entity.Entity { public abstract class CraftEntity implements org.bukkit.entity.Entity {
private static final Map<String, CraftPlayer> players = new MapMaker().softValues().makeMap();
protected final CraftServer server; protected final CraftServer server;
protected Entity entity; protected Entity entity;
private EntityDamageEvent lastDamageEvent; private EntityDamageEvent lastDamageEvent;
@ -39,7 +34,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
if (entity instanceof EntityLiving) { if (entity instanceof EntityLiving) {
// Players // Players
if (entity instanceof EntityHuman) { if (entity instanceof EntityHuman) {
if (entity instanceof EntityPlayer) { return getPlayer((EntityPlayer) entity); } if (entity instanceof EntityPlayer) { return new CraftPlayer(server, (EntityPlayer) entity); }
else { return new CraftHumanEntity(server, (EntityHuman) entity); } else { return new CraftHumanEntity(server, (EntityHuman) entity); }
} }
else if (entity instanceof EntityCreature) { else if (entity instanceof EntityCreature) {
@ -275,19 +270,6 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return getHandle().uniqueId; return getHandle().uniqueId;
} }
private static CraftPlayer getPlayer(EntityPlayer entity) {
CraftPlayer result = players.get(entity.name);
if (result == null) {
result = new CraftPlayer((CraftServer) Bukkit.getServer(), entity);
players.put(entity.name, result);
} else {
result.setHandle(entity);
}
return result;
}
public int getTicksLived() { public int getTicksLived() {
return getHandle().ticksLived; return getHandle().ticksLived;
} }

Datei anzeigen

@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.entity;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.MapMaker; import com.google.common.collect.MapMaker;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
@ -13,30 +14,17 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import net.minecraft.server.*; import net.minecraft.server.*;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.*;
import net.minecraft.server.Container;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.Packet131ItemData;
import net.minecraft.server.Packet200Statistic;
import net.minecraft.server.Packet201PlayerInfo;
import net.minecraft.server.Packet3Chat;
import net.minecraft.server.Packet51MapChunk;
import net.minecraft.server.Packet53BlockChange;
import net.minecraft.server.Packet54PlayNoteBlock;
import net.minecraft.server.Packet61WorldEvent;
import net.minecraft.server.Packet6SpawnPosition;
import net.minecraft.server.Packet70Bed;
import net.minecraft.server.WorldServer;
import org.apache.commons.lang.NotImplementedException; import org.apache.commons.lang.NotImplementedException;
import org.bukkit.*;
import org.bukkit.Achievement; import org.bukkit.Achievement;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.Statistic; import org.bukkit.Statistic;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.configuration.serialization.DelegateDeserialization; import org.bukkit.configuration.serialization.DelegateDeserialization;
import org.bukkit.conversations.Conversation; import org.bukkit.conversations.Conversation;
import org.bukkit.conversations.ConversationAbandonedEvent; import org.bukkit.conversations.ConversationAbandonedEvent;
@ -57,7 +45,6 @@ import org.bukkit.map.MapView;
import org.bukkit.metadata.MetadataValue; import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.messaging.StandardMessenger; import org.bukkit.plugin.messaging.StandardMessenger;
import org.bukkit.potion.Potion;
@DelegateDeserialization(CraftOfflinePlayer.class) @DelegateDeserialization(CraftOfflinePlayer.class)
public class CraftPlayer extends CraftHumanEntity implements Player { public class CraftPlayer extends CraftHumanEntity implements Player {
@ -211,7 +198,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
if ((this.getName() == null) || (other.getName() == null)) { if ((this.getName() == null) || (other.getName() == null)) {
return false; return false;
} }
return this.getName().equalsIgnoreCase(other.getName());
boolean nameEquals = this.getName().equalsIgnoreCase(other.getName());
boolean idEquals = true;
if (other instanceof CraftPlayer) {
idEquals = this.getEntityId() == ((CraftPlayer) other).getEntityId();
}
return nameEquals && idEquals;
} }
public void kickPlayer(String message) { public void kickPlayer(String message) {
@ -827,6 +822,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
public void disconnect(String reason) { public void disconnect(String reason) {
conversationTracker.abandonAllConversations(); conversationTracker.abandonAllConversations();
perm.clearPermissions();
} }
public boolean isFlying() { public boolean isFlying() {