From 1c866e304ecbca57e68d17772c4baf0642bb0a3c Mon Sep 17 00:00:00 2001 From: zontreck Date: Mon, 18 Dec 2023 18:59:52 -0700 Subject: [PATCH] Store last delay, so if a search takes a long time, it does not bog the server down. --- gradle.properties | 2 +- src/main/java/dev/zontreck/essentials/rtp/RTP.java | 7 +++++++ .../dev/zontreck/essentials/rtp/RandomPositionLocator.java | 5 +++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/gradle.properties b/gradle.properties index d278092..a883c45 100644 --- a/gradle.properties +++ b/gradle.properties @@ -49,7 +49,7 @@ mod_name=Aria's Essentials # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=GPLv3 # The mod version. See https://semver.org/ -mod_version=1.1.121823.1657 +mod_version=1.1.121823.1856 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/dev/zontreck/essentials/rtp/RTP.java b/src/main/java/dev/zontreck/essentials/rtp/RTP.java index 47cd648..68e4bd6 100644 --- a/src/main/java/dev/zontreck/essentials/rtp/RTP.java +++ b/src/main/java/dev/zontreck/essentials/rtp/RTP.java @@ -52,6 +52,13 @@ public class RTP public WorldPosition position; private List BLACKLIST = Lists.of(Blocks.LAVA, Blocks.WATER); protected int tries; + protected int lastThreadDelay = 1; + + protected RTP withThreadDelay(int delay) + { + lastThreadDelay=delay; + return this; + } public boolean isDimension(ServerLevel level) { diff --git a/src/main/java/dev/zontreck/essentials/rtp/RandomPositionLocator.java b/src/main/java/dev/zontreck/essentials/rtp/RandomPositionLocator.java index 4f2b88b..8e35d7b 100644 --- a/src/main/java/dev/zontreck/essentials/rtp/RandomPositionLocator.java +++ b/src/main/java/dev/zontreck/essentials/rtp/RandomPositionLocator.java @@ -70,8 +70,9 @@ public class RandomPositionLocator extends Task }else { // Schedule the task to execute //run(); - RandomPositionLocator next = new RandomPositionLocator(contain); - DelayedExecutorService.getInstance().schedule(next, 1); + + RandomPositionLocator next = new RandomPositionLocator(contain.withThreadDelay(contain.lastThreadDelay+1)); + DelayedExecutorService.getInstance().schedule(next, contain.lastThreadDelay+1); AriasEssentials.LOGGER.info("Giving up current RTP search. Scheduling another search in 1 second"); } }