|
1 | 1 | package de.ntcomputer.minecraft.controllablemobs.implementation; |
2 | 2 |
|
3 | | -import java.lang.reflect.Field; |
4 | | -import java.util.Map; |
5 | | - |
6 | | -import net.minecraft.server.v1_6_R3.EntityTypes; |
7 | | - |
8 | 3 | import org.bukkit.entity.Animals; |
9 | 4 | import org.bukkit.entity.Creature; |
10 | | -import org.bukkit.entity.Entity; |
11 | 5 | import org.bukkit.entity.EntityType; |
12 | 6 | import org.bukkit.entity.HumanEntity; |
13 | 7 | import org.bukkit.entity.LivingEntity; |
14 | 8 | import org.bukkit.entity.Monster; |
15 | 9 | import org.bukkit.entity.Player; |
16 | 10 |
|
| 11 | +import de.ntcomputer.minecraft.controllablemobs.implementation.nativeinterfaces.NativeInterfaces; |
| 12 | + |
17 | 13 | public class ControllableMobHelper { |
18 | 14 |
|
19 | | - public static Class<? extends net.minecraft.server.v1_6_R3.Entity> getNotchEntityClass(final Class<? extends Entity> entityClass) throws IllegalArgumentException { |
| 15 | + @SuppressWarnings("deprecation") |
| 16 | + public static Class<? extends net.minecraft.server.v1_6_R3.Entity> getNmsEntityClass(final Class<? extends LivingEntity> entityClass) throws IllegalArgumentException { |
20 | 17 | if(entityClass==null) throw new IllegalArgumentException("entityClass must not be null"); |
21 | 18 | if(entityClass==HumanEntity.class || entityClass==Player.class) return net.minecraft.server.v1_6_R3.EntityHuman.class; |
22 | 19 | if(entityClass==Monster.class) return net.minecraft.server.v1_6_R3.EntityMonster.class; |
23 | 20 | if(entityClass==Creature.class) return net.minecraft.server.v1_6_R3.EntityCreature.class; |
24 | 21 | if(entityClass==Animals.class) return net.minecraft.server.v1_6_R3.EntityAnimal.class; |
25 | 22 | if(entityClass==LivingEntity.class) return net.minecraft.server.v1_6_R3.EntityLiving.class; |
26 | 23 |
|
27 | | - |
28 | 24 | for(EntityType entityType: EntityType.values()) { |
29 | 25 | if(entityType.getEntityClass()==null || entityType.getTypeId()==-1) continue; |
30 | 26 | if(entityClass.equals(entityType.getEntityClass())) { |
31 | | - return getNotchEntityClass(entityType); |
| 27 | + return getNmsEntityClass(entityType); |
32 | 28 | } |
33 | 29 | } |
34 | 30 |
|
35 | 31 | throw new IllegalArgumentException("Class "+entityClass.getSimpleName()+" is not resolvable to an EntityType"); |
36 | 32 | } |
37 | 33 |
|
38 | | - @SuppressWarnings({ "unchecked", "rawtypes" }) |
39 | | - public static Class<? extends net.minecraft.server.v1_6_R3.Entity> getNotchEntityClass(final EntityType entityType) throws IllegalArgumentException { |
| 34 | + @SuppressWarnings("deprecation") |
| 35 | + public static Class<? extends net.minecraft.server.v1_6_R3.Entity> getNmsEntityClass(final EntityType entityType) throws IllegalArgumentException { |
40 | 36 | if(entityType==null) throw new IllegalArgumentException("EntityType must not be null"); |
41 | 37 | if(entityType==EntityType.PLAYER) return net.minecraft.server.v1_6_R3.EntityHuman.class; |
42 | 38 |
|
43 | 39 | try { |
44 | | - Field mapField = EntityTypes.class.getDeclaredField("d"); |
45 | | - mapField.setAccessible(true); |
46 | | - final Class<? extends net.minecraft.server.v1_6_R3.Entity> entityClass = (Class<? extends net.minecraft.server.v1_6_R3.Entity>) ((Map) mapField.get(null)).get(Integer.valueOf(entityType.getTypeId())); |
47 | | - if(entityClass==null) throw new IllegalArgumentException("EntityType "+entityType.name()+" is not resolvable to a net.minecraft Class"); |
| 40 | + final Class<? extends net.minecraft.server.v1_6_R3.Entity> entityClass = NativeInterfaces.ENTITYTYPES.METHOD_GETCLASSBYID.invoke(entityType.getTypeId()); |
| 41 | + if(entityClass==null) throw new IllegalArgumentException("EntityType "+entityType+" is not resolvable to a net.minecraft Class"); |
48 | 42 | return entityClass; |
49 | 43 | } catch(Exception e) { |
50 | | - throw new IllegalArgumentException("EntityType "+entityType.name()+" is not resolvable to a net.minecraft Class", e); |
| 44 | + throw new IllegalArgumentException("EntityType "+entityType+" is not resolvable to a net.minecraft Class", e); |
51 | 45 | } |
52 | 46 | } |
53 | 47 |
|
|
0 commit comments