Exemplo n.º 1
0
  @Override
  @SuppressWarnings("unchecked")
  public void unregisterEntityTypes() {
    try {
      Field EntityTypes_d = ReflectionUtil.getField(EntityTypes.class, "d");
      Field EntityTypes_f = ReflectionUtil.getField(EntityTypes.class, "f");

      Map<Class, String> d = (Map) EntityTypes_d.get(EntityTypes_d);
      Map<Class, Integer> f = (Map) EntityTypes_f.get(EntityTypes_f);

      Iterator dIterator = d.keySet().iterator();
      while (dIterator.hasNext()) {
        Class clazz = (Class) dIterator.next();
        if (clazz.getCanonicalName().startsWith("de.Keyle.MyPet")) {
          dIterator.remove();
        }
      }

      Iterator fIterator = f.keySet().iterator();
      while (fIterator.hasNext()) {
        Class clazz = (Class) fIterator.next();
        if (clazz.getCanonicalName().startsWith("de.Keyle.MyPet")) {
          fIterator.remove();
        }
      }
    } catch (Exception e) {
      MyPetApi.getLogger().warning("Error while unregistering MyPet entities");
    }
  }
Exemplo n.º 2
0
  @SuppressWarnings("unchecked")
  public void registerEntityType(
      MyPetType type, Class<? extends MyPetMinecraftEntity> entityClass) {
    try {
      Field EntityTypes_d = ReflectionUtil.getField(EntityTypes.class, "d");
      Field EntityTypes_f = ReflectionUtil.getField(EntityTypes.class, "f");

      Map<Class, String> d = (Map) EntityTypes_d.get(EntityTypes_d);
      Map<Class, Integer> f = (Map) EntityTypes_f.get(EntityTypes_f);

      Iterator cIterator = d.keySet().iterator();
      while (cIterator.hasNext()) {
        Class clazz = (Class) cIterator.next();
        if (clazz.getCanonicalName().equals(entityClass.getCanonicalName())) {
          cIterator.remove();
        }
      }

      Iterator eIterator = f.keySet().iterator();
      while (eIterator.hasNext()) {
        Class clazz = (Class) eIterator.next();
        if (clazz.getCanonicalName().equals(entityClass.getCanonicalName())) {
          eIterator.remove();
        }
      }

      d.put(entityClass, type.getMinecraftName());
      f.put(entityClass, type.getTypeID());

    } catch (Exception e) {
      MyPetApi.getLogger().warning("Error while registering " + entityClass.getCanonicalName());
    }
  }
Exemplo n.º 3
0
  @Override
  public MyPetMinecraftEntity createMinecraftEntity(MyPet pet, org.bukkit.World bukkitWorld) {
    EntityMyPet petEntity = null;

    Class<? extends MyPetMinecraftEntity> entityClass = entityClasses.get(pet.getPetType());
    World world = ((CraftWorld) bukkitWorld).getHandle();

    try {
      Constructor<?> ctor = entityClass.getConstructor(World.class, MyPet.class);
      Object obj = ctor.newInstance(world, pet);
      if (obj instanceof EntityMyPet) {
        petEntity = (EntityMyPet) obj;
      }
    } catch (Exception e) {
      MyPetApi.getLogger()
          .info(ChatColor.RED + entityClass.getName() + " is no valid MyPet(Entity)!");
      e.printStackTrace();
    }

    return petEntity;
  }