Files
src
build.gradle
manifest.kod
settings.gradle
Code
23 1,185
src/main/java/com/kodari/marketpulse/MarketPulsePlugin.java
package com.kodari.marketpulse;
import com.kodari.marketpulse.command.MarketCommand;
import com.kodari.marketpulse.config.MarketConfig;
import com.kodari.marketpulse.data.Database;
import com.kodari.marketpulse.data.ListingRepository;
import com.kodari.marketpulse.economy.EconomyGateway;
import com.kodari.marketpulse.listener.MarketListener;
import com.kodari.marketpulse.service.DeliveryService;
import com.kodari.marketpulse.service.MarketService;
import com.kodari.marketpulse.ui.MarketMenu;
import lombok.Getter;
import org.bukkit.command.PluginCommand;
import org.bukkit.NamespacedKey;
import org.bukkit.plugin.java.JavaPlugin;
@Getter
public final class MarketPulsePlugin extends JavaPlugin {
private MarketConfig marketConfig;
private Database database;
private ListingRepository listingRepository;
private EconomyGateway economyGateway;
private DeliveryService deliveryService;
private MarketService marketService;
private MarketMenu marketMenu;
private NamespacedKey listingIdKey;
@Override
public void onEnable() {
saveDefaultConfig();
saveResource("lang.yml", false);
this.marketConfig = MarketConfig.load(this);
this.listingIdKey = new NamespacedKey(this, "listing-id");
this.database = new Database(this, marketConfig.database());
database.migrate();
this.listingRepository = new ListingRepository(database);
this.economyGateway = new EconomyGateway(this);
this.deliveryService = new DeliveryService(this, listingRepository, marketConfig.mailExpiryDays());
this.marketService = new MarketService(this, listingRepository, economyGateway, deliveryService, marketConfig);
this.marketMenu = new MarketMenu(this, marketService, listingRepository, marketConfig);
getServer().getPluginManager().registerEvents(new MarketListener(marketMenu), this);
PluginCommand command = getCommand("market");
if (command != null) {
MarketCommand marketCommand = new MarketCommand(this);
command.setExecutor(marketCommand);
command.setTabCompleter(marketCommand);
}
}
@Override
public void onDisable() {
if (database != null) {
database.close();
}
}
public void reloadMarketConfiguration() {
reloadConfig();
this.marketConfig = MarketConfig.load(this);
}
}