Merge pull request #36 from Foorcee/inventory

Fix "lapis lazuli may disappear when inventory is full?"
This commit is contained in:
Gero 2021-10-18 17:27:40 +02:00 committed by GitHub
commit b0986504b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
package de.gerrygames.viarewind.legacysupport.listener;
import com.viaversion.viaversion.api.Via;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
@ -11,6 +12,8 @@ import org.bukkit.inventory.EnchantingInventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import java.util.Map;
public class EnchantingListener implements Listener {
private final boolean newMaterialNames = Material.getMaterial("LAPIS_LAZULI") != null;
@ -54,6 +57,12 @@ public class EnchantingListener implements Listener {
ItemStack item = inventory.getSecondary();
if (item==null || item.getType()==Material.AIR) return;
inventory.setSecondary(new ItemStack(Material.AIR));
playerInventory.addItem(item);
Map<Integer, ItemStack> remaining = playerInventory.addItem(item);
if (!remaining.isEmpty()) {
Location location = player.getLocation();
for (ItemStack value : remaining.values()) {
player.getWorld().dropItem(location, value);
}
}
}
}