1.0.8, Added auto save, buyers can no longer bid on an item if they don't have enough money (bid increment + current price). debugger is enabled by default in config, and new option to disable hardware info reports

This commit is contained in:
Kiran Hart 2019-04-18 20:01:13 -04:00
parent f160d29d92
commit c5d4210e1c
5 changed files with 68 additions and 12 deletions

View File

@ -6,7 +6,7 @@
<groupId>com.shadebyte</groupId>
<artifactId>auctionhouse</artifactId>
<version>1.0.7</version>
<version>1.0.8</version>
<packaging>jar</packaging>
<name>AuctionHouse</name>

View File

@ -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));

View File

@ -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();

View File

@ -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();

View File

@ -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