From 4b8d17bb98439172fe09acdcd95325e1def1653e Mon Sep 17 00:00:00 2001 From: Boy Date: Sun, 4 Feb 2024 19:51:38 +0100 Subject: [PATCH] feat: auto-discover all vanilla recipes --- src/main/kotlin/com/mineinabyss/looty/LootyCommands.kt | 3 +++ src/main/kotlin/com/mineinabyss/looty/config/LootyConfig.kt | 3 ++- .../looty/features/recipes/RecipeDiscoverySystem.kt | 6 ++++++ src/main/resources/config.yml | 2 -- 4 files changed, 11 insertions(+), 3 deletions(-) delete mode 100644 src/main/resources/config.yml diff --git a/src/main/kotlin/com/mineinabyss/looty/LootyCommands.kt b/src/main/kotlin/com/mineinabyss/looty/LootyCommands.kt index 3abce86..6e054cc 100644 --- a/src/main/kotlin/com/mineinabyss/looty/LootyCommands.kt +++ b/src/main/kotlin/com/mineinabyss/looty/LootyCommands.kt @@ -2,6 +2,7 @@ package com.mineinabyss.looty import com.mineinabyss.idofront.commands.execution.IdofrontCommandExecutor import com.mineinabyss.looty.config.looty +import org.bukkit.Bukkit class LootyCommands : IdofrontCommandExecutor() { override val commands = commands(looty.plugin) { @@ -9,6 +10,8 @@ class LootyCommands : IdofrontCommandExecutor() { "reload" { action { looty.configController.reload() + Bukkit.updateRecipes() + sender.sendMessage("Reloaded Looty config") } } } diff --git a/src/main/kotlin/com/mineinabyss/looty/config/LootyConfig.kt b/src/main/kotlin/com/mineinabyss/looty/config/LootyConfig.kt index c9db6df..d64372b 100644 --- a/src/main/kotlin/com/mineinabyss/looty/config/LootyConfig.kt +++ b/src/main/kotlin/com/mineinabyss/looty/config/LootyConfig.kt @@ -5,5 +5,6 @@ import kotlinx.serialization.Serializable @Serializable data class LootyConfig( val debug: Boolean = false, - val migrateByCustomModelData: Boolean = false + val migrateByCustomModelData: Boolean = false, + val autoDiscoverVanillaRecipes: Boolean = false ) diff --git a/src/main/kotlin/com/mineinabyss/looty/features/recipes/RecipeDiscoverySystem.kt b/src/main/kotlin/com/mineinabyss/looty/features/recipes/RecipeDiscoverySystem.kt index 64328d8..3606e81 100644 --- a/src/main/kotlin/com/mineinabyss/looty/features/recipes/RecipeDiscoverySystem.kt +++ b/src/main/kotlin/com/mineinabyss/looty/features/recipes/RecipeDiscoverySystem.kt @@ -1,5 +1,8 @@ package com.mineinabyss.looty.features.recipes +import com.mineinabyss.looty.config.looty +import org.bukkit.Bukkit +import org.bukkit.Keyed import org.bukkit.NamespacedKey import org.bukkit.event.EventHandler import org.bukkit.event.Listener @@ -11,5 +14,8 @@ class RecipeDiscoverySystem( @EventHandler fun PlayerJoinEvent.showRecipesOnJoin() { player.discoverRecipes(discoveredRecipes) + if (looty.config.autoDiscoverVanillaRecipes) + player.discoverRecipes(Bukkit.recipeIterator().asSequence().filterIsInstance() + .filter { it.key.namespace == "minecraft" && it.key !in discoveredRecipes }.map { it.key }.toList()) } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml deleted file mode 100644 index 9effd4c..0000000 --- a/src/main/resources/config.yml +++ /dev/null @@ -1,2 +0,0 @@ -debug: false -migrateByCustomModelData: false