Archiviert
13
0

Let's handle (bwhaha) the Craft* entities a bit better.

Dieser Commit ist enthalten in:
Erik Broes 2011-03-01 17:08:18 +01:00
Ursprung e6583c0d48
Commit f54469f314
8 geänderte Dateien mit 52 neuen und 53 gelöschten Zeilen

Datei anzeigen

@ -15,4 +15,8 @@ public class CraftAnimals extends CraftCreature implements Animals{
return "CraftAnimals"; return "CraftAnimals";
} }
@Override
public EntityAnimal getHandle() {
return (EntityAnimal) entity;
}
} }

Datei anzeigen

@ -7,14 +7,12 @@ import org.bukkit.entity.Creature;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
public class CraftCreature extends CraftLivingEntity implements Creature{ public class CraftCreature extends CraftLivingEntity implements Creature{
private EntityCreature entity;
public CraftCreature(CraftServer server, EntityCreature entity) { public CraftCreature(CraftServer server, EntityCreature entity) {
super(server, entity); super(server, entity);
this.entity = entity;
} }
public void setTarget(LivingEntity target) { public void setTarget(LivingEntity target) {
EntityCreature entity = getHandle();
if (target == null) { if (target == null) {
entity.d = null; entity.d = null;
} else if (target instanceof CraftLivingEntity) { } else if (target instanceof CraftLivingEntity) {
@ -25,16 +23,14 @@ public class CraftCreature extends CraftLivingEntity implements Creature{
} }
public CraftLivingEntity getTarget() { public CraftLivingEntity getTarget() {
if (entity.d == null) { if (getHandle().d == null) return null;
return null;
} else { return (CraftLivingEntity) getHandle().d.getBukkitEntity();
return (CraftLivingEntity)entity.d.getBukkitEntity();
}
} }
@Override @Override
public EntityCreature getHandle() { public EntityCreature getHandle() {
return entity; return (EntityCreature) entity;
} }
@Override @Override

Datei anzeigen

@ -10,7 +10,7 @@ import org.bukkit.util.Vector;
public abstract class CraftEntity implements org.bukkit.entity.Entity { public abstract class CraftEntity implements org.bukkit.entity.Entity {
protected final CraftServer server; protected final CraftServer server;
private Entity entity; protected Entity entity;
public CraftEntity(final CraftServer server, final Entity entity) { public CraftEntity(final CraftServer server, final Entity entity) {
this.server = server; this.server = server;

Datei anzeigen

@ -9,22 +9,20 @@ import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity { public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
private EntityHuman entity;
private CraftInventoryPlayer inventory; private CraftInventoryPlayer inventory;
public CraftHumanEntity(final CraftServer server, final EntityHuman entity) { public CraftHumanEntity(final CraftServer server, final EntityHuman entity) {
super(server, entity); super(server, entity);
this.entity = entity;
this.inventory = new CraftInventoryPlayer( entity.inventory ); this.inventory = new CraftInventoryPlayer( entity.inventory );
} }
public String getName() { public String getName() {
return entity.name; return getHandle().name;
} }
@Override @Override
public EntityHuman getHandle() { public EntityHuman getHandle() {
return entity; return (EntityHuman) entity;
} }
public void setHandle(final EntityHuman entity) { public void setHandle(final EntityHuman entity) {

Datei anzeigen

@ -23,15 +23,12 @@ import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
public class CraftLivingEntity extends CraftEntity implements LivingEntity { public class CraftLivingEntity extends CraftEntity implements LivingEntity {
private EntityLiving entity;
public CraftLivingEntity(final CraftServer server, final EntityLiving entity) { public CraftLivingEntity(final CraftServer server, final EntityLiving entity) {
super(server, entity); super(server, entity);
this.entity = entity;
} }
public int getHealth() { public int getHealth() {
return entity.health; return getHandle().health;
} }
public void setHealth(int health) { public void setHealth(int health) {
@ -39,12 +36,12 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
throw new IllegalArgumentException("Health must be between 0 and 200"); throw new IllegalArgumentException("Health must be between 0 and 200");
} }
entity.health = health; getHandle().health = health;
} }
@Override @Override
public EntityLiving getHandle() { public EntityLiving getHandle() {
return entity; return (EntityLiving) entity;
} }
public void setHandle(final EntityLiving entity) { public void setHandle(final EntityLiving entity) {
@ -59,14 +56,14 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
public Egg throwEgg() { public Egg throwEgg() {
net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle();
EntityEgg egg = new EntityEgg(world, entity); EntityEgg egg = new EntityEgg(world, getHandle());
world.a(egg); world.a(egg);
return (Egg) egg.getBukkitEntity(); return (Egg) egg.getBukkitEntity();
} }
public Snowball throwSnowball() { public Snowball throwSnowball() {
net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle();
EntitySnowball snowball = new EntitySnowball(world, entity); EntitySnowball snowball = new EntitySnowball(world, getHandle());
world.a(snowball); world.a(snowball);
return (Snowball) snowball.getBukkitEntity(); return (Snowball) snowball.getBukkitEntity();
} }
@ -120,30 +117,30 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
public Arrow shootArrow() { public Arrow shootArrow() {
net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle();
EntityArrow arrow = new EntityArrow(world, entity); EntityArrow arrow = new EntityArrow(world, getHandle());
world.a(arrow); world.a(arrow);
return (Arrow) arrow.getBukkitEntity(); return (Arrow) arrow.getBukkitEntity();
} }
public boolean isInsideVehicle() { public boolean isInsideVehicle() {
return entity.vehicle != null; return getHandle().vehicle != null;
} }
public boolean leaveVehicle() { public boolean leaveVehicle() {
if (entity.vehicle == null) { if (getHandle().vehicle == null) {
return false; return false;
} }
entity.setPassengerOf(null); getHandle().setPassengerOf(null);
return true; return true;
} }
public Vehicle getVehicle() { public Vehicle getVehicle() {
if (entity.vehicle == null) { if (getHandle().vehicle == null) {
return null; return null;
} }
org.bukkit.entity.Entity vehicle = (entity.vehicle.getBukkitEntity()); org.bukkit.entity.Entity vehicle = (getHandle().vehicle.getBukkitEntity());
if (vehicle instanceof Vehicle) { if (vehicle instanceof Vehicle) {
return (Vehicle) vehicle; return (Vehicle) vehicle;
} }
@ -152,18 +149,18 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
} }
public int getRemainingAir() { public int getRemainingAir() {
return entity.airTicks; return getHandle().airTicks;
} }
public void setRemainingAir(int ticks) { public void setRemainingAir(int ticks) {
entity.airTicks = ticks; getHandle().airTicks = ticks;
} }
public int getMaximumAir() { public int getMaximumAir() {
return entity.maxAirTicks; return getHandle().maxAirTicks;
} }
public void setMaximumAir(int ticks) { public void setMaximumAir(int ticks) {
entity.maxAirTicks = ticks; getHandle().maxAirTicks = ticks;
} }
} }

Datei anzeigen

@ -16,4 +16,8 @@ public class CraftMonster extends CraftCreature implements Monster {
return "CraftMonster"; return "CraftMonster";
} }
@Override
public EntityMonster getHandle() {
return (EntityMonster) entity;
}
} }

Datei anzeigen

@ -18,13 +18,10 @@ import org.bukkit.craftbukkit.TextWrapper;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
public class CraftPlayer extends CraftHumanEntity implements Player { public class CraftPlayer extends CraftHumanEntity implements Player {
private EntityPlayer entity;
private String name; private String name;
public CraftPlayer(CraftServer server, EntityPlayer entity) { public CraftPlayer(CraftServer server, EntityPlayer entity) {
super(server, entity); super(server, entity);
this.name = getName();
this.entity = entity;
} }
public boolean isOp() { public boolean isOp() {
@ -46,7 +43,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
} }
public InetSocketAddress getAddress() { public InetSocketAddress getAddress() {
SocketAddress addr = entity.a.b.b(); SocketAddress addr = getHandle().a.b.b();
if (addr instanceof InetSocketAddress) { if (addr instanceof InetSocketAddress) {
return (InetSocketAddress) addr; return (InetSocketAddress) addr;
} else { } else {
@ -56,7 +53,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override @Override
public EntityPlayer getHandle() { public EntityPlayer getHandle() {
return entity; return (EntityPlayer) entity;
} }
public double getEyeHeight() { public double getEyeHeight() {
@ -82,7 +79,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
public void sendMessage(String message) { public void sendMessage(String message) {
for (final String line: TextWrapper.wrapText(message)) { for (final String line: TextWrapper.wrapText(message)) {
entity.a.b(new Packet3Chat(line)); getHandle().a.b(new Packet3Chat(line));
} }
} }
@ -122,15 +119,15 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
} }
public void kickPlayer(String message) { public void kickPlayer(String message) {
entity.a.a(message == null ? "" : message); getHandle().a.a(message == null ? "" : message);
} }
public void setCompassTarget(Location loc) { public void setCompassTarget(Location loc) {
entity.a.b(((Packet) (new Packet6SpawnPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ())))); getHandle().a.b(((Packet) (new Packet6SpawnPosition(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))));
} }
public void chat(String msg) { public void chat(String msg) {
entity.a.chat(msg); getHandle().a.chat(msg);
} }
public boolean performCommand(String command) { public boolean performCommand(String command) {
@ -142,6 +139,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
WorldServer oldWorld = ((CraftWorld)getWorld()).getHandle(); WorldServer oldWorld = ((CraftWorld)getWorld()).getHandle();
WorldServer newWorld = ((CraftWorld)location.getWorld()).getHandle(); WorldServer newWorld = ((CraftWorld)location.getWorld()).getHandle();
ServerConfigurationManager manager = server.getHandle(); ServerConfigurationManager manager = server.getHandle();
EntityPlayer entity = getHandle();
if (oldWorld != newWorld) { if (oldWorld != newWorld) {
manager.c.k.a(entity); manager.c.k.a(entity);
@ -168,21 +166,21 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
manager.b.add(newEntity); manager.b.add(newEntity);
entity.a.e = newEntity; entity.a.e = newEntity;
entity = newEntity; this.entity = newEntity;
} else { } else {
entity.a.a(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch()); entity.a.a(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
} }
} }
public void setSneaking(boolean sneak) { public void setSneaking(boolean sneak) {
entity.b(sneak); getHandle().b(sneak);
} }
public boolean isSneaking() { public boolean isSneaking() {
return entity.U(); return getHandle().U();
} }
public void updateInventory() { public void updateInventory() {
entity.l(); getHandle().l();
} }
} }

Datei anzeigen

@ -7,24 +7,26 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Sheep; import org.bukkit.entity.Sheep;
public class CraftSheep extends CraftAnimals implements Sheep { public class CraftSheep extends CraftAnimals implements Sheep {
public CraftSheep(CraftServer server, EntitySheep entity) { public CraftSheep(CraftServer server, EntitySheep entity) {
super(server, entity); super(server, entity);
} }
@Override
public EntitySheep getHandle() {
return (EntitySheep) entity;
}
@Override @Override
public String toString() { public String toString() {
return "CraftSheep"; return "CraftSheep";
} }
public DyeColor getColor() { public DyeColor getColor() {
EntitySheep entity = (EntitySheep) getHandle(); return DyeColor.getByData((byte) getHandle().n());
return DyeColor.getByData((byte) entity.n());
} }
public void setColor(DyeColor color) { public void setColor(DyeColor color) {
EntitySheep entity = (EntitySheep) getHandle(); getHandle().a_(color.getData());
entity.a_(color.getData());
} }
} }