From eb48e83a13872fc4500b3bffa9ba928f58203294 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 23 Aug 2021 18:11:01 +0100 Subject: [PATCH] Added dynamic mining effect --- .../com/willfp/ecoskills/effects/Effects.java | 2 + .../effects/effects/EffectDynamicMining.kt | 37 +++++++++++++++++++ .../src/main/resources/effects.yml | 14 ++++++- .../src/main/resources/skills/mining.yml | 25 ++++++++++++- 4 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectDynamicMining.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 4bc3982..f92a18b 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.EffectAcceleratedEscape; import com.willfp.ecoskills.effects.effects.EffectBountifulHarvest; +import com.willfp.ecoskills.effects.effects.EffectDynamicMining; import com.willfp.ecoskills.effects.effects.EffectEndangering; import com.willfp.ecoskills.effects.effects.EffectInfernalResistance; import com.willfp.ecoskills.effects.effects.EffectCraftsmanship; @@ -58,6 +59,7 @@ public class Effects { public static final Effect STRONG_IMPACT = new EffectStrongImpact(); public static final Effect ENDANGERING = new EffectEndangering(); public static final Effect SPELUNKING = new EffectSpelunking(); + public static final Effect DYNAMIC_MINING = new EffectDynamicMining(); @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/EffectDynamicMining.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectDynamicMining.kt new file mode 100644 index 0000000..dacd006 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoskills/effects/effects/EffectDynamicMining.kt @@ -0,0 +1,37 @@ +package com.willfp.ecoskills.effects.effects + +import com.willfp.eco.util.NumberUtils +import com.willfp.ecoskills.effects.Effect +import com.willfp.ecoskills.getEffectLevel +import org.bukkit.event.EventHandler +import org.bukkit.event.EventPriority +import org.bukkit.event.block.BlockBreakEvent +import org.bukkit.potion.PotionEffect +import org.bukkit.potion.PotionEffectType + +class EffectDynamicMining : Effect( + "dynamic_mining" +) { + override fun formatDescription(string: String, level: Int): String { + return string.replace("%chance%", NumberUtils.format(config.getDouble("chance-per-level") * level)) + .replace( + "%seconds%", + NumberUtils.format(((config.getInt("ticks-per-level") * level) + config.getInt("base-ticks")) / 20.0) + ) + } + + @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) + fun handle(event: BlockBreakEvent) { + val player = event.player + + val level = player.getEffectLevel(this) + + if (NumberUtils.randFloat(0.0, 100.0) >= config.getDouble("chance-per-level") * level) { + return + } + + val duration = (config.getInt("ticks-per-level") * level) + config.getInt("base-ticks") + + player.addPotionEffect(PotionEffect(PotionEffectType.FAST_DIGGING, duration, config.getInt("level"))) + } +} \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/effects.yml b/eco-core/core-plugin/src/main/resources/effects.yml index d80cd9e..69ad4a6 100644 --- a/eco-core/core-plugin/src/main/resources/effects.yml +++ b/eco-core/core-plugin/src/main/resources/effects.yml @@ -167,8 +167,18 @@ spelunking: - "diamond_ore" - "deepslate_diamond_ore" - # Chance is as a percentage; if the chance for a player is over 100 then it will always be double drops # with a chance to get triple drops. Same goes if above 200, but then it will always be triple with a chance # for quadruple. - chance-per-level: 4 \ No newline at end of file + chance-per-level: 4 +dynamic_mining: + description: "&a%chance%%&8 chance to get Haste III for &a%seconds%&8 when breaking blocks" + + # The base ticks to give nausea for + base-ticks: 18 + # The extra ticks to give nausea for per level + ticks-per-level: 2 + # The chance to give nausea per level, as a percentage + chance-per-level: 1.5 + # The level of haste to give + level: 3 \ No newline at end of file diff --git a/eco-core/core-plugin/src/main/resources/skills/mining.yml b/eco-core/core-plugin/src/main/resources/skills/mining.yml index 97f0f1d..527df8c 100644 --- a/eco-core/core-plugin/src/main/resources/skills/mining.yml +++ b/eco-core/core-plugin/src/main/resources/skills/mining.yml @@ -17,6 +17,8 @@ gui: - " %ecoskills_versatile_tools_description%" - "&8» &r&6Spelunking %ecoskills_spelunking_numeral%" - " %ecoskills_spelunking_description%" + - "&8» &r&6Dynamic Mining %ecoskills_dynamic_mining_numeral%" + - " %ecoskills_dynamic_mining_description%" rewards: # The actual rewards to be given @@ -24,7 +26,8 @@ rewards: - "defense::2" - "ferocity::1:15:100" - "versatile_tools::1" - - "spelunking::1" + - "spelunking::1:10:100" + - "dynamic_mining::1" # The chat messages to send on level up chat-messages: @@ -34,6 +37,14 @@ rewards: - " %ecoskills_versatile_tools_description%" - " &8» &r&6Spelunking %ecoskills_spelunking_numeral%" - " %ecoskills_spelunking_description%" + 10: + - " &8» &r&f+2 %ecoskills_defense_name%" + - " &8» &r&6Versatile Tools %ecoskills_versatile_tools_numeral%" + - " %ecoskills_versatile_tools_description%" + - " &8» &r&6Spelunking %ecoskills_spelunking_numeral%" + - " %ecoskills_spelunking_description%" + - " &8» &r&6Dynamic Mining %ecoskills_dynamic_mining_numeral%" + - " %ecoskills_dynamic_mining_description%" 15: - " &8» &r&f+2 %ecoskills_defense_name%" - " &8» &r&f+1 %ecoskills_ferocity_name%" @@ -41,6 +52,8 @@ rewards: - " %ecoskills_versatile_tools_description%" - " &8» &r&6Spelunking %ecoskills_spelunking_numeral%" - " %ecoskills_spelunking_description%" + - " &8» &r&6Dynamic Mining %ecoskills_dynamic_mining_numeral%" + - " %ecoskills_dynamic_mining_description%" # The lore to show in the levels gui progression-lore: @@ -50,6 +63,14 @@ rewards: - " %ecoskills_versatile_tools_description%" - " &8» &r&6Spelunking %ecoskills_spelunking_numeral%" - " %ecoskills_spelunking_description%" + 10: + - " &8» &r&f+2 %ecoskills_defense_name%" + - " &8» &r&6Versatile Tools %ecoskills_versatile_tools_numeral%" + - " %ecoskills_versatile_tools_description%" + - " &8» &r&6Spelunking %ecoskills_spelunking_numeral%" + - " %ecoskills_spelunking_description%" + - " &8» &r&6Dynamic Mining %ecoskills_dynamic_mining_numeral%" + - " %ecoskills_dynamic_mining_description%" 15: - " &8» &r&f+2 %ecoskills_defense_name%" - " &8» &r&f+1 %ecoskills_ferocity_name%" @@ -57,6 +78,8 @@ rewards: - " %ecoskills_versatile_tools_description%" - " &8» &r&6Spelunking %ecoskills_spelunking_numeral%" - " %ecoskills_spelunking_description%" + - " &8» &r&6Dynamic Mining %ecoskills_dynamic_mining_numeral%" + - " %ecoskills_dynamic_mining_description%" # The xp rewards for each block type # Specify with type:xp