Esempio n. 1
0
  /** Initialise the mods which were loaded */
  private void initMods() {
    loadedModsList = "";
    int loadedModsCount = 0;

    for (Iterator<LiteMod> iter = mods.iterator(); iter.hasNext(); ) {
      LiteMod mod = iter.next();

      try {
        logger.info("Initialising mod " + mod.getName() + " version " + mod.getVersion());

        mod.init();

        if (mod instanceof Tickable) {
          addTickListener((Tickable) mod);
        }

        if (mod instanceof InitCompleteListener) {
          addInitListener((InitCompleteListener) mod);
        }

        if (mod instanceof RenderListener) {
          addRenderListener((RenderListener) mod);
        }

        if (mod instanceof ChatFilter) {
          addChatFilter((ChatFilter) mod);
        }

        if (mod instanceof ChatListener && !(mod instanceof ChatFilter)) {
          addChatListener((ChatListener) mod);
        }

        if (mod instanceof PreLoginListener) {
          addPreLoginListener((PreLoginListener) mod);
        }

        if (mod instanceof LoginListener) {
          addLoginListener((LoginListener) mod);
        }

        if (mod instanceof PluginChannelListener) {
          addPluginChannelListener((PluginChannelListener) mod);
        }

        loadedModsList += String.format("\n    - %s version %s", mod.getName(), mod.getVersion());
        loadedModsCount++;
      } catch (Throwable th) {
        logger.log(Level.WARNING, "Error initialising mod '" + mod.getName(), th);
        iter.remove();
      }
    }

    loadedModsList = String.format("%s loaded mod(s)%s", loadedModsCount, loadedModsList);
  }
Esempio n. 2
0
  /**
   * Create mod instances from the enumerated classes
   *
   * @param modsToLoad List of mods to load
   */
  private void loadMods(HashMap<String, Class> modsToLoad) {
    if (modsToLoad == null) {
      logger.info("Mod class discovery failed. Not loading any mods!");
      return;
    }

    logger.info("Discovered " + modsToLoad.size() + " total mod(s)");

    for (Class mod : modsToLoad.values()) {
      try {
        logger.info("Loading mod from " + mod.getName());

        LiteMod newMod = (LiteMod) mod.newInstance();
        mods.add(newMod);

        logger.info(
            "Successfully added mod " + newMod.getName() + " version " + newMod.getVersion());
      } catch (Throwable th) {
        logger.warning(th.toString());
        th.printStackTrace();
      }
    }
  }