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

View File

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