diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftArrow.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftArrow.java new file mode 100644 index 0000000000..b9dd0c3ead --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftArrow.java @@ -0,0 +1,15 @@ +package org.bukkit.craftbukkit; + +import org.bukkit.Arrow; +import net.minecraft.server.EntityArrow; + +/** + * Represents an arrow. + * + * @author sk89q + */ +public class CraftArrow extends CraftEntity implements Arrow { + CraftArrow(CraftServer server, EntityArrow entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftArrowEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftArrowEntity.java deleted file mode 100644 index 337426d3f9..0000000000 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftArrowEntity.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.bukkit.craftbukkit; - -import org.bukkit.ArrowEntity; -import net.minecraft.server.EntityArrow; - -/** - * Represents an arrow. - * - * @author sk89q - */ -public class CraftArrowEntity extends CraftEntity implements ArrowEntity { - CraftArrowEntity(CraftServer server, EntityArrow entity) { - super(server, entity); - } -} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEgg.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEgg.java new file mode 100644 index 0000000000..d0a5ee8979 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEgg.java @@ -0,0 +1,15 @@ +package org.bukkit.craftbukkit; + +import net.minecraft.server.EntityEgg; +import org.bukkit.Egg; + +/** + * An egg. + * + * @author sk89q + */ +public class CraftEgg extends CraftEntity implements Egg { + public CraftEgg(CraftServer server, EntityEgg ent) { + super(server, ent); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEntity.java index efbb7f2866..11e5847e31 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEntity.java @@ -6,7 +6,7 @@ import net.minecraft.server.WorldServer; import org.bukkit.Location; import org.bukkit.World; -public class CraftEntity implements org.bukkit.Entity { +public abstract class CraftEntity implements org.bukkit.Entity { protected final CraftServer server; private Entity entity; diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java index 9212bad9ce..369314deea 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java @@ -2,8 +2,13 @@ package org.bukkit.craftbukkit; import net.minecraft.server.Entity; +import net.minecraft.server.EntityEgg; import net.minecraft.server.EntityLiving; +import net.minecraft.server.EntitySnowball; + +import org.bukkit.Egg; import org.bukkit.LivingEntity; +import org.bukkit.Snowball; public class CraftLivingEntity extends CraftEntity implements LivingEntity { private EntityLiving entity; @@ -39,4 +44,18 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { public String toString() { return "CraftLivingEntity{" + "id=" + getEntityID() + '}'; } + + public Egg throwEgg() { + net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); + EntityEgg egg = new EntityEgg(world, entity); + world.a(egg); + return new CraftEgg(server, egg); + } + + public Snowball throwSnowball() { + net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); + EntitySnowball snowball = new EntitySnowball(world, entity); + world.a(snowball); + return new CraftSnowball(server, snowball); + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java new file mode 100644 index 0000000000..44082603ba --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java @@ -0,0 +1,87 @@ +package org.bukkit.craftbukkit; + +import net.minecraft.server.EntityMinecart; +import org.bukkit.LivingEntity; +import org.bukkit.Minecart; +import org.bukkit.Vector; + +/** + * A minecart. + * + * @author sk89q + */ +public class CraftMinecart extends CraftVehicle implements Minecart { + /** + * Stores the minecart type ID, which is used by Minecraft to differentiate + * minecart types. Here we use subclasses. + */ + public enum Type { + Minecart(0), + StorageMinecart(1), + PoweredMinecart(2); + + private final int id; + + private Type(int id) { + this.id = id; + } + + public int getID() { + return id; + } + } + + protected EntityMinecart minecart; + + public CraftMinecart(CraftServer server, EntityMinecart entity) { + super(server, entity); + minecart = entity; + } + + public Vector getVelocity() { + return new Vector(minecart.s, minecart.t, minecart.u); + } + + public void setVelocity(Vector vel) { + minecart.s = vel.getX(); + minecart.t = vel.getY(); + minecart.u = vel.getZ(); + } + + public LivingEntity getPassenger() { + // @TODO: Implement + return null; + } + + public boolean isEmpty() { + return minecart.j == null; + } + + public void setDamage(int damage) { + minecart.a = damage; + } + + public int getDamage() { + return minecart.a; + } + + /** + * Internal function to convert an MC entity to an appropriate CraftBukkit + * entity. + * + * @param server + * @param minecart + * @return + */ + public static CraftMinecart getCraftMinecart(CraftServer server, + EntityMinecart minecart) { + if (minecart.d == Type.StorageMinecart.getID()) { + return new CraftStorageMinecart(server, minecart); + } else if (minecart.d == Type.PoweredMinecart.getID()) { + return new CraftPoweredMinecart(server, minecart); + } else { + return new CraftMinecart(server, minecart); + } + } + +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftPoweredMinecart.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftPoweredMinecart.java new file mode 100644 index 0000000000..2a1a8f1f38 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftPoweredMinecart.java @@ -0,0 +1,17 @@ +package org.bukkit.craftbukkit; + +import net.minecraft.server.EntityMinecart; +import org.bukkit.PoweredMinecart; + +/** + * A powered minecart. + * + * @author sk89q + */ +public class CraftPoweredMinecart extends CraftMinecart + implements PoweredMinecart { + public CraftPoweredMinecart(CraftServer server, EntityMinecart entity) { + super(server, entity); + } + +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 811b31435e..e575805136 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -15,17 +15,15 @@ import org.bukkit.plugin.java.JavaPluginLoader; public final class CraftServer implements Server { private final String serverName = "Craftbukkit"; - private final String serverVersion; + private final String serverVersion = "1.1"; private final PluginManager pluginManager = new SimplePluginManager(this); protected final MinecraftServer console; protected final ServerConfigurationManager server; - public CraftServer(MinecraftServer instance, String ver) { - serverVersion = ver; - - console = instance; - server = console.f; + public CraftServer(MinecraftServer console, ServerConfigurationManager server) { + this.console = console; + this.server = server; pluginManager.RegisterInterface(JavaPluginLoader.class); @@ -55,7 +53,7 @@ public final class CraftServer implements Server { } public Player[] getOnlinePlayers() { - List online = server.b; + List online = server.b; Player[] players = new Player[online.size()]; for (int i = 0; i < players.length; i++) { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftSnowball.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftSnowball.java new file mode 100644 index 0000000000..1cefa011a0 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftSnowball.java @@ -0,0 +1,15 @@ +package org.bukkit.craftbukkit; + +import net.minecraft.server.EntitySnowball; +import org.bukkit.Snowball; + +/** + * A snowball. + * + * @author sk89q + */ +public class CraftSnowball extends CraftEntity implements Snowball { + public CraftSnowball(CraftServer server, EntitySnowball ent) { + super(server, ent); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java new file mode 100644 index 0000000000..0adf0a180e --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java @@ -0,0 +1,17 @@ +package org.bukkit.craftbukkit; + +import net.minecraft.server.EntityMinecart; +import org.bukkit.StorageMinecart; + +/** + * A storage minecart. + * + * @author sk89q + */ +public class CraftStorageMinecart extends CraftMinecart + implements StorageMinecart { + public CraftStorageMinecart(CraftServer server, EntityMinecart entity) { + super(server, entity); + } + +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java new file mode 100644 index 0000000000..a5c03868c4 --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java @@ -0,0 +1,16 @@ +package org.bukkit.craftbukkit; + +import net.minecraft.server.Entity; + +import org.bukkit.Vehicle; + +/** + * A vehicle. + * + * @author sk89q + */ +public abstract class CraftVehicle extends CraftEntity implements Vehicle { + public CraftVehicle(CraftServer server, Entity entity) { + super(server, entity); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 20fd62ade1..5cd587b200 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -3,15 +3,20 @@ package org.bukkit.craftbukkit; import java.util.HashMap; import java.util.Map; + +import net.minecraft.server.EntityMinecart; import java.util.Random; import net.minecraft.server.WorldGenBigTree; -import net.minecraft.server.WorldGenTrees; import net.minecraft.server.WorldServer; import net.minecraft.server.EntityArrow; -import org.bukkit.ArrowEntity; +import net.minecraft.server.WorldGenTrees; +import org.bukkit.Arrow; import org.bukkit.Block; import org.bukkit.Chunk; import org.bukkit.Location; +import org.bukkit.Minecart; +import org.bukkit.PoweredMinecart; +import org.bukkit.StorageMinecart; import org.bukkit.Vector; import org.bukkit.World; @@ -79,13 +84,40 @@ public class CraftWorld implements World { return world; } - public ArrowEntity spawnArrow(Location loc, Vector velocity, float speed, + public Arrow spawnArrow(Location loc, Vector velocity, float speed, float spread) { EntityArrow arrow = new EntityArrow(world); arrow.c(loc.getX(), loc.getY(), loc.getZ()); world.a(arrow); arrow.a(velocity.getX(), velocity.getY(), velocity.getZ(), speed, spread); - return new CraftArrowEntity(world.getServer(), arrow); + return new CraftArrow(world.getServer(), arrow); + } + + public Minecart spawnMinecart(Location loc) { + EntityMinecart minecart = new EntityMinecart( + world, + loc.getX(), loc.getY(), loc.getZ(), + CraftMinecart.Type.Minecart.getID()); + world.a(minecart); + return new CraftMinecart(world.getServer(), minecart); + } + + public StorageMinecart spawnStorageMinecart(Location loc) { + EntityMinecart minecart = new EntityMinecart( + world, + loc.getX(), loc.getY(), loc.getZ(), + CraftMinecart.Type.StorageMinecart.getID()); + world.a(minecart); + return new CraftStorageMinecart(world.getServer(), minecart); + } + + public PoweredMinecart spawnPoweredMinecart(Location loc) { + EntityMinecart minecart = new EntityMinecart( + world, + loc.getX(), loc.getY(), loc.getZ(), + CraftMinecart.Type.PoweredMinecart.getID()); + world.a(minecart); + return new CraftPoweredMinecart(world.getServer(), minecart); } public boolean generateTree(Location loc) {