bug fixes and completely new filter system

This commit is contained in:
Kiran Hart 2021-06-21 12:59:14 -04:00
parent bcb0df88a6
commit 04178d9910
19 changed files with 517 additions and 195 deletions

View File

@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>ca.tweetzy</groupId>
<artifactId>auctionhouse</artifactId>
<version>2.13.3</version>
<version>2.14.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -137,7 +137,7 @@
<dependency>
<groupId>ca.tweetzy</groupId>
<artifactId>tweetycore</artifactId>
<version>2.4.0</version>
<version>2.5.1</version>
</dependency>
<dependency>
<groupId>com.github.MilkBowl</groupId>

View File

@ -255,6 +255,23 @@ public class AuctionAPI {
return lore;
}
/**
* Used to get the names of all the enchantments on an item
*
* @param stack is the itemstack being checked
* @return a list of all the enchantment names
*/
public List<String> getItemEnchantments(ItemStack stack) {
List<String> enchantments = new ArrayList<>();
Objects.requireNonNull(stack, "Item Stack cannot be null when getting enchantments");
if (!stack.getEnchantments().isEmpty()) {
stack.getEnchantments().forEach((k, i) -> {
enchantments.add(k.getName());
});
}
return enchantments;
}
/**
* Used to match patterns
*
@ -265,7 +282,22 @@ public class AuctionAPI {
public boolean match(String pattern, String sentence) {
Pattern patt = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
Matcher matcher = patt.matcher(sentence);
return matcher.find();
return matcher.matches();
}
/**
*
* @param pattern is the keyword that you're currently searching for
* @param lines is the lines being checked for the keyword
* @return whether the keyword was found in any of the lines provided
*/
public boolean match(String pattern, List<String> lines) {
for (String line : lines) {
if (match(pattern, line)) {
return true;
}
}
return false;
}
/**
@ -397,95 +429,4 @@ public class AuctionAPI {
ItemUtils.addGlow(item);
return item;
}
/**
* Used to end an auction
*
* @param item is the auction item you want to end
*/
public void endAuction(AuctionItem item) {
// check if the auction item owner is the same as the highest bidder
if (item.getOwner().equals(item.getHighestBidder())) {
// was not sold
item.setExpired(true);
} else {
// the item was sold ?? then do the checks
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(item.getHighestBidder());
AuctionEndEvent auctionEndEvent;
if (offlinePlayer.isOnline()) {
if (AuctionHouse.getInstance().getEconomy().has(offlinePlayer, item.getCurrentPrice())) {
auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(item.getOwner()), offlinePlayer, item, AuctionSaleType.USED_BIDDING_SYSTEM);
AuctionHouse.getInstance().getServer().getPluginManager().callEvent(auctionEndEvent);
if (!auctionEndEvent.isCancelled()) {
// withdraw money and give to the owner
AuctionHouse.getInstance().getEconomy().withdrawPlayer(offlinePlayer, item.getCurrentPrice());
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(item.getOwner()), item.getCurrentPrice());
// send a message to each of them
AuctionHouse.getInstance().getLocale().getMessage("auction.bidwon")
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getType().name().replace("_", " ")))
.processPlaceholder("amount", AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getAmount())
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice()))
.sendPrefixedMessage(offlinePlayer.getPlayer());
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice())).sendPrefixedMessage(offlinePlayer.getPlayer());
// if the original owner is online, let them know they sold an item
if (Bukkit.getOfflinePlayer(item.getOwner()).isOnline()) {
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getType().name().replace("_", " ")))
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice()))
.processPlaceholder("buyer_name", Bukkit.getOfflinePlayer(item.getHighestBidder()).getName())
.sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
}
// since they're online, try to add the item to their inventory
// TODO CLEAN THIS UP A BIT
if (Settings.ALLOW_PURCHASE_IF_INVENTORY_FULL.getBoolean()) {
PlayerUtils.giveItem(offlinePlayer.getPlayer(), AuctionAPI.getInstance().deserializeItem(item.getRawItem()));
AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey());
} else {
if (offlinePlayer.getPlayer().getInventory().firstEmpty() == -1) {
item.setOwner(offlinePlayer.getUniqueId());
item.setExpired(true);
} else {
PlayerUtils.giveItem(offlinePlayer.getPlayer(), AuctionAPI.getInstance().deserializeItem(item.getRawItem()));
AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey());
}
}
}
} else {
// they don't have enough money to buy it, so send it back to the original owner
item.setExpired(true);
}
} else {
// offline, so save their purchase in the collection inventory
if (AuctionHouse.getInstance().getEconomy().has(offlinePlayer, item.getCurrentPrice())) {
auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(item.getOwner()), offlinePlayer, item, AuctionSaleType.USED_BIDDING_SYSTEM);
AuctionHouse.getInstance().getServer().getPluginManager().callEvent(auctionEndEvent);
if (!auctionEndEvent.isCancelled()) {
// withdraw money and give to the owner
AuctionHouse.getInstance().getEconomy().withdrawPlayer(offlinePlayer, item.getCurrentPrice());
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(item.getOwner()), item.getCurrentPrice());
if (Bukkit.getOfflinePlayer(item.getOwner()).isOnline()) {
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(item.getRawItem()).getType().name().replace("_", " ")))
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice()))
.processPlaceholder("buyer_name", Bukkit.getOfflinePlayer(item.getHighestBidder()).getName())
.sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(item.getCurrentPrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(item.getOwner()).getPlayer());
}
item.setOwner(offlinePlayer.getUniqueId());
item.setExpired(true);
}
} else {
// they don't have enough money to buy it, so send it back to the original owner
item.setExpired(true);
}
}
}
}
}

View File

@ -103,7 +103,7 @@ public class AuctionItem implements Serializable {
lore.addAll(Settings.AUCTION_PURCHASE_CONTROL_HEADER.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
lore.addAll(this.bidStartPrice <= 0 || this.bidIncPrice <= 0 ? Settings.AUCTION_PURCHASE_CONTROLS_BID_OFF.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()) : Settings.AUCTION_PURCHASE_CONTROLS_BID_ON.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
if (NBTEditor.contains(itemStack, "AuctionBundleItem") || (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11) && itemStack.getType().name().contains("SHULKER_BOX")) || (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_14) && itemStack.getType() == XMaterial.SHULKER_BOX.parseMaterial() || itemStack.getType() == XMaterial.BARREL.parseMaterial())) {
if (NBTEditor.contains(itemStack, "AuctionBundleItem") || (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_11) && itemStack.getType().name().contains("SHULKER_BOX"))) {
lore.addAll(Settings.AUCTION_PURCHASE_CONTROLS_INSPECTION.getStringList().stream().map(TextUtils::formatText).collect(Collectors.toList()));
}

