117 lines
3.0 KiB
Java
117 lines
3.0 KiB
Java
package org.bukkit.craftbukkit.entity;
|
|
|
|
import java.net.InetSocketAddress;
|
|
import java.net.SocketAddress;
|
|
import net.minecraft.server.EntityHuman;
|
|
import net.minecraft.server.EntityPlayer;
|
|
import net.minecraft.server.Packet;
|
|
import net.minecraft.server.Packet3Chat;
|
|
import net.minecraft.server.Packet6SpawnPosition;
|
|
import org.bukkit.Location;
|
|
import org.bukkit.craftbukkit.CraftServer;
|
|
import org.bukkit.entity.Player;
|
|
|
|
public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
private EntityPlayer entity;
|
|
private String name;
|
|
|
|
public CraftPlayer(CraftServer server, EntityPlayer entity) {
|
|
super(server, entity);
|
|
this.name = getName();
|
|
this.entity = entity;
|
|
}
|
|
|
|
public boolean isOp() {
|
|
return server.getHandle().g(getName());
|
|
}
|
|
|
|
public boolean isPlayer() {
|
|
return true;
|
|
}
|
|
|
|
public boolean isOnline() {
|
|
for (Object obj: server.getHandle().b) {
|
|
EntityPlayer player = (EntityPlayer) obj;
|
|
if (player.name.equalsIgnoreCase(getName())) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public InetSocketAddress getAddress() {
|
|
SocketAddress addr = entity.a.b.b();
|
|
if (addr instanceof InetSocketAddress) {
|
|
return (InetSocketAddress) addr;
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public EntityPlayer getHandle() {
|
|
return entity;
|
|
}
|
|
|
|
public void setHandle(final EntityPlayer entity) {
|
|
super.setHandle((EntityHuman) 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());
|
|
}
|
|
|
|
public String getDisplayName() {
|
|
return name;
|
|
}
|
|
|
|
public void setDisplayName(final String name) {
|
|
this.name = name;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "CraftPlayer{" + "name=" + getName() + '}';
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object obj) {
|
|
if (obj == null) {
|
|
return false;
|
|
}
|
|
if (getClass() != obj.getClass()) {
|
|
return false;
|
|
}
|
|
final CraftPlayer other = (CraftPlayer) obj;
|
|
if ((this.getName() == null) ? (other.getName() != null) : !this.getName().equals(other.getName())) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
int hash = 5;
|
|
hash = 97 * hash + (this.getName() != null ? this.getName().hashCode() : 0);
|
|
return hash;
|
|
}
|
|
|
|
public void kickPlayer(String message) {
|
|
entity.a.a(message);
|
|
}
|
|
|
|
public void setCompassTarget(Location loc) {
|
|
entity.a.b(((Packet) (new Packet6SpawnPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))));
|
|
}
|
|
|
|
public boolean performCommand(String command) {
|
|
return server.dispatchCommand(this, command);
|
|
}
|
|
}
|