From 2cb9cbf05cc7cefdf646f0d2b4bc4c2d94afd28d Mon Sep 17 00:00:00 2001 From: Wesley Wolfe Date: Fri, 15 Mar 2013 23:09:04 -0500 Subject: [PATCH] Handle the newly refactored minecarts. --- .../org/bukkit/craftbukkit/CraftWorld.java | 65 ++++++++++--------- .../craftbukkit/entity/CraftEntity.java | 8 +-- .../craftbukkit/entity/CraftMinecart.java | 13 +--- ...eMinecart.java => CraftMinecartChest.java} | 7 +- ...inecart.java => CraftMinecartFurnace.java} | 9 +-- .../entity/CraftMinecartHopper.java | 10 ++- .../entity/CraftMinecartMobSpawner.java | 10 ++- .../entity/CraftMinecartRideable.java | 22 +++++++ .../craftbukkit/entity/CraftMinecartTNT.java | 17 ++++- 9 files changed, 100 insertions(+), 61 deletions(-) rename src/main/java/org/bukkit/craftbukkit/entity/{CraftStorageMinecart.java => CraftMinecartChest.java} (70%) rename src/main/java/org/bukkit/craftbukkit/entity/{CraftPoweredMinecart.java => CraftMinecartFurnace.java} (66%) create mode 100644 src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartRideable.java diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 9218f074fe..adb2bba3ba 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -1,52 +1,54 @@ package org.bukkit.craftbukkit; import java.io.File; -import java.util.Iterator; -import java.util.Set; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Random; +import java.util.Set; import java.util.UUID; -import org.apache.commons.lang.Validate; - -import org.bukkit.craftbukkit.entity.*; -import org.bukkit.craftbukkit.metadata.BlockMetadataStore; -import org.bukkit.entity.*; -import org.bukkit.entity.Entity; import net.minecraft.server.*; -import org.bukkit.entity.Arrow; -import org.bukkit.Effect; -import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; -import org.bukkit.event.weather.WeatherChangeEvent; -import org.bukkit.event.weather.ThunderChangeEvent; -import org.bukkit.event.world.SpawnChangeEvent; -import org.bukkit.block.Block; -import org.bukkit.block.BlockFace; -import org.bukkit.entity.Boat; -import org.bukkit.Chunk; -import org.bukkit.inventory.ItemStack; -import org.bukkit.metadata.MetadataValue; -import org.bukkit.plugin.Plugin; -import org.bukkit.util.Vector; +import org.apache.commons.lang.Validate; import org.bukkit.BlockChangeDelegate; import org.bukkit.Bukkit; -import org.bukkit.generator.ChunkGenerator; +import org.bukkit.Chunk; import org.bukkit.ChunkSnapshot; +import org.bukkit.Difficulty; +import org.bukkit.Effect; import org.bukkit.Location; +import org.bukkit.Sound; import org.bukkit.TreeType; import org.bukkit.World; import org.bukkit.block.Biome; -import org.bukkit.generator.BlockPopulator; -import org.bukkit.Difficulty; -import org.bukkit.Sound; +import org.bukkit.block.Block; +import org.bukkit.block.BlockFace; import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.entity.*; import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.plugin.messaging.StandardMessenger; +import org.bukkit.craftbukkit.metadata.BlockMetadataStore; import org.bukkit.craftbukkit.util.LongHash; +import org.bukkit.entity.*; +import org.bukkit.entity.Entity; +import org.bukkit.entity.minecart.ExplosiveMinecart; +import org.bukkit.entity.minecart.HopperMinecart; +import org.bukkit.entity.minecart.PoweredMinecart; +import org.bukkit.entity.minecart.SpawnerMinecart; +import org.bukkit.entity.minecart.StorageMinecart; +import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; +import org.bukkit.event.weather.ThunderChangeEvent; +import org.bukkit.event.weather.WeatherChangeEvent; +import org.bukkit.event.world.SpawnChangeEvent; +import org.bukkit.generator.BlockPopulator; +import org.bukkit.generator.ChunkGenerator; +import org.bukkit.inventory.ItemStack; +import org.bukkit.metadata.MetadataValue; +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.messaging.StandardMessenger; +import org.bukkit.util.Vector; public class CraftWorld implements World { public static final int CUSTOM_DIMENSION_OFFSET = 10; @@ -252,7 +254,6 @@ public class CraftWorld implements World { return chunk != null; } - @SuppressWarnings("unchecked") private void chunkLoadPostProcess(net.minecraft.server.Chunk chunk, int x, int z) { if (chunk != null) { world.chunkProviderServer.chunks.put(LongHash.toLong(x, z), chunk); @@ -864,13 +865,13 @@ public class CraftWorld implements World { entity = new EntityMinecartFurnace(world, x, y, z); } else if (StorageMinecart.class.isAssignableFrom(clazz)) { entity = new EntityMinecartChest(world, x, y, z); - } else if (MinecartTNT.class.isAssignableFrom(clazz)) { + } else if (ExplosiveMinecart.class.isAssignableFrom(clazz)) { entity = new EntityMinecartTNT(world, x, y, z); - } else if (MinecartHopper.class.isAssignableFrom(clazz)) { + } else if (HopperMinecart.class.isAssignableFrom(clazz)) { entity = new EntityMinecartHopper(world, x, y, z); - } else if (MinecartMobSpawner.class.isAssignableFrom(clazz)) { + } else if (SpawnerMinecart.class.isAssignableFrom(clazz)) { entity = new EntityMinecartMobSpawner(world, x, y, z); - } else { + } else { // Default to rideable minecart for pre-rideable compatibility entity = new EntityMinecartRideable(world, x, y, z); } } else if (EnderSignal.class.isAssignableFrom(clazz)) { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index f88092e155..0edf2d95c4 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -137,12 +137,12 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { else { return new CraftWeather(server, (EntityWeather) entity); } } else if (entity instanceof EntityMinecartAbstract) { - if (entity instanceof EntityMinecartFurnace) { return new CraftPoweredMinecart(server, (EntityMinecartFurnace) entity); } - else if (entity instanceof EntityMinecartChest) { return new CraftStorageMinecart(server, (EntityMinecartChest) entity); } + if (entity instanceof EntityMinecartFurnace) { return new CraftMinecartFurnace(server, (EntityMinecartFurnace) entity); } + else if (entity instanceof EntityMinecartChest) { return new CraftMinecartChest(server, (EntityMinecartChest) entity); } else if (entity instanceof EntityMinecartTNT) { return new CraftMinecartTNT(server, (EntityMinecartTNT) entity); } else if (entity instanceof EntityMinecartHopper) { return new CraftMinecartHopper(server, (EntityMinecartHopper) entity); } else if (entity instanceof EntityMinecartMobSpawner) { return new CraftMinecartMobSpawner(server, (EntityMinecartMobSpawner) entity); } - else { return new CraftMinecart(server, (EntityMinecartRideable) entity); } + else if (entity instanceof EntityMinecartRideable) { return new CraftMinecartRideable(server, (EntityMinecartRideable) entity); } } else if (entity instanceof EntityHanging) { if (entity instanceof EntityPainting) { return new CraftPainting(server, (EntityPainting) entity); } else if (entity instanceof EntityItemFrame) { return new CraftItemFrame(server, (EntityItemFrame) entity); } @@ -151,7 +151,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { else if (entity instanceof EntityTNTPrimed) { return new CraftTNTPrimed(server, (EntityTNTPrimed) entity); } else if (entity instanceof EntityFireworks) { return new CraftFirework(server, (EntityFireworks) entity); } - throw new IllegalArgumentException("Unknown entity"); + throw new AssertionError("Unknown entity " + entity == null ? null : entity.getClass()); } public Location getLocation() { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java index 73e807e1f0..acbad192c6 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecart.java @@ -1,12 +1,12 @@ package org.bukkit.craftbukkit.entity; import net.minecraft.server.EntityMinecartAbstract; + import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.entity.EntityType; import org.bukkit.entity.Minecart; import org.bukkit.util.Vector; -public class CraftMinecart extends CraftVehicle implements Minecart { +public abstract class CraftMinecart extends CraftVehicle implements Minecart { public CraftMinecart(CraftServer server, EntityMinecartAbstract entity) { super(server, entity); } @@ -57,13 +57,4 @@ public class CraftMinecart extends CraftVehicle implements Minecart { public EntityMinecartAbstract getHandle() { return (EntityMinecartAbstract) entity; } - - @Override - public String toString() { - return "CraftMinecart"; - } - - public EntityType getType() { - return EntityType.MINECART; - } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftStorageMinecart.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartChest.java similarity index 70% rename from src/main/java/org/bukkit/craftbukkit/entity/CraftStorageMinecart.java rename to src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartChest.java index ef86e41353..f5a18757fd 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftStorageMinecart.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartChest.java @@ -8,10 +8,11 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.StorageMinecart; import org.bukkit.inventory.Inventory; -public class CraftStorageMinecart extends CraftMinecart implements StorageMinecart { +@SuppressWarnings("deprecation") +public class CraftMinecartChest extends CraftMinecart implements StorageMinecart { private final CraftInventory inventory; - public CraftStorageMinecart(CraftServer server, EntityMinecartChest entity) { + public CraftMinecartChest(CraftServer server, EntityMinecartChest entity) { super(server, entity); inventory = new CraftInventory(entity); } @@ -22,7 +23,7 @@ public class CraftStorageMinecart extends CraftMinecart implements StorageMineca @Override public String toString() { - return "CraftStorageMinecart{" + "inventory=" + inventory + '}'; + return "CraftMinecartChest{" + "inventory=" + inventory + '}'; } public EntityType getType() { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPoweredMinecart.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartFurnace.java similarity index 66% rename from src/main/java/org/bukkit/craftbukkit/entity/CraftPoweredMinecart.java rename to src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartFurnace.java index a07829e2ee..463b4ceeb2 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPoweredMinecart.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartFurnace.java @@ -1,19 +1,20 @@ package org.bukkit.craftbukkit.entity; -import org.bukkit.craftbukkit.entity.CraftMinecart; import net.minecraft.server.EntityMinecartFurnace; + import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.EntityType; import org.bukkit.entity.PoweredMinecart; -public class CraftPoweredMinecart extends CraftMinecart implements PoweredMinecart { - public CraftPoweredMinecart(CraftServer server, EntityMinecartFurnace entity) { +@SuppressWarnings("deprecation") +public class CraftMinecartFurnace extends CraftMinecart implements PoweredMinecart { + public CraftMinecartFurnace(CraftServer server, EntityMinecartFurnace entity) { super(server, entity); } @Override public String toString() { - return "CraftPoweredMinecart"; + return "CraftMinecartFurnace"; } public EntityType getType() { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartHopper.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartHopper.java index 67fcbb47b5..e34d082dd6 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartHopper.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartHopper.java @@ -1,15 +1,21 @@ package org.bukkit.craftbukkit.entity; import net.minecraft.server.EntityMinecartHopper; + import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.EntityType; -import org.bukkit.entity.MinecartHopper; +import org.bukkit.entity.minecart.HopperMinecart; -final class CraftMinecartHopper extends CraftMinecart implements MinecartHopper { +final class CraftMinecartHopper extends CraftMinecart implements HopperMinecart { CraftMinecartHopper(CraftServer server, EntityMinecartHopper entity) { super(server, entity); } + @Override + public String toString() { + return "CraftMinecartHopper"; + } + public EntityType getType() { return EntityType.MINECART_HOPPER; } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartMobSpawner.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartMobSpawner.java index 83be050b25..a78d81691b 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartMobSpawner.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartMobSpawner.java @@ -1,15 +1,21 @@ package org.bukkit.craftbukkit.entity; import net.minecraft.server.EntityMinecartMobSpawner; + import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.EntityType; -import org.bukkit.entity.MinecartMobSpawner; +import org.bukkit.entity.minecart.SpawnerMinecart; -final class CraftMinecartMobSpawner extends CraftMinecart implements MinecartMobSpawner { +final class CraftMinecartMobSpawner extends CraftMinecart implements SpawnerMinecart { CraftMinecartMobSpawner(CraftServer server, EntityMinecartMobSpawner entity) { super(server, entity); } + @Override + public String toString() { + return "CraftMinecartMobSpawner"; + } + public EntityType getType() { return EntityType.MINECART_MOB_SPAWNER; } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartRideable.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartRideable.java new file mode 100644 index 0000000000..9305d8841f --- /dev/null +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartRideable.java @@ -0,0 +1,22 @@ +package org.bukkit.craftbukkit.entity; + +import net.minecraft.server.EntityMinecartAbstract; + +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.minecart.RideableMinecart; + +public class CraftMinecartRideable extends CraftMinecart implements RideableMinecart { + public CraftMinecartRideable(CraftServer server, EntityMinecartAbstract entity) { + super(server, entity); + } + + @Override + public String toString() { + return "CraftMinecartRideable"; + } + + public EntityType getType() { + return EntityType.MINECART; + } +} diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartTNT.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartTNT.java index 861b01fe11..0c8109bb16 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartTNT.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMinecartTNT.java @@ -1,11 +1,22 @@ package org.bukkit.craftbukkit.entity; import net.minecraft.server.EntityMinecartTNT; -import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.entity.MinecartTNT; -final class CraftMinecartTNT extends CraftMinecart implements MinecartTNT { +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.minecart.ExplosiveMinecart; + +final class CraftMinecartTNT extends CraftMinecart implements ExplosiveMinecart { CraftMinecartTNT(CraftServer server, EntityMinecartTNT entity) { super(server, entity); } + + @Override + public String toString() { + return "CraftMinecartTNT"; + } + + public EntityType getType() { + return EntityType.MINECART_TNT; + } }