diff --git a/pom.xml b/pom.xml
index 6c41f2b..5dbedad 100644
--- a/pom.xml
+++ b/pom.xml
@@ -98,5 +98,11 @@
http-request
6.0
+
+ com.zaxxer
+ HikariCP
+ LATEST
+ compile
+
diff --git a/src/main/java/com/shadebyte/auctionhouse/Core.java b/src/main/java/com/shadebyte/auctionhouse/Core.java
index 986db3c..68120f4 100644
--- a/src/main/java/com/shadebyte/auctionhouse/Core.java
+++ b/src/main/java/com/shadebyte/auctionhouse/Core.java
@@ -14,6 +14,7 @@ import com.shadebyte.auctionhouse.events.TransactionListener;
import com.shadebyte.auctionhouse.util.Debugger;
import com.shadebyte.auctionhouse.util.Locale;
import com.shadebyte.auctionhouse.util.storage.ConfigWrapper;
+import com.zaxxer.hikari.HikariDataSource;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@@ -25,9 +26,6 @@ import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CopyOnWriteArrayList;
@@ -57,9 +55,7 @@ public final class Core extends JavaPlugin {
public List auctionItems;
//Database
- private Connection connection;
- public String host, database, username, password;
- public int port;
+ private HikariDataSource hikari;
public boolean dbConnected;
//Timing
@@ -95,7 +91,19 @@ public final class Core extends JavaPlugin {
initEvents();
initStorage();
- if (getConfig().getBoolean("database.enabled")) mysqlSetup();
+ if (getConfig().getBoolean("database.enabled")) {
+ hikari = new HikariDataSource();
+ hikari.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
+ hikari.addDataSourceProperty("serverName", getConfig().getString("database.host"));
+ hikari.addDataSourceProperty("port", getConfig().getInt("database.port"));
+ hikari.addDataSourceProperty("databaseName", getConfig().getString("database.database"));
+ hikari.addDataSourceProperty("user", getConfig().getString("database.username"));
+ hikari.addDataSourceProperty("password", getConfig().getString("database.password"));
+ if(!hikari.isClosed()) {
+ dbConnected = true;
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&aConnected to database"));
+ }
+ }
try {
MassiveStats stats = new MassiveStats(this);
@@ -112,52 +120,8 @@ public final class Core extends JavaPlugin {
@Override
public void onDisable() {
saveAuctions();
- }
-
-
- private void mysqlSetup() {
- host = this.getConfig().getString("database.host");
- port = this.getConfig().getInt("database.port");
- database = this.getConfig().getString("database.database");
- username = this.getConfig().getString("database.username");
- password = this.getConfig().getString("database.password");
-
- try {
-
- synchronized (this) {
- if (getConnection() != null && !getConnection().isClosed()) {
- return;
- }
-
- connect();
- Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&aSuccessfully Connected to MySQL"));
- dbConnected = true;
- }
- } catch (SQLException e) {
- Debugger.report(e);
- Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&cCould not connect to MySQL"));
- }
- }
-
- public void connect() {
- try {
- Class.forName("com.mysql.jdbc.Driver");
- setConnection(DriverManager.getConnection("jdbc:mysql://" + this.host + ":" + this.port + "/" + this.database, this.username, this.password));
- } catch (SQLException e) {
- Debugger.report(e);
- } catch (ClassNotFoundException e) {
- Debugger.report(e);
- Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&cCould not connect to MySQL"));
-
- }
- }
-
- public Connection getConnection() {
- return connection;
- }
-
- public void setConnection(Connection connection) {
- this.connection = connection;
+ if (hikari != null)
+ hikari.close();
}
private void loadAuctions() {
@@ -338,4 +302,8 @@ public final class Core extends JavaPlugin {
public Settings getSettings() {
return settings;
}
+
+ public HikariDataSource getHikari() {
+ return hikari;
+ }
}
diff --git a/src/main/java/com/shadebyte/auctionhouse/api/enums/Permissions.java b/src/main/java/com/shadebyte/auctionhouse/api/enums/Permissions.java
index 52a020f..d7a7917 100644
--- a/src/main/java/com/shadebyte/auctionhouse/api/enums/Permissions.java
+++ b/src/main/java/com/shadebyte/auctionhouse/api/enums/Permissions.java
@@ -10,8 +10,10 @@ public enum Permissions {
BASE("AuctionHouse"),
RELOAD_CMD(BASE.getNode() + ".cmd.reload"),
+ HELP_CMD(BASE.getNode() + ".cmd.help"),
SELL_CMD(BASE.getNode() + ".cmd.sell"),
EXPIRED_CMD(BASE.getNode() + ".cmd.expired"),
+ LISTINGS_CMD(BASE.getNode() + ".cmd.listings"),
MAX_AUCTIONS(BASE.getNode() + ".maxauctions"),
;
diff --git a/src/main/java/com/shadebyte/auctionhouse/cmds/CommandManager.java b/src/main/java/com/shadebyte/auctionhouse/cmds/CommandManager.java
index 34d770d..64b645e 100644
--- a/src/main/java/com/shadebyte/auctionhouse/cmds/CommandManager.java
+++ b/src/main/java/com/shadebyte/auctionhouse/cmds/CommandManager.java
@@ -3,9 +3,12 @@ package com.shadebyte.auctionhouse.cmds;
import com.shadebyte.auctionhouse.Core;
import com.shadebyte.auctionhouse.api.enums.Lang;
import com.shadebyte.auctionhouse.api.enums.Permissions;
+import com.shadebyte.auctionhouse.cmds.subcmds.ExpiredCommand;
+import com.shadebyte.auctionhouse.cmds.subcmds.ListedCommand;
import com.shadebyte.auctionhouse.cmds.subcmds.ReloadCommand;
import com.shadebyte.auctionhouse.cmds.subcmds.SellCommand;
import com.shadebyte.auctionhouse.inventory.inventories.AuctionGUI;
+import com.shadebyte.auctionhouse.inventory.inventories.ListingsGUI;
import com.shadebyte.auctionhouse.util.Debugger;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
@@ -42,6 +45,8 @@ public class CommandManager implements CommandExecutor {
Core.getInstance().getCommand(main).setExecutor(this);
this.commands.add(new SellCommand());
this.commands.add(new ReloadCommand());
+ this.commands.add(new ListedCommand());
+ this.commands.add(new ExpiredCommand());
}
@Override
diff --git a/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/HelpCommand.java b/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/HelpCommand.java
index 2423a38..b25befd 100644
--- a/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/HelpCommand.java
+++ b/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/HelpCommand.java
@@ -1,10 +1,45 @@
package com.shadebyte.auctionhouse.cmds.subcmds;
+import com.shadebyte.auctionhouse.Core;
+import com.shadebyte.auctionhouse.api.enums.Lang;
+import com.shadebyte.auctionhouse.api.enums.Permissions;
+import com.shadebyte.auctionhouse.cmds.SubCommand;
+import org.bukkit.command.CommandSender;
+
/**
* The current file has been created by Kiran Hart
* Date Created: 7/6/2018
* Time Created: 11:51 AM
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
*/
-public class HelpCommand {
+public class HelpCommand extends SubCommand {
+
+ @Override
+ public void onCommand(CommandSender sender, String[] args) {
+
+ if (!sender.hasPermission(Permissions.HELP_CMD.getNode())) {
+ sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NO_PERMISSION.getNode()));
+ return;
+ }
+
+ for (int i = 0; i <= 7; i++) {
+ sender.sendMessage(Core.getInstance().getLocale().getMessage("cmd.help." + i));
+ }
+ }
+
+ @Override
+ public String name() {
+ return Core.getInstance().getCommandManager().help;
+ }
+
+ @Override
+ public String info() {
+ return null;
+ }
+
+ @Override
+ public String[] aliases() {
+ return new String[0];
+ }
+
}
diff --git a/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/ListedCommand.java b/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/ListedCommand.java
index 42fe686..0647ec5 100644
--- a/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/ListedCommand.java
+++ b/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/ListedCommand.java
@@ -1,10 +1,51 @@
package com.shadebyte.auctionhouse.cmds.subcmds;
+import com.shadebyte.auctionhouse.Core;
+import com.shadebyte.auctionhouse.api.enums.Lang;
+import com.shadebyte.auctionhouse.api.enums.Permissions;
+import com.shadebyte.auctionhouse.cmds.SubCommand;
+import com.shadebyte.auctionhouse.inventory.inventories.ExpiredGUI;
+import com.shadebyte.auctionhouse.inventory.inventories.ListingsGUI;
+import org.bukkit.command.CommandSender;
+import org.bukkit.entity.Player;
+
/**
* The current file has been created by Kiran Hart
* Date Created: 7/6/2018
* Time Created: 11:51 AM
* Usage of any code found within this class is prohibited unless given explicit permission otherwise.
*/
-public class ListedCommand {
+public class ListedCommand extends SubCommand {
+
+ @Override
+ public void onCommand(CommandSender sender, String[] args) {
+
+ if (!sender.hasPermission(Permissions.LISTINGS_CMD.getNode())) {
+ sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.NO_PERMISSION.getNode()));
+ return;
+ }
+
+ if (!(sender instanceof Player)) {
+ sender.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.PLAYERS_ONLY.getNode()));
+ return;
+ }
+
+ Player p = (Player) sender;
+ p.openInventory(new ListingsGUI(p).getInventory());
+ }
+
+ @Override
+ public String name() {
+ return Core.getInstance().getCommandManager().listed;
+ }
+
+ @Override
+ public String info() {
+ return null;
+ }
+
+ @Override
+ public String[] aliases() {
+ return new String[0];
+ }
}
diff --git a/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/ReloadCommand.java b/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/ReloadCommand.java
index 2c2bb3b..735201a 100644
--- a/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/ReloadCommand.java
+++ b/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/ReloadCommand.java
@@ -28,13 +28,10 @@ public class ReloadCommand extends SubCommand {
long start = System.currentTimeMillis();
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bReloading config.yml"));
- Core.getInstance().saveConfig();
Core.getInstance().reloadConfig();
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bReloading transactions.yml"));
- Core.getInstance().getTransactions().saveConfig();
Core.getInstance().getTransactions().reloadConfig();
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bReloading data.yml"));
- Core.getInstance().getData().saveConfig();
Core.getInstance().getData().reloadConfig();
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bReloading language file."));
Core.getInstance().getLocale().reloadMessages();
diff --git a/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/SellCommand.java b/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/SellCommand.java
index 8f5a755..264da33 100644
--- a/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/SellCommand.java
+++ b/src/main/java/com/shadebyte/auctionhouse/cmds/subcmds/SellCommand.java
@@ -62,21 +62,6 @@ public class SellCommand extends SubCommand {
}
}
- if (args.length == 5) {
- int buyNow = ThreadLocalRandom.current().nextInt(2, 100000);
- int startPrice = ThreadLocalRandom.current().nextInt(2, 10000);
- int increment = ThreadLocalRandom.current().nextInt(2, 10000);
-
- AuctionItem auctionItem = new AuctionItem(p.getUniqueId().toString(), AuctionAPI.getItemInHand(p), Core.getInstance().getConfig().getInt("settings.default-auction-time"), startPrice, increment, buyNow);
- Core.getInstance().auctionItems.add(0, auctionItem);
-
- if (AuctionAPI.getItemInHand(p).getAmount() >= 2) {
- AuctionAPI.getItemInHand(p).setAmount(AuctionAPI.getItemInHand(p).getAmount() - 1);
- } else {
- AuctionAPI.setItemInHand(p, null);
- }
- }
-
if (args.length == 4) {
if (AuctionAPI.getInstance().isNumeric(args[1]) && AuctionAPI.getInstance().isNumeric(args[2]) && AuctionAPI.getInstance().isNumeric(args[3])) {
if (new AuctionPlayer(p).getLimit() - 1 < new AuctionPlayer(p).getTotalActiveAuctions()) {
diff --git a/src/main/java/com/shadebyte/auctionhouse/util/storage/MySQL.java b/src/main/java/com/shadebyte/auctionhouse/util/storage/MySQL.java
index 238b6e2..330bd89 100644
--- a/src/main/java/com/shadebyte/auctionhouse/util/storage/MySQL.java
+++ b/src/main/java/com/shadebyte/auctionhouse/util/storage/MySQL.java
@@ -7,7 +7,9 @@ import com.shadebyte.auctionhouse.util.Debugger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
+import java.sql.Connection;
import java.sql.PreparedStatement;
+import java.sql.SQLException;
/**
* The current file has been created by Kiran Hart
@@ -18,13 +20,10 @@ import java.sql.PreparedStatement;
public class MySQL {
public void logTransaction(Transaction transaction) {
- Bukkit.getServer().getScheduler().runTaskAsynchronously(Core.getInstance(), () -> {
- try {
- if (Core.getInstance().getConnection().isClosed() || !Core.getInstance().dbConnected || Core.getInstance().getConnection() == null) {
- Core.getInstance().connect();
- Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&cDatabase connection is close, attempting re-connect"));
- }
- PreparedStatement insert = Core.getInstance().getConnection().prepareStatement("INSERT INTO transactions (buyer, seller, auctiontype, startprice, buynowprice, increment, item, displayname, lore, enchantments, auctionid, timesold, finalprice) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)");
+
+ Bukkit.getServer().getScheduler().runTaskAsynchronously(Core.getInstance(), ()->{
+ try (Connection connection = Core.getInstance().getHikari().getConnection();
+ PreparedStatement insert = connection.prepareStatement("INSERT INTO transactions (buyer, seller, auctiontype, startprice, buynowprice, increment, item, displayname, lore, enchantments, auctionid, timesold, finalprice) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)")) {
insert.setString(1, transaction.getBuyer());
insert.setString(2, transaction.getAuctionItem().getOwner());
insert.setString(3, transaction.getTransactionType().getTransactionType());
@@ -42,7 +41,8 @@ public class MySQL {
insert.setInt(13, (transaction.getTransactionType() == Transaction.TransactionType.BOUGHT) ? transaction.getAuctionItem().getBuyNowPrice() : transaction.getAuctionItem().getCurrentPrice());
insert.executeUpdate();
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&aRecorded transaction id: &b" + transaction.getAuctionItem().getKey() + "&a to database."));
- } catch (Exception e) {
+
+ } catch (SQLException e) {
Debugger.report(e);
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&cCould not save the transaction to the database, saved to transactions.yml"));
}
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index a13fb6e..2ca57fd 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -21,15 +21,15 @@ settings:
#MySql stuff for databases if you want
database:
enabled: true
- host: 162.241.217.18
- port: 3306
+ host:
+ port:
database: "kiranhar_auctionhouse"
username: "kiranhar_admin"
- password: "TweetyHart1."
+ password: ""
discord:
enabled: true
- webhook: "https://discordapp.com/api/webhooks/470085392901734410/_ls7Ps5GzlKqBJlHLaZt6GZgVTKkuwuIuWK1JU5j_pt-DwWhSYAITlI17ePiIuNTmdua"
+ webhook: ""
title: "Auction House"
description: "A new item has been listed!"
description-complete: "A transaction has been completed!"
diff --git a/src/main/resources/en_US.lang b/src/main/resources/en_US.lang
index c523ff2..445b585 100644
--- a/src/main/resources/en_US.lang
+++ b/src/main/resources/en_US.lang
@@ -3,6 +3,14 @@ prefix = "&8[&eAuctionHouse&8]"
cmd.invalid = "&cThat isn't a valid subcommand!"
cmd.sell = "&e/ah sell "
+cmd.help.1 = "&e&lAuction House"
+cmd.help.2 = ""
+cmd.help.3 = "&f/&eah help"
+cmd.help.4 = "&f/&eah sell"
+cmd.help.5 = "&f/&eah listed"
+cmd.help.6 = "&f/&eah expired"
+cmd.help.7 = ""
+
nopermission = "&cYou do not have permission to do that!"
playersonly = "&cOnly player's may use the command!"
notanumber = "&CThat isn't a valid number"
diff --git a/src/test/java/com/shadebyte/server/ServerTest.java b/src/test/java/com/shadebyte/server/ServerTest.java
index b47fc48..508c7db 100644
--- a/src/test/java/com/shadebyte/server/ServerTest.java
+++ b/src/test/java/com/shadebyte/server/ServerTest.java
@@ -13,6 +13,9 @@ public class ServerTest {
public static void main(String[] args) {
- System.out.println(new SimpleDateFormat("MMMM dd yyyy").format(new Date(System.currentTimeMillis())));
+ for (int i = 1; i <= 7; i++) {
+ System.out.println(i);
+ }
+
}
}