From 88f8d96b7824e2cb36aa7e144d6ea308a0c9f3ff Mon Sep 17 00:00:00 2001 From: jascotty2 Date: Mon, 12 Aug 2019 09:22:24 -0500 Subject: [PATCH] fix rare double-crash + dead items --- src/main/java/com/songoda/epichoppers/EpicHoppers.java | 4 ++++ .../epichoppers/hopper/levels/modules/ModuleSuction.java | 2 ++ 2 files changed, 6 insertions(+) diff --git a/src/main/java/com/songoda/epichoppers/EpicHoppers.java b/src/main/java/com/songoda/epichoppers/EpicHoppers.java index 816bca9..4ebf83b 100644 --- a/src/main/java/com/songoda/epichoppers/EpicHoppers.java +++ b/src/main/java/com/songoda/epichoppers/EpicHoppers.java @@ -185,6 +185,10 @@ public class EpicHoppers extends JavaPlugin { * Saves registered hoppers to file. */ private void saveToFile() { + // double-check that we're ok to save + if(EpicHoppers.getInstance().getLevelManager() == null) + return; + checkStorage(); for (Level level : EpicHoppers.getInstance().getLevelManager().getLevels().values()) diff --git a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java index 39fdf98..8f1a3e8 100644 --- a/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java +++ b/src/main/java/com/songoda/epichoppers/hopper/levels/modules/ModuleSuction.java @@ -48,6 +48,7 @@ public class ModuleSuction extends Module { Set itemsToSuck = hopper.getLocation().getWorld().getNearbyEntities(hopper.getLocation().add(0.5, 0.5, 0.5), radius, radius, radius) .stream() .filter(entity -> entity.getType() == EntityType.DROPPED_ITEM + && !entity.isDead() && entity.getTicksLived() >= ((Item) entity).getPickupDelay() && entity.getLocation().getBlock().getType() != Material.HOPPER) .map(entity -> (Item) entity) @@ -56,6 +57,7 @@ public class ModuleSuction extends Module { boolean filterEndpoint = hopper.getFilter().getEndPoint() != null; for (Item item : itemsToSuck) { + ItemStack itemStack = item.getItemStack(); if (item.getPickupDelay() == 0) {