Пример #1
0
  @Override
  public void onDisable() {
    if (crashed) {
      crashed = false;
      return;
    }

    try {
      for (Player player : Bukkit.getOnlinePlayers()) {
        OnlineSessionCache.fetch(player).logout(player.getLocation());
      }
      DatabaseTask.commit();
      serverStatistics.pluginShutdown();
      OnlineSessionCache.dumpSessions();
      CachedData.stopAll();

      Bukkit.getScheduler().cancelTasks(this);

      if (vaultHook != null) {
        vaultHook.onDisable();
      }
      if (worldGuardHook != null) {
        worldGuardHook.onDisable();
      }

      Database.close();
    } catch (Throwable t) {
      Message.log(Level.SEVERE, t.getMessage());
      if (LocalConfiguration.Debug.asBoolean()) t.printStackTrace();
    }
  }
Пример #2
0
  @Override
  public void onEnable() {

    if (!new File(getDataFolder(), "config.yml").exists()) {
      Message.log("Config.yml not found. Creating a one for you.");
      getConfig().options().copyDefaults(true);
      saveConfig();
      crashed = true;
      this.setEnabled(false);
      return;
    }

    if (LocalConfiguration.FetchPatches.asBoolean()) new PatchFetcher();
    new Query();

    try {
      new Database();
    } catch (Exception e) {
      crashed = true;
      Message.log(Level.SEVERE, "Cannot establish a database connection!");
      Message.log(Level.SEVERE, "Is the plugin set up correctly?");
      if (LocalConfiguration.Debug.asBoolean()) e.printStackTrace();
      this.setEnabled(false);
      return;
    }

    Message.log("Database connection established.");

    if (getServer().getPluginManager().getPlugin("Vault") != null && Module.Vault.isEnabled()) {
      vaultHook = new VaultHook();
      vaultHook.onEnable();
    }

    if (getServer().getPluginManager().getPlugin("WorldGuard") != null
        && getServer().getPluginManager().getPlugin("WorldEdit") != null
        && Module.WorldGuard.isEnabled()) {
      worldGuardHook = new WorldGuardHook();
      worldGuardHook.onEnable();
    }

    ConfigurationSerialization.registerClass(StatsSign.class, "StatsSign");

    new ServerListener(this);
    new PlayerListener(this);
    if (Module.Blocks.isEnabled()) new BlockListener(this);
    if (Module.Items.isEnabled()) new ItemListener(this);
    if (Module.Deaths.isEnabled()) new DeathListener(this);
    new StatsSignListener(this);
    if (isCraftBukkitCompatible()) new StatsBookListener(this);

    serverStatistics = new ServerStatistics();
    serverTotals = new ServerTotals();

    long ping = RemoteConfiguration.Ping.asInteger() * 20;

    try {
      metrics = new PluginMetrics(this);
      if (!metrics.isOptOut()) metrics.start();
    } catch (IOException e) {
      Message.log(Level.SEVERE, "An error occurred while connecting to PluginMetrics");
    }

    CachedData.startAll();

    Bukkit.getScheduler().runTaskTimerAsynchronously(this, new DatabaseTask(), (ping / 2), ping);
    Bukkit.getScheduler().runTaskTimerAsynchronously(this, new RefreshTask(), 0L, 20L);

    Bukkit.getScheduler().runTaskTimer(this, new SignRefreshTask(), ping, ping);
    Bukkit.getScheduler().runTaskTimer(this, new TickTask(), 0L, 1L);
  }