diff --git a/pom.xml b/pom.xml
index 070e3b6..b5fea12 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
4.0.0
ca.tweetzy
auctionhouse
- 2.13.1
+ 2.13.2
UTF-8
diff --git a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionPlayer.java b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionPlayer.java
index 126c2b1..668f49d 100644
--- a/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionPlayer.java
+++ b/src/main/java/ca/tweetzy/auctionhouse/auction/AuctionPlayer.java
@@ -5,7 +5,9 @@ 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;
@@ -27,7 +29,21 @@ public class AuctionPlayer {
}
public List getItems(boolean getExpired) {
- return Collections.unmodifiableList(AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().stream().filter(item -> item.getOwner().equals(this.player.getUniqueId()) && item.isExpired() == getExpired).collect(Collectors.toList()));
+ List auctionItems = AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems();
+ List items = new ArrayList<>();
+
+ synchronized (auctionItems) {
+ Iterator 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;
}
public int getSellLimit() {
diff --git a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java
index a4892ea..60b45bc 100644
--- a/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java
+++ b/src/main/java/ca/tweetzy/auctionhouse/guis/GUIAuctionHouse.java
@@ -21,10 +21,7 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BlockStateMeta;
import org.bukkit.scheduler.BukkitTask;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -38,7 +35,7 @@ import java.util.stream.Collectors;
public class GUIAuctionHouse extends Gui {
final AuctionPlayer auctionPlayer;
- List items;
+ private List items;
private int taskId;
private BukkitTask task;
@@ -51,6 +48,7 @@ public class GUIAuctionHouse extends Gui {
setTitle(TextUtils.formatText(Settings.GUI_AUCTION_HOUSE_TITLE.getString()));
setRows(6);
setAcceptsItems(false);
+ setAllowShiftClick(false);
draw();
if (Settings.AUTO_REFRESH_AUCTION_PAGES.getBoolean()) {
@@ -78,19 +76,39 @@ public class GUIAuctionHouse extends Gui {
private void drawItems() {
AuctionHouse.newChain().asyncFirst(() -> {
- this.items = AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().stream().filter(item -> !item.isExpired() && item.getRemainingTime() >= 1).collect(Collectors.toList());
+ List filteredItems = new ArrayList<>();
+ this.items = AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().stream().filter(auctionItem -> !auctionItem.isExpired() && auctionItem.getRemainingTime() >= 1).collect(Collectors.toList());
- if (this.searchPhrase != null && this.searchPhrase.length() != 0) {
- this.items = this.items.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())).collect(Collectors.toList());
+ synchronized (this.items) {
+ Iterator 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());
+ }
+ }
}
- if (this.filterCategory != AuctionItemCategory.ALL)
- this.items = items.stream().filter(item -> item.getCategory() == this.filterCategory).collect(Collectors.toList());
-
- if (this.filterAuctionType != AuctionSaleType.BOTH)
- this.items = this.items.stream().filter(item -> this.filterAuctionType == AuctionSaleType.USED_BIDDING_SYSTEM ? item.getBidStartPrice() >= Settings.MIN_AUCTION_START_PRICE.getDouble() : item.getBidStartPrice() <= 0).collect(Collectors.toList());
-
- return this.items.stream().sorted(Comparator.comparingInt(AuctionItem::getRemainingTime).reversed()).skip((page - 1) * 45L).limit(45).collect(Collectors.toList());
+ filteredItems = filteredItems.stream().skip((page - 1) * 45L).limit(45).sorted(Comparator.comparingInt(AuctionItem::getRemainingTime).reversed()).collect(Collectors.toList());
+ return filteredItems;
}).asyncLast((data) -> {
pages = (int) Math.max(1, Math.ceil(this.items.size() / (double) 45L));
drawPaginationButtons();
@@ -293,7 +311,7 @@ public class GUIAuctionHouse extends Gui {
AuctionHouse.getInstance().getAuctionPlayerManager().addCooldown(this.auctionPlayer.getPlayer().getUniqueId());
}
cleanup();
- e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer, this.filterCategory, this.filterAuctionType));
+ e.manager.showGUI(e.player, new GUIAuctionHouse(this.auctionPlayer));
});
}
diff --git a/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionItemManager.java b/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionItemManager.java
index f2e44eb..9414237 100644
--- a/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionItemManager.java
+++ b/src/main/java/ca/tweetzy/auctionhouse/managers/AuctionItemManager.java
@@ -40,7 +40,7 @@ public class AuctionItemManager {
}
public List getAuctionItems() {
- return Collections.unmodifiableList(this.auctionItems);
+ return Collections.synchronizedList(this.auctionItems);
}
public void loadItems(boolean useDatabase) {
diff --git a/src/main/java/ca/tweetzy/auctionhouse/tasks/TickAuctionsTask.java b/src/main/java/ca/tweetzy/auctionhouse/tasks/TickAuctionsTask.java
index 4c563fe..687f20d 100644
--- a/src/main/java/ca/tweetzy/auctionhouse/tasks/TickAuctionsTask.java
+++ b/src/main/java/ca/tweetzy/auctionhouse/tasks/TickAuctionsTask.java
@@ -2,10 +2,12 @@ package ca.tweetzy.auctionhouse.tasks;
import ca.tweetzy.auctionhouse.AuctionHouse;
import ca.tweetzy.auctionhouse.api.AuctionAPI;
+import ca.tweetzy.auctionhouse.auction.AuctionItem;
import ca.tweetzy.auctionhouse.settings.Settings;
import org.bukkit.scheduler.BukkitRunnable;
-import java.util.stream.Collectors;
+import java.util.Iterator;
+import java.util.List;
/**
* The current file has been created by Kiran Hart
@@ -28,24 +30,27 @@ public class TickAuctionsTask extends BukkitRunnable {
@Override
public void run() {
- try {
- // check if the auction stack even has items
- if (AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().size() == 0) {
+
+ // check if the auction stack even has items
+ List auctionItems = AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems();
+
+ synchronized (auctionItems) {
+ if (auctionItems.size() == 0) {
return;
}
- // tick all the auction items
- AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().forEach(item -> {
+ Iterator iterator = auctionItems.iterator();
+ while (iterator.hasNext()) {
+ AuctionItem item = iterator.next();
if (!item.isExpired()) {
item.updateRemainingTime(Settings.TICK_UPDATE_TIME.getInt());
}
- });
- // filter items where the time is less than or equal to 0
- AuctionHouse.getInstance().getAuctionItemManager().getAuctionItems().stream().filter(item -> item.getRemainingTime() <= 0).collect(Collectors.toList()).iterator().forEachRemaining(AuctionAPI.getInstance()::endAuction);
-
- } catch (Exception e) {
- e.printStackTrace();
+ if (item.getRemainingTime() <= 0) {
+ AuctionAPI.getInstance().endAuction(item);
+ }
+ }
}
+
}
}