aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrakenied <Krakenied1@gmail.com>2023-12-14 10:45:24 +0100
committerLeonardo Bishop <13875753+LMBishop@users.noreply.github.com>2023-12-21 16:09:02 +0000
commit98e55ac17ce1d433ca0ba45ac2c03f370fcc7251 (patch)
tree73d8086bf7568942e6c11f9755e09af5a4742a13
parentee59747c8b645eaf0fd52d0e1b3573d0bcc976b8 (diff)
Fix CoreProtect delay caused by queue
Closes https://github.com/LMBishop/Quests/issues/162
-rw-r--r--bukkit/src/main/java/com/leonardobishop/quests/bukkit/hook/coreprotect/CoreProtectHook.java44
1 files changed, 34 insertions, 10 deletions
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 6d905736..516f5ae2 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
@@ -3,7 +3,6 @@ package com.leonardobishop.quests.bukkit.hook.coreprotect;
import com.leonardobishop.quests.bukkit.BukkitQuestsPlugin;
import net.coreprotect.CoreProtect;
import net.coreprotect.CoreProtectAPI;
-import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import java.util.List;
@@ -16,25 +15,50 @@ public class CoreProtectHook implements AbstractCoreProtectHook {
public CoreProtectHook(BukkitQuestsPlugin plugin) {
this.plugin = plugin;
- api = ((CoreProtect) Bukkit.getPluginManager().getPlugin("CoreProtect")).getAPI();
+ this.api = CoreProtect.getInstance().getAPI();
}
@Override
public CompletableFuture<Boolean> checkBlock(Block block, int time) {
CompletableFuture<Boolean> future = new CompletableFuture<>();
plugin.getScheduler().doAsync(() -> {
- List<String[]> lookup = api.blockLookup(block, time);
- if (lookup.isEmpty()) {
- plugin.getScheduler().doSync(() -> future.complete(false));
- } else {
- String[] result = lookup.get(0);
+ List<String[]> 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
+ String[] result = queueLookup.get(1);
CoreProtectAPI.ParseResult parseResult = api.parseResult(result);
- boolean value = !parseResult.getPlayer().isEmpty() && parseResult.getActionId() == 1;
- plugin.getScheduler().doSync(() -> future.complete(value));
+ // queue lookup returns only break and place actions
+ // so we dont need to skip all the interations (action id 2)
+ // https://github.com/PlayPro/CoreProtect/blob/master/src/main/java/net/coreprotect/api/QueueLookup.java#L55
+ if (!parseResult.getPlayer().isEmpty() && parseResult.getActionId() == 1) {
+ plugin.getScheduler().doSync(() -> future.complete(true));
+ return;
+ }
}
+
+ List<String[]> blockLookup = api.blockLookup(block, time);
+ for (String[] result : blockLookup) {
+ CoreProtectAPI.ParseResult parseResult = api.parseResult(result);
+
+ // we need to skip all the interations like door opening (action id 2)
+ if (parseResult.getActionId() == 2) {
+ 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)
+ // https://docs.coreprotect.net/api/version/v9/#parseresult-parseresultstring-result
+ boolean placed = parseResult.getActionId() == 1;
+
+ plugin.getScheduler().doSync(() -> future.complete(placed));
+ return;
+ }
+
+ plugin.getScheduler().doSync(() -> future.complete(false));
});
return future;
}
-
}