Permalink
Browse files

Fix for minecart naming

  • Loading branch information...
wizjany committed Mar 16, 2013
1 parent 9ac04f8 commit 0d52d22bd8964988faaf01b19cfbd38f0fe6a591
Showing with 17 additions and 2 deletions.
  1. +17 −2 src/main/java/com/sk89q/worldedit/bukkit/BukkitWorld.java
@@ -65,7 +65,6 @@
import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Minecart;
-import org.bukkit.entity.MinecartTNT;
import org.bukkit.entity.Painting;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.TNTPrimed;
@@ -115,13 +114,29 @@
private static Method nmsGetMethod;
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.
* @param world
*/
public BukkitWorld(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
// only run once per server startup
@@ -1032,7 +1047,7 @@ public int removeEntities(EntityType type, Vector origin, int radius) {
++num;
}
} else if (type == EntityType.TNT) {
- if (ent instanceof TNTPrimed || ent instanceof MinecartTNT) {
+ if (ent instanceof TNTPrimed || ent.getType() == tntMinecartType) {
ent.remove();
++num;
}

0 comments on commit 0d52d22

Please sign in to comment.