From 73a3438896d4539e5407619da056e33383c7eec6 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sat, 21 Aug 2021 13:11:22 +0100 Subject: [PATCH] Added efficient brewing --- .../com/willfp/ecoskills/effects/Effects.java | 2 + .../effects/effects/EffectEfficientBrewing.kt | 60 +++++++++++++++++++ .../ecoskills/skills/skills/SkillAlchemy.kt | 11 +++- .../core-plugin/src/main/resources/config.yml | 3 + .../core-plugin/src/main/resources/lang.yml | 4 ++ .../src/main/resources/skills/alchemy.yml | 6 +- 6 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectEfficientBrewing.kt diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/effects/Effects.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/effects/Effects.java index 8ddae06..f7c4ab1 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/effects/Effects.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoskills/effects/Effects.java @@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableSet; import com.willfp.eco.core.config.updating.ConfigUpdater; import com.willfp.ecoskills.effects.effects.EffectBountifulHarvest; import com.willfp.ecoskills.effects.effects.EffectCraftsmanship; +import com.willfp.ecoskills.effects.effects.EffectEfficientBrewing; import com.willfp.ecoskills.effects.effects.EffectEyeOfTheDepths; import com.willfp.ecoskills.effects.effects.EffectPotionmaster; import com.willfp.ecoskills.effects.effects.EffectSeamlessMovement; @@ -35,6 +36,7 @@ public class Effects { public static final Effect SERRATED_STRIKES = new EffectSerratedStrikes(); public static final Effect SHAMANISM = new EffectShamanism(); public static final Effect VERSATILE_TOOLS = new EffectVersatileTools(); + public static final Effect EFFICIENT_BREWING = new EffectEfficientBrewing(); @ApiStatus.Internal public static void registerNewEffect(@NotNull final Effect effect) { diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectEfficientBrewing.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectEfficientBrewing.kt new file mode 100644 index 0000000..b84d28f --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectEfficientBrewing.kt @@ -0,0 +1,60 @@ +package com.willfp.ecoskills.effects.effects + +import com.willfp.eco.util.NumberUtils +import com.willfp.eco.util.StringUtils +import com.willfp.ecoskills.effects.Effect +import com.willfp.ecoskills.getEffectLevel +import com.willfp.ecoskills.util.PotionUtils +import org.bukkit.Bukkit +import org.bukkit.block.BrewingStand +import org.bukkit.entity.Player +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.entity.PotionSplashEvent +import org.bukkit.event.inventory.BrewEvent +import org.bukkit.event.inventory.InventoryClickEvent +import org.bukkit.event.player.PlayerItemConsumeEvent +import org.bukkit.inventory.meta.PotionMeta +import org.bukkit.persistence.PersistentDataType +import org.bukkit.potion.PotionData +import org.bukkit.potion.PotionEffect +import org.bukkit.potion.PotionEffectType +import org.bukkit.potion.PotionType + + +class EffectEfficientBrewing : Effect( + "efficient_brewing" +) { + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + fun handle(event: InventoryClickEvent) { + val player = event.whoClicked + + if (player !is Player) { + return + } + + if (player.getEffectLevel(this) == 0) { + return + } + + if (event.inventory.holder !is BrewingStand) { + return + } + + val stand = event.inventory.holder as BrewingStand + + this.plugin.scheduler.runLater({ + if (stand.brewingTime == 400) { + val multiplier = ((player.getEffectLevel(this) * this.config.getDouble("percent-faster-per-level")) / 100) + 1 + stand.brewingTime = (stand.brewingTime / multiplier).toInt() + this.plugin.runnableFactory.create { task -> + if (stand.brewingTime - 20 <= 0) { + stand.brewingTime = 1 + task.cancel(); + } + stand.brewingTime = stand.brewingTime - 20 + }.runTaskTimer(0, 2) + } + }, 2) + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillAlchemy.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillAlchemy.kt index eae2aad..5e407d6 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillAlchemy.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/skills/skills/SkillAlchemy.kt @@ -17,6 +17,7 @@ import org.bukkit.event.block.BlockBreakEvent import org.bukkit.event.enchantment.EnchantItemEvent import org.bukkit.event.entity.EntityDamageByEntityEvent import org.bukkit.event.inventory.BrewEvent +import org.bukkit.inventory.meta.PotionMeta import java.util.* class SkillAlchemy : Skill( @@ -52,9 +53,17 @@ class SkillAlchemy : Skill( return } + var mult = 0; + + for (i in 0..2) { + if (event.contents.getItem(i)?.itemMeta is PotionMeta) { + mult++ + } + } + val type = event.contents.ingredient?.type ?: return val toGive = rewards[type] ?: return - player.giveSkillExperience(this, toGive) + player.giveSkillExperience(this, toGive * mult) } } \ 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 83ee248..3f4d2c9 100644 --- a/eco-core/core-plugin/src/main/resources/config.yml +++ b/eco-core/core-plugin/src/main/resources/config.yml @@ -360,6 +360,9 @@ effects: # This will follow a binomial distribution where the amount of trials is the durability check (30 by default, see above) # Since this chance will be called many times, it would be best to have this be low. chance-per-level: 0.1 + efficient_brewing: + # The percent faster brewing time for each level + percent-faster-per-level: 4 damage-indicators: # Requires HolographicDisplays to be installed diff --git a/eco-core/core-plugin/src/main/resources/lang.yml b/eco-core/core-plugin/src/main/resources/lang.yml index 74a47b9..9b4b6e7 100644 --- a/eco-core/core-plugin/src/main/resources/lang.yml +++ b/eco-core/core-plugin/src/main/resources/lang.yml @@ -91,3 +91,7 @@ effects: name: "Second Chance" color: "&6" description: "Chance to instantly fix items on low durability" + efficient_brewing: + name: "Efficient Brewing" + color: "&6" + description: "Decrease the time taken to brew potions" diff --git a/eco-core/core-plugin/src/main/resources/skills/alchemy.yml b/eco-core/core-plugin/src/main/resources/skills/alchemy.yml index 05d650c..ce11b29 100644 --- a/eco-core/core-plugin/src/main/resources/skills/alchemy.yml +++ b/eco-core/core-plugin/src/main/resources/skills/alchemy.yml @@ -9,6 +9,7 @@ gui-lore: - "&f" - "&fEffects:" - "&8» &r&6Potionmaster %ecoskills_potionmaster_numeral%" + - "&8» &r&6Efficient Brewing %ecoskills_efficient_brewing_numeral%" # The maximum obtainable level max-level: 50 @@ -18,16 +19,19 @@ level-up-rewards: - "crit_chance:2" - "wisdom:1" - "potionmaster:1" + - "efficient_brewing:1" rewards-messages: - " &8» &r&f+2 %ecoskills_crit_chance_name%" - " &8» &r&f+1 %ecoskills_wisdom_name%" - " &8» &r&6Potionmaster %ecoskills_potionmaster_numeral%" + - " &8» &r&6Efficient Brewing %ecoskills_efficient_brewing_numeral%" rewards-gui-lore: - " &8» &r&f+2 %ecoskills_crit_chance_name%" - " &8» &r&f+1 %ecoskills_wisdom_name%" - " &8» &r&6Potionmaster %ecoskills_potionmaster_numeral%" + - " &8» &r&6Efficient Brewing %ecoskills_efficient_brewing_numeral%" # The experience to give for each brewing ingredient xp-rewards: @@ -46,5 +50,5 @@ xp-rewards: - "golden_carrot:22" - "blaze_powder:12" - "ghast_tear:12" - - "turtle_shell:80" + - "turtle_helmet:80" - "phantom_membrane:34" \ No newline at end of file