diff --git a/pom.xml b/pom.xml index 4e96ff6..465c73b 100644 --- a/pom.xml +++ b/pom.xml @@ -116,11 +116,6 @@ 1.7 provided - - ca.tweetzy - tweetycore - 3.7.0 - org.mineacademy.plugin CMI-API @@ -270,7 +265,6 @@ ${flight.path}:flight* - ca.tweetzy:tweetycore com.zaxxer:HikariCP org.slf4j:slf4j-api org.slf4j:slf4j-nop @@ -290,10 +284,6 @@ - - ca.tweetzy.core - ${project.groupId}.${project.artifactId}.core - ca.tweetzy.flight ${project.groupId}.${project.artifactId}.flight diff --git a/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java index 7f22b41..79ec575 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java +++ b/src/main/java/ca/tweetzy/auctionhouse/AuctionHouse.java @@ -18,47 +18,21 @@ package ca.tweetzy.auctionhouse; -import ca.tweetzy.auctionhouse.auction.AuctionedItem; -import ca.tweetzy.auctionhouse.commands.*; import ca.tweetzy.auctionhouse.database.DataManager; import ca.tweetzy.auctionhouse.database.migrations.*; import ca.tweetzy.auctionhouse.helpers.UpdateChecker; -import ca.tweetzy.auctionhouse.hooks.PlaceholderAPIHook; -import ca.tweetzy.auctionhouse.hooks.UltraEconomyHook; -import ca.tweetzy.auctionhouse.listeners.*; import ca.tweetzy.auctionhouse.managers.*; -import ca.tweetzy.auctionhouse.settings.LocaleSettings; -import ca.tweetzy.auctionhouse.settings.Settings; -import ca.tweetzy.auctionhouse.tasks.AutoSaveTask; -import ca.tweetzy.auctionhouse.tasks.TickAuctionsTask; -import ca.tweetzy.core.TweetyCore; -import ca.tweetzy.core.TweetyPlugin; -import ca.tweetzy.core.commands.CommandManager; -import ca.tweetzy.core.compatibility.ServerProject; -import ca.tweetzy.core.compatibility.ServerVersion; -import ca.tweetzy.core.configuration.Config; -import ca.tweetzy.core.database.DataMigrationManager; -import ca.tweetzy.core.database.DatabaseConnector; -import ca.tweetzy.core.database.MySQLConnector; -import ca.tweetzy.core.database.SQLiteConnector; -import ca.tweetzy.core.gui.GuiManager; -import ca.tweetzy.core.hooks.EconomyManager; -import ca.tweetzy.core.hooks.PluginHook; -import ca.tweetzy.core.hooks.economies.Economy; -import ca.tweetzy.core.utils.Metrics; -import ca.tweetzy.core.utils.TextUtils; -import co.aikar.taskchain.BukkitTaskChainFactory; +import ca.tweetzy.auctionhouse.settings.v3.Settings; +import ca.tweetzy.auctionhouse.settings.v3.Translations; +import ca.tweetzy.flight.FlightPlugin; +import ca.tweetzy.flight.database.DataMigrationManager; +import ca.tweetzy.flight.database.DatabaseConnector; +import ca.tweetzy.flight.database.SQLiteConnector; +import ca.tweetzy.flight.utils.Common; import co.aikar.taskchain.TaskChain; import co.aikar.taskchain.TaskChainFactory; import lombok.Getter; import lombok.Setter; -import org.bukkit.Bukkit; -import org.bukkit.configuration.file.YamlConfiguration; - -import java.io.File; -import java.io.IOException; -import java.util.List; -import java.util.stream.Collectors; /** @@ -68,26 +42,27 @@ import java.util.stream.Collectors; * Usage of any code found within this class is prohibited unless given explicit permission otherwise */ -public class AuctionHouse extends TweetyPlugin { +public class AuctionHouse extends FlightPlugin { //========================================================================== - + private DatabaseConnector databaseConnector; + private DataManager dataManager; private static TaskChainFactory taskChainFactory; private static AuctionHouse instance; - private PluginHook ultraEconomyHook; +// private PluginHook ultraEconomyHook; @Getter @Setter private boolean migrating = false; - @Getter - private final GuiManager guiManager = new GuiManager(this); - - protected Metrics metrics; - - @Getter - private CommandManager commandManager; +// @Getter +// private final GuiManager guiManager = new GuiManager(this); +// +// protected Metrics metrics; +// +// @Getter +// private CommandManager commandManager; @Getter @@ -114,101 +89,19 @@ public class AuctionHouse extends TweetyPlugin { @Getter private PaymentsManager paymentsManager; - @Getter - private DatabaseConnector databaseConnector; - - @Getter - private DataManager dataManager; - @Getter private UpdateChecker.UpdateStatus status; @Override - public void onPluginLoad() { - instance = this; - } + protected void onFlight() { + Settings.init(); + Translations.init(); - @Override - public void onPluginEnable() { - TweetyCore.registerPlugin(this, 1, "CHEST"); + Common.setPrefix(Settings.PREFIX.getStringOr("&8[&EAuctionHouse&8]")); - // Check server version - if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_7)) { - getServer().getPluginManager().disablePlugin(this); - return; - } - - taskChainFactory = BukkitTaskChainFactory.create(this); - - // Settings - Settings.setup(); - - if (Settings.AUTO_BSTATS.getBoolean()) { - final File file = new File("plugins" + File.separator + "bStats" + File.separator + "config.yml"); - if (file.exists()) { - final YamlConfiguration configuration = YamlConfiguration.loadConfiguration(file); - configuration.set("enabled", true); - try { - configuration.save(file); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - this.ultraEconomyHook = PluginHook.addHook(Economy.class, "UltraEconomy", UltraEconomyHook.class); - - // v3 translations & Settings -// Translations.init(); - - // Load Economy - EconomyManager.load(); - - // local - setLocale(Settings.LANG.getString()); - LocaleSettings.setup(); - - // Setup Economy - final String ECO_PLUGIN = Settings.ECONOMY_PLUGIN.getString(); - - - if (ECO_PLUGIN.startsWith("UltraEconomy")) { - EconomyManager.getManager().setPreferredHook(this.ultraEconomyHook); - } else { - EconomyManager.getManager().setPreferredHook(ECO_PLUGIN); - } - - if (!EconomyManager.getManager().isEnabled()) { - getLogger().severe("Could not find a valid economy provider for Auction House"); - getServer().getPluginManager().disablePlugin(this); - return; - } - - // listeners - Bukkit.getServer().getPluginManager().registerEvents(new PlayerListeners(), this); - Bukkit.getServer().getPluginManager().registerEvents(new MeteorClientListeners(), this); - Bukkit.getServer().getPluginManager().registerEvents(new AuctionListeners(), this); - - if (getServer().getPluginManager().isPluginEnabled("ChestShop")) - Bukkit.getServer().getPluginManager().registerEvents(new ChestShopListener(), this); - - if (getServer().getPluginManager().isPluginEnabled("CMI")) - Bukkit.getServer().getPluginManager().registerEvents(new CMIListener(), this); - - // Setup the database if enabled - this.databaseConnector = Settings.DATABASE_USE.getBoolean() ? new MySQLConnector( - this, - Settings.DATABASE_HOST.getString(), - Settings.DATABASE_PORT.getInt(), - Settings.DATABASE_NAME.getString(), - Settings.DATABASE_USERNAME.getString(), - Settings.DATABASE_PASSWORD.getString(), - Settings.DATABASE_CUSTOM_PARAMS.getString().equalsIgnoreCase("None") ? "" : Settings.DATABASE_CUSTOM_PARAMS.getString() - ) : new SQLiteConnector(this); - - // Use a custom table prefix if using a remote database. The default prefix setting acts exactly like if the prefix is null - final String tablePrefix = Settings.DATABASE_USE.getBoolean() ? Settings.DATABASE_TABLE_PREFIX.getString() : null; - this.dataManager = new DataManager(this.databaseConnector, this, tablePrefix); + // Set up the database if enabled + this.databaseConnector = new SQLiteConnector(this); + this.dataManager = new DataManager(this.databaseConnector, this, null); DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager, new _1_InitialMigration(), @@ -235,152 +128,269 @@ public class AuctionHouse extends TweetyPlugin { ); dataMigrationManager.runMigrations(); - - // load auction items - this.auctionItemManager = new AuctionItemManager(); - this.auctionItemManager.start(); - - // load transactions - this.transactionManager = new TransactionManager(); - this.transactionManager.loadTransactions(); - - // load the filter whitelist items - this.filterManager = new FilterManager(); - this.filterManager.loadItems(); - - // load the bans - this.auctionBanManager = new AuctionBanManager(); - this.auctionBanManager.loadBans(); - - this.minItemPriceManager = new MinItemPriceManager(); - this.minItemPriceManager.loadMinPrices(); - - this.auctionStatisticManager = new AuctionStatisticManager(); - this.auctionStatisticManager.loadStatistics(); - - // auction players - this.auctionPlayerManager = new AuctionPlayerManager(); - this.auctionPlayerManager.loadPlayers(); - - // payments - this.paymentsManager = new PaymentsManager(); - this.paymentsManager.loadPayments(); - - // gui manager - this.guiManager.init(); - - // commands - this.commandManager = new CommandManager(this); - this.commandManager.setSyntaxErrorMessage(TextUtils.formatText(getLocale().getMessage("commands.invalid_syntax").getMessage().split("\n"))); - this.commandManager.setNoPermsMessage(TextUtils.formatText(getLocale().getMessage("commands.no_permission").getMessage())); - this.commandManager.addCommand(new CommandAuctionHouse()).addSubCommands( - new CommandSell(), - new CommandActive(), - new CommandExpired(), - new CommandTransactions(), - new CommandSearch(), - new CommandSettings(), - new CommandToggleListInfo(), - new CommandMigrate(), - new CommandReload(), - new CommandFilter(), - new CommandAdmin(), - new CommandBan(), - new CommandUnban(), - new CommandMarkChest(), - new CommandUpload(), - new CommandMinPrice(), - new CommandStats(), - new CommandPayments(), - new CommandBids(), - new CommandConfirm(), - new CommandRequest() - ); - - // Placeholder API - if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { - new PlaceholderAPIHook(this).register(); - } - - // start the auction tick task - TickAuctionsTask.startTask(); - - // auto save task - if (Settings.AUTO_SAVE_ENABLED.getBoolean()) { - AutoSaveTask.startTask(); - } - - // update check - if (Settings.UPDATE_CHECKER.getBoolean() && ServerProject.getServerVersion() != ServerProject.UNKNOWN) - getServer().getScheduler().runTaskLaterAsynchronously(this, () -> this.status = new UpdateChecker(this, 60325, getConsole()).check().getStatus(), 1L); - - // metrics - this.metrics = new Metrics(this, 6806); - this.metrics.addCustomChart(new Metrics.SimplePie("using_mysql", () -> String.valueOf(Settings.DATABASE_USE.getBoolean()))); - - getServer().getScheduler().runTaskLater(this, () -> { - if (!ServerProject.isServer(ServerProject.SPIGOT, ServerProject.PAPER)) { - getLogger().severe("You're running Auction House on a non-supported Jar"); - getLogger().severe("You will not receive any support while using a non-supported jar, support jars: Spigot or Paper"); - } - - if (ServerVersion.isServerVersionBelow(ServerVersion.V1_16)) { - getLogger().severe("You are receiving this message because you're running Auction House on a Minecraft version older than 1.16. As a heads up, Auction House 3.0 is going to be for 1.16+ only"); - } - - if (!ServerProject.isServer(ServerProject.PAPER, ServerProject.SPIGOT)) { - getLogger().warning("You're running Auction House on a non supported server jar, although small, there's a chance somethings will not work or just entirely break."); - } - - final String uIDPartOne = "%%__US"; - final String uIDPartTwo = "ER__%%"; - - if (USER.contains(uIDPartOne) && USER.contains(uIDPartTwo)) { - getLogger().severe("Could not detect user ID, are you running a cracked / self-compiled copy of auction house?"); - } else { - getConsole().sendMessage(TextUtils.formatText("&e&m--------------------------------------------------------")); - getConsole().sendMessage(TextUtils.formatText("")); - getConsole().sendMessage(TextUtils.formatText("&aThank you for purchasing Auction House, it means a lot")); - getConsole().sendMessage(TextUtils.formatText("&7 - Kiran Hart")); - getConsole().sendMessage(TextUtils.formatText("")); - getConsole().sendMessage(TextUtils.formatText("&e&m--------------------------------------------------------")); - } - }, 1L); } - @Override - public void onPluginDisable() { - if (this.dataManager != null) { - // clean up the garbage items - AuctionHouse.getInstance().getDataManager().deleteItems(AuctionHouse.getInstance().getAuctionItemManager().getDeletedItems().values().stream().map(AuctionedItem::getId).collect(Collectors.toList())); +// @Override +// public void onPluginEnable() { +// TweetyCore.registerPlugin(this, 1, "CHEST"); +// +// // Check server version +// if (ServerVersion.isServerVersionAtOrBelow(ServerVersion.V1_7)) { +// getServer().getPluginManager().disablePlugin(this); +// return; +// } +// +// taskChainFactory = BukkitTaskChainFactory.create(this); +// +// // Settings +// Settings.setup(); +// +// if (Settings.AUTO_BSTATS.getBoolean()) { +// final File file = new File("plugins" + File.separator + "bStats" + File.separator + "config.yml"); +// if (file.exists()) { +// final YamlConfiguration configuration = YamlConfiguration.loadConfiguration(file); +// configuration.set("enabled", true); +// try { +// configuration.save(file); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// } +// +// this.ultraEconomyHook = PluginHook.addHook(Economy.class, "UltraEconomy", UltraEconomyHook.class); +// +// // v3 translations & Settings +//// Translations.init(); +// +// // Load Economy +// EconomyManager.load(); +// +// // local +//// setLocale(Settings.LANG.getString()); +//// LocaleSettings.setup(); +// +// // Setup Economy +// final String ECO_PLUGIN = Settings.ECONOMY_PLUGIN.getString(); +// +// +// if (ECO_PLUGIN.startsWith("UltraEconomy")) { +// EconomyManager.getManager().setPreferredHook(this.ultraEconomyHook); +// } else { +// EconomyManager.getManager().setPreferredHook(ECO_PLUGIN); +// } +// +// if (!EconomyManager.getManager().isEnabled()) { +// getLogger().severe("Could not find a valid economy provider for Auction House"); +// getServer().getPluginManager().disablePlugin(this); +// return; +// } +// +// // listeners +// Bukkit.getServer().getPluginManager().registerEvents(new PlayerListeners(), this); +// Bukkit.getServer().getPluginManager().registerEvents(new MeteorClientListeners(), this); +// Bukkit.getServer().getPluginManager().registerEvents(new AuctionListeners(), this); +// +// if (getServer().getPluginManager().isPluginEnabled("ChestShop")) +// Bukkit.getServer().getPluginManager().registerEvents(new ChestShopListener(), this); +// +// if (getServer().getPluginManager().isPluginEnabled("CMI")) +// Bukkit.getServer().getPluginManager().registerEvents(new CMIListener(), this); +// +// // Setup the database if enabled +// this.databaseConnector = Settings.DATABASE_USE.getBoolean() ? new MySQLConnector( +// this, +// Settings.DATABASE_HOST.getString(), +// Settings.DATABASE_PORT.getInt(), +// Settings.DATABASE_NAME.getString(), +// Settings.DATABASE_USERNAME.getString(), +// Settings.DATABASE_PASSWORD.getString(), +// Settings.DATABASE_CUSTOM_PARAMS.getString().equalsIgnoreCase("None") ? "" : Settings.DATABASE_CUSTOM_PARAMS.getString() +// ) : new SQLiteConnector(this); +// +// // Use a custom table prefix if using a remote database. The default prefix setting acts exactly like if the prefix is null +// final String tablePrefix = Settings.DATABASE_USE.getBoolean() ? Settings.DATABASE_TABLE_PREFIX.getString() : null; +// this.dataManager = new DataManager(this.databaseConnector, this, tablePrefix); +// +// DataMigrationManager dataMigrationManager = new DataMigrationManager(this.databaseConnector, this.dataManager, +// new _1_InitialMigration(), +// new _2_FilterWhitelistMigration(), +// new _3_BansMigration(), +// new _4_ItemsChangeMigration(), +// new _5_TransactionChangeMigration(), +// new _6_BigIntMigration(), +// new _7_TransactionBigIntMigration(), +// new _8_ItemPerWorldMigration(), +// new _9_StatsMigration(), +// new _10_InfiniteItemsMigration(), +// new _11_AdminLogMigration(), +// new _12_SerializeFormatDropMigration(), +// new _13_MinItemPriceMigration(), +// new _14_PartialQtyBuyMigration(), +// new _15_AuctionPlayerMigration(), +// new _16_StatisticVersionTwoMigration(), +// new _17_PaymentsMigration(), +// new _18_PaymentsItemMigration(), +// new _19_ServerAuctionMigration(), +// new _20_AuctionRequestsMigration(), +// new _21_RequestsDynAmtMigration() +// ); +// +// dataMigrationManager.runMigrations(); +// +// // load auction items +// this.auctionItemManager = new AuctionItemManager(); +// this.auctionItemManager.start(); +// +// // load transactions +// this.transactionManager = new TransactionManager(); +// this.transactionManager.loadTransactions(); +// +// // load the filter whitelist items +// this.filterManager = new FilterManager(); +// this.filterManager.loadItems(); +// +// // load the bans +// this.auctionBanManager = new AuctionBanManager(); +// this.auctionBanManager.loadBans(); +// +// this.minItemPriceManager = new MinItemPriceManager(); +// this.minItemPriceManager.loadMinPrices(); +// +// this.auctionStatisticManager = new AuctionStatisticManager(); +// this.auctionStatisticManager.loadStatistics(); +// +// // auction players +// this.auctionPlayerManager = new AuctionPlayerManager(); +// this.auctionPlayerManager.loadPlayers(); +// +// // payments +// this.paymentsManager = new PaymentsManager(); +// this.paymentsManager.loadPayments(); +// +// // gui manager +// this.guiManager.init(); +// +// // commands +// this.commandManager = new CommandManager(this); +//// this.commandManager.setSyntaxErrorMessage(TextUtils.formatText(getLocale().getMessage("commands.invalid_syntax").getMessage().split("\n"))); +//// this.commandManager.setNoPermsMessage(TextUtils.formatText(getLocale().getMessage("commands.no_permission").getMessage())); +// this.commandManager.addCommand(new CommandAuctionHouse()).addSubCommands( +// new CommandSell(), +// new CommandActive(), +// new CommandExpired(), +// new CommandTransactions(), +// new CommandSearch(), +// new CommandSettings(), +// new CommandToggleListInfo(), +// new CommandMigrate(), +// new CommandReload(), +// new CommandFilter(), +// new CommandAdmin(), +// new CommandBan(), +// new CommandUnban(), +// new CommandMarkChest(), +// new CommandUpload(), +// new CommandMinPrice(), +// new CommandStats(), +// new CommandPayments(), +// new CommandBids(), +// new CommandConfirm(), +// new CommandRequest() +// ); +// +// // Placeholder API +// if (Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null) { +// new PlaceholderAPIHook(this).register(); +// } +// +// // start the auction tick task +// TickAuctionsTask.startTask(); +// +// // auto save task +// if (Settings.AUTO_SAVE_ENABLED.getBoolean()) { +// AutoSaveTask.startTask(); +// } +// +// // update check +//// if (Settings.UPDATE_CHECKER.getBoolean() && ServerProject.getServerVersion() != ServerProject.UNKNOWN) +//// getServer().getScheduler().runTaskLaterAsynchronously(this, () -> this.status = new UpdateChecker(this, 60325, getConsole()).check().getStatus(), 1L); +// +// // metrics +// this.metrics = new Metrics(this, 6806); +// this.metrics.addCustomChart(new Metrics.SimplePie("using_mysql", () -> String.valueOf(Settings.DATABASE_USE.getBoolean()))); +// +// getServer().getScheduler().runTaskLater(this, () -> { +// if (!ServerProject.isServer(ServerProject.SPIGOT, ServerProject.PAPER)) { +// getLogger().severe("You're running Auction House on a non-supported Jar"); +// getLogger().severe("You will not receive any support while using a non-supported jar, support jars: Spigot or Paper"); +// } +// +// if (ServerVersion.isServerVersionBelow(ServerVersion.V1_16)) { +// getLogger().severe("You are receiving this message because you're running Auction House on a Minecraft version older than 1.16. As a heads up, Auction House 3.0 is going to be for 1.16+ only"); +// } +// +// if (!ServerProject.isServer(ServerProject.PAPER, ServerProject.SPIGOT)) { +// getLogger().warning("You're running Auction House on a non supported server jar, although small, there's a chance somethings will not work or just entirely break."); +// } +// +// final String uIDPartOne = "%%__US"; +// final String uIDPartTwo = "ER__%%"; +// +// if (USER.contains(uIDPartOne) && USER.contains(uIDPartTwo)) { +// getLogger().severe("Could not detect user ID, are you running a cracked / self-compiled copy of auction house?"); +// } else { +//// getConsole().sendMessage(TextUtils.formatText("&e&m--------------------------------------------------------")); +//// getConsole().sendMessage(TextUtils.formatText("")); +//// getConsole().sendMessage(TextUtils.formatText("&aThank you for purchasing Auction House, it means a lot")); +//// getConsole().sendMessage(TextUtils.formatText("&7 - Kiran Hart")); +//// getConsole().sendMessage(TextUtils.formatText("")); +//// getConsole().sendMessage(TextUtils.formatText("&e&m--------------------------------------------------------")); +// } +// }, 1L); +// } - this.auctionItemManager.end(); - this.filterManager.saveFilterWhitelist(false); - this.auctionBanManager.saveBans(false); - this.dataManager.close(); - } +// @Override +// public void onPluginDisable() { +// if (this.dataManager != null) { +// // clean up the garbage items +// AuctionHouse.getInstance().getDataManager().deleteItems(AuctionHouse.getInstance().getAuctionItemManager().getDeletedItems().values().stream().map(AuctionedItem::getId).collect(Collectors.toList())); +// +// this.auctionItemManager.end(); +// this.filterManager.saveFilterWhitelist(false); +// this.auctionBanManager.saveBans(false); +// this.dataManager.close(); +// } +// +// getServer().getScheduler().cancelTasks(this); +// } - getServer().getScheduler().cancelTasks(this); - } +// @Override +// public void onConfigReload() { +// EconomyManager.load(); +// Settings.setup(); +// EconomyManager.getManager().setPreferredHook(Settings.ECONOMY_PLUGIN.getString()); +// setLocale(Settings.LANG.getString()); +// LocaleSettings.setup(); +// this.commandManager.setSyntaxErrorMessage(TextUtils.formatText(getLocale().getMessage("commands.invalid_syntax").getMessage().split("\n"))); +// this.commandManager.setNoPermsMessage(TextUtils.formatText(getLocale().getMessage("commands.no_permission").getMessage())); +// } - @Override - public void onConfigReload() { - EconomyManager.load(); - Settings.setup(); - EconomyManager.getManager().setPreferredHook(Settings.ECONOMY_PLUGIN.getString()); - setLocale(Settings.LANG.getString()); - LocaleSettings.setup(); - this.commandManager.setSyntaxErrorMessage(TextUtils.formatText(getLocale().getMessage("commands.invalid_syntax").getMessage().split("\n"))); - this.commandManager.setNoPermsMessage(TextUtils.formatText(getLocale().getMessage("commands.no_permission").getMessage())); - } - - @Override - public List getExtraConfig() { - return null; - } +// @Override +// public List getExtraConfig() { +// return null; +// } public static AuctionHouse getInstance() { - return instance; + return (AuctionHouse) FlightPlugin.getInstance(); + } + + public static DatabaseConnector getDatabaseConnector() { + return getInstance().databaseConnector; + } + + public static DataManager getDataManager() { + return getInstance().dataManager; } public static TaskChain newChain() { diff --git a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java index 9103417..bed5f3c 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java +++ b/src/main/java/ca/tweetzy/auctionhouse/commands/CommandUpload.java @@ -21,9 +21,9 @@ package ca.tweetzy.auctionhouse.commands; import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.database.DataManager; import ca.tweetzy.core.commands.AbstractCommand; -import ca.tweetzy.core.database.DatabaseConnector; -import ca.tweetzy.core.database.SQLiteConnector; import ca.tweetzy.core.utils.TextUtils; +import ca.tweetzy.flight.database.DatabaseConnector; +import ca.tweetzy.flight.database.SQLiteConnector; import org.bukkit.command.CommandSender; import java.util.Arrays; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java index 220e686..39874c1 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/DataManager.java @@ -25,9 +25,9 @@ import ca.tweetzy.auctionhouse.auction.enums.*; import ca.tweetzy.auctionhouse.settings.Settings; import ca.tweetzy.auctionhouse.transaction.Transaction; import ca.tweetzy.auctionhouse.transaction.TransactionViewFilter; -import ca.tweetzy.core.database.DataManagerAbstract; -import ca.tweetzy.core.database.DatabaseConnector; -import ca.tweetzy.core.database.MySQLConnector; +import ca.tweetzy.flight.database.DataManagerAbstract; +import ca.tweetzy.flight.database.DatabaseConnector; +import ca.tweetzy.flight.database.MySQLConnector; import lombok.NonNull; import org.bukkit.Bukkit; import org.bukkit.inventory.ItemStack; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_10_InfiniteItemsMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_10_InfiniteItemsMigration.java index ad716f2..7a7ac2b 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_10_InfiniteItemsMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_10_InfiniteItemsMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_11_AdminLogMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_11_AdminLogMigration.java index f00d209..e07879b 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_11_AdminLogMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_11_AdminLogMigration.java @@ -19,8 +19,8 @@ package ca.tweetzy.auctionhouse.database.migrations; import ca.tweetzy.auctionhouse.AuctionHouse; -import ca.tweetzy.core.database.DataMigration; -import ca.tweetzy.core.database.MySQLConnector; +import ca.tweetzy.flight.database.DataMigration; +import ca.tweetzy.flight.database.MySQLConnector; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_12_SerializeFormatDropMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_12_SerializeFormatDropMigration.java index 0dfdca0..7881726 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_12_SerializeFormatDropMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_12_SerializeFormatDropMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_13_MinItemPriceMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_13_MinItemPriceMigration.java index bb2a95d..d9fcf30 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_13_MinItemPriceMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_13_MinItemPriceMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_14_PartialQtyBuyMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_14_PartialQtyBuyMigration.java index ab03703..0941b7e 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_14_PartialQtyBuyMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_14_PartialQtyBuyMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_15_AuctionPlayerMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_15_AuctionPlayerMigration.java index 5ae7294..e297ef5 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_15_AuctionPlayerMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_15_AuctionPlayerMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_16_StatisticVersionTwoMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_16_StatisticVersionTwoMigration.java index cc814bf..efce940 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_16_StatisticVersionTwoMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_16_StatisticVersionTwoMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_17_PaymentsMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_17_PaymentsMigration.java index a80cfa0..73d28e2 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_17_PaymentsMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_17_PaymentsMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_18_PaymentsItemMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_18_PaymentsItemMigration.java index fadb8cd..5e04cf0 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_18_PaymentsItemMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_18_PaymentsItemMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_19_ServerAuctionMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_19_ServerAuctionMigration.java index d8d3bf1..e18c812 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_19_ServerAuctionMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_19_ServerAuctionMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_1_InitialMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_1_InitialMigration.java index 8483012..da8f7a8 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_1_InitialMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_1_InitialMigration.java @@ -19,8 +19,8 @@ package ca.tweetzy.auctionhouse.database.migrations; import ca.tweetzy.auctionhouse.AuctionHouse; -import ca.tweetzy.core.database.DataMigration; -import ca.tweetzy.core.database.MySQLConnector; +import ca.tweetzy.flight.database.DataMigration; +import ca.tweetzy.flight.database.MySQLConnector; import java.sql.Connection; import java.sql.SQLException; @@ -40,7 +40,7 @@ public class _1_InitialMigration extends DataMigration { @Override public void migrate(Connection connection, String tablePrefix) throws SQLException { - String autoIncrement = AuctionHouse.getInstance().getDatabaseConnector() instanceof MySQLConnector ? " AUTO_INCREMENT" : ""; + String autoIncrement = AuctionHouse.getDatabaseConnector() instanceof MySQLConnector ? " AUTO_INCREMENT" : ""; try (Statement statement = connection.createStatement()) { statement.execute("CREATE TABLE " + tablePrefix + "items (" + diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_20_AuctionRequestsMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_20_AuctionRequestsMigration.java index 07d19c1..d054134 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_20_AuctionRequestsMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_20_AuctionRequestsMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_21_RequestsDynAmtMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_21_RequestsDynAmtMigration.java index e38ee74..90cb05f 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_21_RequestsDynAmtMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_21_RequestsDynAmtMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_2_FilterWhitelistMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_2_FilterWhitelistMigration.java index e9a5670..b1a6ddc 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_2_FilterWhitelistMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_2_FilterWhitelistMigration.java @@ -19,8 +19,8 @@ package ca.tweetzy.auctionhouse.database.migrations; import ca.tweetzy.auctionhouse.AuctionHouse; -import ca.tweetzy.core.database.DataMigration; -import ca.tweetzy.core.database.MySQLConnector; +import ca.tweetzy.flight.database.DataMigration; +import ca.tweetzy.flight.database.MySQLConnector; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_3_BansMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_3_BansMigration.java index f51b3c0..32f93c4 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_3_BansMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_3_BansMigration.java @@ -19,8 +19,8 @@ package ca.tweetzy.auctionhouse.database.migrations; import ca.tweetzy.auctionhouse.AuctionHouse; -import ca.tweetzy.core.database.DataMigration; -import ca.tweetzy.core.database.MySQLConnector; +import ca.tweetzy.flight.database.DataMigration; +import ca.tweetzy.flight.database.MySQLConnector; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_4_ItemsChangeMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_4_ItemsChangeMigration.java index cd1d343..822f0e3 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_4_ItemsChangeMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_4_ItemsChangeMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_5_TransactionChangeMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_5_TransactionChangeMigration.java index ff43a33..e1c3a72 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_5_TransactionChangeMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_5_TransactionChangeMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_6_BigIntMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_6_BigIntMigration.java index f482520..cb03875 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_6_BigIntMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_6_BigIntMigration.java @@ -19,8 +19,8 @@ package ca.tweetzy.auctionhouse.database.migrations; import ca.tweetzy.auctionhouse.AuctionHouse; -import ca.tweetzy.core.database.DataMigration; -import ca.tweetzy.core.database.MySQLConnector; +import ca.tweetzy.flight.database.DataMigration; +import ca.tweetzy.flight.database.MySQLConnector; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_7_TransactionBigIntMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_7_TransactionBigIntMigration.java index 8500226..4d61f67 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_7_TransactionBigIntMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_7_TransactionBigIntMigration.java @@ -19,8 +19,8 @@ package ca.tweetzy.auctionhouse.database.migrations; import ca.tweetzy.auctionhouse.AuctionHouse; -import ca.tweetzy.core.database.DataMigration; -import ca.tweetzy.core.database.MySQLConnector; +import ca.tweetzy.flight.database.DataMigration; +import ca.tweetzy.flight.database.MySQLConnector; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_8_ItemPerWorldMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_8_ItemPerWorldMigration.java index b8b3019..3206679 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_8_ItemPerWorldMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_8_ItemPerWorldMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_9_StatsMigration.java b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_9_StatsMigration.java index 0c4166c..62abdc2 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_9_StatsMigration.java +++ b/src/main/java/ca/tweetzy/auctionhouse/database/migrations/_9_StatsMigration.java @@ -18,7 +18,7 @@ package ca.tweetzy.auctionhouse.database.migrations; -import ca.tweetzy.core.database.DataMigration; +import ca.tweetzy.flight.database.DataMigration; import java.sql.Connection; import java.sql.SQLException; diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/abstraction/AuctionBaseGUI.java b/src/main/java/ca/tweetzy/auctionhouse/guis/abstraction/AuctionBaseGUI.java deleted file mode 100644 index ed88cc8..0000000 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/abstraction/AuctionBaseGUI.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Auction House - * Copyright 2023 Kiran Hart - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package ca.tweetzy.auctionhouse.guis.abstraction; - -import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper; -import ca.tweetzy.auctionhouse.settings.Settings; -import ca.tweetzy.flight.comp.enums.CompSound; -import ca.tweetzy.flight.gui.Gui; -import ca.tweetzy.flight.gui.template.BaseGUI; -import lombok.Getter; -import lombok.NonNull; -import org.bukkit.entity.Player; - -public abstract class AuctionBaseGUI extends BaseGUI { - - @Getter - protected final Player player; - - public AuctionBaseGUI(Gui parent, @NonNull final Player player, @NonNull String title, int rows) { - super(parent, title, rows); - this.player = player; - setTitle(title); - applyDefaults(); - } - - public AuctionBaseGUI(Gui parent, @NonNull final Player player, @NonNull String title) { - super(parent, title); - this.player = player; - setTitle(title); - applyDefaults(); - } - - public AuctionBaseGUI(@NonNull final Player player, @NonNull String title) { - super(title); - this.player = player; - setTitle(title); - applyDefaults(); - } - - private void applyDefaults() { - setDefaultItem(ConfigurationItemHelper.createConfigurationItem(this.player, Settings.GUI_FILLER.getString())); - setNavigateSound(CompSound.matchCompSound(Settings.SOUNDS_NAVIGATE_GUI_PAGES.getString()).orElse(CompSound.ENTITY_BAT_TAKEOFF)); - } - -// @Override -// protected ItemStack getBackButton() { -// return QuickItem -// .of(Settings.GUI_SHARED_ITEMS_BACK_BUTTON.getItemStack()) -// .name(TranslationManager.string(this.player, Translations.GUI_SHARED_ITEMS_BACK_BUTTON_NAME)) -// .lore(TranslationManager.list(this.player, Translations.GUI_SHARED_ITEMS_BACK_BUTTON_LORE, "left_click", TranslationManager.string(this.player, Translations.MOUSE_LEFT_CLICK))) -// .make(); -// } -// -// @Override -// protected ItemStack getExitButton() { -// return QuickItem -// .of(Settings.GUI_SHARED_ITEMS_EXIT_BUTTON.getItemStack()) -// .name(TranslationManager.string(this.player, Translations.GUI_SHARED_ITEMS_EXIT_BUTTON_NAME)) -// .lore(TranslationManager.list(this.player, Translations.GUI_SHARED_ITEMS_EXIT_BUTTON_LORE, "left_click", TranslationManager.string(this.player, Translations.MOUSE_LEFT_CLICK))) -// .make(); -// } -// -// @Override -// protected ItemStack getPreviousButton() { -// return QuickItem -// .of(Settings.GUI_BACK_BTN_ITEM.getString()) -// .name(TranslationManager.string(this.player, Translations.GUI_SHARED_ITEMS_PREVIOUS_BUTTON_NAME)) -// .lore(TranslationManager.list(this.player, Translations.GUI_SHARED_ITEMS_PREVIOUS_BUTTON_LORE, "left_click", TranslationManager.string(this.player, Translations.MOUSE_LEFT_CLICK))) -// .make(); -// } -// -// @Override -// protected ItemStack getNextButton() { -// return QuickItem -// .of(Settings.GUI_SHARED_ITEMS_NEXT_BUTTON.getItemStack()) -// .name(TranslationManager.string(this.player, Translations.GUI_SHARED_ITEMS_NEXT_BUTTON_NAME)) -// .lore(TranslationManager.list(this.player, Translations.GUI_SHARED_ITEMS_NEXT_BUTTON_LORE, "left_click", TranslationManager.string(this.player, Translations.MOUSE_LEFT_CLICK))) -// .make(); -// } - - @Override - protected int getPreviousButtonSlot() { - return 48; - } - - @Override - protected int getNextButtonSlot() { - return 50; - } -} \ No newline at end of file diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/abstraction/AuctionPagedGUI.java b/src/main/java/ca/tweetzy/auctionhouse/guis/abstraction/AuctionPagedGUI.java index f6d74bd..61efde7 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/abstraction/AuctionPagedGUI.java +++ b/src/main/java/ca/tweetzy/auctionhouse/guis/abstraction/AuctionPagedGUI.java @@ -18,5 +18,160 @@ package ca.tweetzy.auctionhouse.guis.abstraction; -public final class AuctionPagedGUI { -} +import ca.tweetzy.auctionhouse.AuctionHouse; +import ca.tweetzy.auctionhouse.settings.v3.Settings; +import ca.tweetzy.flight.comp.enums.CompMaterial; +import ca.tweetzy.flight.gui.Gui; +import ca.tweetzy.flight.gui.events.GuiClickEvent; +import ca.tweetzy.flight.gui.template.BaseGUI; +import ca.tweetzy.flight.utils.Common; +import ca.tweetzy.flight.utils.QuickItem; +import lombok.Getter; +import lombok.NonNull; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; +import org.bukkit.scheduler.BukkitTask; + +import java.util.List; +import java.util.stream.Collectors; + +public abstract class AuctionPagedGUI extends BaseGUI { + + @Getter + protected final Player player; + protected final Gui parent; + protected List items; + protected final int updateDelay; + protected BukkitTask task; + + public AuctionPagedGUI(final Gui parent, @NonNull final Player player, @NonNull final String title, final int rows, int updateDelay, @NonNull final List items) { + super(parent, title, rows); + this.parent = parent; + this.player = player; + this.items = items; + this.updateDelay = updateDelay; + applyDefaults(); + } + + public AuctionPagedGUI(@NonNull final Player player, @NonNull final String title, final int rows, int updateDelay, @NonNull final List items) { + this(null, player, title, rows, updateDelay, items); + } + + private void applyDefaults() { + setDefaultItem(QuickItem.bg(Settings.GUI_SHARED_FILLER.getItemStack())); +// setNavigateSound(CompSound.matchCompSound(Settings.SOUNDS_NAVIGATE_GUI_PAGES.getString()).orElse(CompSound.ENTITY_BAT_TAKEOFF)); + } + + @Override + protected void draw() { + reset(); + populateItems(); + drawFixed(); + } + + protected void startTask() { + this.task = Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(AuctionHouse.getInstance(), () -> { +// this.fillSlots().forEach(slot -> setItem(slot, getDefaultItem())); + populateItems(); + }, 0L, updateDelay); + } + + protected void applyClose() { + setOnClose(close -> cancelTask()); + } + + protected void prePopulate() { + } + + protected void drawFixed() { + } + + protected void cancelTask() { + if (this.task != null) { + this.task.cancel(); + Common.log("Cancelled updating task in menu"); + } + } + + private void populateItems() { + if (this.items != null) { + AuctionHouse.newChain().asyncFirst(() -> { + this.fillSlots().forEach(slot -> setItem(slot, getDefaultItem())); + prePopulate(); + + final List itemsToFill = this.items.stream().skip((page - 1) * (long) this.fillSlots().size()).limit(this.fillSlots().size()).collect(Collectors.toList()); + return itemsToFill; + }).asyncLast((data) -> { + pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) this.fillSlots().size())); + + setPrevPage(getPreviousButtonSlot(), getPreviousButton()); + setNextPage(getNextButtonSlot(), getNextButton()); + setOnPage(e -> draw()); + + for (int i = 0; i < this.rows * 9; i++) { + if (this.fillSlots().contains(i) && this.fillSlots().indexOf(i) < data.size()) { + final T object = data.get(this.fillSlots().indexOf(i)); + setButton(i, this.makeDisplayItem(object), click -> this.onClick(object, click)); + } + } + }).execute(); + } + } + + protected abstract ItemStack makeDisplayItem(final T object); + + protected abstract void onClick(final T object, final GuiClickEvent clickEvent); + + protected ItemStack getPreviousButton() { + return QuickItem.of(CompMaterial.ARROW, "&ePrevious").make(); + } + + protected ItemStack getNextButton() { + return QuickItem.of(CompMaterial.ARROW, "&eNext").make(); + } + + protected int getPreviousButtonSlot() { + return 48; + } + + protected int getNextButtonSlot() { + return 50; + } + + // @Override +// protected ItemStack getBackButton() { +// return QuickItem +// .of(Settings.GUI_SHARED_ITEMS_BACK_BUTTON.getItemStack()) +// .name(TranslationManager.string(this.player, Translations.GUI_SHARED_ITEMS_BACK_BUTTON_NAME)) +// .lore(TranslationManager.list(this.player, Translations.GUI_SHARED_ITEMS_BACK_BUTTON_LORE, "left_click", TranslationManager.string(this.player, Translations.MOUSE_LEFT_CLICK))) +// .make(); +// } +// +// @Override +// protected ItemStack getExitButton() { +// return QuickItem +// .of(Settings.GUI_SHARED_ITEMS_EXIT_BUTTON.getItemStack()) +// .name(TranslationManager.string(this.player, Translations.GUI_SHARED_ITEMS_EXIT_BUTTON_NAME)) +// .lore(TranslationManager.list(this.player, Translations.GUI_SHARED_ITEMS_EXIT_BUTTON_LORE, "left_click", TranslationManager.string(this.player, Translations.MOUSE_LEFT_CLICK))) +// .make(); +// } +// +// @Override +// protected ItemStack getPreviousPageButton() { +// return QuickItem +// .of(Settings.GUI_SHARED_ITEMS_PREVIOUS_BUTTON.getItemStack()) +// .name(TranslationManager.string(this.player, Translations.GUI_SHARED_ITEMS_PREVIOUS_BUTTON_NAME)) +// .lore(TranslationManager.list(this.player, Translations.GUI_SHARED_ITEMS_PREVIOUS_BUTTON_LORE, "left_click", TranslationManager.string(this.player, Translations.MOUSE_LEFT_CLICK))) +// .make(); +// } +// +// @Override +// protected ItemStack getNextPageButton() { +// return QuickItem +// .of(Settings.GUI_SHARED_ITEMS_NEXT_BUTTON.getItemStack()) +// .name(TranslationManager.string(this.player, Translations.GUI_SHARED_ITEMS_NEXT_BUTTON_NAME)) +// .lore(TranslationManager.list(this.player, Translations.GUI_SHARED_ITEMS_NEXT_BUTTON_LORE, "left_click", TranslationManager.string(this.player, Translations.MOUSE_LEFT_CLICK))) +// .make(); +// } +} \ No newline at end of file diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/abstraction/AuctionUpdatingPagedGUI.java b/src/main/java/ca/tweetzy/auctionhouse/guis/abstraction/AuctionUpdatingPagedGUI.java deleted file mode 100644 index b491dd0..0000000 --- a/src/main/java/ca/tweetzy/auctionhouse/guis/abstraction/AuctionUpdatingPagedGUI.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Auction House - * Copyright 2023 Kiran Hart - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package ca.tweetzy.auctionhouse.guis.abstraction; - -import ca.tweetzy.auctionhouse.AuctionHouse; -import ca.tweetzy.flight.comp.enums.CompMaterial; -import ca.tweetzy.core.gui.Gui; -import ca.tweetzy.core.gui.events.GuiClickEvent; -import ca.tweetzy.core.gui.BaseGUI; -import ca.tweetzy.flight.utils.Common; -import ca.tweetzy.flight.utils.QuickItem; -import lombok.Getter; -import lombok.NonNull; -import org.bukkit.Bukkit; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.scheduler.BukkitTask; - -import java.util.List; -import java.util.stream.Collectors; - -public abstract class AuctionUpdatingPagedGUI extends BaseGUI { - - @Getter - protected final Player player; - protected final Gui parent; - protected List items; - protected final int updateDelay; - protected BukkitTask task; - - public AuctionUpdatingPagedGUI(final Gui parent, @NonNull final Player player, @NonNull final String title, final int rows, int updateDelay, @NonNull final List items) { - super(parent, title, rows); - this.parent = parent; - this.player = player; - this.items = items; - this.updateDelay = updateDelay; - } - - public AuctionUpdatingPagedGUI(@NonNull final Player player, @NonNull final String title, final int rows, int updateDelay, @NonNull final List items) { - this(null, player, title, rows, updateDelay, items); - } - - @Override - protected void draw() { - reset(); - drawFixed(); - populateItems(); - } - - protected void startTask() { - this.task = Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(AuctionHouse.getInstance(), () -> { -// this.fillSlots().forEach(slot -> setItem(slot, getDefaultItem())); - populateItems(); - }, 0L, updateDelay); - } - - protected void applyClose() { - setOnClose(close -> cancelTask()); - } - - protected void prePopulate() { - } - - protected void drawFixed() { - } - - protected void cancelTask() { - if (this.task != null) { - this.task.cancel(); - Common.log("Cancelled updating task in menu"); - } - } - - private void populateItems() { - if (this.items != null) { - AuctionHouse.newChain().asyncFirst(() -> { - this.fillSlots().forEach(slot -> setItem(slot, getDefaultItem())); - prePopulate(); - - final List itemsToFill = this.items.stream().skip((page - 1) * (long) this.fillSlots().size()).limit(this.fillSlots().size()).collect(Collectors.toList()); - return itemsToFill; - }).asyncLast((data) -> { - pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) this.fillSlots().size())); - - setPrevPage(getPreviousButtonSlot(), getPreviousButton()); - setNextPage(getNextButtonSlot(), getNextButton()); - setOnPage(e -> draw()); - - for (int i = 0; i < this.rows * 9; i++) { - if (this.fillSlots().contains(i) && this.fillSlots().indexOf(i) < data.size()) { - final T object = data.get(this.fillSlots().indexOf(i)); - setButton(i, this.makeDisplayItem(object), click -> this.onClick(object, click)); - } - } - }).execute(); - } - } - - protected abstract ItemStack makeDisplayItem(final T object); - - protected abstract void onClick(final T object, final GuiClickEvent clickEvent); - - protected ItemStack getPreviousButton() { - return QuickItem.of(CompMaterial.ARROW, "&ePrevious").make(); - } - - protected ItemStack getNextButton() { - return QuickItem.of(CompMaterial.ARROW, "&eNext").make(); - } - - protected int getPreviousButtonSlot() { - return 48; - } - - protected int getNextButtonSlot() { - return 50; - } - - // @Override -// protected ItemStack getBackButton() { -// return QuickItem -// .of(Settings.GUI_SHARED_ITEMS_BACK_BUTTON.getItemStack()) -// .name(TranslationManager.string(this.player, Translations.GUI_SHARED_ITEMS_BACK_BUTTON_NAME)) -// .lore(TranslationManager.list(this.player, Translations.GUI_SHARED_ITEMS_BACK_BUTTON_LORE, "left_click", TranslationManager.string(this.player, Translations.MOUSE_LEFT_CLICK))) -// .make(); -// } -// -// @Override -// protected ItemStack getExitButton() { -// return QuickItem -// .of(Settings.GUI_SHARED_ITEMS_EXIT_BUTTON.getItemStack()) -// .name(TranslationManager.string(this.player, Translations.GUI_SHARED_ITEMS_EXIT_BUTTON_NAME)) -// .lore(TranslationManager.list(this.player, Translations.GUI_SHARED_ITEMS_EXIT_BUTTON_LORE, "left_click", TranslationManager.string(this.player, Translations.MOUSE_LEFT_CLICK))) -// .make(); -// } -// -// @Override -// protected ItemStack getPreviousPageButton() { -// return QuickItem -// .of(Settings.GUI_SHARED_ITEMS_PREVIOUS_BUTTON.getItemStack()) -// .name(TranslationManager.string(this.player, Translations.GUI_SHARED_ITEMS_PREVIOUS_BUTTON_NAME)) -// .lore(TranslationManager.list(this.player, Translations.GUI_SHARED_ITEMS_PREVIOUS_BUTTON_LORE, "left_click", TranslationManager.string(this.player, Translations.MOUSE_LEFT_CLICK))) -// .make(); -// } -// -// @Override -// protected ItemStack getNextPageButton() { -// return QuickItem -// .of(Settings.GUI_SHARED_ITEMS_NEXT_BUTTON.getItemStack()) -// .name(TranslationManager.string(this.player, Translations.GUI_SHARED_ITEMS_NEXT_BUTTON_NAME)) -// .lore(TranslationManager.list(this.player, Translations.GUI_SHARED_ITEMS_NEXT_BUTTON_LORE, "left_click", TranslationManager.string(this.player, Translations.MOUSE_LEFT_CLICK))) -// .make(); -// } -} \ No newline at end of file diff --git a/src/main/java/ca/tweetzy/auctionhouse/settings/v3/Settings.java b/src/main/java/ca/tweetzy/auctionhouse/settings/v3/Settings.java index 4489e43..b8bcdee 100644 --- a/src/main/java/ca/tweetzy/auctionhouse/settings/v3/Settings.java +++ b/src/main/java/ca/tweetzy/auctionhouse/settings/v3/Settings.java @@ -18,6 +18,7 @@ package ca.tweetzy.auctionhouse.settings.v3; +import ca.tweetzy.auctionhouse.AuctionHouse; import ca.tweetzy.auctionhouse.api.AuctionUsageMode; import ca.tweetzy.flight.comp.enums.CompMaterial; import ca.tweetzy.flight.config.ConfigEntry; @@ -114,6 +115,9 @@ public final class Settings extends FlightSettings { */ // ==================== Main Auction Menu ==================== // + public static ConfigEntry GUI_SHARED_FILLER = create("gui.shared options.filler item", CompMaterial.BLACK_STAINED_GLASS_PANE.name(), "The filler item for menus"); + + public static ConfigEntry GUI_MAIN_ROWS = create("gui.main.rows", 6, "How many rows should the gui have"); public static ConfigEntry GUI_MAIN_FILL_SLOTS = create("gui.main.fill slots", IntStream.rangeClosed(0, 44).boxed().collect(Collectors.toList()), "Slot numbers where auction items will be placed"); public static ConfigEntry GUI_MAIN_DECORATION = create("gui.main.decoration", Collections.singletonList(""), "Additional Decoration Items, format is MATERIAL_NAME:slot so ex. DIAMOND:1"); @@ -173,4 +177,7 @@ public final class Settings extends FlightSettings { public static ConfigEntry CONFIRM_ACCEPT_BID = create("settings.confirmation.accept bid", false, "Ask for confirmation before accepting current bid?"); public static ConfigEntry CONFIRM_CANCEL_LISTING = create("settings.confirmation.cancel listing", false, "Ask for confirmation before canceling a listing?"); + public static void init() { + AuctionHouse.getCoreConfig().init(); + } }