From ccddfa53992d868ecc3ae71b71975f1163061b06 Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Mon, 3 Jun 2024 18:55:05 -0500 Subject: [PATCH 1/4] Working spill protect --- .../movecraft/listener/BlockListener.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java index f1188f139..f47118770 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java @@ -187,20 +187,19 @@ public void onBlockDispense(@NotNull BlockDispenseEvent e) { } @EventHandler - public void onFlow(@NotNull BlockFromToEvent e) { - if (Settings.DisableSpillProtection || e.isCancelled()) + public void onFlow(BlockFromToEvent e) { + if (Settings.DisableSpillProtection) return; - Block block = e.getToBlock(); - if (!Tags.FLUID.contains(block.getType())) + if (!e.getBlock().isLiquid()) return; - MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(e.getBlock().getLocation()); MovecraftLocation toLoc = MathUtils.bukkit2MovecraftLoc(e.getToBlock().getLocation()); - Craft craft = MathUtils.fastNearestCraftToLoc(CraftManager.getInstance().getCrafts(), e.getBlock().getLocation()); - if (craft == null || !craft.getHitBox().contains((loc)) || craft.getFluidLocations().contains(toLoc)) - return; - - e.setCancelled(true); + for (Craft craft : CraftManager.getInstance().getCraftsInWorld(e.getBlock().getWorld())) { + if (craft.getHitBox().contains((loc)) && !craft.getFluidLocations().contains(toLoc)) { + e.setCancelled(true); + break; + } + } } @EventHandler From 328f6d8b5cd2a9b3872b312ae2fa277ceec469cf Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Mon, 3 Jun 2024 19:27:02 -0500 Subject: [PATCH 2/4] Start working back toward performance gains --- .../movecraft/listener/BlockListener.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java index f47118770..403b339cc 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java @@ -186,19 +186,18 @@ public void onBlockDispense(@NotNull BlockDispenseEvent e) { e.setCancelled(true); } - @EventHandler + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) public void onFlow(BlockFromToEvent e) { - if (Settings.DisableSpillProtection) - return; - if (!e.getBlock().isLiquid()) + if (Settings.DisableSpillProtection || !Tags.FLUID.contains(e.getBlock().getType())) return; + MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(e.getBlock().getLocation()); MovecraftLocation toLoc = MathUtils.bukkit2MovecraftLoc(e.getToBlock().getLocation()); - for (Craft craft : CraftManager.getInstance().getCraftsInWorld(e.getBlock().getWorld())) { - if (craft.getHitBox().contains((loc)) && !craft.getFluidLocations().contains(toLoc)) { - e.setCancelled(true); - break; - } + for (Craft craft : CraftManager.getInstance().getCrafts()) { + if (craft.getWorld() != e.getBlock().getWorld() || !craft.getHitBox().contains(loc) || craft.getFluidLocations().contains(toLoc)) + continue; + + e.setCancelled(true); } } From 5d5bd9ba3873c652ab790f03f75fc59750f1a33a Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Mon, 3 Jun 2024 20:08:23 -0500 Subject: [PATCH 3/4] More changing back --- .../countercraft/movecraft/listener/BlockListener.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java index 403b339cc..df108498e 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java @@ -186,12 +186,15 @@ public void onBlockDispense(@NotNull BlockDispenseEvent e) { e.setCancelled(true); } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.HIGHEST) public void onFlow(BlockFromToEvent e) { - if (Settings.DisableSpillProtection || !Tags.FLUID.contains(e.getBlock().getType())) + if (Settings.DisableSpillProtection || e.isCancelled()) + return; + Block block = e.getBlock(); + if (!Tags.FLUID.contains(block.getType())) return; - MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(e.getBlock().getLocation()); + MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(block.getLocation()); MovecraftLocation toLoc = MathUtils.bukkit2MovecraftLoc(e.getToBlock().getLocation()); for (Craft craft : CraftManager.getInstance().getCrafts()) { if (craft.getWorld() != e.getBlock().getWorld() || !craft.getHitBox().contains(loc) || craft.getFluidLocations().contains(toLoc)) From fac185e3e03095a07b6df52a0f7dd42e91ff2fad Mon Sep 17 00:00:00 2001 From: TylerS1066 Date: Mon, 3 Jun 2024 20:11:54 -0500 Subject: [PATCH 4/4] Even closer --- .../movecraft/listener/BlockListener.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java b/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java index df108498e..394048dcd 100644 --- a/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java +++ b/modules/Movecraft/src/main/java/net/countercraft/movecraft/listener/BlockListener.java @@ -186,8 +186,8 @@ public void onBlockDispense(@NotNull BlockDispenseEvent e) { e.setCancelled(true); } - @EventHandler(priority = EventPriority.HIGHEST) - public void onFlow(BlockFromToEvent e) { + @EventHandler + public void onFlow(@NotNull BlockFromToEvent e) { if (Settings.DisableSpillProtection || e.isCancelled()) return; Block block = e.getBlock(); @@ -196,12 +196,11 @@ public void onFlow(BlockFromToEvent e) { MovecraftLocation loc = MathUtils.bukkit2MovecraftLoc(block.getLocation()); MovecraftLocation toLoc = MathUtils.bukkit2MovecraftLoc(e.getToBlock().getLocation()); - for (Craft craft : CraftManager.getInstance().getCrafts()) { - if (craft.getWorld() != e.getBlock().getWorld() || !craft.getHitBox().contains(loc) || craft.getFluidLocations().contains(toLoc)) - continue; + Craft craft = MathUtils.fastNearestCraftToLoc(CraftManager.getInstance().getCrafts(), e.getBlock().getLocation()); + if (craft == null || !craft.getHitBox().contains((loc)) || craft.getFluidLocations().contains(toLoc)) + return; - e.setCancelled(true); - } + e.setCancelled(true); } @EventHandler