diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java index 2919bcb08..d38d1a675 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoNet.java @@ -8,13 +8,12 @@ import java.util.List; import java.util.Map; import java.util.Optional; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import org.bukkit.Location; import org.bukkit.block.Block; -import org.bukkit.block.BlockState; import org.bukkit.inventory.Inventory; -import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.api.network.Network; @@ -274,7 +273,8 @@ public class CargoNet extends ChestTerminalNetwork { } private void routeItems(Location inputNode, Block inputTarget, int frequency, Map> outputNodes) { - ItemStackAndInteger slot = CargoUtils.withdraw(inputNode.getBlock(), inputTarget); + AtomicReference inventory = new AtomicReference<>(); + ItemStackAndInteger slot = CargoUtils.withdraw(inputNode.getBlock(), inputTarget, inventory); if (slot == null) { return; @@ -289,9 +289,11 @@ public class CargoNet extends ChestTerminalNetwork { } if (stack != null) { - DirtyChestMenu menu = CargoUtils.getChestMenu(inputTarget); + Object inputInventory = inventory.get(); + + if (inputInventory instanceof DirtyChestMenu) { + DirtyChestMenu menu = (DirtyChestMenu) inputInventory; - if (menu != null) { if (menu.getItemInSlot(previousSlot) == null) { menu.replaceExistingItem(previousSlot, stack); } @@ -299,18 +301,15 @@ public class CargoNet extends ChestTerminalNetwork { inputTarget.getWorld().dropItem(inputTarget.getLocation().add(0, 1, 0), stack); } } - else if (CargoUtils.hasInventory(inputTarget)) { - BlockState state = inputTarget.getState(); - if (state instanceof InventoryHolder) { - Inventory inv = ((InventoryHolder) state).getInventory(); + if (inputInventory instanceof Inventory) { + Inventory inv = (Inventory) inputInventory; - if (inv.getItem(previousSlot) == null) { - inv.setItem(previousSlot, stack); - } - else { - inputTarget.getWorld().dropItem(inputTarget.getLocation().add(0, 1, 0), stack); - } + if (inv.getItem(previousSlot) == null) { + inv.setItem(previousSlot, stack); + } + else { + inputTarget.getWorld().dropItem(inputTarget.getLocation().add(0, 1, 0), stack); } } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java index 8d1be290e..0d4426c94 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/CargoUtils.java @@ -2,6 +2,7 @@ package io.github.thebusybiscuit.slimefun4.core.networks.cargo; import java.util.LinkedList; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import org.bukkit.Material; @@ -153,7 +154,7 @@ final class CargoUtils { return null; } - static ItemStackAndInteger withdraw(Block node, Block target) { + static ItemStackAndInteger withdraw(Block node, Block target, AtomicReference inventory) { DirtyChestMenu menu = getChestMenu(target); if (menu != null) { @@ -162,6 +163,7 @@ final class CargoUtils { if (matchesFilter(node, is)) { menu.replaceExistingItem(slot, null); + inventory.set(menu); return new ItemStackAndInteger(is, slot); } } @@ -189,6 +191,7 @@ final class CargoUtils { if (matchesFilter(node, is)) { inv.setItem(slot, null); + inventory.set(inv); return new ItemStackAndInteger(is, slot); } } diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java index 7ccfa5606..2edafc0e7 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/networks/cargo/ChestTerminalNetwork.java @@ -12,6 +12,7 @@ import java.util.Map; import java.util.Optional; import java.util.Queue; import java.util.Set; +import java.util.concurrent.atomic.AtomicReference; import org.bukkit.Location; import org.bukkit.Material; @@ -194,7 +195,7 @@ abstract class ChestTerminalNetwork extends Network { Optional target = getAttachedBlock(bus.getBlock()); if (target.isPresent()) { - ItemStackAndInteger stack = CargoUtils.withdraw(bus.getBlock(), target.get()); + ItemStackAndInteger stack = CargoUtils.withdraw(bus.getBlock(), target.get(), new AtomicReference<>()); if (stack != null) { menu.replaceExistingItem(17, stack.getItem()); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java index 1b88383f4..2e549ef20 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/profiler/PerformanceRating.java @@ -24,7 +24,8 @@ public enum PerformanceRating implements Predicate { OKAY(ChatColor.GREEN, 30), MODERATE(ChatColor.YELLOW, 55), SEVERE(ChatColor.RED, 85), - HURTFUL(ChatColor.DARK_RED, Float.MAX_VALUE); + HURTFUL(ChatColor.DARK_RED, 500), + BAD(ChatColor.DARK_RED, Float.MAX_VALUE); private final ChatColor color; private final float threshold; diff --git a/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java b/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java index 9a8f979a6..97b5c1b65 100644 --- a/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java +++ b/src/main/java/me/mrCookieSlime/Slimefun/api/Slimefun.java @@ -231,6 +231,10 @@ public final class Slimefun { return null; } + if (SlimefunPlugin.instance == null || !SlimefunPlugin.instance.isEnabled()) { + return null; + } + return Bukkit.getScheduler().runTask(SlimefunPlugin.instance, r); } @@ -240,6 +244,10 @@ public final class Slimefun { return null; } + if (SlimefunPlugin.instance == null || !SlimefunPlugin.instance.isEnabled()) { + return null; + } + return Bukkit.getScheduler().runTaskLater(SlimefunPlugin.instance, r, delay); } } \ No newline at end of file