SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 94 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package fr.nathan.hub.customentities;
  2.  
  3. import java.lang.reflect.Field;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.Map;
  7.  
  8. import org.bukkit.entity.EntityType;
  9. import org.bukkit.entity.Player;
  10.  
  11. import net.minecraft.server.v1_8_R3.BiomeBase;
  12. import net.minecraft.server.v1_8_R3.BiomeBase.BiomeMeta;
  13. import net.minecraft.server.v1_8_R3.EntityCaveSpider;
  14. import net.minecraft.server.v1_8_R3.EntityChicken;
  15. import net.minecraft.server.v1_8_R3.EntityCow;
  16. import net.minecraft.server.v1_8_R3.EntityCreeper;
  17. import net.minecraft.server.v1_8_R3.EntityEnderman;
  18. import net.minecraft.server.v1_8_R3.EntityHorse;
  19. import net.minecraft.server.v1_8_R3.EntityHuman;
  20. import net.minecraft.server.v1_8_R3.EntityInsentient;
  21. import net.minecraft.server.v1_8_R3.EntityIronGolem;
  22. import net.minecraft.server.v1_8_R3.EntityLiving;
  23. import net.minecraft.server.v1_8_R3.EntityMagmaCube;
  24. import net.minecraft.server.v1_8_R3.EntityMushroomCow;
  25. import net.minecraft.server.v1_8_R3.EntityOcelot;
  26. import net.minecraft.server.v1_8_R3.EntityPig;
  27. import net.minecraft.server.v1_8_R3.EntityPigZombie;
  28. import net.minecraft.server.v1_8_R3.EntitySheep;
  29. import net.minecraft.server.v1_8_R3.EntitySilverfish;
  30. import net.minecraft.server.v1_8_R3.EntitySkeleton;
  31. import net.minecraft.server.v1_8_R3.EntitySlime;
  32. import net.minecraft.server.v1_8_R3.EntitySpider;
  33. import net.minecraft.server.v1_8_R3.EntityTypes;
  34. import net.minecraft.server.v1_8_R3.EntityWitch;
  35. import net.minecraft.server.v1_8_R3.EntityWolf;
  36. import net.minecraft.server.v1_8_R3.EntityZombie;
  37.  
  38. public enum CustomEntityType
  39. {
  40.     SILVERFISH("§eSilverfish", 60, EntityType.SILVERFISH, (Class<? extends EntityInsentient>)EntitySilverfish.class, (Class<? extends EntityInsentient>)CustomEntitySilverfish.class),
  41.     SLIME("§eSlime", 55, EntityType.SLIME, (Class<? extends EntityInsentient>)EntitySlime.class, (Class<? extends EntityInsentient>)CustomEntitySlime.class),
  42.     ZOMBIE_PIGMAN("§eZombie PigMan", 57, EntityType.PIG_ZOMBIE, (Class<? extends EntityInsentient>)EntityPigZombie.class, (Class<? extends EntityInsentient>)CustomEntityPigZombie.class),
  43.     WITCH("§eSorcière", 66, EntityType.WITCH, (Class<? extends EntityInsentient>)EntityWitch.class, (Class<? extends EntityInsentient>)CustomEntityWitch.class),
  44.     SKELETON("§eSkelette", 51, EntityType.SKELETON, (Class<? extends EntityInsentient>)EntitySkeleton.class, (Class<? extends EntityInsentient>)CustomEntitySkeleton.class),
  45.     CREEPER("§eCreeper", 50, EntityType.CREEPER, (Class<? extends EntityInsentient>)EntityCreeper.class, (Class<? extends EntityInsentient>)CustomEntityCreeper.class),
  46.     MAGMA_CUBE("§eMagma Cube", 62, EntityType.MAGMA_CUBE, (Class<? extends EntityInsentient>)EntityMagmaCube.class, (Class<? extends EntityInsentient>)CustomEntityMagmaCube.class),
  47.     ENDERMAN("§eEnderman", 58, EntityType.ENDERMAN, (Class<? extends EntityInsentient>)EntityEnderman.class, (Class<? extends EntityInsentient>)CustomEntityEnderman.class),
  48.     OCELOT("§eOcelot", 98, EntityType.OCELOT, (Class<? extends EntityInsentient>)EntityOcelot.class, (Class<? extends EntityInsentient>)CustomEntityOcelot.class),
  49.     IRONGOLEM("§eGolden de fer", 99, EntityType.IRON_GOLEM, (Class<? extends EntityInsentient>)EntityIronGolem.class, (Class<? extends EntityInsentient>)CustomEntityIronGolem.class),
  50.     ZOMBIE_HORSE("§eCheval Zombie", 100, EntityType.HORSE, (Class<? extends EntityInsentient>)EntityHorse.class, (Class<? extends EntityInsentient>)CustomEntityZombieHorse.class),
  51.     UNDEAD_HORSE("§eCheval Mort-Vivant", 100, EntityType.HORSE, (Class<? extends EntityInsentient>)EntityHorse.class, (Class<? extends EntityInsentient>)CustomEntityUndeadHorse.class),
  52.     HORSE("§eCheval", 100, EntityType.HORSE, (Class<? extends EntityInsentient>)EntityHorse.class, (Class<? extends EntityInsentient>)CustomEntityHorse.class),
  53.     COW("§eVache", 92, EntityType.COW, (Class<? extends EntityInsentient>)EntityCow.class, (Class<? extends EntityInsentient>)CustomEntityCow.class),
  54.     SHEEP("§eMouton", 91, EntityType.SHEEP, (Class<? extends EntityInsentient>)EntitySheep.class, (Class<? extends EntityInsentient>)CustomEntitySheep.class),
  55.     PIG("§eCochon", 90, EntityType.PIG, (Class<? extends EntityInsentient>)EntityPig.class, (Class<? extends EntityInsentient>)CustomEntityPig.class),
  56.     SPIDER("§eAraigniée", 52, EntityType.SPIDER, (Class<? extends EntityInsentient>)EntitySpider.class, (Class<? extends EntityInsentient>)CustomEntitySpider.class),
  57.     CAVE_SPIDER("§eAraignée des caves", 59, EntityType.CAVE_SPIDER, (Class<? extends EntityInsentient>)EntityCaveSpider.class, (Class<? extends EntityInsentient>)CustomEntityCaveSpider.class),
  58.     DISCO_SHEEP("§eDiscoSheep", 91, EntityType.SHEEP, (Class<? extends EntityInsentient>)EntitySheep.class, (Class<? extends EntityInsentient>)CustomEntityDiscoSheep.class),
  59.     ZOMBIE("§eZombie", 54, EntityType.ZOMBIE, (Class<? extends EntityInsentient>)EntityZombie.class, (Class<? extends EntityInsentient>)CustomEntityZombie.class),
  60.     CHICKEN("§ePoulet", 93, EntityType.CHICKEN, (Class<? extends EntityInsentient>)EntityChicken.class, (Class<? extends EntityInsentient>)CustomEntityChicken.class),
  61.     WOLF("§eLoup", 95, EntityType.WOLF, (Class<? extends EntityInsentient>)EntityWolf.class, (Class<? extends EntityInsentient>)CustomEntityWolf.class),
  62.     MUSHROOM_COW("§eVache Champi", 96, EntityType.MUSHROOM_COW, (Class<? extends EntityInsentient>)EntityMushroomCow.class, (Class<? extends EntityInsentient>)CustomEntityMushroomCow.class);
  63.    
  64.     private String name;
  65.     private int id;
  66.     private EntityType entityType;
  67.     private Class<? extends EntityInsentient> nmsClass;
  68.     private Class<? extends EntityInsentient> customClass;
  69.    
  70.     private CustomEntityType(final String name, final int id, final EntityType entityType, final Class<? extends EntityInsentient> nmsClass, final Class<? extends EntityInsentient> customClass) {
  71.         this.name = name;
  72.         this.id = id;
  73.         this.entityType = entityType;
  74.         this.nmsClass = nmsClass;
  75.         this.customClass = customClass;
  76.     }
  77.    
  78.     public String getName() {
  79.         return this.name;
  80.     }
  81.    
  82.     public int getID() {
  83.         return this.id;
  84.     }
  85.    
  86.     public EntityType getEntityType() {
  87.         return this.entityType;
  88.     }
  89.    
  90.     public Class<? extends EntityInsentient> getNMSClass() {
  91.         return this.nmsClass;
  92.     }
  93.    
  94.     public Class<? extends EntityInsentient> getCustomClass() {
  95.         return this.customClass;
  96.     }
  97.    
  98.     public static void registerEntities() {
  99.         CustomEntityType[] var3;
  100.         for (int var2 = (var3 = values()).length, var4 = 0; var4 < var2; ++var4) {
  101.             final CustomEntityType var5 = var3[var4];
  102.             a(var5.getCustomClass(), var5.getName(), var5.getID());
  103.         }
  104.         BiomeBase[] var6;
  105.         try {
  106.             var6 = (BiomeBase[])getPrivateStatic(BiomeBase.class, "biomes");
  107.         }
  108.         catch (Exception var19) {
  109.             return;
  110.         }
  111.         final BiomeBase[] var7 = var6;
  112.         for (int var8 = var6.length, var2 = 0; var2 < var8; ++var2) {
  113.             final BiomeBase var9 = var7[var2];
  114.             if (var9 == null) {
  115.                 break;
  116.             }
  117.             String[] var11;
  118.             for (int var10 = (var11 = new String[] { "at", "au", "av", "aw" }).length, var12 = 0; var12 < var10; ++var12) {
  119.                 final String field = var11[var12];
  120.                 try {
  121.                     final Field var13 = BiomeBase.class.getDeclaredField(field);
  122.                     var13.setAccessible(true);
  123.                     final List<BiomeMeta> mobList = new ArrayList<BiomeMeta>();
  124.                     for (final BiomeBase.BiomeMeta meta : mobList) {
  125.                         CustomEntityType[] var16;
  126.                         for (int var15 = (var16 = values()).length, var17 = 0; var17 < var15; ++var17) {
  127.                             final CustomEntityType entity = var16[var17];
  128.                             if (entity.getNMSClass().equals(meta.b)) {
  129.                                 meta.b = entity.getCustomClass();
  130.                             }
  131.                         }
  132.                     }
  133.                 }
  134.                 catch (Exception var18) {
  135.                     var18.printStackTrace();
  136.                 }
  137.             }
  138.         }
  139.     }
  140.    
  141.     public static void unregisterEntities() {
  142.         CustomEntityType[] var3;
  143.         for (int var2 = (var3 = values()).length, biomeBase = 0; biomeBase < var2; ++biomeBase) {
  144.             final CustomEntityType biomes = var3[biomeBase];
  145.             try {
  146.                 ((Map)getPrivateStatic(EntityTypes.class, "d")).remove(biomes.getCustomClass());
  147.             }
  148.             catch (Exception var4) {
  149.                 var4.printStackTrace();
  150.             }
  151.             try {
  152.                 ((Map)getPrivateStatic(EntityTypes.class, "f")).remove(biomes.getCustomClass());
  153.             }
  154.             catch (Exception var5) {
  155.                 var5.printStackTrace();
  156.             }
  157.         }
  158.         for (int var2 = (var3 = values()).length, biomeBase = 0; biomeBase < var2; ++biomeBase) {
  159.             final CustomEntityType biomes = var3[biomeBase];
  160.             try {
  161.                 a(biomes.getNMSClass(), biomes.getName(), biomes.getID());
  162.             }
  163.             catch (Exception var6) {
  164.                 var6.printStackTrace();
  165.             }
  166.         }
  167.         BiomeBase[] var7;
  168.         try {
  169.             var7 = (BiomeBase[])getPrivateStatic(BiomeBase.class, "biomes");
  170.         }
  171.         catch (Exception var19) {
  172.             return;
  173.         }
  174.         final BiomeBase[] e = var7;
  175.         for (int var8 = var7.length, var2 = 0; var2 < var8; ++var2) {
  176.             final BiomeBase var9 = e[var2];
  177.             if (var9 == null) {
  178.                 break;
  179.             }
  180.             String[] var11;
  181.             for (int var10 = (var11 = new String[] { "at", "au", "av", "aw" }).length, var12 = 0; var12 < var10; ++var12) {
  182.                 final String field = var11[var12];
  183.                 try {
  184.                     final Field var13 = BiomeBase.class.getDeclaredField(field);
  185.                     var13.setAccessible(true);
  186.                     final List<BiomeMeta> mobList = new ArrayList<BiomeMeta>();
  187.                     for (final BiomeBase.BiomeMeta meta : mobList) {
  188.                         CustomEntityType[] var16;
  189.                         for (int var15 = (var16 = values()).length, var17 = 0; var17 < var15; ++var17) {
  190.                             final CustomEntityType entity = var16[var17];
  191.                             if (entity.getCustomClass().equals(meta.b)) {
  192.                                 meta.b = entity.getNMSClass();
  193.                             }
  194.                         }
  195.                     }
  196.                 }
  197.                 catch (Exception var18) {
  198.                     var18.printStackTrace();
  199.                 }
  200.             }
  201.         }
  202.     }
  203.    
  204.     private static Object getPrivateStatic(final Class clazz, final String f) throws Exception {
  205.         final Field field = clazz.getDeclaredField(f);
  206.         field.setAccessible(true);
  207.         return field.get(null);
  208.     }
  209.    
  210.     private static void a(final Class paramClass, final String paramString, final int paramInt) {
  211.         try {
  212.             ((Map)getPrivateStatic(EntityTypes.class, "c")).put(paramString, paramClass);
  213.             ((Map)getPrivateStatic(EntityTypes.class, "d")).put(paramClass, paramString);
  214.             ((Map)getPrivateStatic(EntityTypes.class, "e")).put(paramInt, paramClass);
  215.             ((Map)getPrivateStatic(EntityTypes.class, "f")).put(paramClass, paramInt);
  216.             ((Map)getPrivateStatic(EntityTypes.class, "g")).put(paramString, paramInt);
  217.         }
  218.         catch (Exception ex) {}
  219.     }
  220.    
  221.     public static boolean shouldDie(final EntityLiving mount, final Player player) {
  222.         if (mount.passenger != null && mount.passenger instanceof EntityHuman) {
  223.             return false;
  224.         }
  225.         mount.die();
  226.         return true;
  227.     }
  228. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top