9
0
mirror of https://github.com/Auxilor/EcoMobs.git synced 2025-12-21 07:59:28 +00:00

Added discover-recipes

This commit is contained in:
Auxilor
2021-08-14 13:37:05 +01:00
parent c66b914104
commit d837311ae2
3 changed files with 49 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import com.willfp.ecobosses.bosses.listeners.PassiveListeners;
import com.willfp.ecobosses.bosses.listeners.SpawnListeners; import com.willfp.ecobosses.bosses.listeners.SpawnListeners;
import com.willfp.ecobosses.bosses.util.BossUtils; import com.willfp.ecobosses.bosses.util.BossUtils;
import com.willfp.ecobosses.commands.CommandEcobosses; import com.willfp.ecobosses.commands.CommandEcobosses;
import com.willfp.ecobosses.util.DiscoverRecipeListener;
import lombok.Getter; import lombok.Getter;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
@@ -54,6 +55,7 @@ public class EcoBossesPlugin extends EcoPlugin {
new AttackListeners(this), new AttackListeners(this),
new DeathListeners(this), new DeathListeners(this),
new SpawnListeners(this), new SpawnListeners(this),
new DiscoverRecipeListener(this),
new PassiveListeners(this) new PassiveListeners(this)
); );
} }

View File

@@ -0,0 +1,46 @@
package com.willfp.ecobosses.util;
import com.willfp.eco.core.EcoPlugin;
import com.willfp.eco.core.PluginDependent;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.inventory.ShapedRecipe;
import org.jetbrains.annotations.NotNull;
public class DiscoverRecipeListener extends PluginDependent<EcoPlugin> implements Listener {
/**
* Register listener.
*
* @param plugin Talismans.
*/
public DiscoverRecipeListener(@NotNull final EcoPlugin plugin) {
super(plugin);
}
/**
* Unlock all recipes on player join.
*
* @param event The event to listen for.
*/
@EventHandler
public void onJoin(@NotNull final PlayerJoinEvent event) {
Player player = event.getPlayer();
if (this.getPlugin().getConfigYml().getBool("discover-recipes")) {
Bukkit.getServer().recipeIterator().forEachRemaining(recipe -> {
if (recipe instanceof ShapedRecipe) {
NamespacedKey key = ((ShapedRecipe) recipe).getKey();
if (key.getNamespace().equals("ecobosses")) {
if (!key.getKey().contains("displayed")) {
player.discoverRecipe(key);
}
}
}
});
}
}
}

View File

@@ -4,5 +4,6 @@
# #
bossbar-radius: 50 # How far away players should be able to see the boss bar for bosses. bossbar-radius: 50 # How far away players should be able to see the boss bar for bosses.
discover-recipes: true
# Read the wiki! https://ecobosses.willfp.com/ # Read the wiki! https://ecobosses.willfp.com/