Moved add item method to sync.

This commit is contained in:
Brianna 2021-01-03 10:48:17 -06:00
parent cc0f4df840
commit 29828da0be
2 changed files with 6 additions and 4 deletions

View File

@ -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());

View File

@ -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()));
Bukkit.getScheduler().runTask(plugin, () -> {
Methods.animate(farm.getLocation(), cropTypeData.getYieldMaterial());
farm.addItem(stack);
});
if (getCollectionType(farm) != CollectionType.NO_SEEDS)
farm.addItem(seedStack);
return true;