View File

@ -15,7 +15,12 @@ public enum AuctionItemCategory {
ARMOR("Armor"),
BLOCKS("Blocks"),
TOOLS("Tools"),
MISC("Misc");
WEAPONS("Weapons"),
SPAWNERS("Spawners"),
ENCHANTS("Enchants"),
MISC("Misc"),
SEARCH("Search"),
SELF("Self");
private final String type;
@ -42,6 +47,16 @@ public enum AuctionItemCategory {
return AuctionHouse.getInstance().getLocale().getMessage("auction_filter.categories.tools").getMessage();
case MISC:
return AuctionHouse.getInstance().getLocale().getMessage("auction_filter.categories.misc").getMessage();
case ENCHANTS:
return AuctionHouse.getInstance().getLocale().getMessage("auction_filter.categories.enchants").getMessage();
case SPAWNERS:
return AuctionHouse.getInstance().getLocale().getMessage("auction_filter.categories.spawners").getMessage();
case WEAPONS:
return AuctionHouse.getInstance().getLocale().getMessage("auction_filter.categories.weapons").getMessage();
case SELF:
return AuctionHouse.getInstance().getLocale().getMessage("auction_filter.categories.self").getMessage();
case SEARCH:
return AuctionHouse.getInstance().getLocale().getMessage("auction_filter.categories.search").getMessage();
}
return getType();
}

View File

