From 29828da0beb82bcae8f8b27c831a6063dc3d58ec Mon Sep 17 00:00:00 2001 From: Brianna Date: Sun, 3 Jan 2021 10:48:17 -0600 Subject: [PATCH] Moved add item method to sync. --- src/main/java/com/songoda/epicfarming/farming/Farm.java | 3 ++- .../farming/levels/modules/ModuleAutoCollect.java | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/songoda/epicfarming/farming/Farm.java b/src/main/java/com/songoda/epicfarming/farming/Farm.java index 2b72a2a..33bcb16 100644 --- a/src/main/java/com/songoda/epicfarming/farming/Farm.java +++ b/src/main/java/com/songoda/epicfarming/farming/Farm.java @@ -176,8 +176,9 @@ public class Farm { return Collections.unmodifiableList(items); } + // Should be used in sync. public void addItem(ItemStack toAdd) { - for (ItemStack item : new ArrayList<>(getItems())) { + for (ItemStack item : new ArrayList<>(items)) { if (item.getType() != toAdd.getType() || item.getAmount() + toAdd.getAmount() > item.getMaxStackSize()) continue; item.setAmount(item.getAmount() + toAdd.getAmount()); diff --git a/src/main/java/com/songoda/epicfarming/farming/levels/modules/ModuleAutoCollect.java b/src/main/java/com/songoda/epicfarming/farming/levels/modules/ModuleAutoCollect.java index 41c2656..5d0d6bf 100644 --- a/src/main/java/com/songoda/epicfarming/farming/levels/modules/ModuleAutoCollect.java +++ b/src/main/java/com/songoda/epicfarming/farming/levels/modules/ModuleAutoCollect.java @@ -220,9 +220,10 @@ public class ModuleAutoCollect extends Module { ItemStack seedStack = new ItemStack(cropTypeData.getSeedMaterial(), random.nextInt(3) + 1 + (useBoneMeal(farm) ? 1 : 0)); if (!farm.willFit(stack) || !farm.willFit(seedStack)) return false; - Bukkit.getScheduler().runTask(plugin, () -> - Methods.animate(farm.getLocation(), cropTypeData.getYieldMaterial())); - farm.addItem(stack); + Bukkit.getScheduler().runTask(plugin, () -> { + Methods.animate(farm.getLocation(), cropTypeData.getYieldMaterial()); + farm.addItem(stack); + }); if (getCollectionType(farm) != CollectionType.NO_SEEDS) farm.addItem(seedStack); return true;