Files
src
manifest.kod
pom.xml
Code
22 2,195
src/main/java/com/kodari/auctionbattleeconomy/AuctionBattleEconomyPlugin.java
package com.kodari.auctionbattleeconomy;
import org.bukkit.plugin.java.JavaPlugin;
import java.sql.SQLException;
public final class AuctionBattleEconomyPlugin extends JavaPlugin {
private DatabaseManager databaseManager;
private EconomyService economyService;
private AuctionService auctionService;
private TeamService teamService;
private com.kodari.auctionbattleeconomy.inventory.gui.GUIManager guiManager;
@Override
public void onEnable() {
saveDefaultConfig();
databaseManager = new DatabaseManager(this);
try {
databaseManager.initialize();
} catch (SQLException exception) {
getLogger().severe("Unable to initialize the database: " + exception.getMessage());
getServer().getPluginManager().disablePlugin(this);
return;
}
economyService = new EconomyService(this, databaseManager);
teamService = new TeamService(this, databaseManager, economyService);
auctionService = new AuctionService(this, databaseManager, economyService, teamService);
auctionService.start();
guiManager = new com.kodari.auctionbattleeconomy.inventory.gui.GUIManager();
EconomyCommand economyCommand = new EconomyCommand(this, economyService);
if (getCommand("acoins") != null) {
getCommand("acoins").setExecutor(economyCommand);
}
if (getCommand("abaltop") != null) {
getCommand("abaltop").setExecutor(economyCommand);
}
AuctionCommand auctionCommand = new AuctionCommand(this, auctionService);
if (getCommand("auction") != null) {
getCommand("auction").setExecutor(auctionCommand);
}
if (getCommand("bid") != null) {
getCommand("bid").setExecutor(auctionCommand);
}
if (getCommand("abid") != null) {
getCommand("abid").setExecutor(auctionCommand);
}
if (getCommand("aah") != null) {
getCommand("aah").setExecutor(auctionCommand);
}
if (getCommand("asell") != null) {
getCommand("asell").setExecutor(auctionCommand);
}
if (getCommand("asold") != null) {
getCommand("asold").setExecutor(auctionCommand);
}
if (getCommand("aintro") != null) {
getCommand("aintro").setExecutor(new IntroductionCommand(this, economyService));
}
if (getCommand("ateam") != null) {
getCommand("ateam").setExecutor(new TeamCommand(this, teamService));
}
if (getCommand("abal") != null) {
getCommand("abal").setExecutor((sender, command, label, args) -> {
if (!(sender instanceof org.bukkit.entity.Player player)) {
sender.sendMessage("This command can only be used by a player.");
return true;
}
guiManager.openGUI(new AuctionHouseGUI(this, auctionService, guiManager), player);
return true;
});
}
getServer().getPluginManager().registerEvents(new PlayerListener(this, economyService, teamService), this);
getServer().getPluginManager().registerEvents(new com.kodari.auctionbattleeconomy.inventory.gui.GUIListener(guiManager), this);
getLogger().info("AuctionBattleEconomy has been enabled.");
}
@Override
public void onDisable() {
if (auctionService != null) {
auctionService.stop();
}
if (databaseManager != null) {
databaseManager.close();
}
getLogger().info("AuctionBattleEconomy has been disabled.");
}
public DatabaseManager getDatabaseManager() {
return databaseManager;
}
public EconomyService getEconomyService() {
return economyService;
}
public AuctionService getAuctionService() {
return auctionService;
}
public TeamService getTeamService() {
return teamService;
}
public com.kodari.auctionbattleeconomy.inventory.gui.GUIManager getGuiManager() {
return guiManager;
}
}