Ejemplo n.º 1
0
 @Override
 public void onDisable() {
   // For testing reasons, we can't just invoke a SaveAllJobsTask instance and invoke run()
   // Bukkit also won't let us invoke a new instance of a BukkitTask in the onDisable() function
   while (!sql.open()) {;
   }
   if (getServer().getOnlinePlayers().length == 0) return;
   for (Player player : getServer().getOnlinePlayers()) {
     String job = getJob(player);
     int level = getLevel(player);
     try {
       // ToDo:  Consolidate to one SQL operation
       sql.query(
           String.format(
               "UPDATE Accounts SET job='%s' WHERE user_name='%s '", job, player.getName()));
       sql.query(
           String.format(
               "UPDATE Accounts SET level=%d WHERE user_name='%s'", level, player.getName()));
     } catch (SQLException e) {
       e.printStackTrace();
     }
   }
   while (!sql.close()) {;
   }
 }
Ejemplo n.º 2
0
  @Override
  public void onEnable() {

    /* Check if the data folder exists, create it if it does not */
    File dataFolder = getDataFolder();
    if (!dataFolder.exists()) {
      dataFolder.mkdir();
    }

    sql =
        new SQLite(
            getLogger(),
            "[BitGoldJobs] ",
            this.getDataFolder().getAbsolutePath(),
            "BitGoldJobs",
            ".sqlite");

    try {
      if (sql.open()) {
        sql.query(
            "CREATE TABLE IF NOT EXISTS Accounts "
                + "(user_name varchar(16), job varchar(16), level int)");
        sql.close();
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }

    getCommand("jobs").setExecutor(new JobsCommandExecutor(this));

    getServer().getPluginManager().registerEvents(new NewAccountListener(this), this);
    getServer().getPluginManager().registerEvents(new LoginMetadataJobsListener(this), this);
    getServer().getPluginManager().registerEvents(new LogoutMetadataJobsListener(this), this);

    getServer().getPluginManager().registerEvents(new JobBlockBreakListener(this), this);

    new LoadAllJobsTask(this).runTask(this); // Task not implemented
    // BukkitTask saveAll = new SaveAllJobsTask(this).runTaskTimer(this, 0, secondsToTicks(5));

    new JobPeriodTask(this).runTaskTimer(this, 0, secondsToTicks(60 * 1));
  }