From 2aaaa3e524e621169f582f6cbc1d0a548b6c1dab Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 30 Jul 2021 00:16:59 +0100 Subject: [PATCH] Added particles to villagers when it gets a special enchantment --- .../support/obtaining/VillagerListeners.java | 47 +++++++++++++++++++ .../core-plugin/src/main/resources/lang.yml | 2 + 2 files changed, 49 insertions(+) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java index 026a4623..e205f5df 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java @@ -7,7 +7,11 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.enchantments.EcoEnchants; import com.willfp.ecoenchants.enchantments.meta.EnchantmentTarget; import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; +import org.bukkit.Color; +import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.Particle; +import org.bukkit.entity.Entity; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.VillagerAcquireTradeEvent; @@ -66,6 +70,8 @@ public class VillagerListeners extends PluginDependent implements Lis double multiplier = 0.01 / this.getPlugin().getConfigYml().getDouble("villager.book-times-less-likely"); + EcoEnchant applied = null; + for (EcoEnchant enchantment : enchantments) { if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getVillagerProbability() * multiplier) { continue; @@ -97,14 +103,24 @@ public class VillagerListeners extends PluginDependent implements Lis meta.getStoredEnchants().forEach(((enchantment1, integer) -> meta.removeStoredEnchant(enchantment1))); meta.addStoredEnchant(enchantment, level, false); + + applied = enchantment; break; } + if (applied == null) { + return; + } + result.setItemMeta(meta); MerchantRecipe recipe = new MerchantRecipe(result, uses, maxUses, experienceReward, villagerExperience, priceMultiplier); recipe.setIngredients(ingredients); event.setRecipe(recipe); + + if (applied.getType().equals(EnchantmentType.SPECIAL)) { + showParticles(event.getEntity()); + } } /** @@ -217,5 +233,36 @@ public class VillagerListeners extends PluginDependent implements Lis MerchantRecipe recipe = new MerchantRecipe(result, uses, maxUses, experienceReward, villagerExperience, priceMultiplier); recipe.setIngredients(ingredients); event.setRecipe(recipe); + + if (toAdd.keySet().stream().anyMatch(enchant -> enchant.getType().equals(EnchantmentType.SPELL))) { + showParticles(event.getEntity()); + } + } + + private void showParticles(@NotNull final Entity villager) { + Particle.DustOptions extra = new Particle.DustOptions( + Color.fromRGB(Integer.parseInt( + this.getPlugin().getLangYml().getString("special-particle-color").substring(1), + 16 + )), + 1.0f + ); + + Location location = villager.getLocation().clone(); + + location.add(0, 1, 0); + + int limit = NumberUtils.randInt(8, 13); + + for (int i = 0; i < limit; i++) { + Location spawnLoc = location.clone(); + spawnLoc.add( + NumberUtils.randFloat(-1.2, 1.2), + NumberUtils.randFloat(-0.3, 1.2), + NumberUtils.randFloat(-1.2, 1.2) + ); + + spawnLoc.getWorld().spawnParticle(Particle.REDSTONE, spawnLoc, 1, 0, 0, 0, 0, extra, true); + } } } diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index a00ca164..88c08a99 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -42,6 +42,8 @@ spell-color: "&9" description-color: "&8" +special-particle-color: "#FF69B4" + enchantments: protection: name: "Protection"