From e181fa6f77d373e6e717b3545e0f0fcd766b447d Mon Sep 17 00:00:00 2001 From: AverageGithub Date: Tue, 12 Mar 2024 16:19:30 +0100 Subject: [PATCH] Add lumber break limit --- .../com/artillexstudios/axminions/api/config/Config.kt | 2 ++ .../com/artillexstudios/axminions/api/utils/MinionUtils.kt | 7 +++++++ build.gradle | 3 +-- .../com/artillexstudios/axminions/AxMinionsPlugin.kt | 4 ++-- common/src/main/resources/config.yml | 5 ++++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Config.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Config.kt index b6412df..0b0aaf2 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Config.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/config/Config.kt @@ -50,6 +50,8 @@ class Config(file: File, stream: InputStream) { @JvmStatic fun WORK_WHEN_OWNER_OFFLINE() = AxMinionsAPI.INSTANCE.getConfig().get("work-when-owner-offline", true) @JvmStatic + fun MAX_BREAKS_PER_TICK() = AxMinionsAPI.INSTANCE.getConfig().get("max-breaks-per-tick", 200) + @JvmStatic fun DEBUG(): Boolean { if (debug === null) { debug = AxMinionsAPI.INSTANCE.getConfig().get("debug", false) diff --git a/api/src/main/kotlin/com/artillexstudios/axminions/api/utils/MinionUtils.kt b/api/src/main/kotlin/com/artillexstudios/axminions/api/utils/MinionUtils.kt index dd3616c..8a18939 100644 --- a/api/src/main/kotlin/com/artillexstudios/axminions/api/utils/MinionUtils.kt +++ b/api/src/main/kotlin/com/artillexstudios/axminions/api/utils/MinionUtils.kt @@ -1,5 +1,6 @@ package com.artillexstudios.axminions.api.utils +import com.artillexstudios.axminions.api.config.Config import java.util.LinkedList import java.util.Queue import org.bukkit.Location @@ -65,6 +66,8 @@ object MinionUtils { @JvmStatic fun getTree(startBlock: Block): Set { + val max: Int = Config.MAX_BREAKS_PER_TICK() + var count: Int = 0 val queue: Queue = LinkedList() val visited = mutableSetOf() val tree = mutableSetOf() @@ -76,6 +79,10 @@ object MinionUtils { val type = block.type.toString() if (type.endsWith("_WOOD") || type.endsWith("_LOG")) { + if (count >= max) { + return tree + } + count++ tree.add(block) FACES.fastFor { diff --git a/build.gradle b/build.gradle index 5b2cecb..a5df676 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group = 'com.artillexstudios.axminions' -version = '1.0.6' +version = '1.0.7' repositories { mavenCentral() @@ -129,7 +129,6 @@ allprojects { compileOnly 'com.palmergames.bukkit.towny:towny:0.100.1.0' implementation platform('com.intellectualsites.bom:bom-newest:1.35') implementation("com.artillexstudios.axapi:axapi:1.4.87") - implementation("net.byteflux:libby-bukkit:1.3.0") implementation("com.zaxxer:HikariCP:5.1.0") implementation("org.bstats:bstats-bukkit:3.0.2") compileOnly 'org.black_ixx:playerpoints:3.2.6' diff --git a/common/src/main/kotlin/com/artillexstudios/axminions/AxMinionsPlugin.kt b/common/src/main/kotlin/com/artillexstudios/axminions/AxMinionsPlugin.kt index 596163a..112984d 100644 --- a/common/src/main/kotlin/com/artillexstudios/axminions/AxMinionsPlugin.kt +++ b/common/src/main/kotlin/com/artillexstudios/axminions/AxMinionsPlugin.kt @@ -34,8 +34,8 @@ import com.artillexstudios.axminions.minions.miniontype.MinerMinionType import com.artillexstudios.axminions.minions.miniontype.SellerMinionType import com.artillexstudios.axminions.minions.miniontype.SlayerMinionType import java.io.File -import net.byteflux.libby.BukkitLibraryManager -import net.byteflux.libby.Library +import com.artillexstudios.axapi.libs.libby.BukkitLibraryManager +import com.artillexstudios.axapi.libs.libby.Library import org.bstats.bukkit.Metrics import org.bukkit.Bukkit import revxrsal.commands.bukkit.BukkitCommandHandler diff --git a/common/src/main/resources/config.yml b/common/src/main/resources/config.yml index 05080cf..e43c8ed 100644 --- a/common/src/main/resources/config.yml +++ b/common/src/main/resources/config.yml @@ -42,6 +42,9 @@ pull-tools-from-chest: false # If the minion should work when the owner is offline (only if the chunk is loaded) work-when-owner-offline: true +# The maximum amount of blocks a single lumber minion may break at a time +max-breaks-per-tick: 200 + # What type of message we should send when the upgrade fails # due to insufficient funds # Possible options: chat, title, subtitle, actionbar @@ -98,4 +101,4 @@ gui: debug: false # Do not change! -config-version: 4 \ No newline at end of file +config-version: 5 \ No newline at end of file