diff options
author | snowleo <schneeleo@gmail.com> | 2011-06-23 14:10:27 +0200 |
---|---|---|
committer | snowleo <schneeleo@gmail.com> | 2011-06-23 14:10:27 +0200 |
commit | 50ac21466f128ca52ea1a145bf3612002cd69c11 (patch) | |
tree | b0b0bd4b3f4833e46f3f2f0365f3cb36960e5a88 | |
parent | 5dc1a70bcb6193c82a7612d9b61da9c1462e741c (diff) | |
download | Essentials-50ac21466f128ca52ea1a145bf3612002cd69c11.tar Essentials-50ac21466f128ca52ea1a145bf3612002cd69c11.tar.gz Essentials-50ac21466f128ca52ea1a145bf3612002cd69c11.tar.lz Essentials-50ac21466f128ca52ea1a145bf3612002cd69c11.tar.xz Essentials-50ac21466f128ca52ea1a145bf3612002cd69c11.zip |
Updated /spawnmob to use bukkit code
Less code that breaks with future minecraft updates.
-rw-r--r-- | Essentials/src/com/earth2me/essentials/Mob.java | 17 | ||||
-rw-r--r-- | Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java | 31 |
2 files changed, 23 insertions, 25 deletions
diff --git a/Essentials/src/com/earth2me/essentials/Mob.java b/Essentials/src/com/earth2me/essentials/Mob.java index 771d54abe..3c16ae01a 100644 --- a/Essentials/src/com/earth2me/essentials/Mob.java +++ b/Essentials/src/com/earth2me/essentials/Mob.java @@ -1,15 +1,11 @@ package com.earth2me.essentials; -import java.lang.reflect.Constructor; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import net.minecraft.server.Entity; -import net.minecraft.server.WorldServer; import org.bukkit.Server; -import org.bukkit.craftbukkit.entity.CraftEntity; -import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -84,14 +80,15 @@ public enum Mob { "unchecked", "CallToThreadDumpStack" }) - public CraftEntity spawn(Player player, Server server) throws MobException + public Entity spawn(Player player, Server server) throws MobException { try { - WorldServer world = ((org.bukkit.craftbukkit.CraftWorld)player.getWorld()).getHandle(); - Constructor<CraftEntity> craft = (Constructor<CraftEntity>)ClassLoader.getSystemClassLoader().loadClass("org.bukkit.craftbukkit.entity.Craft" + craftClass).getConstructors()[0]; - Constructor<Entity> entity = (Constructor<Entity>)ClassLoader.getSystemClassLoader().loadClass("net.minecraft.server.Entity" + entityClass).getConstructors()[0]; - return craft.newInstance((CraftServer)server, entity.newInstance(world)); + return player.getWorld().spawn(player.getLocation(), (Class<Entity>)ClassLoader.getSystemClassLoader().loadClass("net.minecraft.server.Entity" + entityClass)); + //WorldServer world = ((org.bukkit.craftbukkit.CraftWorld)player.getWorld()).getHandle(); + //Constructor<CraftEntity> craft = (Constructor<CraftEntity>)ClassLoader.getSystemClassLoader().loadClass("org.bukkit.craftbukkit.entity.Craft" + craftClass).getConstructors()[0]; + //Constructor<Entity> entity = (Constructor<Entity>)ClassLoader.getSystemClassLoader().loadClass("net.minecraft.server.Entity" + entityClass).getConstructors()[0]; + //return craft.newInstance((CraftServer)server, entity.newInstance(world)); } catch (Exception ex) { diff --git a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java index 480e23aea..47edc831e 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commandspawnmob.java @@ -3,8 +3,6 @@ package com.earth2me.essentials.commands; import net.minecraft.server.WorldServer; import org.bukkit.Location; import org.bukkit.Server; -import org.bukkit.craftbukkit.entity.CraftEntity; -import com.earth2me.essentials.Essentials; import com.earth2me.essentials.User; import com.earth2me.essentials.Mob; import com.earth2me.essentials.Mob.MobException; @@ -20,6 +18,7 @@ import org.bukkit.craftbukkit.entity.CraftCreeper; import org.bukkit.craftbukkit.entity.CraftSheep; import org.bukkit.craftbukkit.entity.CraftSlime; import org.bukkit.craftbukkit.entity.CraftWolf; +import org.bukkit.entity.Entity; public class Commandspawnmob extends EssentialsCommand @@ -62,9 +61,9 @@ public class Commandspawnmob extends EssentialsCommand } - CraftEntity spawnedMob = null; + Entity spawnedMob = null; Mob mob = null; - CraftEntity spawnedMount = null; + Entity spawnedMount = null; Mob mobMount = null; mob = Mob.fromName(mobType); @@ -96,8 +95,8 @@ public class Commandspawnmob extends EssentialsCommand loc.setY(loc.getY() + 1); block = user.getWorld().getBlockAt(loc); } - spawnedMob.teleportTo(loc); - world.addEntity(spawnedMob.getHandle()); + spawnedMob.teleport(loc); + //world.addEntity((CraftEntity)spawnedMob).getHandle()); if (mountType != null) { @@ -116,9 +115,10 @@ public class Commandspawnmob extends EssentialsCommand user.sendMessage(Util.i18n("unableToSpawnMob")); return; } - spawnedMount.teleportTo(spawnedMob); - spawnedMount.getHandle().setPassengerOf(spawnedMob.getHandle()); - world.addEntity(spawnedMount.getHandle()); + spawnedMount.teleport(spawnedMob); + spawnedMob.setPassenger(spawnedMount); + //spawnedMount.getHandle().setPassengerOf(spawnedMob.getHandle()); + //world.addEntity(spawnedMount.getHandle()); } if (mobData != null) { @@ -143,8 +143,8 @@ public class Commandspawnmob extends EssentialsCommand for (int i = 1; i < mobCount; i++) { spawnedMob = mob.spawn(user, server); - spawnedMob.teleportTo(loc); - world.addEntity(spawnedMob.getHandle()); + spawnedMob.teleport(loc); + //world.addEntity(spawnedMob.getHandle()); if (mobMount != null) { try @@ -156,9 +156,10 @@ public class Commandspawnmob extends EssentialsCommand user.sendMessage(Util.i18n("unableToSpawnMob")); return; } - spawnedMount.teleportTo(spawnedMob); - spawnedMount.getHandle().setPassengerOf(spawnedMob.getHandle()); - world.addEntity(spawnedMount.getHandle()); + spawnedMount.teleport(spawnedMob); + spawnedMob.setPassenger(spawnedMount); + //spawnedMount.getHandle().setPassengerOf(spawnedMob.getHandle()); + //world.addEntity(spawnedMount.getHandle()); } if (mobData != null) { @@ -195,7 +196,7 @@ public class Commandspawnmob extends EssentialsCommand return s.toUpperCase().charAt(0) + s.toLowerCase().substring(1); } - private void changeMobData(String type, CraftEntity spawned, String data, User user) throws Exception + private void changeMobData(String type, Entity spawned, String data, User user) throws Exception { if ("Slime".equalsIgnoreCase(type)) { |