Fix for minecart naming

This commit is contained in:
wizjany 2013-03-16 12:16:16 -04:00
parent 9ac04f8cfe
commit 0d52d22bd8

View File

@ -65,7 +65,6 @@ import org.bukkit.entity.Item;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity; import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Minecart; import org.bukkit.entity.Minecart;
import org.bukkit.entity.MinecartTNT;
import org.bukkit.entity.Painting; import org.bukkit.entity.Painting;
import org.bukkit.entity.Projectile; import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
@ -115,6 +114,18 @@ public class BukkitWorld extends LocalWorld {
private static Method nmsGetMethod; private static Method nmsGetMethod;
private static Method nmsSetSafeMethod; private static Method nmsSetSafeMethod;
// copied from WG
private static <T extends Enum<T>> T tryEnum(Class<T> enumType, String ... values) {
for (String val : values) {
try {
return Enum.valueOf(enumType, val);
} catch (IllegalArgumentException e) {}
}
return null;
}
private static org.bukkit.entity.EntityType tntMinecartType;
private static boolean checkMinecartType = true;
/** /**
* Construct the object. * Construct the object.
* @param world * @param world
@ -122,6 +133,10 @@ public class BukkitWorld extends LocalWorld {
public BukkitWorld(World world) { public BukkitWorld(World world) {
this.world = world; this.world = world;
if (checkMinecartType) {
tntMinecartType = tryEnum(org.bukkit.entity.EntityType.class, "MINECART_TNT");
checkMinecartType = false;
}
// check if we have a class we can use for nms access // check if we have a class we can use for nms access
// only run once per server startup // only run once per server startup
@ -1032,7 +1047,7 @@ public class BukkitWorld extends LocalWorld {
++num; ++num;
} }
} else if (type == EntityType.TNT) { } else if (type == EntityType.TNT) {
if (ent instanceof TNTPrimed || ent instanceof MinecartTNT) { if (ent instanceof TNTPrimed || ent.getType() == tntMinecartType) {
ent.remove(); ent.remove();
++num; ++num;
} }