From b3568f83e7e7e07696022734ce3131f6778f8ebf Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 3 Jan 2011 14:11:04 +0800 Subject: [PATCH 1/8] Renamed ArrowEntity->Arrow to be consistent. By: sk89q --- .../java/org/bukkit/craftbukkit/CraftArrow.java | 15 +++++++++++++++ .../org/bukkit/craftbukkit/CraftArrowEntity.java | 15 --------------- .../java/org/bukkit/craftbukkit/CraftWorld.java | 6 +++--- 3 files changed, 18 insertions(+), 18 deletions(-) create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/CraftArrow.java delete mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/CraftArrowEntity.java 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/CraftWorld.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 20fd62ade1..9c03efff80 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -8,7 +8,7 @@ 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 org.bukkit.Arrow; import org.bukkit.Block; import org.bukkit.Chunk; import org.bukkit.Location; @@ -79,13 +79,13 @@ 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 boolean generateTree(Location loc) { From bccefe4c85304231b8acc19783a8e59e86bd616c Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sun, 2 Jan 2011 21:41:57 -0800 Subject: [PATCH 2/8] Added minecart classes and World.spawn*Minecart(). Minecart.getPassenger() is still a stub that needs to be implemented (due to of a need of a MC entity -> CraftBukkit entity lookup) and StorageMinecart.getInventory() is waiting on the implementation of inventory. By: sk89q --- .../org/bukkit/craftbukkit/CraftMinecart.java | 69 +++++++++++++++++++ .../craftbukkit/CraftPoweredMinecart.java | 17 +++++ .../craftbukkit/CraftStorageMinecart.java | 17 +++++ .../org/bukkit/craftbukkit/CraftVehicle.java | 16 +++++ .../org/bukkit/craftbukkit/CraftWorld.java | 33 ++++++++- 5 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/CraftPoweredMinecart.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/CraftStorageMinecart.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java 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..69a647b18b --- /dev/null +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java @@ -0,0 +1,69 @@ +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; + } + + @Override + 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; + } + +} 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/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 9c03efff80..b82773e903 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,19 @@ 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.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; @@ -88,6 +92,33 @@ public class CraftWorld implements World { 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) { WorldGenTrees treeGen = new WorldGenTrees(); return treeGen.a(world, rand, From e8b157df9905c5b53d1b8d3965c8e613eacf73b9 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 3 Jan 2011 01:28:06 -0800 Subject: [PATCH 3/8] Implemented some minecart vehicle hooks, but there's a some things missing in CraftBukkit before the implementation can be finished. By: sk89q --- .../org/bukkit/craftbukkit/CraftMinecart.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java index 69a647b18b..a817d0a930 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java @@ -65,5 +65,24 @@ public class CraftMinecart extends CraftVehicle implements Minecart { 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); + } + } } From 73f551d19c48ca1708444915b7ad980e9dc1518e Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 3 Jan 2011 15:13:29 +0000 Subject: [PATCH 4/8] Fixed missing import for craftworld By: Dinnerbone --- .../src/main/java/org/bukkit/craftbukkit/CraftWorld.java | 1 + 1 file changed, 1 insertion(+) 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 b82773e903..5cd587b200 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -9,6 +9,7 @@ import java.util.Random; import net.minecraft.server.WorldGenBigTree; import net.minecraft.server.WorldServer; import net.minecraft.server.EntityArrow; +import net.minecraft.server.WorldGenTrees; import org.bukkit.Arrow; import org.bukkit.Block; import org.bukkit.Chunk; From 1e159ac83200f109c8c1052ffa7fb1d656ede5d7 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 3 Jan 2011 17:44:43 +0800 Subject: [PATCH 5/8] Added LivingEntity.throwEgg() and LivingEntity.throwSnowball(). By: sk89q --- .../java/org/bukkit/craftbukkit/CraftEgg.java | 15 +++++++++++++ .../bukkit/craftbukkit/CraftLivingEntity.java | 21 +++++++++++++++++++ .../org/bukkit/craftbukkit/CraftSnowball.java | 15 +++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/CraftEgg.java create mode 100644 paper-server/src/main/java/org/bukkit/craftbukkit/CraftSnowball.java 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/CraftLivingEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java index 9212bad9ce..b94af6bfe7 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,20 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { public String toString() { return "CraftLivingEntity{" + "id=" + getEntityID() + '}'; } + + @Override + 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); + } + + @Override + 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/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); + } +} From 46bdde71805dfdf056d7b490863439985d409763 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 3 Jan 2011 17:41:26 +0800 Subject: [PATCH 6/8] Mark CraftEntity as abstract, add dummy health methods to CraftArrowEntity. By: angelsl --- .../src/main/java/org/bukkit/craftbukkit/CraftEntity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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; From 9b1f8245dfa78b3047187936281b9c3d75713939 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 3 Jan 2011 16:37:08 +0000 Subject: [PATCH 7/8] Fixed compile errors By: Dinnerbone --- .../src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java | 2 -- .../src/main/java/org/bukkit/craftbukkit/CraftMinecart.java | 1 - 2 files changed, 3 deletions(-) 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 b94af6bfe7..369314deea 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java @@ -45,7 +45,6 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { return "CraftLivingEntity{" + "id=" + getEntityID() + '}'; } - @Override public Egg throwEgg() { net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); EntityEgg egg = new EntityEgg(world, entity); @@ -53,7 +52,6 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { return new CraftEgg(server, egg); } - @Override public Snowball throwSnowball() { net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); EntitySnowball snowball = new EntitySnowball(world, entity); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java index a817d0a930..44082603ba 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftMinecart.java @@ -38,7 +38,6 @@ public class CraftMinecart extends CraftVehicle implements Minecart { minecart = entity; } - @Override public Vector getVelocity() { return new Vector(minecart.s, minecart.t, minecart.u); } From 449fb6523ac2a777189981426960a0a337bb76e3 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Mon, 3 Jan 2011 19:41:23 +0000 Subject: [PATCH 8/8] Fixed NPE on Player related methods in CraftServer By: Dinnerbone --- .../java/org/bukkit/craftbukkit/CraftServer.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) 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++) {