示例#1
0
  public void onDisable() {
    this.getLogger().info("Disabling Minecraftno plugin...");

    // Enable whitelist to stop players joining while we're shutting down.
    if (this.getConfig().getBoolean("whitelist.on_disable.toggle", false)) {
      this.getServer()
          .setWhitelist(this.getConfig().getBoolean("whitelist.on_disable.toggle", true));

      // Kick everyone who's already online before we start disabling functionality.
      // They're not supposed to be here anyway.
      for (Player player : this.getServer().getOnlinePlayers()) {
        player.kickPlayer(
            this.getConfig().getString("whitelist.message", "The server is shutting down..."));
      }
    }

    if (configuration.irc && bot.isConnected()) {
      this.getLogger().info(" - Disabling IRC bot...");
      bot.disconnect();
      bot.dispose();
    }

    this.getLogger().info(" - Handlers cleanup...");
    this.groupHandler.cleanup();
    this.userHandler.cleanup();

    try {
      configuration.cleanup();
    } catch (Exception e) {
      e.printStackTrace();
    }

    if (this.blockHandler != null) {
      if (this.blockHandler.getQueueSize() > 0) {
        this.getLogger().info(" - Waiting for block handler to finish...");

        try {
          Thread.sleep(3000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
        this.blockHandler.run();
      }
    }

    if (sqlc != null) {
      this.getLogger().info(" - Closing SQL connection...");
      sqlc.close();
    }

    this.getLogger().info(" - Cancelling scheduled tasks...");
    getServer().getScheduler().cancelAllTasks();

    this.getLogger().info("Finished disabling Minecraftno plugin.");
  }
示例#2
0
  public void onEnable() {
    hardwork.onEnable();

    // Use the default Bukkit logger.
    // Previous log handler is no longer needed, as "Overloaded!" messages can be disabled in
    // config.
    Minecraftno.log = this.getLogger();
    Minecraftno.debugLog = this.getLogger();

    this.getLogger().info("Loading native Bukkit configuration...");
    this.saveDefaultConfig();
    this.getConfig().options().copyDefaults(true);
    this.saveConfig();

    this.getLogger().info("Loading custom configuration...");
    try {
      this.configuration.load();
    } catch (Exception e) {
      e.printStackTrace();
    }

    this.getLogger().info("Enabling Minecraftno plugin...");

    this.getLogger().info(" - Enabling IRC bot...");
    bot.ircBot();

    this.getLogger().info(" - Binding to events...");
    registerEvents();

    this.getLogger().info(" - Connecting to SQL server...");
    if (!sqlConnection()) {
      return;
    }

    this.getLogger().info(" - Initializing handlers...");
    this.userHandler.initialise();
    this.bankHandler.initialise();
    this.weBridge.initialise();
    this.worldHandler.initialise();
    this.sandtakHandler.initialise();

    this.getLogger().info(" - Initializing handlers, part 2...");
    // this.afkkickhandler.reloadAllAfk();
    this.userHandler.reloadUsers();
    this.startupHandler.weather();
    this.startupHandler.checkSpace();
    this.groupHandler.getAllGroups();

    this.getLogger().info(" - Scheduling tasks...");
    new WorldBackup(this).scheduleWorldBackup();
    new ServerLogBackup(this).scheduleServerLogBackup();
    new SpawnProtection(this).scheduleSpawnProtection();

    if (getServer()
            .getScheduler()
            .runTaskTimerAsynchronously(this, this.blockHandler, 20, 20)
            .getTaskId()
        > 0) {
      this.getLogger().info("Scheduled start up.");
    } else {
      this.getLogger().info("Scheduled failed. Starting now manualy.");
      timer = new Timer();
      timer.scheduleAtFixedRate(this.blockHandler, 1000, 1000);
    }

    this.getLogger().info(" - Enabling custom recipes...");
    new RecipeHandler(this).registerRecipes();

    this.getLogger().info(" - Registering commands...");
    registerCommands();

    // Enable or disable whitelist on plugin load.
    // Enable whitelist in server.properties to ensures nobody
    // can join the server until we're really ready for it.
    if (this.getConfig().getBoolean("whitelist.on_enable.toggle", false)) {
      this.getServer()
          .setWhitelist(this.getConfig().getBoolean("whitelist.on_enable.state", false));
    }

    this.getLogger().info("Finished enabling Minecraftno plugin.");
  }