Files
src
build.gradle
manifest.kod
Code
43 2,797
src/main/java/com/craftwoods/woodspixelbazaar/WoodsPixelBazaar.java
package com.craftwoods.woodspixelbazaar;
import com.craftwoods.woodspixelbazaar.api.BazaarAPI;
import com.craftwoods.woodspixelbazaar.command.AdminCommand;
import com.craftwoods.woodspixelbazaar.command.BazaarCommand;
import com.craftwoods.woodspixelbazaar.database.DatabaseManager;
import com.craftwoods.woodspixelbazaar.inventory.gui.GUIListener;
import com.craftwoods.woodspixelbazaar.inventory.gui.GUIManager;
import com.craftwoods.woodspixelbazaar.listener.PlayerListener;
import com.craftwoods.woodspixelbazaar.manager.*;
import com.craftwoods.woodspixelbazaar.task.OrderProcessingTask;
import com.craftwoods.woodspixelbazaar.task.PriceUpdateTask;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
@Getter
public class WoodsPixelBazaar extends JavaPlugin {
private static WoodsPixelBazaar instance;
private ConfigManager configManager;
private DatabaseManager databaseManager;
private CacheManager cacheManager;
private BazaarManager bazaarManager;
private OrderManager orderManager;
private PriceManager priceManager;
private TransactionManager transactionManager;
private GUIManager guiManager;
private BazaarAPI api;
@Override
public void onEnable() {
instance = this;
long startTime = System.currentTimeMillis();
getLogger().info("===========================================");
getLogger().info(" WoodsPixelBazaar v" + getDescription().getVersion());
getLogger().info(" Author: Craftwoods8785");
getLogger().info("===========================================");
if (!initializeManagers()) {
getLogger().severe("Failed to initialize managers! Disabling plugin...");
Bukkit.getPluginManager().disablePlugin(this);
return;
}
registerCommands();
registerListeners();
startTasks();
long loadTime = System.currentTimeMillis() - startTime;
getLogger().info("Successfully enabled in " + loadTime + "ms!");
getLogger().info("===========================================");
}
@Override
public void onDisable() {
getLogger().info("Shutting down WoodsPixelBazaar...");
if (orderManager != null) {
orderManager.shutdown();
}
if (databaseManager != null) {
databaseManager.shutdown();
}
if (cacheManager != null) {
cacheManager.shutdown();
}
getLogger().info("WoodsPixelBazaar disabled successfully!");
}
private boolean initializeManagers() {
try {
configManager = new ConfigManager(this);
configManager.loadConfigs();
databaseManager = new DatabaseManager(this);
if (!databaseManager.initialize()) {
return false;
}
cacheManager = new CacheManager(this);
priceManager = new PriceManager(this);
transactionManager = new TransactionManager(this);
orderManager = new OrderManager(this);
bazaarManager = new BazaarManager(this);
guiManager = new GUIManager();
api = bazaarManager;
bazaarManager.loadItems();
orderManager.loadActiveOrders();
priceManager.loadPrices();
return true;
} catch (Exception e) {
getLogger().severe("Error initializing managers: " + e.getMessage());
e.printStackTrace();
return false;
}
}
private void registerCommands() {
getCommand("bazaar").setExecutor(new BazaarCommand(this));
getCommand("bzadmin").setExecutor(new AdminCommand(this));
}
private void registerListeners() {
Bukkit.getPluginManager().registerEvents(new GUIListener(guiManager), this);
Bukkit.getPluginManager().registerEvents(new PlayerListener(this), this);
}
private void startTasks() {
int orderProcessInterval = configManager.getConfig().getInt("order-processing-interval", 20);
new OrderProcessingTask(this).runTaskTimerAsynchronously(this, 20L, orderProcessInterval);
int priceUpdateInterval = configManager.getConfig().getInt("price-update-interval", 600);
new PriceUpdateTask(this).runTaskTimerAsynchronously(this, 100L, priceUpdateInterval);
}
public static WoodsPixelBazaar getInstance() {
return instance;
}
}