Moved telekinesis to be libreforge-based

This commit is contained in:
Auxilor 2023-07-04 14:19:23 +01:00
parent 033dbf4cac
commit 298f8b7f5a
3 changed files with 3 additions and 130 deletions

View File

@ -3,14 +3,12 @@ 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 +18,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") {

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

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