Implemented entities

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
CraftBukkit/Spigot 2010-12-30 04:30:12 +00:00
parent f8d2b930f9
commit 837fa8ac26
5 changed files with 154 additions and 20 deletions

View file

@ -0,0 +1,68 @@
package org.bukkit.craftbukkit;
import net.minecraft.server.Entity;
import net.minecraft.server.WorldServer;
import org.bukkit.Location;
import org.bukkit.World;
public class CraftEntity implements org.bukkit.Entity {
protected final CraftServer server;
private final Entity entity;
public CraftEntity(final CraftServer server, final Entity entity) {
this.server = server;
this.entity = entity;
}
public Location getLocation() {
return new Location(getWorld(), entity.p, entity.q, entity.r, entity.v, entity.w);
}
public World getWorld() {
return server.getWorld((WorldServer)entity.l);
}
public void teleportTo(Location location) {
entity.b(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
}
public int getEntityID() {
return entity.g;
}
public Entity getHandle() {
return entity;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final CraftEntity other = (CraftEntity) obj;
if (this.server != other.server && (this.server == null || !this.server.equals(other.server))) {
return false;
}
if (this.entity != other.entity && (this.entity == null || !this.entity.equals(other.entity))) {
return false;
}
return true;
}
@Override
public int hashCode() {
int hash = 7;
hash = 89 * hash + (this.server != null ? this.server.hashCode() : 0);
hash = 89 * hash + (this.entity != null ? this.entity.hashCode() : 0);
return hash;
}
@Override
public String toString() {
return "CraftEntity{" + "id=" + getEntityID() + '}';
}
}

View file

@ -0,0 +1,36 @@
package org.bukkit.craftbukkit;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.InventoryPlayer;
import org.bukkit.HumanEntity;
import org.bukkit.ItemStack;
public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
private final EntityPlayer entity;
public CraftHumanEntity(final CraftServer server, final EntityPlayer entity) {
super(server, entity);
this.entity = entity;
}
public ItemStack getSelectedItem() {
// TODO: Implement inventories
final InventoryPlayer inventory = entity.an;
return new ItemStack(inventory.e().c, inventory.e().a);
}
public String getName() {
return entity.aw;
}
@Override
public EntityPlayer getHandle() {
return entity;
}
@Override
public String toString() {
return "CraftHumanEntity{" + "id=" + getEntityID() + "name=" + getName() + '}';
}
}

View file

@ -0,0 +1,36 @@
package org.bukkit.craftbukkit;
import net.minecraft.server.EntityLiving;
import org.bukkit.LivingEntity;
public class CraftLivingEntity extends CraftEntity implements LivingEntity {
private final EntityLiving entity;
public CraftLivingEntity(final CraftServer server, final EntityLiving entity) {
super(server, entity);
this.entity = entity;
}
public int getHealth() {
return entity.ba;
}
public void setHealth(int health) {
if ((health < 0) || (health > 20)) {
throw new IllegalArgumentException("Health must be between 0 and 20");
}
entity.ba = health;
}
@Override
public EntityLiving getHandle() {
return entity;
}
@Override
public String toString() {
return "CraftLivingEntity{" + "id=" + getEntityID() + '}';
}
}

View file

@ -2,19 +2,16 @@
package org.bukkit.craftbukkit;
import net.minecraft.server.EntityPlayerMP;
import org.bukkit.Location;
import org.bukkit.Player;
import org.bukkit.World;
public class CraftPlayer implements Player {
private EntityPlayerMP player;
public class CraftPlayer extends CraftHumanEntity implements Player {
private final EntityPlayerMP entity;
private final String name;
private final CraftServer server;
public CraftPlayer(CraftServer serv, EntityPlayerMP handle) {
player = handle;
name = player.aw;
server = serv;
public CraftPlayer(CraftServer server, EntityPlayerMP entity) {
super(server, entity);
this.entity = entity;
name = entity.aw;
}
public String getName() {
@ -22,19 +19,12 @@ public class CraftPlayer implements Player {
}
public boolean isOnline() {
return server.server.g(name);
return server.getHandle().g(name);
}
public Location getLocation() {
return new Location(getWorld(), player.p, player.q, player.r, player.v, player.w);
}
public World getWorld() {
return server.getWorld(player.b.e);
}
public EntityPlayerMP getEntity() {
return player;
@Override
public EntityPlayerMP getHandle() {
return entity;
}
@Override

View file

@ -100,4 +100,8 @@ public final class CraftServer implements Server {
return result;
}
public ServerConfigurationManager getHandle() {
return server;
}
}