Files
src
build.gradle
manifest.kod
settings.gradle
Code
26 3,445
src/main/java/com/kodari/auction/AuctionHousePlugin.java
package com.kodari.auction;
import com.kodari.auction.command.AuctionCommand;
import com.kodari.auction.core.AuctionManager;
import com.kodari.auction.data.PlayerDataStore;
import com.kodari.auction.gui.AuctionMenus;
import com.kodari.auction.gui.DialogService;
import com.kodari.auction.integration.AuctionPlaceholders;
import com.kodari.auction.util.MessageService;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.command.PluginCommand;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
public final class AuctionHousePlugin extends JavaPlugin {
private Economy economy;
private AuctionManager auctionManager;
private AuctionMenus auctionMenus;
private DialogService dialogService;
private MessageService messages;
@Override
public void onEnable() {
saveDefaultConfig();
ensureResources();
if (!setupEconomy()) {
getLogger().severe("Vault economy provider is required; disabling plugin.");
getServer().getPluginManager().disablePlugin(this);
return;
}
messages = new MessageService(this);
PlayerDataStore store = new PlayerDataStore(this);
auctionManager = new AuctionManager(this, store, economy, messages);
auctionManager.load();
auctionMenus = new AuctionMenus(this, auctionManager, messages);
dialogService = new DialogService(this, auctionManager, auctionMenus, messages);
auctionMenus.setDialogService(dialogService);
getServer().getPluginManager().registerEvents(auctionMenus, this);
AuctionCommand command = new AuctionCommand(this, auctionManager, auctionMenus, dialogService, messages);
bindCommand("ah", command);
bindCommand("ahadmin", command);
bindCommand("dialogah", command);
bindCommand("dialogsell", command);
bindCommand("ahfastbuy", command);
bindCommand("ahfastsell", command);
bindCommand("ahalerts", command);
long saveInterval = Math.max(20L, getConfig().getLong("autosave-interval-ticks", 1200L));
Bukkit.getScheduler().runTaskTimer(this, auctionManager::saveDirty, saveInterval, saveInterval);
long expiryInterval = Math.max(20L, getConfig().getLong("expire-check-interval-ticks", 1200L));
Bukkit.getScheduler().runTaskTimer(this, auctionManager::checkExpirations, expiryInterval, expiryInterval);
Bukkit.getPluginManager().registerEvents(auctionManager, this);
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
new AuctionPlaceholders(this, auctionManager).registerAll();
}
}
@Override
public void onDisable() {
if (auctionManager != null) auctionManager.flushAll();
}
private void ensureResources() {
String[] resources = {"lang.yml", "gui/main_gui.yml", "gui/transactions_gui.yml", "gui/shulker_view_gui.yml",
"gui/confirm_listing_gui.yml", "gui/confirm_purchase_gui.yml", "gui/my_items_gui.yml",
"gui/insert_item_gui.yml", "gui/admin_view_gui.yml", "gui/dialogs.yml", "dialogs/dialogs.yml"};
for (String resource : resources) {
File target = new File(getDataFolder(), resource);
if (!target.exists()) {
File parent = target.getParentFile();
if (parent != null) parent.mkdirs();
saveResource(resource, false);
}
}
new File(getDataFolder(), "playerdata").mkdirs();
}
private boolean setupEconomy() {
if (getServer().getPluginManager().getPlugin("Vault") == null) return false;
RegisteredServiceProvider<Economy> registration = getServer().getServicesManager().getRegistration(Economy.class);
if (registration == null) return false;
economy = registration.getProvider();
return economy != null;
}
private void bindCommand(String name, AuctionCommand executor) {
PluginCommand command = getCommand(name);
if (command != null) {
command.setExecutor(executor);
command.setTabCompleter(executor);
} else {
getLogger().severe("Command " + name + " is missing from plugin.yml");
}
}
public AuctionManager auctionManager() { return auctionManager; }
public AuctionMenus auctionMenus() { return auctionMenus; }
public DialogService dialogService() { return dialogService; }
public MessageService messages() { return messages; }
}