Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-20 21:40:06 +01:00
Fixed rare NPEs with CraftItemStack. This fixes BUKKIT-51
Dieser Commit ist enthalten in:
Ursprung
4ce061ccbe
Commit
d02a2eb49d
@ -3,7 +3,6 @@ package org.bukkit.craftbukkit.inventory;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.minecraft.server.EnchantmentManager;
|
import net.minecraft.server.EnchantmentManager;
|
||||||
import net.minecraft.server.NBTBase;
|
|
||||||
import net.minecraft.server.NBTTagCompound;
|
import net.minecraft.server.NBTTagCompound;
|
||||||
import net.minecraft.server.NBTTagList;
|
import net.minecraft.server.NBTTagList;
|
||||||
import org.bukkit.enchantments.Enchantment;
|
import org.bukkit.enchantments.Enchantment;
|
||||||
@ -135,7 +134,7 @@ public class CraftItemStack extends ItemStack {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMaxStackSize() {
|
public int getMaxStackSize() {
|
||||||
return item.getItem().getMaxStackSize();
|
return (item == null) ? 0 : item.getItem().getMaxStackSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -152,6 +151,7 @@ public class CraftItemStack extends ItemStack {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getEnchantmentLevel(Enchantment ench) {
|
public int getEnchantmentLevel(Enchantment ench) {
|
||||||
|
if (item == null) return 0;
|
||||||
return EnchantmentManager.getEnchantmentLevel(ench.getId(), item);
|
return EnchantmentManager.getEnchantmentLevel(ench.getId(), item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ public class CraftItemStack extends ItemStack {
|
|||||||
@Override
|
@Override
|
||||||
public Map<Enchantment, Integer> getEnchantments() {
|
public Map<Enchantment, Integer> getEnchantments() {
|
||||||
Map<Enchantment, Integer> result = new HashMap<Enchantment, Integer>();
|
Map<Enchantment, Integer> result = new HashMap<Enchantment, Integer>();
|
||||||
NBTTagList list = item.getEnchantments();
|
NBTTagList list = (item == null) ? null : item.getEnchantments();
|
||||||
|
|
||||||
if (list == null) {
|
if (list == null) {
|
||||||
return result;
|
return result;
|
||||||
@ -185,6 +185,8 @@ public class CraftItemStack extends ItemStack {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void rebuildEnchantments(Map<Enchantment, Integer> enchantments) {
|
private void rebuildEnchantments(Map<Enchantment, Integer> enchantments) {
|
||||||
|
if (item == null) return;
|
||||||
|
|
||||||
NBTTagCompound tag = item.tag;
|
NBTTagCompound tag = item.tag;
|
||||||
NBTTagList list = new NBTTagList("ench");
|
NBTTagList list = new NBTTagList("ench");
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren