mirror of
https://github.com/kiranhart/Auction-House.git
synced 2025-02-21 20:11:19 +01:00
Bug Snipping
This commit is contained in:
parent
bff676e5b5
commit
d41c930461
6
pom.xml
6
pom.xml
@ -89,5 +89,11 @@
|
||||
<version>1.7</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.zaxxer</groupId>
|
||||
<artifactId>HikariCP</artifactId>
|
||||
<version>LATEST</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -12,6 +12,7 @@ import com.kiranhart.auctionhouse.util.locale.Locale;
|
||||
import com.kiranhart.auctionhouse.util.storage.ConfigWrapper;
|
||||
import com.kiranhart.auctionhouse.util.tasks.LoadAuctionsTask;
|
||||
import com.kiranhart.auctionhouse.util.tasks.TickAuctionsTask;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import org.apache.commons.lang.ArrayUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
@ -40,6 +41,9 @@ public final class Core extends JavaPlugin {
|
||||
private ConfigWrapper transactions;
|
||||
private ConfigWrapper data;
|
||||
|
||||
private HikariDataSource hikari;
|
||||
private boolean dbConnected;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
|
||||
@ -55,6 +59,7 @@ public final class Core extends JavaPlugin {
|
||||
|
||||
console.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&6AuctionHouse&8]&a Initializing instance"));
|
||||
instance = this;
|
||||
dbConnected = false;
|
||||
console.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&6AuctionHouse&8]&a Checking server version"));
|
||||
serverVersion = ServerVersion.fromPackageName(Bukkit.getServer().getClass().getPackage().getName());
|
||||
|
||||
@ -89,6 +94,22 @@ public final class Core extends JavaPlugin {
|
||||
commandManager = new CommandManager();
|
||||
commandManager.initialize();
|
||||
|
||||
//Database
|
||||
if (AuctionSettings.DB_ENABLED) {
|
||||
hikari = new HikariDataSource();
|
||||
hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
|
||||
hikari.addDataSourceProperty("serverName", AuctionSettings.DB_HOST);
|
||||
hikari.addDataSourceProperty("port", AuctionSettings.DB_PORT);
|
||||
hikari.addDataSourceProperty("databaseName", AuctionSettings.DB_NAME);
|
||||
hikari.addDataSourceProperty("user", AuctionSettings.DB_USERNAME);
|
||||
hikari.addDataSourceProperty("password", AuctionSettings.DB_PASSWORD);
|
||||
|
||||
if (!hikari.isClosed()) {
|
||||
dbConnected = true;
|
||||
console.sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&6AuctionHouse&8]&a Connected to database!"));
|
||||
}
|
||||
}
|
||||
|
||||
//Listeners
|
||||
pm.registerEvents(new AGUIListener(), this);
|
||||
|
||||
@ -101,6 +122,8 @@ public final class Core extends JavaPlugin {
|
||||
console.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aLoaded successfully in " + (System.currentTimeMillis() - start) + "ms"));
|
||||
console.sendMessage(ChatColor.translateAlternateColorCodes('&', "&6========================================="));
|
||||
|
||||
//Database.getInstance().performTableCreation(Database.Tables.TRANSACTIONS);
|
||||
|
||||
//Begin Auction Tick
|
||||
TickAuctionsTask.startTask(this);
|
||||
}
|
||||
@ -127,6 +150,9 @@ public final class Core extends JavaPlugin {
|
||||
index++;
|
||||
}
|
||||
getData().saveConfig();
|
||||
|
||||
if (hikari != null)
|
||||
hikari.close();
|
||||
}
|
||||
|
||||
private void initDataFiles() {
|
||||
@ -172,6 +198,10 @@ public final class Core extends JavaPlugin {
|
||||
return transactions;
|
||||
}
|
||||
|
||||
public HikariDataSource getHikari() {
|
||||
return hikari;
|
||||
}
|
||||
|
||||
public CommandManager getCommandManager() {
|
||||
return commandManager;
|
||||
}
|
||||
|
@ -31,7 +31,12 @@ public class AuctionSettings {
|
||||
public static int DECREASE_SECONDS_BY_TICK = 5;
|
||||
public static int UPDATE_EVERY_TICK = 5;
|
||||
|
||||
|
||||
public static boolean DB_ENABLED = false;
|
||||
public static String DB_HOST = "localhost";
|
||||
public static int DB_PORT = 3306;
|
||||
public static String DB_NAME = "auctionhouse";
|
||||
public static String DB_USERNAME = "root";
|
||||
public static String DB_PASSWORD = "";
|
||||
|
||||
public AuctionSettings () {
|
||||
DEFAULT_AUCTION_TIME = Core.getInstance().getConfig().getInt("settings.default-auction-time");
|
||||
@ -52,5 +57,12 @@ public class AuctionSettings {
|
||||
TIME_TO_INCREASE_BY_BID = Core.getInstance().getConfig().getInt("settings.time-to-increase-by-bid");
|
||||
DECREASE_SECONDS_BY_TICK = Core.getInstance().getConfig().getInt("settings.decrease-seconds-by-tick");
|
||||
UPDATE_EVERY_TICK = Core.getInstance().getConfig().getInt("settings.update-every-tick");
|
||||
|
||||
DB_ENABLED = Core.getInstance().getConfig().getBoolean("database.enabled");
|
||||
DB_HOST = Core.getInstance().getConfig().getString("database.host");
|
||||
DB_PORT = Core.getInstance().getConfig().getInt("database.port");
|
||||
DB_NAME = Core.getInstance().getConfig().getString("database.name");
|
||||
DB_USERNAME = Core.getInstance().getConfig().getString("database.username");
|
||||
DB_PASSWORD = Core.getInstance().getConfig().getString("database.password");
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class AuctionPlayer {
|
||||
public List<AuctionItem> getAuctionItems() {
|
||||
List<AuctionItem> list = new ArrayList<>();
|
||||
for (AuctionItem item : Core.getInstance().getAuctionItems()) {
|
||||
if (item.getOwner().equals(player.getUniqueId().toString())) {
|
||||
if (item.getOwner().equals(player.getUniqueId())) {
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import com.kiranhart.auctionhouse.Core;
|
||||
import com.kiranhart.auctionhouse.api.statics.AuctionLang;
|
||||
import com.kiranhart.auctionhouse.api.statics.AuctionPermissions;
|
||||
import com.kiranhart.auctionhouse.cmds.SubCommand;
|
||||
import com.kiranhart.auctionhouse.inventory.inventories.ExpiredGUI;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -29,7 +30,7 @@ public class ExpiredCommand extends SubCommand {
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
// p.openInventory(new ExpiredGUI(p).getInventory());
|
||||
p.openInventory(new ExpiredGUI(p).getInventory());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,7 +30,7 @@ public class ListedCommand extends SubCommand {
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
//p.openInventory(new ListingsGUI(p).getInventory());
|
||||
p.openInventory(new ListingsGUI(p).getInventory());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -30,7 +30,7 @@ public class TransactionsCommand extends SubCommand {
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
//p.openInventory(new AllTransactionsGUI(p).getInventory());
|
||||
p.openInventory(new AllTransactionsGUI(p).getInventory());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -139,14 +139,14 @@ public class AuctionGUI implements AGUI {
|
||||
} else {
|
||||
//Not enough money to bid
|
||||
e.getClickedInventory().setItem(slot, AuctionAPI.getInstance().createNotEnoughMoneyIcon());
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(Core.getInstance(), () -> {
|
||||
Bukkit.getServer().getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
p.closeInventory();
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
}, 20);
|
||||
}
|
||||
|
||||
p.closeInventory();
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
// p.closeInventory();
|
||||
// p.openInventory(new AuctionGUI(p).getInventory());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -171,14 +171,14 @@ public class AuctionGUI implements AGUI {
|
||||
} else {
|
||||
//Not enough money to purchase
|
||||
e.getClickedInventory().setItem(slot, AuctionAPI.getInstance().createNotEnoughMoneyIcon());
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(Core.getInstance(), () -> {
|
||||
Bukkit.getServer().getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
p.closeInventory();
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
}, 20);
|
||||
}
|
||||
|
||||
p.closeInventory();
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
// p.closeInventory();
|
||||
// p.openInventory(new AuctionGUI(p).getInventory());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -203,14 +203,14 @@ public class AuctionGUI implements AGUI {
|
||||
} else {
|
||||
//Not enough money to purchase
|
||||
e.getClickedInventory().setItem(slot, AuctionAPI.getInstance().createNotEnoughMoneyIcon());
|
||||
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(Core.getInstance(), () -> {
|
||||
Bukkit.getServer().getScheduler().runTaskLater(Core.getInstance(), () -> {
|
||||
p.closeInventory();
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
}, 20);
|
||||
}
|
||||
|
||||
p.closeInventory();
|
||||
p.openInventory(new AuctionGUI(p).getInventory());
|
||||
// p.closeInventory();
|
||||
// p.openInventory(new AuctionGUI(p).getInventory());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,66 @@
|
||||
package com.kiranhart.auctionhouse.util.storage;
|
||||
/*
|
||||
The current file was created by Kiran Hart
|
||||
Date: August 12 2019
|
||||
Time: 4:17 PM
|
||||
|
||||
Code within this class is not to be redistributed without proper permission.
|
||||
*/
|
||||
|
||||
import com.kiranhart.auctionhouse.Core;
|
||||
import com.kiranhart.auctionhouse.util.Debugger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
|
||||
public class Database {
|
||||
|
||||
private static Database instance;
|
||||
|
||||
private Database() {
|
||||
}
|
||||
|
||||
public static Database getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new Database();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public enum Tables {
|
||||
|
||||
TRANSACTIONS("transactions"),
|
||||
;
|
||||
|
||||
private String tableName;
|
||||
|
||||
Tables(String tableName) {
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean performTableCreation(Tables... tables) {
|
||||
try {
|
||||
//Loop through each of the passed in tables
|
||||
for (Tables table : tables) {
|
||||
|
||||
//Check if the table is TRANSACTIONS
|
||||
if (table == Tables.TRANSACTIONS) {
|
||||
//Perform the table creation;
|
||||
String query = "CREATE TABLE IF NOT EXISTS `transactions` ( `id` INT NOT NULL AUTO_INCREMENT , `transaction_type` TEXT NOT NULL , `seller` TEXT NOT NULL , `buyer` TEXT NOT NULL , `start_price` TEXT NOT NULL , `bid_increment` TEXT NOT NULL , `buy_now_price` TEXT NOT NULL , `final_price` TEXT NOT NULL , `time_left` INT NOT NULL , `auction_id` INT NOT NULL , `time_completed` TEXT NOT NULL , `item_type` TEXT NOT NULL , `item_name` TEXT NOT NULL , `item_lore` TEXT NOT NULL , `item_enchants` TEXT NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB";
|
||||
Connection connection = Core.getInstance().getHikari().getConnection();
|
||||
PreparedStatement statement = connection.prepareStatement(query);
|
||||
statement.executeQuery();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Debugger.report(e);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -35,8 +35,8 @@ public class SaveTransactionTask extends BukkitRunnable {
|
||||
@Override
|
||||
public void run() {
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + transaction.getTimeCompleted() + transaction.getAuctionItem().getKey() + ".transaction-type", transaction.getTransactionType().getTransactionType());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + transaction.getTimeCompleted() + transaction.getAuctionItem().getKey() + ".seller", transaction.getAuctionItem().getOwner());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + transaction.getTimeCompleted() + transaction.getAuctionItem().getKey() + ".buyer", transaction.getBuyer());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + transaction.getTimeCompleted() + transaction.getAuctionItem().getKey() + ".seller", transaction.getAuctionItem().getOwner().toString());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + transaction.getTimeCompleted() + transaction.getAuctionItem().getKey() + ".buyer", transaction.getBuyer().toString());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + transaction.getTimeCompleted() + transaction.getAuctionItem().getKey() + ".start-price", transaction.getAuctionItem().getStartPrice());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + transaction.getTimeCompleted() + transaction.getAuctionItem().getKey() + ".bid-increment", transaction.getAuctionItem().getBidIncrement());
|
||||
Core.getInstance().getTransactions().getConfig().set("transactions." + transaction.getTimeCompleted() + transaction.getAuctionItem().getKey() + ".current-price", transaction.getAuctionItem().getCurrentPrice());
|
||||
|
@ -38,7 +38,7 @@ public class TickAuctionsTask extends BukkitRunnable {
|
||||
plugin = core;
|
||||
if (instance == null) {
|
||||
instance = new TickAuctionsTask(plugin);
|
||||
instance.runTaskTimerAsynchronously(plugin, 0, 20 * 5);
|
||||
instance.runTaskTimerAsynchronously(plugin, 0, 20 * AuctionSettings.UPDATE_EVERY_TICK);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
@ -138,14 +138,14 @@ public class TickAuctionsTask extends BukkitRunnable {
|
||||
Bukkit.getOnlinePlayers().forEach(p -> {
|
||||
if (p.getOpenInventory().getTitle().equalsIgnoreCase(ChatColor.translateAlternateColorCodes('&', Core.getInstance().getConfig().getString("guis.auctionhouse.title")))) {
|
||||
p.getOpenInventory().getTopInventory().clear();
|
||||
p.getOpenInventory().getTopInventory().setItem(45, AuctionAPI.getInstance().createConfigurationItem("gui.auction.items.yourauctions", new AuctionPlayer(p).getTotalActiveAuctions(), 0));
|
||||
p.getOpenInventory().getTopInventory().setItem(46, AuctionAPI.getInstance().createConfigurationItem("gui.auction.items.collectionbin", 0, new AuctionPlayer(p).getTotalExpiredAuctions()));
|
||||
p.getOpenInventory().getTopInventory().setItem(48, AuctionAPI.getInstance().createConfigurationItem("gui.auction.items.previouspage", 0, 0));
|
||||
p.getOpenInventory().getTopInventory().setItem(49, AuctionAPI.getInstance().createConfigurationItem("gui.auction.items.refresh", 0, 0));
|
||||
p.getOpenInventory().getTopInventory().setItem(50, AuctionAPI.getInstance().createConfigurationItem("gui.auction.items.nextpage", 0, 0));
|
||||
p.getOpenInventory().getTopInventory().setItem(51, AuctionAPI.getInstance().createConfigurationItem("gui.auction.items.transactions", 0, 0));
|
||||
p.getOpenInventory().getTopInventory().setItem(52, AuctionAPI.getInstance().createConfigurationItem("gui.auction.items.howtosell", 0, 0));
|
||||
p.getOpenInventory().getTopInventory().setItem(53, AuctionAPI.getInstance().createConfigurationItem("gui.auction.items.guide", 0, 0));
|
||||
p.getOpenInventory().getTopInventory().setItem(45, AuctionAPI.getInstance().createConfigurationItem("guis.auctionhouse.items.yourauctions", new AuctionPlayer(p).getTotalActiveAuctions(), 0));
|
||||
p.getOpenInventory().getTopInventory().setItem(46, AuctionAPI.getInstance().createConfigurationItem("guis.auctionhouse.items.collectionbin", 0, new AuctionPlayer(p).getTotalExpiredAuctions()));
|
||||
p.getOpenInventory().getTopInventory().setItem(48, AuctionAPI.getInstance().createConfigurationItem("guis.auctionhouse.items.previouspage", 0, 0));
|
||||
p.getOpenInventory().getTopInventory().setItem(49, AuctionAPI.getInstance().createConfigurationItem("guis.auctionhouse.items.refresh", 0, 0));
|
||||
p.getOpenInventory().getTopInventory().setItem(50, AuctionAPI.getInstance().createConfigurationItem("guis.auctionhouse.items.nextpage", 0, 0));
|
||||
p.getOpenInventory().getTopInventory().setItem(51, AuctionAPI.getInstance().createConfigurationItem("guis.auctionhouse.items.transactions", 0, 0));
|
||||
p.getOpenInventory().getTopInventory().setItem(52, AuctionAPI.getInstance().createConfigurationItem("guis.auctionhouse.items.howtosell", 0, 0));
|
||||
p.getOpenInventory().getTopInventory().setItem(53, AuctionAPI.getInstance().createConfigurationItem("guis.auctionhouse.items.guide", 0, 0));
|
||||
|
||||
List<List<AuctionItem>> chunks = Lists.partition(Core.getInstance().getAuctionItems(), 45);
|
||||
chunks.get(0).forEach(item -> p.getOpenInventory().getTopInventory().setItem(p.getOpenInventory().getTopInventory().firstEmpty(), item.getAuctionStack(AuctionItem.AuctionItemType.MAIN)));
|
||||
@ -157,5 +157,7 @@ public class TickAuctionsTask extends BukkitRunnable {
|
||||
} catch (Exception e) {
|
||||
Debugger.report(e);
|
||||
}
|
||||
|
||||
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&8[&6AuctionHouse&8]&a Ran Auction Tick at rate of " + AuctionSettings.UPDATE_EVERY_TICK + "s"));
|
||||
}
|
||||
}
|
||||
|
@ -23,10 +23,10 @@ settings:
|
||||
|
||||
#MySql stuff for databases if you want
|
||||
database:
|
||||
enabled: false
|
||||
enabled: true
|
||||
host: "localhost"
|
||||
port: 3306
|
||||
database: "auctionhouse"
|
||||
name: "auctionhouse"
|
||||
username: "root"
|
||||
password: ""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user