Files
src
build.gradle
manifest.kod
settings.gradle
Code
36 2,094
src/main/java/com/kodari/flameinventory/FlameInventoryPlugin.java
package com.kodari.flameinventory;
import com.kodari.flameinventory.api.FlameInventoryAPI;
import com.kodari.flameinventory.backup.BackupManager;
import com.kodari.flameinventory.backup.SQLiteBackupRepository;
import com.kodari.flameinventory.command.InventoryCommand;
import com.kodari.flameinventory.gui.GUIListener;
import com.kodari.flameinventory.gui.GUIManager;
import com.kodari.flameinventory.listener.InventoryListener;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
public class FlameInventoryPlugin extends JavaPlugin {
private SQLiteBackupRepository repository;
private BackupManager backupManager;
private GUIManager guiManager;
private FlameInventoryAPI api;
@Override
public void onEnable() {
saveDefaultConfig();
saveBundledConfiguration("database.yml");
saveBundledConfiguration("backup.yml");
saveBundledConfiguration("restore.yml");
saveBundledConfiguration("inventory-gui.yml");
saveBundledConfiguration("messages.yml");
saveBundledConfiguration("cleanup.yml");
saveBundledConfiguration("permissions.yml");
saveBundledConfiguration("integrations.yml");
this.repository = new SQLiteBackupRepository(this);
this.repository.initialize();
this.guiManager = new GUIManager();
this.backupManager = new BackupManager(this, repository);
this.api = new FlameInventoryAPI(this, backupManager);
Bukkit.getPluginManager().registerEvents(new GUIListener(guiManager), this);
Bukkit.getPluginManager().registerEvents(new InventoryListener(this), this);
backupManager.cleanup();
Bukkit.getScheduler().runTaskTimer(this, () -> backupManager.cleanup(), 20L * 60L * 60L * 6L, 20L * 60L * 60L * 6L);
InventoryCommand command = new InventoryCommand(this);
if (getCommand("finv") != null) {
getCommand("finv").setExecutor(command);
getCommand("finv").setTabCompleter(command);
}
getLogger().info("FlameInventory enabled with SQLite storage.");
}
@Override
public void onDisable() {
if (repository != null) {
repository.close();
}
}
private void saveBundledConfiguration(String name) {
File file = new File(getDataFolder(), name);
if (!file.exists()) {
saveResource(name, false);
}
}
public void runSync(Runnable task) {
if (Bukkit.isPrimaryThread()) {
task.run();
return;
}
Bukkit.getScheduler().runTask(this, task);
}
public SQLiteBackupRepository getRepository() {
return repository;
}
public BackupManager getBackupManager() {
return backupManager;
}
public GUIManager getGuiManager() {
return guiManager;
}
public FlameInventoryAPI getApi() {
return api;
}
}