diff --git a/pom.xml b/pom.xml
index d3d6730..1ea24d8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.shadebyte
auctionhouse
- 1.0.7
+ 1.0.8
jar
AuctionHouse
diff --git a/src/main/java/com/shadebyte/auctionhouse/Core.java b/src/main/java/com/shadebyte/auctionhouse/Core.java
index af9dea1..aa78b22 100644
--- a/src/main/java/com/shadebyte/auctionhouse/Core.java
+++ b/src/main/java/com/shadebyte/auctionhouse/Core.java
@@ -109,17 +109,20 @@ public final class Core extends JavaPlugin {
}
}
- try {
- MassiveStats stats = new MassiveStats(this);
- stats.setListenerDisabled(false);
- } catch (Exception e) {
- Debugger.report(e);
+ if (getConfig().getBoolean("send-report-data")) {
+ try {
+ MassiveStats stats = new MassiveStats(this);
+ stats.setListenerDisabled(false);
+ } catch (Exception e) {
+ Debugger.report(e);
+ }
}
loadAuctions();
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&bFound a total of &6" + Transaction.getTotalTransactions() + " &brecorded transactions"));
Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&bAuction House finished loading, took " + (System.currentTimeMillis() - startTime) + " ms"));
tickAuctions();
+ Bukkit.getServer().getScheduler().runTaskTimerAsynchronously(this, () -> saveAllAuctions(), 0, 20 * getConfig().getInt("auto-save-increment"));
}
@Override
@@ -133,6 +136,45 @@ public final class Core extends JavaPlugin {
hikari.close();
}
+ private void saveAllAuctions() {
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&b============================"));
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&aGETTING READY TO PERFORM SAVE"));
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&b============================"));
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', " "));
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', " "));
+ long autoSaveStart = System.currentTimeMillis();
+ clearAuctionDataFolder();
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&e---------------------------"));
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&cFinished clearing data.yml"));
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&e---------------------------"));
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', " "));
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', " "));
+ saveAuctions();
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&e-------------------------------"));
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&cFinished saving active auctions"));
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&e-------------------------------"));
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', " "));
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', " "));
+ Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', "&eAuction Saving took: " + (System.currentTimeMillis() - autoSaveStart) + "ms"));
+ }
+
+ private void clearAuctionDataFolder() {
+ try {
+ ConfigurationSection section = data.getConfig().getConfigurationSection("active");
+ if (section.getKeys(false).size() != 0) {
+ Bukkit.getServer().getScheduler().runTaskAsynchronously(this, () -> {
+ for (String node : section.getKeys(false)) {
+ int xNode = Integer.parseInt(node);
+ data.getConfig().set("active." + xNode, null);
+ }
+ data.saveConfig();
+ });
+ }
+ } catch (Exception e) {
+ Debugger.report(e);
+ }
+ }
+
private void loadAuctions() {
try {
ConfigurationSection section = data.getConfig().getConfigurationSection("active");
@@ -193,10 +235,13 @@ public final class Core extends JavaPlugin {
highestBidder.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.AUCTION_BUY.getNode()).replace("{itemname}", auctionItem.getDisplayName()).replace("{price}", AuctionAPI.getInstance().friendlyNumber(auctionItem.getCurrentPrice())));
getEconomy().withdrawPlayer(highestBidder, auctionItem.getCurrentPrice());
getEconomy().depositPlayer(Bukkit.getOfflinePlayer(UUID.fromString(auctionItem.getOwner())), auctionItem.getCurrentPrice());
- if (AuctionAPI.getInstance().availableSlots(highestBidder.getInventory()) < 1)
- highestBidder.getWorld().dropItemNaturally(highestBidder.getLocation(), auctionItem.getItem());
- else
+
+ if (AuctionAPI.getInstance().availableSlots(highestBidder.getInventory()) == 0) {
+ data.getConfig().set("expired." + auctionItem.getHighestBidder() + "." + auctionItem.getKey() + ".item", auctionItem.getItem());
+ data.getConfig().set("expired." + auctionItem.getHighestBidder() + "." + auctionItem.getKey() + ".display", AuctionAPI.getInstance().expiredAuctionItem(auctionItem));
+ } else
highestBidder.getInventory().addItem(auctionItem.getItem());
+
Transaction transaction = new Transaction(Transaction.TransactionType.AUCTION_WON, auctionItem, highestBidder.getUniqueId().toString(), System.currentTimeMillis());
transaction.saveTransaction();
getServer().getPluginManager().callEvent(new TransactionCompleteEvent(transaction));
diff --git a/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/AuctionGUI.java b/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/AuctionGUI.java
index e25d28e..882f3a6 100644
--- a/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/AuctionGUI.java
+++ b/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/AuctionGUI.java
@@ -91,7 +91,7 @@ public class AuctionGUI implements AGUI {
if (auctionItem.getKey().equalsIgnoreCase(key)) item = auctionItem;
}
- if (Core.getEconomy().getBalance(p) < item.getBidIncrement()) {
+ if (Core.getEconomy().getBalance(p) < item.getBidIncrement() + item.getCurrentPrice()) {
e.getClickedInventory().setItem(slot, AuctionAPI.getInstance().createConfigItem("gui.auction.items.not-enough-money", 0, 0));
Bukkit.getServer().getScheduler().runTaskLaterAsynchronously(Core.getInstance(), () -> {
p.closeInventory();
diff --git a/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/ConfirmationGUI.java b/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/ConfirmationGUI.java
index d61501c..8909439 100644
--- a/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/ConfirmationGUI.java
+++ b/src/main/java/com/shadebyte/auctionhouse/inventory/inventories/ConfirmationGUI.java
@@ -42,7 +42,13 @@ public class ConfirmationGUI implements AGUI {
} else {
Core.getEconomy().withdrawPlayer(p, auctionItem.getBuyNowPrice());
Core.getEconomy().depositPlayer(Bukkit.getOfflinePlayer(UUID.fromString(auctionItem.getOwner())), auctionItem.getBuyNowPrice());
- p.getInventory().addItem(auctionItem.getItem());
+
+ if (AuctionAPI.getInstance().availableSlots(p.getInventory()) == 0) {
+ Core.getInstance().getData().getConfig().set("expired." + p.getUniqueId().toString() + "." + auctionItem.getKey() + ".item", auctionItem.getItem());
+ Core.getInstance().getData().getConfig().set("expired." + p.getUniqueId().toString() + "." + auctionItem.getKey() + ".display", AuctionAPI.getInstance().expiredAuctionItem(auctionItem));
+ } else
+ p.getInventory().addItem(auctionItem.getItem());
+
p.sendMessage(Core.getInstance().getSettings().getPrefix() + Core.getInstance().getLocale().getMessage(Lang.AUCTION_BUY.getNode()).replace("{itemname}", auctionItem.getDisplayName()).replace("{price}", AuctionAPI.getInstance().friendlyNumber(auctionItem.getBuyNowPrice())));
Player owner = Bukkit.getPlayer(UUID.fromString(auctionItem.getOwner()));
@@ -60,6 +66,9 @@ public class ConfirmationGUI implements AGUI {
Core.getInstance().getServer().getPluginManager().callEvent(completeEvent);
p.openInventory(new AuctionGUI(p).getInventory());
}
+ } else {
+ p.closeInventory();
+ p.openInventory(new AuctionGUI(p).getInventory());
}
} else if (clicked.isSimilar(AuctionAPI.getInstance().fill("&c&lNo", 14))) {
p.closeInventory();
diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml
index 5981d9a..73a4ffb 100644
--- a/src/main/resources/config.yml
+++ b/src/main/resources/config.yml
@@ -4,9 +4,11 @@
#Lang name formats: https://www.science.co.il/language/Locale-codes.php
lang: "en_US"
debugger: true
+auto-save-increment: 600 #Auto save active auctions every 10 minutes
+send-report-data: true #This will send hardware information to MassiveStats
settings:
- default-auction-time: 150 # 15 Minutes by default
+ default-auction-time: 900 # 15 Minutes by default
max-auction-price: 2000000000
max-auction-start: 2000000000
max-auction-increment: 2000000000