From f4a7eaac7a63551490eee1accf60acd5c41f14c7 Mon Sep 17 00:00:00 2001 From: ceze88 Date: Sat, 21 Jan 2023 16:15:24 +0100 Subject: [PATCH] Fix ClassNotFoundException in older versions when dropping items --- .../songoda/ultimatestacker/UltimateStacker.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java index a66e984..f4817cc 100644 --- a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java +++ b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java @@ -53,6 +53,7 @@ import org.apache.commons.lang.WordUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.World; import org.bukkit.entity.EntityType; import org.bukkit.entity.Item; import org.bukkit.entity.Player; @@ -399,10 +400,18 @@ public class UltimateStacker extends SongodaPlugin { */ public static void spawnStackedItem(ItemStack item, int amount, Location location) { if (item.getType() == Material.AIR) return; - Objects.requireNonNull(location.getWorld()).dropItem(location, item, dropped -> { + World world = location.getWorld(); + if (world == null) return; + if (ServerVersion.isServerVersionAtLeast(ServerVersion.V1_17)) { + world.dropItem(location, item, dropped -> { + if (dropped.getItemStack().getType() == Material.AIR) return; + updateItemMeta(dropped, item, amount); + }); + } else { + Item dropped = world.dropItem(location, item); if (dropped.getItemStack().getType() == Material.AIR) return; updateItemMeta(dropped, item, amount); - }); + } } /**