Fix bug where items added to the backpack were not saved correctly

This commit is contained in:
GeorgH93 2020-02-25 01:00:46 +01:00
parent 160efba42e
commit fbf76b19dc
No known key found for this signature in database
GPG Key ID: D1630D37F9E4B3C8
3 changed files with 6 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2019 GeorgH93
* Copyright (C) 2020 GeorgH93
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -123,6 +123,7 @@ public interface Backpack extends InventoryHolder
*/
default @NotNull Map<Integer, ItemStack> addItems(ItemStack... itemStacks)
{
setChanged();
return getInventory().addItem(itemStacks);
}
}

View File

@ -28,8 +28,8 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.scheduler.BukkitTask;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class ItemsCollector extends BukkitRunnable
{
@ -69,7 +69,7 @@ public class ItemsCollector extends BukkitRunnable
if(!item.isDead() && item.getPickupDelay() <= 0)
{
if(itemFilter != null && itemFilter.isItemBlocked(item.getItemStack())) continue;
HashMap<Integer, ItemStack> full = backpack.getInventory().addItem(item.getItemStack());
Map<Integer, ItemStack> full = backpack.addItems(item.getItemStack());
backpack.setChanged();
if(!full.isEmpty())
{

View File

@ -44,7 +44,6 @@ import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.Nullable;
import java.util.Iterator;
import java.util.Map;
import java.util.UUID;
public class ItemShortcut implements Listener
@ -178,8 +177,8 @@ public class ItemShortcut implements Listener
final ItemStack stack = event.getCursor();
if(plugin.getItemFilter() == null || !plugin.getItemFilter().isItemBlocked(stack))
{
Map<Integer, ItemStack> full = backpack.getInventory().addItem(stack);
stack.setAmount((full.isEmpty()) ? 0 : full.get(0).getAmount());
ItemStack full = backpack.addItem(stack);
stack.setAmount((full == null) ? 0 : full.getAmount());
event.setCancelled(true);
}
else