Пример #1
0
  /** Loads all plugins, calling onLoad, &c. */
  private void loadPlugins() {
    // clear the map
    commandMap.clearCommands();
    commandMap.register("glowstone", new ColorCommand("colors"));
    commandMap.register("glowstone", new TellrawCommand());

    File folder = new File(config.getString(ServerConfig.Key.PLUGIN_FOLDER));
    if (!folder.isDirectory() && !folder.mkdirs()) {
      logger.log(Level.SEVERE, "Could not create plugins directory: " + folder);
    }

    // clear plugins and prepare to load
    pluginManager.clearPlugins();
    pluginManager.registerInterface(JavaPluginLoader.class);
    Plugin[] plugins = pluginManager.loadPlugins(folder);

    // call onLoad methods
    for (Plugin plugin : plugins) {
      try {
        plugin.onLoad();
      } catch (Exception ex) {
        logger.log(Level.SEVERE, "Error loading " + plugin.getDescription().getFullName(), ex);
      }
    }
  }
Пример #2
0
  /** Stops this server. */
  @Override
  public void shutdown() {
    // Just in case this gets called twice
    if (isShuttingDown) {
      return;
    }
    isShuttingDown = true;
    logger.info("The server is shutting down...");

    // Disable plugins
    pluginManager.clearPlugins();

    // Kick all players (this saves their data too)
    for (Player player : getOnlinePlayers()) {
      player.kickPlayer(getShutdownMessage());
    }

    // Stop the network servers - starts the shutdown process
    // It may take a second or two for Netty to totally clean up
    networkServer.shutdown();
    if (queryServer != null) {
      queryServer.shutdown();
    }
    if (rconServer != null) {
      rconServer.shutdown();
    }

    // Save worlds
    for (World world : getWorlds()) {
      logger.info("Saving world: " + world.getName());
      unloadWorld(world, true);
    }

    // Stop scheduler and console
    scheduler.stop();
    consoleManager.stop();

    // Wait for a while and terminate any rogue threads
    new ShutdownMonitorThread().start();
  }