Added Replenish

This commit is contained in:
Auxilor 2022-09-05 17:13:54 +01:00
parent 335dc1814c
commit 78748b9b7e
3 changed files with 82 additions and 0 deletions

View File

@ -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)

View File

@ -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
}
}
}
}

View File

@ -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: [ ]