public Result query(final String query, boolean retry) {
    if (!isConnected()) open();
    try {
      PreparedStatement statement = null;
      try {
        if (!isConnected()) open();
        statement = c.prepareStatement(query);
        if (statement.execute()) return new Result(statement, statement.getResultSet());
      } catch (final SQLException e) {
        final String msg = e.getMessage();
        logger.severe("Database query error: " + msg);

        if (retry && msg.contains("_BUSY")) {
          logger.severe("Retrying query...");
          plugin
              .getServer()
              .getScheduler()
              .scheduleSyncDelayedTask(
                  plugin,
                  new Runnable() {
                    public void run() {
                      query(query, false);
                    }
                  },
                  20);
        }
      }
      if (statement != null) statement.close();
    } catch (SQLException ex) {
      plugin.log(ex.getMessage(), Level.SEVERE);
    }
    return null;
  }
 public void close() {
   try {
     if (c != null) c.close();
   } catch (SQLException ex) {
     plugin.log(ex.getMessage(), Level.SEVERE);
   }
   c = null;
 }
Esempio n. 3
0
  public Boss newBoss(Boss b) {
    String boss = b.getConfigName();
    bosses.remove(boss);
    bossNames.remove(boss);

    FileConfiguration config = plugin.getConfigManager().getConfig("maps.yml");
    ConfigurationSection section =
        config.getConfigurationSection(plugin.getMapManager().getCurrentMap().getName());
    ConfigurationSection sec = section.getConfigurationSection("bosses");

    Boss bb =
        new Boss(
            boss,
            sec.getInt(boss + ".hearts") * 2,
            sec.getString(boss + ".name"),
            Util.parseLocation(
                plugin.getMapManager().getCurrentMap().getWorld(), sec.getString(boss + ".spawn")),
            Util.parseLocation(
                plugin.getMapManager().getCurrentMap().getWorld(), sec.getString(boss + ".chest")));
    bosses.put(boss, bb);

    return bb;
  }