Files
src
build.gradle
manifest.kod
Code
27 1,957
src/main/java/com/velthara/auctionhouse/VeltharAuctionHouse.java
package com.velthara.auctionhouse;
import com.velthara.auctionhouse.command.AuctionCommand;
import com.velthara.auctionhouse.config.ConfigManager;
import com.velthara.auctionhouse.database.Database;
import com.velthara.auctionhouse.database.MySQLDatabase;
import com.velthara.auctionhouse.database.SQLiteDatabase;
import com.velthara.auctionhouse.inventory.gui.GUIListener;
import com.velthara.auctionhouse.inventory.gui.GUIManager;
import com.velthara.auctionhouse.manager.AuctionManager;
import com.velthara.auctionhouse.manager.EconomyManager;
import com.velthara.auctionhouse.manager.MailboxManager;
import com.velthara.auctionhouse.task.ExpiryTask;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@Getter
public class VeltharAuctionHouse extends JavaPlugin {
private ConfigManager configManager;
private Database database;
private EconomyManager economyManager;
private GUIManager guiManager;
private AuctionManager auctionManager;
private MailboxManager mailboxManager;
private ExpiryTask expiryTask;
@Override
public void onEnable() {
this.configManager = new ConfigManager(this);
this.economyManager = new EconomyManager(this);
if (!this.economyManager.setupEconomy()) {
getLogger().severe("Vault not found! Disabling plugin...");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
String dbType = getConfig().getString("database.type", "SQLITE");
if (dbType.equalsIgnoreCase("MYSQL")) {
this.database = new MySQLDatabase(this);
} else {
this.database = new SQLiteDatabase(this);
}
this.database.connect().thenRun(() -> {
getLogger().info("Database connected successfully.");
}).exceptionally(ex -> {
getLogger().severe("Failed to connect to database: " + ex.getMessage());
Bukkit.getPluginManager().disablePlugin(this);
return null;
});
this.guiManager = new GUIManager();
this.mailboxManager = new MailboxManager(this);
this.auctionManager = new AuctionManager(this);
Bukkit.getPluginManager().registerEvents(new GUIListener(guiManager), this);
this.getCommand("ah").setExecutor(new AuctionCommand(this));
long checkInterval = getConfig().getLong("expire.check-interval", 300) * 20L;
this.expiryTask = new ExpiryTask(this);
this.expiryTask.runTaskTimerAsynchronously(this, checkInterval, checkInterval);
getLogger().info("VeltharAuctionHouse enabled successfully.");
}
@Override
public void onDisable() {
if (this.expiryTask != null) {
this.expiryTask.cancel();
}
if (this.database != null) {
this.database.disconnect();
}
getLogger().info("VeltharAuctionHouse disabled.");
}
}