Esempio 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");
    }
  }
Esempio 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());
    }
  }