Merge remote-tracking branch 'origin/master'

This commit is contained in:
Auxilor 2023-07-12 12:53:48 +01:00
commit da0668f0f8
7 changed files with 12 additions and 190 deletions

View File

@ -65,7 +65,7 @@ class EcoEnchantsPlugin : LibreforgePlugin() {
registerPlayerRefreshFunction { it.clearEnchantCache() }
registerHolderPlaceholderProvider<FoundEcoEnchantLevel> { it, _ ->
listOf(
NamedValue("level", it.level),
NamedValue("level", it.level.level),
NamedValue("active_level", it.activeLevel)
)
}

View File

@ -3,14 +3,11 @@ package com.willfp.ecoenchants.enchants
import com.google.common.collect.HashBiMap
import com.google.common.collect.ImmutableSet
import com.willfp.eco.core.config.interfaces.Config
import com.willfp.eco.core.config.updating.ConfigUpdater
import com.willfp.ecoenchants.EcoEnchantsPlugin
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.EnchantmentSoulbound
import com.willfp.ecoenchants.enchants.impl.EnchantmentTelekinesis
import com.willfp.ecoenchants.integrations.EnchantRegistrations
import com.willfp.ecoenchants.rarity.EnchantmentRarities
import com.willfp.ecoenchants.target.EnchantmentTargets
@ -20,7 +17,6 @@ import com.willfp.libreforge.loader.configs.ConfigCategory
import org.bukkit.ChatColor
import org.bukkit.NamespacedKey
import org.bukkit.enchantments.Enchantment
import org.bukkit.event.Listener
@Suppress("UNUSED")
object EcoEnchants : ConfigCategory("enchant", "enchants") {
@ -195,10 +191,8 @@ object EcoEnchants : ConfigCategory("enchant", "enchants") {
private fun registerHardcodedEnchantments(
plugin: EcoEnchantsPlugin
) {
EnchantmentTelekinesis(plugin)
EnchantmentPermanenceCurse(plugin)
EnchantmentRepairing(plugin)
EnchantmentRapid(plugin)
EnchantmentReplenish(plugin)
EnchantmentSoulbound(plugin)
}

View File

@ -1,51 +0,0 @@
package com.willfp.ecoenchants.enchants.impl
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.target.EnchantLookup.getActiveEnchantLevel
import com.willfp.ecoenchants.target.EnchantLookup.getEnchantLevel
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.entity.EntityShootBowEvent
import kotlin.math.min
class EnchantmentRapid(
plugin: EcoEnchantsPlugin
) : EcoEnchant(
"rapid",
plugin,
force = false
) {
override fun onInit() {
this.registerListener(RapidHandler(this))
}
private class RapidHandler(
private val enchant: EcoEnchant
) : Listener {
@EventHandler(
priority = EventPriority.LOW,
ignoreCancelled = true
)
fun handle(event: EntityShootBowEvent) {
val player = event.entity as? Player ?: return
val level = player.getActiveEnchantLevel(enchant)
val multiplier = 1 - enchant.config.getDouble("percent-faster-per-level") * level / 100
if (event.force < multiplier) {
return
}
val force = min(1.0 / event.force, Double.MAX_VALUE)
var velocity = event.projectile.velocity.multiply(force)
if (velocity.length() > 3) {
velocity = velocity.normalize().multiply(3)
}
event.projectile.velocity = velocity
}
}
}

View File

@ -1,125 +0,0 @@
package com.willfp.ecoenchants.enchants.impl
import com.willfp.eco.core.drops.DropQueue
import com.willfp.eco.core.events.EntityDeathByEntityEvent
import com.willfp.eco.core.integrations.antigrief.AntigriefManager
import com.willfp.eco.util.TelekinesisUtils
import com.willfp.eco.util.tryAsPlayer
import com.willfp.ecoenchants.EcoEnchantsPlugin
import com.willfp.ecoenchants.enchants.EcoEnchant
import com.willfp.ecoenchants.target.EnchantLookup.hasEnchant
import com.willfp.ecoenchants.target.EnchantLookup.hasEnchantActive
import org.bukkit.GameMode
import org.bukkit.Material
import org.bukkit.entity.Player
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.block.BlockBreakEvent
import org.bukkit.event.block.BlockDropItemEvent
class EnchantmentTelekinesis(
plugin: EcoEnchantsPlugin
) : EcoEnchant(
"telekinesis",
plugin,
force = false
) {
override fun onInit() {
this.registerListener(TelekinesisHandler(this))
TelekinesisUtils.registerTest { it.hasEnchantActive(this) }
}
private class TelekinesisHandler(
private val enchant: EcoEnchant
) : Listener {
@EventHandler(
priority = EventPriority.HIGH,
ignoreCancelled = true
)
fun handle(event: BlockDropItemEvent) {
val player = event.player
val block = event.block
if (!AntigriefManager.canBreakBlock(player, block)) {
return
}
val drops = event.items.map { it.itemStack }
event.items.clear()
DropQueue(player)
.setLocation(block.location)
.addItems(drops)
.push()
}
@EventHandler(
priority = EventPriority.HIGH,
ignoreCancelled = true
)
fun handle(event: BlockBreakEvent) {
val player = event.player
val block = event.block
if (!player.hasEnchantActive(enchant)) {
return
}
if (!AntigriefManager.canBreakBlock(player, block)) {
return
}
if (player.gameMode == GameMode.CREATIVE || player.gameMode == GameMode.SPECTATOR) {
return
}
// Filter out telekinesis spawner xp to prevent dupe
if (block.type == Material.SPAWNER && player.hasEnchant(enchant)) {
event.expToDrop = 0
}
DropQueue(player)
.setLocation(block.location)
.addXP(event.expToDrop)
.push()
event.expToDrop = 0
}
@EventHandler(
priority = EventPriority.HIGH,
ignoreCancelled = true
)
fun handle(event: EntityDeathByEntityEvent) {
val victim = event.victim
if (victim is Player && enchant.config.getBool("not-on-players")) {
return
}
val player = event.killer.tryAsPlayer() ?: return
// Only DropQueue-ify entity drops with telekinesis
if (!player.hasEnchantActive(enchant)) {
return
}
val xp = event.xp
val drops = event.drops
drops.removeAll { it == null }
DropQueue(player)
.addItems(drops)
.setLocation(victim.location)
.addXP(xp)
.forceTelekinesis()
.push()
event.deathEvent.droppedExp = 0
event.deathEvent.drops.clear()
}
}
}

View File

@ -13,6 +13,9 @@ tradeable: true
discoverable: true
enchantable: true
conditions: [ ]
effects:
- id: rapid_bows
args:
percent_faster: "15 * %level%"
percent-faster-per-level: 15
conditions: [ ]

View File

@ -14,6 +14,7 @@ tradeable: true
discoverable: true
enchantable: true
conditions: [ ]
effects:
- id: telekinesis
not-on-players: true
conditions: [ ]

View File

@ -1,5 +1,5 @@
#libreforge-updater
#Wed Jun 21 10:23:37 BST 2023
#Sun Jul 09 17:24:20 BST 2023
kotlin.code.style=official
libreforge-version=4.20.1
version=10.20.1
libreforge-version=4.22.0
version=10.22.0