diff --git a/src/main/java/net/seyarada/pandeloot/nms/v1_17_R1/V1_17_R1.java b/src/main/java/net/seyarada/pandeloot/nms/v1_17_R1/V1_17_R1.java index aee6598..d43d6ec 100644 --- a/src/main/java/net/seyarada/pandeloot/nms/v1_17_R1/V1_17_R1.java +++ b/src/main/java/net/seyarada/pandeloot/nms/v1_17_R1/V1_17_R1.java @@ -46,7 +46,6 @@ import org.bukkit.craftbukkit.v1_17_R1.util.CraftChatMessage; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; import java.util.ArrayList; @@ -97,10 +96,11 @@ public static void destroyEntity(int toBeDestroyed, Entity entity) { public static void spawnHologram(DamageUtil damageUtil) { UUID uuid = damageUtil.getUUID(); for (UUID playerUUID : DamageTracker.get(uuid).keySet()) { - Player player = Bukkit.getPlayer(playerUUID); + final Player player = Bukkit.getPlayer(playerUUID); + if(player == null) continue; - Location location = Bukkit.getEntity(uuid).getLocation(); - WorldServer wS = ((CraftWorld) location.getWorld()).getHandle(); + final Location location = Bukkit.getEntity(uuid).getLocation(); + final WorldServer wS = ((CraftWorld) location.getWorld()).getHandle(); double lX = location.getX(); double lY = location.getY() + 1.2; double lZ = location.getZ(); @@ -124,22 +124,17 @@ public static void spawnHologram(DamageUtil damageUtil) { PacketPlayOutSpawnEntity packetPlayOutSpawnEntity = new PacketPlayOutSpawnEntity(armorStand, 1); PacketPlayOutEntityMetadata metadata = new PacketPlayOutEntityMetadata(armorStand.getId(), armorStand.getDataWatcher(), true); - if (player != null && player.isOnline() && ((CraftPlayer) player).getHandle() != null) { + if (player.isOnline() && ((CraftPlayer) player).getHandle() != null) { final PlayerConnection connection = ((CraftPlayer) player).getHandle().b; connection.sendPacket(packetPlayOutSpawnEntity); connection.sendPacket(metadata); } - if (player != null) { - new BukkitRunnable() { - @Override - public void run() { - if (player.isOnline()) { - PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(armorStand.getId()); - ((CraftPlayer) player).getHandle().b.sendPacket(destroy); - } - } - }.runTaskLater(PandeLoot.getInstance(), 300); - } + Bukkit.getScheduler().runTaskLater(PandeLoot.getInstance(), () -> { + if (player.isOnline()) { + PacketPlayOutEntityDestroy destroy = new PacketPlayOutEntityDestroy(armorStand.getId()); + ((CraftPlayer) player).getHandle().b.sendPacket(destroy); + } + }, 300); } }