@ -5,9 +5,6 @@ import lombok.Getter;
import lombok.Setter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
@ -24,28 +21,28 @@ public class AuctionPlayer {
private final Player player;
private AuctionSaleType selectedSaleType;
private AuctionItemCategory selectedFilter;
private AuctionSortType auctionSortType;
private String currentSearchPhrase;
public AuctionPlayer(Player player) {
this.player = player;
resetFilter();
}
public List<AuctionItem> getItems(boolean getExpired) {
List<AuctionItem> auctionItems = AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems();
List<AuctionItem> items = new ArrayList<>();
synchronized (auctionItems) {
Iterator<AuctionItem> iterator = auctionItems.iterator();
while(iterator.hasNext()) {
AuctionItem item = iterator.next();
if (item.getOwner().equals(this.player.getUniqueId()) && item.isExpired() == getExpired) {
items.add(item);
}
}
}
// return Collections.unmodifiableList(AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().stream().filter(item -> item.getOwner().equals(this.player.getUniqueId()) && item.isExpired() == getExpired).collect(Collectors.toList()));
return items;
return AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().stream().filter(item -> item.getOwner().equals(this.player.getUniqueId()) && !AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().contains(item) && item.isExpired() == getExpired).collect(Collectors.toList());
}
public void resetFilter() {
this.selectedFilter = AuctionItemCategory.ALL;
this.auctionSortType = AuctionSortType.RECENT;
this.selectedSaleType = AuctionSaleType.BOTH;
this.currentSearchPhrase = "";
}
public int getSellLimit() {
if (player.hasPermission("auctionhouse.maxsell.*")) return Integer.MAX_VALUE;
for (int i = 1001; i > 0; i--) {

View File

@ -12,7 +12,6 @@ public enum AuctionSaleType {
USED_BIDDING_SYSTEM("Biddable"),
WITHOUT_BIDDING_SYSTEM("Not Biddable"),
// Didn't feel like making an entirely new enumeration, so BOTH is really only used in the auction filtering
BOTH("All");
private final String type;

View File

@ -0,0 +1,40 @@
package ca.tweetzy.auctionhouse.auction;
import ca.tweetzy.auctionhouse.AuctionHouse;
/**
* The current file has been created by Kiran Hart
* Date Created: June 18 2021
* Time Created: 3:00 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
public enum AuctionSortType {
RECENT("Recent"),
PRICE("Price");
final String type;
AuctionSortType(String type) {
this.type = type;
}
public String getTranslatedType() {
switch(this) {
case PRICE:
return AuctionHouse.getInstance().getLocale().getMessage("auction_filter.sort_order.price").getMessage();
case RECENT:
return AuctionHouse.getInstance().getLocale().getMessage("auction_filter.sort_order.recent").getMessage();
default:
return getType();
}
}
public String getType() {
return type;
}
public AuctionSortType next() {
return values()[(this.ordinal() + 1) % values().length];
}
}

View File

@ -227,8 +227,8 @@ public class CommandSell extends AbstractCommand {
.processPlaceholder("amount", itemToSell.getAmount())
.processPlaceholder("item", AuctionAPI.getInstance().getItemName(itemToSell))
.processPlaceholder("base_price", listingPrices.get(0) <= -1 ? AuctionHouse.getInstance().getLocale().getMessage("auction.biditemwithdisabledbuynow").getMessage() : AuctionAPI.getInstance().formatNumber(listingPrices.get(0)))
.processPlaceholder("start_price", AuctionAPI.getInstance().formatNumber(listingPrices.get(1)))
.processPlaceholder("increment_price", AuctionAPI.getInstance().formatNumber(listingPrices.get(2)))::sendPrefixedMessage);
.processPlaceholder("start_price", isBiddingItem ? AuctionAPI.getInstance().formatNumber(listingPrices.get(1)) : 0)
.processPlaceholder("increment_price", isBiddingItem ? AuctionAPI.getInstance().formatNumber(listingPrices.get(2)) : 0)::sendPrefixedMessage);
}
return ReturnType.SUCCESS;
}

View File

@ -82,7 +82,7 @@ public class GUIActiveAuctions extends Gui {
break;
case RIGHT:
if (Settings.ALLOW_PLAYERS_TO_ACCEPT_BID.getBoolean() && item.getBidStartPrice() != 0 && !item.getHighestBidder().equals(e.player.getUniqueId())) {
AuctionHouse.newChain().async(() -> AuctionAPI.getInstance().endAuction(item)).sync(this::draw).execute();
item.setRemainingTime(0);
}
break;
}

View File

@ -8,7 +8,6 @@ import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.managers.SoundManager;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.compatibility.ServerVersion;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.gui.Gui;
import ca.tweetzy.core.gui.events.GuiClickEvent;
import ca.tweetzy.core.utils.TextUtils;
@ -31,7 +30,6 @@ import java.util.stream.Collectors;
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
// TODO CLEAN UP THE ENTIRE CLICK SYSTEM, IT'S KINDA MESSY
public class GUIAuctionHouse extends Gui {
final AuctionPlayer auctionPlayer;
@ -39,8 +37,6 @@ public class GUIAuctionHouse extends Gui {
private int taskId;
private BukkitTask task;
private AuctionItemCategory filterCategory = AuctionItemCategory.ALL;
private AuctionSaleType filterAuctionType = AuctionSaleType.BOTH;
private String searchPhrase = "";
public GUIAuctionHouse(AuctionPlayer auctionPlayer) {
@ -62,12 +58,6 @@ public class GUIAuctionHouse extends Gui {
this.searchPhrase = phrase;
}
public GUIAuctionHouse(AuctionPlayer auctionPlayer, AuctionItemCategory filterCategory, AuctionSaleType filterAuctionType) {
this(auctionPlayer);
this.filterCategory = filterCategory;
this.filterAuctionType = filterAuctionType;
}
public void draw() {
reset();
drawFixedButtons();
@ -76,39 +66,36 @@ public class GUIAuctionHouse extends Gui {
private void drawItems() {
AuctionHouse.newChain().asyncFirst(() -> {
List<AuctionItem> filteredItems = new ArrayList<>();
this.items = AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().stream().filter(auctionItem -> !auctionItem.isExpired() && auctionItem.getRemainingTime() >= 1).collect(Collectors.toList());
synchronized (this.items) {
Iterator<AuctionItem> iterator = this.items.iterator();
while (iterator.hasNext()) {
AuctionItem item = iterator.next();
if (!item.isExpired() && item.getRemainingTime() >= 1) {
filteredItems.add(item);
}
// do the filter here now
if (this.searchPhrase != null && this.searchPhrase.length() != 0) {
filteredItems = filteredItems.stream().filter(auctionItem ->
AuctionAPI.getInstance().match(this.searchPhrase, auctionItem.getItemName()) ||
AuctionAPI.getInstance().match(this.searchPhrase, auctionItem.getCategory().getTranslatedType()) ||
AuctionAPI.getInstance().match(this.searchPhrase, Bukkit.getOfflinePlayer(auctionItem.getOwner()).getName())) // TODO add enchantment searching
.collect(Collectors.toList());
}
if (this.filterCategory != AuctionItemCategory.ALL) {
filteredItems = filteredItems.stream().filter(auctionItem -> auctionItem.getCategory() == this.filterCategory).collect(Collectors.toList());
}
if (this.filterAuctionType != AuctionSaleType.BOTH) {
filteredItems = filteredItems.stream().filter(auctionItem -> this.filterAuctionType == AuctionSaleType.USED_BIDDING_SYSTEM ? auctionItem.getBidStartPrice() >= Settings.MIN_AUCTION_START_PRICE.getDouble() : auctionItem.getBidStartPrice() <= 0).collect(Collectors.toList());
}
}
this.items = new ArrayList<>(AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems()).stream().filter(item -> !item.isExpired() && item.getRemainingTime() >= 1 && !AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().contains(item)).collect(Collectors.toList());
if (this.searchPhrase != null && this.searchPhrase.length() != 0) {
this.items = this.items.stream().filter(item -> checkSearchCriteria(this.searchPhrase, item)).collect(Collectors.toList());
}
filteredItems = filteredItems.stream().skip((page - 1) * 45L).limit(45).sorted(Comparator.comparingInt(AuctionItem::getRemainingTime).reversed()).collect(Collectors.toList());
return filteredItems;
if (this.auctionPlayer.getSelectedFilter() != AuctionItemCategory.ALL && this.auctionPlayer.getSelectedFilter() != AuctionItemCategory.SEARCH && this.auctionPlayer.getSelectedFilter() != AuctionItemCategory.SELF) {
this.items = this.items.stream().filter(item -> item.getCategory() == this.auctionPlayer.getSelectedFilter()).collect(Collectors.toList());
} else if (this.auctionPlayer.getSelectedFilter() == AuctionItemCategory.SELF) {
this.items = this.items.stream().filter(item -> item.getOwner().equals(this.auctionPlayer.getPlayer().getUniqueId())).collect(Collectors.toList());
} else if (this.auctionPlayer.getSelectedFilter() == AuctionItemCategory.SEARCH && this.auctionPlayer.getCurrentSearchPhrase().length() != 0) {
this.items = this.items.stream().filter(item -> checkSearchCriteria(this.auctionPlayer.getCurrentSearchPhrase(), item)).collect(Collectors.toList());
}
if (this.auctionPlayer.getSelectedSaleType() == AuctionSaleType.USED_BIDDING_SYSTEM) {
this.items = this.items.stream().filter(item -> item.getBidStartPrice() >= 1 && item.getBidIncPrice() >= 1).collect(Collectors.toList());
}
if (this.auctionPlayer.getSelectedSaleType() == AuctionSaleType.WITHOUT_BIDDING_SYSTEM) {
this.items = this.items.stream().filter(item -> item.getBidStartPrice() <= 0 && item.getBidIncPrice() <= 0).collect(Collectors.toList());
}
if (this.auctionPlayer.getAuctionSortType() == AuctionSortType.PRICE) {
this.items = this.items.stream().sorted(Comparator.comparingDouble(AuctionItem::getCurrentPrice).reversed()).collect(Collectors.toList());
}
if (this.auctionPlayer.getAuctionSortType() == AuctionSortType.RECENT) {
this.items = this.items.stream().sorted(Comparator.comparingDouble(AuctionItem::getRemainingTime).reversed()).collect(Collectors.toList());
}
return this.items.stream().skip((page - 1) * 45L).limit(45L).collect(Collectors.toList());
}).asyncLast((data) -> {
pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) 45L));
drawPaginationButtons();
@ -116,6 +103,14 @@ public class GUIAuctionHouse extends Gui {
}).execute();
}
private boolean checkSearchCriteria(String phrase, AuctionItem item) {
return AuctionAPI.getInstance().match(phrase, item.getItemName()) ||
AuctionAPI.getInstance().match(phrase, item.getCategory().getTranslatedType()) ||
AuctionAPI.getInstance().match(phrase, Bukkit.getOfflinePlayer(item.getOwner()).getName()) ||
AuctionAPI.getInstance().match(phrase, AuctionAPI.getInstance().getItemLore(AuctionAPI.getInstance().deserializeItem(item.getRawItem()))) ||
AuctionAPI.getInstance().match(phrase, AuctionAPI.getInstance().getItemEnchantments(AuctionAPI.getInstance().deserializeItem(item.getRawItem())));
}
/*
====================== CLICK HANDLES ======================
*/
@ -192,7 +187,7 @@ public class GUIAuctionHouse extends Gui {
if (Settings.SEND_REMOVED_ITEM_BACK_TO_PLAYER.getBoolean()) {
AuctionHouse.getInstance().getAuctionItemManager().getItem(auctionItem.getKey()).setExpired(true);
} else {
AuctionHouse.getInstance().getAuctionItemManager().removeItem(auctionItem.getKey());
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(auctionItem);
}
cleanup();
@ -316,29 +311,99 @@ public class GUIAuctionHouse extends Gui {
}
private void drawFilterButton() {
if (Settings.USE_SEPARATE_FILTER_MENU.getBoolean()) {
String materialToBeUsed = Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_ITEM.getString();
switch (auctionPlayer.getSelectedFilter()) {
case ALL:
materialToBeUsed = Settings.GUI_FILTER_ITEMS_ALL_ITEM.getString();
break;
case ARMOR:
materialToBeUsed = Settings.GUI_FILTER_ITEMS_ARMOR_ITEM.getString();
break;
case BLOCKS:
materialToBeUsed = Settings.GUI_FILTER_ITEMS_BLOCKS_ITEM.getString();
break;
case TOOLS:
materialToBeUsed = Settings.GUI_FILTER_ITEMS_TOOLS_ITEM.getString();
break;
case WEAPONS:
materialToBeUsed = Settings.GUI_FILTER_ITEMS_WEAPONS_ITEM.getString();
break;
case SPAWNERS:
materialToBeUsed = Settings.GUI_FILTER_ITEMS_SPAWNERS_ITEM.getString();
break;
case ENCHANTS:
materialToBeUsed = Settings.GUI_FILTER_ITEMS_ENCHANTS_ITEM.getString();
break;
case MISC:
materialToBeUsed = Settings.GUI_FILTER_ITEMS_MISC_ITEM.getString();
break;
case SEARCH:
materialToBeUsed = Settings.GUI_FILTER_ITEMS_SEARCH_ITEM.getString();
break;
case SELF:
materialToBeUsed = "PLAYER_HEAD";
break;
}
HashMap<String, Object> replacements = new HashMap<String, Object>() {{
put("%filter_category%", auctionPlayer.getSelectedFilter().getTranslatedType());
put("%filter_auction_type%", auctionPlayer.getSelectedSaleType().getTranslatedType());
put("%filter_sort_order%", auctionPlayer.getAuctionSortType().getTranslatedType());
}};
ItemStack item = materialToBeUsed.equalsIgnoreCase("PLAYER_HEAD") ? ConfigurationItemHelper.createConfigurationItem(AuctionAPI.getInstance().getPlayerHead(this.auctionPlayer.getPlayer().getName()), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_LORE.getStringList(), replacements) : ConfigurationItemHelper.createConfigurationItem(materialToBeUsed, Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_LORE.getStringList(), replacements);
setButton(5, 2, item, e -> {
switch (e.clickType) {
case LEFT:
e.manager.showGUI(e.player, new GUIFilterSelection(this.auctionPlayer));
break;
case MIDDLE:
this.auctionPlayer.resetFilter();
draw();
break;
case RIGHT:
this.auctionPlayer.setSelectedSaleType(this.auctionPlayer.getSelectedSaleType().next());
draw();
break;
case SHIFT_RIGHT:
this.auctionPlayer.setAuctionSortType(this.auctionPlayer.getAuctionSortType().next());
draw();
break;
}
});
return;
}
setButton(5, 2, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_ITEM.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_NAME.getString(), Settings.GUI_AUCTION_HOUSE_ITEMS_FILTER_LORE.getStringList(), new HashMap<String, Object>() {{
put("%filter_category%", filterCategory.getTranslatedType());
put("%filter_auction_type%", filterAuctionType.getTranslatedType());
put("%filter_category%", auctionPlayer.getSelectedFilter().getTranslatedType());
put("%filter_auction_type%", auctionPlayer.getSelectedSaleType().getTranslatedType());
put("%filter_sort_order%", auctionPlayer.getAuctionSortType().getTranslatedType());
}}), e -> {
switch (e.clickType) {
case MIDDLE:
this.auctionPlayer.resetFilter();
draw();
break;
case LEFT:
this.filterCategory = this.filterCategory.next();
this.auctionPlayer.setSelectedFilter(this.auctionPlayer.getSelectedFilter().next());
draw();
break;
case RIGHT:
this.filterAuctionType = this.filterAuctionType.next();
this.auctionPlayer.setSelectedSaleType(this.auctionPlayer.getSelectedSaleType().next());
draw();
break;
case SHIFT_RIGHT:
this.auctionPlayer.setAuctionSortType(this.auctionPlayer.getAuctionSortType().next());
draw();
break;
}
});
}
private void updateFilter() {
setItems(0, 44, XMaterial.AIR.parseItem());
drawItems();
drawFilterButton();
}
/*
====================== AUTO REFRESH ======================
*/

View File

@ -118,7 +118,7 @@ public class GUIConfirmPurchase extends Gui {
transferFunds(e.player, this.purchaseQuantity * this.pricePerItem);
} else {
transferFunds(e.player, located.getBasePrice());
AuctionHouse.getInstance().getAuctionItemManager().removeItem(located.getKey());
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(located);
}
PlayerUtils.giveItem(e.player, item);
@ -126,7 +126,7 @@ public class GUIConfirmPurchase extends Gui {
} else {
transferFunds(e.player, located.getBasePrice());
AuctionHouse.getInstance().getAuctionItemManager().removeItem(located.getKey());
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(located);
PlayerUtils.giveItem(e.player, AuctionAPI.getInstance().deserializeItem(located.getRawItem()));
sendMessages(e, located, false, 0);
}

View File

@ -52,7 +52,7 @@ public class GUIExpiredItems extends Gui {
setButton(5, 0, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_CLOSE_BTN_ITEM.getString(), Settings.GUI_CLOSE_BTN_NAME.getString(), Settings.GUI_CLOSE_BTN_LORE.getStringList(), null), e -> e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer)));
setButton(5, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_EXPIRED_AUCTIONS_ITEM.getString(), Settings.GUI_EXPIRED_AUCTIONS_NAME.getString(), Settings.GUI_EXPIRED_AUCTIONS_LORE.getStringList(), null), e -> {
this.auctionPlayer.getItems(true).forEach(item -> {
AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey());
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(item);
PlayerUtils.giveItem(e.player, AuctionAPI.getInstance().deserializeItem(item.getRawItem()));
});
draw();
@ -62,7 +62,7 @@ public class GUIExpiredItems extends Gui {
int slot = 0;
for (AuctionItem item : data) {
setButton(slot++, AuctionAPI.getInstance().deserializeItem(item.getRawItem()), e -> {
AuctionHouse.getInstance().getAuctionItemManager().removeItem(item.getKey());
AuctionHouse.getInstance().getAuctionItemManager().sendToGarbage(item);
PlayerUtils.giveItem(e.player, AuctionAPI.getInstance().deserializeItem(item.getRawItem()));
draw();
});

View File

@ -0,0 +1,104 @@
package ca.tweetzy.auctionhouse.guis;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.auction.AuctionItemCategory;
import ca.tweetzy.auctionhouse.auction.AuctionPlayer;
import ca.tweetzy.auctionhouse.helpers.ConfigurationItemHelper;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.gui.Gui;
import ca.tweetzy.core.gui.GuiUtils;
import ca.tweetzy.core.input.ChatPrompt;
import ca.tweetzy.core.utils.TextUtils;
import java.util.HashMap;
/**
* The current file has been created by Kiran Hart
* Date Created: June 18 2021
* Time Created: 2:10 p.m.
* Usage of any code found within this class is prohibited unless given explicit permission otherwise
*/
//TODO IN the main auction house, switch the filter icon to the currently selected filter
public class GUIFilterSelection extends Gui {
final AuctionPlayer auctionPlayer;
public GUIFilterSelection(AuctionPlayer auctionPlayer) {
this.auctionPlayer = auctionPlayer;
setTitle(TextUtils.formatText(Settings.GUI_FILTER_TITLE.getString()));
setRows(4);
setAcceptsItems(false);
setDefaultItem(Settings.GUI_FILTER_BG_ITEM.getMaterial().parseItem());
setUseLockedCells(true);
draw();
setOnClose(closed -> closed.manager.showGUI(closed.player, new GUIAuctionHouse(this.auctionPlayer)));
}
private void draw() {
setButton(1, 3, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_ITEMS_ALL_ITEM.getString(), Settings.GUI_FILTER_ITEMS_ALL_NAME.getString(), Settings.GUI_FILTER_ITEMS_ALL_LORE.getStringList(), null), e -> {
this.auctionPlayer.setSelectedFilter(AuctionItemCategory.ALL);
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
});
setButton(1, 4, GuiUtils.createButtonItem(AuctionAPI.getInstance().getPlayerHead(this.auctionPlayer.getPlayer().getName()), TextUtils.formatText(Settings.GUI_FILTER_ITEMS_OWN_NAME.getString()), TextUtils.formatText(Settings.GUI_FILTER_ITEMS_OWN_LORE.getStringList())), e -> {
this.auctionPlayer.setSelectedFilter(AuctionItemCategory.SELF);
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
});
setButton(1, 5, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_ITEMS_SEARCH_ITEM.getString(), Settings.GUI_FILTER_ITEMS_SEARCH_NAME.getString(), Settings.GUI_FILTER_ITEMS_SEARCH_LORE.getStringList(), new HashMap<String, Object>(){{
put("%filter_search_phrase%", auctionPlayer.getCurrentSearchPhrase());
}}), e -> {
//TODO ADD AN ACTUAL MESSAGE NODE FOR THIS
e.gui.exit();
ChatPrompt.showPrompt(AuctionHouse.getInstance(), this.auctionPlayer.getPlayer(), AuctionHouse.getInstance().getLocale().getMessage("general.entersearchphrase").getMessage(), chat -> {
if (chat.getMessage() != null && chat.getMessage().length() !=0) {
// the keyword is valid
this.auctionPlayer.setCurrentSearchPhrase(chat.getMessage().trim());
this.auctionPlayer.setSelectedFilter(AuctionItemCategory.SEARCH);
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
}
});
});
setButton(2, 1, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_ITEMS_MISC_ITEM.getString(), Settings.GUI_FILTER_ITEMS_MISC_NAME.getString(), Settings.GUI_FILTER_ITEMS_MISC_LORE.getStringList(), null), e -> {
this.auctionPlayer.setSelectedFilter(AuctionItemCategory.MISC);
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
});
setButton(2, 2, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_ITEMS_ENCHANTS_ITEM.getString(), Settings.GUI_FILTER_ITEMS_ENCHANTS_NAME.getString(), Settings.GUI_FILTER_ITEMS_ENCHANTS_LORE.getStringList(), null), e -> {
this.auctionPlayer.setSelectedFilter(AuctionItemCategory.ENCHANTS);
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
});
setButton(2, 3, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_ITEMS_ARMOR_ITEM.getString(), Settings.GUI_FILTER_ITEMS_ARMOR_NAME.getString(), Settings.GUI_FILTER_ITEMS_ARMOR_LORE.getStringList(), null), e -> {
this.auctionPlayer.setSelectedFilter(AuctionItemCategory.ARMOR);
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
});
setButton(2, 4, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_ITEMS_WEAPONS_ITEM.getString(), Settings.GUI_FILTER_ITEMS_WEAPONS_NAME.getString(), Settings.GUI_FILTER_ITEMS_WEAPONS_LORE.getStringList(), null), e -> {
this.auctionPlayer.setSelectedFilter(AuctionItemCategory.WEAPONS);
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
});
setButton(2, 5, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_ITEMS_TOOLS_ITEM.getString(), Settings.GUI_FILTER_ITEMS_TOOLS_NAME.getString(), Settings.GUI_FILTER_ITEMS_TOOLS_LORE.getStringList(), null), e -> {
this.auctionPlayer.setSelectedFilter(AuctionItemCategory.TOOLS);
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
});
setButton(2, 6, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_ITEMS_SPAWNERS_ITEM.getString(), Settings.GUI_FILTER_ITEMS_SPAWNERS_NAME.getString(), Settings.GUI_FILTER_ITEMS_SPAWNERS_LORE.getStringList(), null), e -> {
this.auctionPlayer.setSelectedFilter(AuctionItemCategory.SPAWNERS);
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
});
setButton(2, 7, ConfigurationItemHelper.createConfigurationItem(Settings.GUI_FILTER_ITEMS_BLOCKS_ITEM.getString(), Settings.GUI_FILTER_ITEMS_BLOCKS_NAME.getString(), Settings.GUI_FILTER_ITEMS_BLOCKS_LORE.getStringList(), null), e -> {
this.auctionPlayer.setSelectedFilter(AuctionItemCategory.BLOCKS);
e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
});
}
}

