📦 bundle auto open on claim, closes #42

Took 8 minutes

Took 19 seconds
This commit is contained in:
Kiran Hart 2023-03-19 02:08:56 -04:00
parent 7fa641834d
commit 17865973b7
No known key found for this signature in database
GPG Key ID: 5F36C7BC79D3EBC3
2 changed files with 31 additions and 2 deletions

View File

@ -19,6 +19,7 @@
package ca.tweetzy.auctionhouse.guis;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.ahv3.model.BundleUtil;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.auction.AuctionedItem;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
@ -27,6 +28,7 @@ import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.utils.PlayerUtils;
import ca.tweetzy.core.utils.TextUtils;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import java.util.Comparator;
import java.util.List;
@ -99,12 +101,24 @@ public class GUIExpiredItems extends AbstractPlaceholderGui {
}
for (AuctionedItem auctionItem : data) {
final boolean isBundle = BundleUtil.isBundledItem(auctionItem.getItem());
if (e.player.getInventory().firstEmpty() == -1) {
AuctionHouse.getInstance().getLocale().getMessage("general.noroomclaim").sendPrefixedMessage(e.player);
break;
}
PlayerUtils.giveItem(e.player, auctionItem.getItem());
if (isBundle) {
if (Settings.BUNDLE_IS_OPENED_ON_RECLAIM.getBoolean()) {
final List<ItemStack> bundleItems = BundleUtil.extractBundleItems(auctionItem.getItem());
PlayerUtils.giveItem(e.player, bundleItems);
} else {
PlayerUtils.giveItem(e.player, auctionItem.getItem());
}
} else {
PlayerUtils.giveItem(e.player, auctionItem.getItem()); // I despise these else statements
}
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(auctionItem);
}
@ -116,6 +130,8 @@ public class GUIExpiredItems extends AbstractPlaceholderGui {
setButton(slot++, auctionItem.getItem(), ClickType.LEFT, e -> {
if (!Settings.ALLOW_INDIVIDUAL_ITEM_CLAIM.getBoolean()) return;
final boolean isBundle = BundleUtil.isBundledItem(auctionItem.getItem());
if (e.player.getInventory().firstEmpty() == -1) {
AuctionHouse.getInstance().getLocale().getMessage("general.noroomclaim").sendPrefixedMessage(e.player);
return;
@ -129,8 +145,20 @@ public class GUIExpiredItems extends AbstractPlaceholderGui {
this.lastClicked = System.currentTimeMillis() + Settings.CLAIM_MS_DELAY.getInt();
}
PlayerUtils.giveItem(e.player, auctionItem.getItem());
if (isBundle) {
if (Settings.BUNDLE_IS_OPENED_ON_RECLAIM.getBoolean()) {
final List<ItemStack> bundleItems = BundleUtil.extractBundleItems(auctionItem.getItem());
PlayerUtils.giveItem(e.player, bundleItems);
} else {
PlayerUtils.giveItem(e.player, auctionItem.getItem());
}
} else {
PlayerUtils.giveItem(e.player, auctionItem.getItem()); // I despise these else statements
}// todo this is repeated code, put into own method
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(auctionItem);
e.manager.showGUI(e.player, new GUIExpiredItems(this.auctionPlayer, this.lastClicked));
});
}

View File

@ -94,6 +94,7 @@ public class Settings {
public static final ConfigSetting TICK_UPDATE_GUI_TIME = new ConfigSetting(config, "auction setting.refresh gui every", 10, "How many seconds should pass before the auction gui auto refreshes?");
public static final ConfigSetting RECORD_TRANSACTIONS = new ConfigSetting(config, "auction setting.record transactions", true, "Should every transaction be recorded (everything an auction is won or an item is bought)");
public static final ConfigSetting BUNDLE_IS_OPENED_ON_RECLAIM = new ConfigSetting(config, "auction setting.open bundle on reclaim", true, "When the player claims an expired item, if its a bundle, should it be automatically opened. (items that cannot fit will drop to the ground)");
public static final ConfigSetting BROADCAST_AUCTION_LIST = new ConfigSetting(config, "auction setting.broadcast auction list", false, "Should the entire server be alerted when a player lists an item?");
public static final ConfigSetting BROADCAST_AUCTION_BID = new ConfigSetting(config, "auction setting.broadcast auction bid", false, "Should the entire server be alerted when a player bids on an item?");