mirror of
https://github.com/kiranhart/Auction-House.git
synced 2024-11-26 06:05:25 +01:00
improved garbage system, fixed minor bug
Took 3 minutes
This commit is contained in:
parent
c3832374ad
commit
f82eafcf91
@ -4,6 +4,7 @@ import ca.tweetzy.auctionhouse.api.UpdateChecker;
|
||||
import ca.tweetzy.auctionhouse.api.hook.PlaceholderAPIHook;
|
||||
import ca.tweetzy.auctionhouse.api.hook.UltraEconomyHook;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
|
||||
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
|
||||
import ca.tweetzy.auctionhouse.commands.*;
|
||||
import ca.tweetzy.auctionhouse.database.DataManager;
|
||||
import ca.tweetzy.auctionhouse.database.migrations.*;
|
||||
@ -43,6 +44,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
@ -295,6 +297,9 @@ public class AuctionHouse extends TweetyPlugin {
|
||||
@Override
|
||||
public void onPluginDisable() {
|
||||
if (this.dataManager != null) {
|
||||
// clean up the garbage items
|
||||
AuctionHouse.getInstance().getDataManager().deleteItems(AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().values().stream().map(AuctionedItem::getId).collect(Collectors.toList()));
|
||||
|
||||
this.auctionItemManager.end();
|
||||
this.filterManager.saveFilterWhitelist(false);
|
||||
this.auctionBanManager.saveBans(false);
|
||||
|
@ -11,9 +11,6 @@ import ca.tweetzy.auctionhouse.transaction.Transaction;
|
||||
import ca.tweetzy.core.database.DataManagerAbstract;
|
||||
import ca.tweetzy.core.database.DatabaseConnector;
|
||||
import ca.tweetzy.core.database.MySQLConnector;
|
||||
import ca.tweetzy.core.utils.TextUtils;
|
||||
import net.royawesome.jlibnoise.module.combiner.Min;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -199,7 +196,7 @@ public class DataManager extends DataManagerAbstract {
|
||||
}
|
||||
}
|
||||
|
||||
deleteItems(toRemove);
|
||||
deleteItemsAsync(toRemove);
|
||||
callback.accept(null, items);
|
||||
} catch (Exception e) {
|
||||
resolveCallback(callback, e);
|
||||
@ -508,7 +505,7 @@ public class DataManager extends DataManagerAbstract {
|
||||
}
|
||||
|
||||
public void deleteItems(Collection<UUID> items) {
|
||||
this.async(() -> this.databaseConnector.connect(connection -> {
|
||||
this.databaseConnector.connect(connection -> {
|
||||
connection.setAutoCommit(false);
|
||||
PreparedStatement statement = connection.prepareStatement("DELETE FROM " + this.getTablePrefix() + "auctions WHERE id = ?");
|
||||
for (UUID id : items) {
|
||||
@ -518,7 +515,11 @@ public class DataManager extends DataManagerAbstract {
|
||||
|
||||
statement.executeBatch();
|
||||
connection.setAutoCommit(true);
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteItemsAsync(Collection<UUID> items) {
|
||||
this.thread.execute(() -> deleteItems(items));
|
||||
}
|
||||
|
||||
private AuctionedItem extractAuctionedItem(ResultSet resultSet) throws SQLException {
|
||||
|
@ -31,14 +31,14 @@ public final class GarbageBinTask extends BukkitRunnable {
|
||||
|
||||
// timed mode
|
||||
if (Settings.GARBAGE_DELETION_TIMED_MODE.getBoolean()) {
|
||||
AuctionHouse.getInstance().getDataManager().deleteItems(AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().values().stream().map(AuctionedItem::getId).collect(Collectors.toList()));
|
||||
AuctionHouse.getInstance().getDataManager().deleteItemsAsync(AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().values().stream().map(AuctionedItem::getId).collect(Collectors.toList()));
|
||||
AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// item mode
|
||||
if (AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().size() >= Settings.GARBAGE_DELETION_MAX_ITEMS.getInt()) {
|
||||
AuctionHouse.getInstance().getDataManager().deleteItems(AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().values().stream().map(AuctionedItem::getId).collect(Collectors.toList()));
|
||||
AuctionHouse.getInstance().getDataManager().deleteItemsAsync(AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().values().stream().map(AuctionedItem::getId).collect(Collectors.toList()));
|
||||
AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().clear();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user