From 2896ac51941202d5c652cab224462667458e9ed3 Mon Sep 17 00:00:00 2001 From: Krakenied Date: Thu, 22 Feb 2024 18:58:46 +0100 Subject: Improve CoreProtect check behaviour even more Add CoreProtect block lookup delay option --- .../bukkit/hook/coreprotect/CoreProtectHook.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'bukkit/src/main/java') diff --git a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/coreprotect/CoreProtectHook.java b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/coreprotect/CoreProtectHook.java index 516f5ae2..e2bf8e78 100644 --- a/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/coreprotect/CoreProtectHook.java +++ b/bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/coreprotect/CoreProtectHook.java @@ -23,6 +23,7 @@ public class CoreProtectHook implements AbstractCoreProtectHook { CompletableFuture future = new CompletableFuture<>(); plugin.getScheduler().doAsync(() -> { List queueLookup = api.queueLookup(block); + if (queueLookup.size() >= 2) { // first queue element when breaking a block is always // a break action so we just get the second one @@ -38,7 +39,17 @@ public class CoreProtectHook implements AbstractCoreProtectHook { } } + long blockLookupDelay = plugin.getConfig().getLong("options.coreprotect-block-lookup-delay", -1L); + if (blockLookupDelay > 0L) { + try { + Thread.sleep(blockLookupDelay); + } catch (InterruptedException ignored) { + } + } + List blockLookup = api.blockLookup(block, time); + boolean first = true; + for (String[] result : blockLookup) { CoreProtectAPI.ParseResult parseResult = api.parseResult(result); @@ -47,6 +58,13 @@ public class CoreProtectHook implements AbstractCoreProtectHook { continue; } + // we need to skip first break interaction too in case it's already been inserted + if (first && parseResult.getActionId() == 0) { + first = false; + + continue; + } + // due to the order the first element that is not // an interaction is always the one we need to check // (0=removed, 1=placed, 2=interaction) -- cgit v1.2.3-70-g09d2