9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-28 03:19:15 +00:00

Fixed database

This commit is contained in:
HeroBrineGoat
2022-01-22 01:10:59 -05:00
parent 80f6e02598
commit 45c51492a3
11 changed files with 164 additions and 62 deletions

View File

@@ -4,6 +4,7 @@ import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import io.github.fisher2911.hmccosmetics.command.CosmeticsCommand;
import io.github.fisher2911.hmccosmetics.concurrent.Threads;
import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager;
import io.github.fisher2911.hmccosmetics.database.Database;
import io.github.fisher2911.hmccosmetics.database.DatabaseFactory;
@@ -18,7 +19,9 @@ import io.github.fisher2911.hmccosmetics.user.UserManager;
import me.mattstudios.mf.base.CommandManager;
import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitTask;
import java.sql.SQLException;
import java.util.Arrays;
@@ -36,6 +39,8 @@ public class HMCCosmetics extends JavaPlugin {
private CommandManager commandManager;
private Database database;
private BukkitTask saveTask;
@Override
public void onEnable() {
final int pluginId = 13873;
@@ -63,13 +68,29 @@ public class HMCCosmetics extends JavaPlugin {
}
HookManager.getInstance().registerListeners(this);
this.saveTask = Bukkit.getScheduler().runTaskTimerAsynchronously(
this,
() -> {
for (final Player player : Bukkit.getOnlinePlayers()) {
this.userManager.get(player.getUniqueId()).ifPresent(
this.database::saveUser
);
}
},
20,
20 * 60
);
}
@Override
public void onDisable() {
this.saveTask.cancel();
this.database.saveAll();
this.messageHandler.close();
this.userManager.cancelTeleportTask();
this.userManager.removeAll();
Threads.getInstance().onDisable();
this.database.close();
}