From fb889b2936af47152de36bd63a1d5a227f8fe5b9 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Tue, 21 Jun 2022 18:49:34 +0100 Subject: [PATCH] Added discover-recipes --- .../com/willfp/ecopets/EcoPetsPlugin.kt | 4 +++- .../ecopets/pets/DiscoverRecipeListener.kt | 24 +++++++++++++++++++ .../core-plugin/src/main/resources/config.yml | 2 ++ 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/DiscoverRecipeListener.kt diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt index bee2b9d..42a856d 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/EcoPetsPlugin.kt @@ -7,6 +7,7 @@ import com.willfp.eco.util.toSingletonList import com.willfp.ecopets.commands.CommandEcopets import com.willfp.ecopets.commands.CommandPets import com.willfp.ecopets.config.PetsYml +import com.willfp.ecopets.pets.DiscoverRecipeListener import com.willfp.ecopets.pets.PetDisplay import com.willfp.ecopets.pets.PetLevelListener import com.willfp.ecopets.pets.PetTriggerXPGainListener @@ -73,7 +74,8 @@ class EcoPetsPlugin : LibReforgePlugin() { PetLevelListener(this), PetTriggerXPGainListener, SpawnEggHandler(this), - petDisplay + petDisplay, + DiscoverRecipeListener(this) ) } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/DiscoverRecipeListener.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/DiscoverRecipeListener.kt new file mode 100644 index 0000000..55b74cf --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecopets/pets/DiscoverRecipeListener.kt @@ -0,0 +1,24 @@ +package com.willfp.ecopets.pets + +import com.willfp.eco.core.EcoPlugin +import org.bukkit.Bukkit +import org.bukkit.Keyed +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.player.PlayerJoinEvent +import org.bukkit.inventory.Recipe + +class DiscoverRecipeListener(private val plugin: EcoPlugin) : Listener { + @EventHandler + fun onJoin(event: PlayerJoinEvent) { + if (!plugin.configYml.getBool("discover-recipes")) { + return + } + mutableListOf() + .apply { Bukkit.getServer().recipeIterator().forEachRemaining(this::add) } + .filterIsInstance().map { it.key } + .filter { it.namespace == plugin.name.lowercase() } + .filter { !it.key.contains("displayed") } + .forEach { event.player.discoverRecipe(it) } + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/config.yml b/eco-core/core-plugin/src/main/resources/config.yml index 1d0daaa..430e2ac 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -3,6 +3,8 @@ # by Auxilor # +discover-recipes: true + gui: rows: 6