View File

@ -2,11 +2,14 @@ package ca.tweetzy.auctionhouse.helpers;
import ca.tweetzy.core.compatibility.XMaterial;
import ca.tweetzy.core.utils.TextUtils;
import ca.tweetzy.core.utils.nms.NBTEditor;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
@ -17,12 +20,12 @@ import java.util.stream.Collectors;
*/
public class ConfigurationItemHelper {
public static ItemStack createConfigurationItem(String item, String title, List<String> lore, HashMap<String, Object> replacements) {
ItemStack stack = XMaterial.matchXMaterial(item.toUpperCase()).orElse(XMaterial.RED_STAINED_GLASS_PANE).parseItem();
public static ItemStack createConfigurationItem(ItemStack stack, String title, List<String> lore, HashMap<String, Object> replacements, String... nbtData) {
ItemMeta meta = stack.getItemMeta();
assert meta != null;
meta.setDisplayName(TextUtils.formatText(title));
if (replacements != null) {
if (replacements != null) {
for (String key : replacements.keySet()) {
if (title.contains(key)) title = title.replace(key, String.valueOf(replacements.get(key)));
}
@ -39,6 +42,15 @@ public class ConfigurationItemHelper {
meta.setDisplayName(TextUtils.formatText(title));
meta.setLore(lore.stream().map(TextUtils::formatText).collect(Collectors.toList()));
stack.setItemMeta(meta);
if (nbtData != null) {
for (String nbt : nbtData) {
stack = NBTEditor.set(stack, nbt.split(";")[1], nbt.split(";")[0]);
}
}
return stack;
}
public static ItemStack createConfigurationItem(String item, String title, List<String> lore, HashMap<String, Object> replacements) {
return createConfigurationItem(Objects.requireNonNull(XMaterial.matchXMaterial(item).get().parseItem()), title, lore, replacements);
}
}

View File

@ -1,6 +1,7 @@
package ca.tweetzy.auctionhouse.helpers;
import ca.tweetzy.auctionhouse.auction.AuctionItemCategory;
import ca.tweetzy.core.compatibility.XMaterial;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
@ -17,10 +18,19 @@ public class MaterialCategorizer {
}
public static AuctionItemCategory getMaterialCategory(Material material) {
if (material == XMaterial.SPAWNER.parseMaterial()) return AuctionItemCategory.SPAWNERS;
if (material.isEdible()) return AuctionItemCategory.FOOD;
if (material.isBlock()) return AuctionItemCategory.BLOCKS;
if (material == XMaterial.ENCHANTED_BOOK.parseMaterial()) return AuctionItemCategory.ENCHANTS;
// Armor filter
if (material.name().endsWith("_HELMET") || material.name().endsWith("_CHESTPLATE") || material.name().endsWith("_LEGGINGS") || material.name().endsWith("_BOOTS")) return AuctionItemCategory.ARMOR;
if (material.name().endsWith("_AXE") || material.name().endsWith("_PICKAXE") || material.name().endsWith("_SWORD") || material.name().endsWith("_HOE") || material.name().endsWith("SHOVEL") || material.name().equals("BOW")) return AuctionItemCategory.TOOLS;
// Weapon Filter
if (material.name().endsWith("_SWORD") || material.name().equals("BOW") || material.name().equals("TRIDENT") || material.name().equals("CROSSBOW")) return AuctionItemCategory.WEAPONS;
// Tool Filter
if (material.name().endsWith("_AXE") || material.name().endsWith("_PICKAXE") || material.name().endsWith("_HOE") || material.name().endsWith("SHOVEL")) return AuctionItemCategory.TOOLS;
return AuctionItemCategory.MISC;
}
}

View File

@ -20,14 +20,16 @@ import java.util.stream.Collectors;
public class AuctionItemManager {
private final ArrayList<AuctionItem> auctionItems = new ArrayList<>();
private final Set<AuctionItem> garbageBin = new HashSet<>();
public void addItem(AuctionItem auctionItem) {
if (auctionItem == null) return;
this.auctionItems.add(auctionItem);
}
public void removeItem(UUID uuid) {
this.auctionItems.removeIf(item -> item.getKey().equals(uuid));
public void sendToGarbage(AuctionItem auctionItem) {
if (auctionItem == null) return;
this.garbageBin.add(auctionItem);
}
public void removeUnknownOwnerItems() {
@ -40,7 +42,11 @@ public class AuctionItemManager {
}
public List<AuctionItem> getAuctionItems() {
return Collections.synchronizedList(this.auctionItems);
return this.auctionItems;
}
public Set<AuctionItem> getGarbageBin() {
return garbageBin;
}
public void loadItems(boolean useDatabase) {

View File

@ -33,6 +33,7 @@ public class LocaleSettings {
languageNodes.put("general.endedallauctions", "&cYou force ended all active auctions");
languageNodes.put("general.relisteditems", "&aYou relisted all expired items!");
languageNodes.put("general.cannotsellbundleditem", "&cYou cannot sell a bundled item as a bundle.");
languageNodes.put("general.entersearchphrase", "&Enter a search phrase into chat");
languageNodes.put("pricing.minbaseprice", "&cThe minimum base price must be &a$%price%");
@ -68,6 +69,14 @@ public class LocaleSettings {
languageNodes.put("auction_filter.categories.blocks", "Blocks");
languageNodes.put("auction_filter.categories.tools", "Tools");
languageNodes.put("auction_filter.categories.misc", "Misc");
languageNodes.put("auction_filter.categories.spawners", "Spawners");
languageNodes.put("auction_filter.categories.enchants", "Enchants");
languageNodes.put("auction_filter.categories.weapons", "Weapons");
languageNodes.put("auction_filter.categories.self", "Self");
languageNodes.put("auction_filter.categories.search", "Search");
languageNodes.put("auction_filter.sort_order.recent", "Recent");
languageNodes.put("auction_filter.sort_order.price", "Price");
languageNodes.put("auction.listed.withbid", "&eListed &fx%amount% &6%item% &e&lBuy Now&f: &a%base_price% &e&lStarting&f: &a%start_price% &e&lIncrement&f: &a%increment_price%");
languageNodes.put("auction.listed.nobid", "&eListed &fx%amount% &6%item% &efor &a%base_price%");

View File

@ -63,6 +63,8 @@ public class Settings {
public static final ConfigSetting DATE_FORMAT = new ConfigSetting(config, "auction setting.date format", "MMM dd, yyyy hh:mm aa", "You can learn more about date formats by googling SimpleDateFormat patterns or visiting this link", "https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html");
public static final ConfigSetting ALLOW_PLAYERS_TO_ACCEPT_BID = new ConfigSetting(config, "auction setting.allow players to accept bid", true, "If true, players can right click a biddable item inside their active listings menu to accept the current bid");
public static final ConfigSetting USE_SEPARATE_FILTER_MENU = new ConfigSetting(config, "auction setting.use separate filter menu", false, "If true, rather than using a single filter item inside the auction menu", "it will open an entirely new menu to select the filter");
public static final ConfigSetting ALLOW_ITEM_BUNDLES = new ConfigSetting(config, "auction setting.bundles.enabled", true, "If true, players can use -b in the sell command to bundle all similar items into a single item.");
public static final ConfigSetting ITEM_BUNDLE_ITEM = new ConfigSetting(config, "auction setting.bundles.item", XMaterial.GOLD_BLOCK.name());
public static final ConfigSetting ITEM_BUNDLE_NAME = new ConfigSetting(config, "auction setting.bundles.name", "%item_name% &7Bundle");
@ -300,9 +302,25 @@ public class Settings {
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_LORE = new ConfigSetting(config, "gui.auction house.items.filter.lore", Arrays.asList(
"&eItem Category&f: &7%filter_category%",
"&eAuction Type&f: &7%filter_auction_type%",
"&eSort Order&f: &7%filter_sort_order%",
"",
"&7Left-Click to change item category",
"&7Right-Click to change change auction type"
"&7Right-Click to change change auction type",
"&7Shift Right-Click to change sort order",
"&7Middle-Click to reset filters"
));
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_ITEM = new ConfigSetting(config, "gui.auction house.items.filter menu.item", "HOPPER");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_NAME = new ConfigSetting(config, "gui.auction house.items.filter menu.name", "&e&lCurrent Filter&f: &6%filter_category%");
public static final ConfigSetting GUI_AUCTION_HOUSE_ITEMS_FILTER_MENU_LORE = new ConfigSetting(config, "gui.auction house.items.filter menu.lore", Arrays.asList(
"&eItem Category&f: &7%filter_category%",
"&eAuction Type&f: &7%filter_auction_type%",
"&eSort Order&f: &7%filter_sort_order%",
"",
"&7Left-Click to change item category",
"&7Right-Click to change change auction type",
"&7Shift Right-Click to change sort order",
"&7Middle-Click to reset filters"
));
/* ===============================
@ -458,6 +476,54 @@ public class Settings {
public static final ConfigSetting GUI_INSPECT_TITLE = new ConfigSetting(config, "gui.inspect.title", "&7&LInspecting Container");
public static final ConfigSetting GUI_INSPECT_BG_ITEM = new ConfigSetting(config, "gui.inspect.bg item", XMaterial.BLACK_STAINED_GLASS_PANE.name());
/* ===============================
* FILTER GUI
* ===============================*/
public static final ConfigSetting GUI_FILTER_TITLE = new ConfigSetting(config, "gui.filter.title", "&7Auction House - &eFilter Selection");
public static final ConfigSetting GUI_FILTER_BG_ITEM = new ConfigSetting(config, "gui.filter.bg item", XMaterial.BLACK_STAINED_GLASS_PANE.name());
public static final ConfigSetting GUI_FILTER_ITEMS_ALL_ITEM = new ConfigSetting(config, "gui.filter.items.all.item", XMaterial.HOPPER.name());
public static final ConfigSetting GUI_FILTER_ITEMS_ALL_NAME = new ConfigSetting(config, "gui.filter.items.all.name", "&e&lAll");
public static final ConfigSetting GUI_FILTER_ITEMS_ALL_LORE = new ConfigSetting(config, "gui.filter.items.all.lore", Collections.singletonList("&7Click to set the filter to&f: &eAll"));
public static final ConfigSetting GUI_FILTER_ITEMS_OWN_NAME = new ConfigSetting(config, "gui.filter.items.own.name", "&e&lYour Listings");
public static final ConfigSetting GUI_FILTER_ITEMS_OWN_LORE = new ConfigSetting(config, "gui.filter.items.own.lore", Collections.singletonList("&7Click to set the filter to&f: &eYour Listings"));
public static final ConfigSetting GUI_FILTER_ITEMS_SEARCH_ITEM = new ConfigSetting(config, "gui.filter.items.search.item", XMaterial.NAME_TAG.name());
public static final ConfigSetting GUI_FILTER_ITEMS_SEARCH_NAME = new ConfigSetting(config, "gui.filter.items.search.name", "&e&lSearch");
public static final ConfigSetting GUI_FILTER_ITEMS_SEARCH_LORE = new ConfigSetting(config, "gui.filter.items.search.lore", Arrays.asList(
"&7Click to set the filter to&f: &eSearch",
"&7Current search phrase&f: &e%filter_search_phrase%"
));
public static final ConfigSetting GUI_FILTER_ITEMS_MISC_ITEM = new ConfigSetting(config, "gui.filter.items.misc.item", XMaterial.OAK_SIGN.name());
public static final ConfigSetting GUI_FILTER_ITEMS_MISC_NAME = new ConfigSetting(config, "gui.filter.items.misc.name", "&e&lMiscellaneous");
public static final ConfigSetting GUI_FILTER_ITEMS_MISC_LORE = new ConfigSetting(config, "gui.filter.items.misc.lore", Collections.singletonList("&7Click to set the filter to&f: &eMiscellaneous"));
public static final ConfigSetting GUI_FILTER_ITEMS_ENCHANTS_ITEM = new ConfigSetting(config, "gui.filter.items.enchants.item", XMaterial.ENCHANTED_BOOK.name());
public static final ConfigSetting GUI_FILTER_ITEMS_ENCHANTS_NAME = new ConfigSetting(config, "gui.filter.items.enchants.name", "&e&lEnchantments");
public static final ConfigSetting GUI_FILTER_ITEMS_ENCHANTS_LORE = new ConfigSetting(config, "gui.filter.items.enchants.lore", Collections.singletonList("&7Click to set the filter to&f: &eEnchantments"));
public static final ConfigSetting GUI_FILTER_ITEMS_ARMOR_ITEM = new ConfigSetting(config, "gui.filter.items.armor.item", XMaterial.CHAINMAIL_CHESTPLATE.name());
public static final ConfigSetting GUI_FILTER_ITEMS_ARMOR_NAME = new ConfigSetting(config, "gui.filter.items.armor.name", "&e&lArmor");
public static final ConfigSetting GUI_FILTER_ITEMS_ARMOR_LORE = new ConfigSetting(config, "gui.filter.items.armor.lore", Collections.singletonList("&7Click to set the filter to&f: &eArmor"));
public static final ConfigSetting GUI_FILTER_ITEMS_WEAPONS_ITEM = new ConfigSetting(config, "gui.filter.items.weapons.item", XMaterial.DIAMOND_SWORD.name());
public static final ConfigSetting GUI_FILTER_ITEMS_WEAPONS_NAME = new ConfigSetting(config, "gui.filter.items.weapons.name", "&e&lWeapons");
public static final ConfigSetting GUI_FILTER_ITEMS_WEAPONS_LORE = new ConfigSetting(config, "gui.filter.items.weapons.lore", Collections.singletonList("&7Click to set the filter to&f: &eWeapons"));
public static final ConfigSetting GUI_FILTER_ITEMS_TOOLS_ITEM = new ConfigSetting(config, "gui.filter.items.tools.item", XMaterial.IRON_PICKAXE.name());
public static final ConfigSetting GUI_FILTER_ITEMS_TOOLS_NAME = new ConfigSetting(config, "gui.filter.items.tools.name", "&e&lTools");
public static final ConfigSetting GUI_FILTER_ITEMS_TOOLS_LORE = new ConfigSetting(config, "gui.filter.items.tools.lore", Collections.singletonList("&7Click to set the filter to&f: &eTools"));
public static final ConfigSetting GUI_FILTER_ITEMS_SPAWNERS_ITEM = new ConfigSetting(config, "gui.filter.items.spawners.item", XMaterial.CREEPER_SPAWN_EGG.name());
public static final ConfigSetting GUI_FILTER_ITEMS_SPAWNERS_NAME = new ConfigSetting(config, "gui.filter.items.spawners.name", "&e&LSpawners");
public static final ConfigSetting GUI_FILTER_ITEMS_SPAWNERS_LORE = new ConfigSetting(config, "gui.filter.items.spawners.lore", Collections.singletonList("&7Click to set the filter to&f: &eSpawners"));
public static final ConfigSetting GUI_FILTER_ITEMS_BLOCKS_ITEM = new ConfigSetting(config, "gui.filter.items.blocks.item", XMaterial.GOLD_BLOCK.name());
public static final ConfigSetting GUI_FILTER_ITEMS_BLOCKS_NAME = new ConfigSetting(config, "gui.filter.items.blocks.name", "&e&lBlocks");
public static final ConfigSetting GUI_FILTER_ITEMS_BLOCKS_LORE = new ConfigSetting(config, "gui.filter.items.blocks.lore", Collections.singletonList("&7Click to set the filter to&f: &eBlocks"));
/* ===============================
* AUCTION STACKS

View File

@ -2,12 +2,17 @@ package ca.tweetzy.auctionhouse.tasks;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
import ca.tweetzy.auctionhouse.api.events.AuctionEndEvent;
import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.auction.AuctionSaleType;
import ca.tweetzy.auctionhouse.settings.Settings;
import ca.tweetzy.core.utils.PlayerUtils;
import org.apache.commons.lang.WordUtils;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Iterator;
import java.util.List;
/**
* The current file has been created by Kiran Hart
@ -32,25 +37,78 @@ public class TickAuctionsTask extends BukkitRunnable {
public void run() {
// check if the auction stack even has items
List<AuctionItem> auctionItems = AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems();
Iterator<AuctionItem> auctionItemIterator = AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().listIterator();
synchronized (auctionItems) {
if (auctionItems.size() == 0) {
return;
while (auctionItemIterator.hasNext()) {
AuctionItem auctionItem = auctionItemIterator.next();
if (AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().contains(auctionItem)) {
AuctionHouse.getInstance().getAuctionItemManager().getGarbageBin().remove(auctionItem);
auctionItemIterator.remove();
continue;
}
Iterator<AuctionItem> iterator = auctionItems.iterator();
while (iterator.hasNext()) {
AuctionItem item = iterator.next();
if (!item.isExpired()) {
item.updateRemainingTime(Settings.TICK_UPDATE_TIME.getInt());
if (!auctionItem.isExpired()) {
auctionItem.updateRemainingTime(Settings.TICK_UPDATE_TIME.getInt());
}
if (auctionItem.getRemainingTime() <= 0) {
if (auctionItem.getOwner().equals(auctionItem.getHighestBidder())) {
auctionItem.setExpired(true);
continue;
}
if (item.getRemainingTime() <= 0) {
AuctionAPI.getInstance().endAuction(item);
OfflinePlayer auctionWinner = Bukkit.getOfflinePlayer(auctionItem.getHighestBidder());
if (!AuctionHouse.getInstance().getEconomy().has(auctionWinner, auctionItem.getCurrentPrice())) {
auctionItem.setExpired(true);
continue;
}
AuctionEndEvent auctionEndEvent = new AuctionEndEvent(Bukkit.getOfflinePlayer(auctionItem.getOwner()), auctionWinner, auctionItem, AuctionSaleType.USED_BIDDING_SYSTEM);
AuctionHouse.getInstance().getServer().getPluginManager().callEvent(auctionEndEvent);
if (!auctionEndEvent.isCancelled()) continue;
AuctionHouse.getInstance().getEconomy().withdrawPlayer(auctionWinner, auctionItem.getCurrentPrice());
AuctionHouse.getInstance().getEconomy().depositPlayer(Bukkit.getOfflinePlayer(auctionItem.getOwner()), auctionItem.getCurrentPrice());
if (Bukkit.getOfflinePlayer(auctionItem.getOwner()).isOnline()) {
AuctionHouse.getInstance().getLocale().getMessage("auction.itemsold")
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem()).getType().name().replace("_", " ")))
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(auctionItem.getCurrentPrice()))
.processPlaceholder("buyer_name", Bukkit.getOfflinePlayer(auctionItem.getHighestBidder()).getName())
.sendPrefixedMessage(Bukkit.getOfflinePlayer(auctionItem.getOwner()).getPlayer());
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyadd").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(auctionItem.getCurrentPrice())).sendPrefixedMessage(Bukkit.getOfflinePlayer(auctionItem.getOwner()).getPlayer());
}
if (auctionWinner.isOnline()) {
AuctionHouse.getInstance().getLocale().getMessage("auction.bidwon")
.processPlaceholder("item", WordUtils.capitalizeFully(AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem()).getType().name().replace("_", " ")))
.processPlaceholder("amount", AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem()).getAmount())
.processPlaceholder("price", AuctionAPI.getInstance().formatNumber(auctionItem.getCurrentPrice()))
.sendPrefixedMessage(auctionWinner.getPlayer());
AuctionHouse.getInstance().getLocale().getMessage("pricing.moneyremove").processPlaceholder("price", AuctionAPI.getInstance().formatNumber(auctionItem.getCurrentPrice())).sendPrefixedMessage(auctionWinner.getPlayer());
if (Settings.ALLOW_PURCHASE_IF_INVENTORY_FULL.getBoolean()) {
PlayerUtils.giveItem(auctionWinner.getPlayer(), AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem()));
auctionItemIterator.remove();
continue;
}
if (auctionWinner.getPlayer().getInventory().firstEmpty() != -1) {
PlayerUtils.giveItem(auctionWinner.getPlayer(), AuctionAPI.getInstance().deserializeItem(auctionItem.getRawItem()));
auctionItemIterator.remove();
continue;
}
auctionItem.setOwner(auctionWinner.getUniqueId());
auctionItem.setExpired(true);
} else {
auctionItem.setOwner(auctionWinner.getUniqueId());
auctionItem.setExpired(true);
}
}
}
}
}