From faf001fdc88ee54b5520c4b3e5884a452d58bf6d Mon Sep 17 00:00:00 2001 From: TomTom <93038247+AverageGithub@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:32:21 +0200 Subject: [PATCH] Add KGenerators support --- build.gradle.kts | 2 ++ .../block/BlockIntegration.java | 11 ++++++- .../block/KGeneratorsIntegrable.java | 31 +++++++++++++++++++ .../effects/implementation/BreakEffect.java | 9 +++++- src/main/resources/plugin.yml | 4 ++- 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/artillexstudios/axminions/integrations/implementation/block/KGeneratorsIntegrable.java diff --git a/build.gradle.kts b/build.gradle.kts index 79497a9..cba3dcb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,6 +11,7 @@ repositories { maven("https://redempt.dev/") maven("https://repo.artillex-studios.com/releases/") + maven("https://repo.codemc.org/repository/maven-public/") maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") } @@ -19,6 +20,7 @@ dependencies { implementation("dev.jorel:commandapi-bukkit-shade:9.5.0") implementation("org.bstats:bstats-bukkit:3.0.2") compileOnly("com.github.ben-manes.caffeine:caffeine:3.1.8") + compileOnly("me.kryniowesegryderiusz:kgenerators-core:7.3") compileOnly("org.spigotmc:spigot-api:1.21-R0.1-SNAPSHOT") compileOnly("org.apache.commons:commons-lang3:3.14.0") compileOnly("com.github.Redempt:Crunch:2.0.3") diff --git a/src/main/java/com/artillexstudios/axminions/integrations/implementation/block/BlockIntegration.java b/src/main/java/com/artillexstudios/axminions/integrations/implementation/block/BlockIntegration.java index 02c60d5..a4ee6d9 100644 --- a/src/main/java/com/artillexstudios/axminions/integrations/implementation/block/BlockIntegration.java +++ b/src/main/java/com/artillexstudios/axminions/integrations/implementation/block/BlockIntegration.java @@ -1,6 +1,7 @@ package com.artillexstudios.axminions.integrations.implementation.block; import com.artillexstudios.axminions.integrations.Integration; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.inventory.ItemStack; @@ -11,12 +12,20 @@ public final class BlockIntegration extends Integration { public BlockIntegration() { this.register(new DefaultBlockIntegrable()); + + if (Bukkit.getPluginManager().getPlugin("KGenerators") != null) { + this.register(new KGeneratorsIntegrable()); + } } public Collection lootAndBreak(Location location, ItemStack itemStack) { for (BlockIntegrable integration : this.integrations()) { Collection items = integration.lootAndBreak(location, itemStack); - if (items == null || items.isEmpty()) { + if (items == null) { + return null; + } + + if (items.isEmpty()) { continue; } diff --git a/src/main/java/com/artillexstudios/axminions/integrations/implementation/block/KGeneratorsIntegrable.java b/src/main/java/com/artillexstudios/axminions/integrations/implementation/block/KGeneratorsIntegrable.java new file mode 100644 index 0000000..3223d64 --- /dev/null +++ b/src/main/java/com/artillexstudios/axminions/integrations/implementation/block/KGeneratorsIntegrable.java @@ -0,0 +1,31 @@ +package com.artillexstudios.axminions.integrations.implementation.block; + +import me.kryniowesegryderiusz.kgenerators.Main; +import me.kryniowesegryderiusz.kgenerators.generators.locations.objects.GeneratorLocation; +import org.bukkit.Location; +import org.bukkit.inventory.ItemStack; + +import java.util.Collection; +import java.util.List; + +public final class KGeneratorsIntegrable implements BlockIntegrable { + + @Override + public Collection lootAndBreak(Location location, ItemStack itemStack) { + if (!Main.getPlacedGenerators().isChunkFullyLoaded(location)) { + return null; + } + + GeneratorLocation generatorLocation = Main.getPlacedGenerators().getLoaded(location); + if (generatorLocation != null) { + if (!generatorLocation.isBlockPossibleToMine(location)) { + return null; + } + + generatorLocation.scheduleGeneratorRegeneration(); + return List.of(generatorLocation.getGenerator().drawGeneratedObject().getCustomDrops().getItem()); + } + + return List.of(); + } +} diff --git a/src/main/java/com/artillexstudios/axminions/minions/actions/effects/implementation/BreakEffect.java b/src/main/java/com/artillexstudios/axminions/minions/actions/effects/implementation/BreakEffect.java index b5edf1d..445f796 100644 --- a/src/main/java/com/artillexstudios/axminions/minions/actions/effects/implementation/BreakEffect.java +++ b/src/main/java/com/artillexstudios/axminions/minions/actions/effects/implementation/BreakEffect.java @@ -5,7 +5,9 @@ import com.artillexstudios.axminions.minions.Minion; import com.artillexstudios.axminions.minions.actions.effects.Effect; import com.artillexstudios.axminions.utils.ItemCollection; import org.bukkit.Location; +import org.bukkit.inventory.ItemStack; +import java.util.Collection; import java.util.Map; public final class BreakEffect extends Effect { @@ -16,7 +18,12 @@ public final class BreakEffect extends Effect { @Override public ItemCollection run(Minion minion, Location argument) { - return new ItemCollection(Integrations.BLOCK.lootAndBreak(argument, minion.tool())); + Collection items = Integrations.BLOCK.lootAndBreak(argument, minion.tool()); + if (items == null) { + return null; + } + + return new ItemCollection(items); } @Override diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index eb38a9f..182ba98 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -2,4 +2,6 @@ name: "AxMinions" main: "com.artillexstudios.axminions.AxMinionsPlugin" version: "${version}" api-version: "1.18" -folia-supported: true \ No newline at end of file +folia-supported: true +softdepend: + - KGenerators \ No newline at end of file