From 78748b9b7ebedcf978869d84e194a78c2484bcc8 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 5 Sep 2022 17:13:54 +0100 Subject: [PATCH] Added Replenish --- .../willfp/ecoenchants/EcoEnchantsPlugin.kt | 2 + .../enchants/impl/EnchantmentReplenish.kt | 64 +++++++++++++++++++ .../src/main/resources/enchants/replenish.yml | 16 +++++ 3 files changed, 82 insertions(+) create mode 100644 eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/impl/EnchantmentReplenish.kt create mode 100644 eco-core/core-plugin/src/main/resources/enchants/replenish.yml diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/EcoEnchantsPlugin.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/EcoEnchantsPlugin.kt index 5732b6db..9631bd4f 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/EcoEnchantsPlugin.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/EcoEnchantsPlugin.kt @@ -15,6 +15,7 @@ import com.willfp.ecoenchants.enchants.LoreConversion import com.willfp.ecoenchants.enchants.impl.EnchantmentPermanenceCurse import com.willfp.ecoenchants.enchants.impl.EnchantmentRapid import com.willfp.ecoenchants.enchants.impl.EnchantmentRepairing +import com.willfp.ecoenchants.enchants.impl.EnchantmentReplenish import com.willfp.ecoenchants.enchants.impl.EnchantmentTelekinesis import com.willfp.ecoenchants.enchants.registerVanillaEnchants import com.willfp.ecoenchants.integrations.EnchantRegistrations @@ -52,6 +53,7 @@ class EcoEnchantsPlugin : LibReforgePlugin() { EnchantmentPermanenceCurse(this) EnchantmentRepairing(this) EnchantmentRapid(this) + EnchantmentReplenish(this) registerVanillaEnchants(this) diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/impl/EnchantmentReplenish.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/impl/EnchantmentReplenish.kt new file mode 100644 index 00000000..bdb662e9 --- /dev/null +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoenchants/enchants/impl/EnchantmentReplenish.kt @@ -0,0 +1,64 @@ +package com.willfp.ecoenchants.enchants.impl + +import com.willfp.ecoenchants.EcoEnchantsPlugin +import com.willfp.ecoenchants.enchants.EcoEnchant +import org.bukkit.Material +import org.bukkit.block.data.Ageable +import org.bukkit.event.EventHandler +import org.bukkit.event.Listener +import org.bukkit.event.block.BlockBreakEvent + +class EnchantmentReplenish( + plugin: EcoEnchantsPlugin +) : EcoEnchant( + "replenish", + plugin, + force = false +) { + init { + this.registerListener(ReplenishHandler(plugin)) + } + + private class ReplenishHandler( + private val plugin: EcoEnchantsPlugin + ) : Listener { + @EventHandler( + ignoreCancelled = true + ) + fun handle(event: BlockBreakEvent) { + val player = event.player + val block = event.block + val type = block.type + + if (type in arrayOf( + Material.GLOW_BERRIES, + Material.SWEET_BERRY_BUSH, + Material.CACTUS, + Material.BAMBOO, + Material.CHORUS_FLOWER, + Material.SUGAR_CANE + ) + ) { + return + } + + val data = block.blockData + + if (data !is Ageable) { + return + } + + if (data.age != data.maximumAge) { + event.isDropItems = false + event.expToDrop = 0 + } + + data.age = 0 + + plugin.scheduler.run { + block.type = type + block.blockData = data + } + } + } +} diff --git a/eco-core/core-plugin/src/main/resources/enchants/replenish.yml b/eco-core/core-plugin/src/main/resources/enchants/replenish.yml new file mode 100644 index 00000000..be3531dc --- /dev/null +++ b/eco-core/core-plugin/src/main/resources/enchants/replenish.yml @@ -0,0 +1,16 @@ +display-name: "Replenish" +description: "Crops are replanted automatically" +type: normal + +targets: + - hoe +conflicts: [ ] +rarity: legendary +max-level: 1 + +tradeable: true +discoverable: true +enchantable: true + +conditions: [ ] +