From 9681e609612e4d24219830cf614c2d5f6b52e15f Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Mon, 4 Dec 2023 22:58:16 +0300 Subject: [PATCH 1/4] - Added CustomBiomes manager for ConditionInBiome integrating with custom generation plugins - Added Terra integration for custom biomes --- build.gradle.kts | 1 + core/build.gradle.kts | 1 + .../libreforge/LibreforgeSpigotPlugin.kt | 2 + .../conditions/impl/ConditionInBiome.kt | 10 ++--- .../integrations/custombiomes/CustomBiome.kt | 4 ++ .../custombiomes/CustomBiomesIntegration.kt | 14 +++++++ .../custombiomes/CustomBiomesManager.kt | 41 +++++++++++++++++++ .../custombiomes/impl/CustomBiomesTerra.kt | 31 ++++++++++++++ core/src/main/resources/plugin.yml | 1 + 9 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiome.kt create mode 100644 core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesIntegration.kt create mode 100644 core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesManager.kt create mode 100644 core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/impl/CustomBiomesTerra.kt diff --git a/build.gradle.kts b/build.gradle.kts index 3795533c8..ff5231cc2 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -35,6 +35,7 @@ allprojects { maven("https://maven.enginehub.org/repo/") maven("https://repo.extendedclip.com/content/repositories/placeholderapi/") maven("https://maven.citizensnpcs.co/repo") + maven("https://nexuslite.gcnt.net/repos/other/") } dependencies { diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 3d95f2e85..33c171689 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { compileOnly("net.citizensnpcs:citizens-main:2.0.31-SNAPSHOT") { exclude(group = "net.byteflux", module = "libby-bukkit") } + compileOnly("com.dfsek.terra:common:6.4.1-BETA+3aef97738") compileOnly(fileTree("../lib") { include("*.jar") diff --git a/core/src/main/kotlin/com/willfp/libreforge/LibreforgeSpigotPlugin.kt b/core/src/main/kotlin/com/willfp/libreforge/LibreforgeSpigotPlugin.kt index 776263437..86a695bb1 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/LibreforgeSpigotPlugin.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/LibreforgeSpigotPlugin.kt @@ -12,6 +12,7 @@ import com.willfp.libreforge.effects.arguments.custom.CustomEffectArguments import com.willfp.libreforge.effects.impl.bossbar.BossBarProgressPlaceholder import com.willfp.libreforge.integrations.aureliumskills.AureliumSkillsIntegration import com.willfp.libreforge.integrations.citizens.CitizensIntegration +import com.willfp.libreforge.integrations.custombiomes.impl.CustomBiomesTerra import com.willfp.libreforge.integrations.jobs.JobsIntegration import com.willfp.libreforge.integrations.levelledmobs.LevelledMobsIntegration import com.willfp.libreforge.integrations.mcmmo.McMMOIntegration @@ -164,6 +165,7 @@ class LibreforgeSpigotPlugin : EcoPlugin() { IntegrationLoader("Vault") { VaultIntegration.load(this) }, IntegrationLoader("WorldGuard") { WorldGuardIntegration.load(this) }, IntegrationLoader("TAB") { TabIntegration.load(this) }, + IntegrationLoader("Terra") { CustomBiomesTerra.load(this) } ) } diff --git a/core/src/main/kotlin/com/willfp/libreforge/conditions/impl/ConditionInBiome.kt b/core/src/main/kotlin/com/willfp/libreforge/conditions/impl/ConditionInBiome.kt index 1c53d510f..234a82d1f 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/conditions/impl/ConditionInBiome.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/conditions/impl/ConditionInBiome.kt @@ -1,11 +1,13 @@ package com.willfp.libreforge.conditions.impl import com.willfp.eco.core.config.interfaces.Config +import com.willfp.eco.util.containsIgnoreCase import com.willfp.libreforge.Dispatcher import com.willfp.libreforge.NoCompileData import com.willfp.libreforge.ProvidedHolder import com.willfp.libreforge.arguments import com.willfp.libreforge.conditions.Condition +import com.willfp.libreforge.integrations.custombiomes.CustomBiomesManager object ConditionInBiome : Condition("in_biome") { override val arguments = arguments { @@ -19,12 +21,8 @@ object ConditionInBiome : Condition("in_biome") { compileData: NoCompileData ): Boolean { val location = dispatcher.location ?: return false - return config.getStrings("biomes").contains( - location.world.getBiome( - location.blockX, - location.blockY, - location.blockZ - ).name.lowercase() + return config.getStrings("biomes").containsIgnoreCase( + CustomBiomesManager.getBiomeAt(location)?.name ?: return false ) } } diff --git a/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiome.kt b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiome.kt new file mode 100644 index 000000000..44d423fea --- /dev/null +++ b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiome.kt @@ -0,0 +1,4 @@ +package com.willfp.libreforge.integrations.custombiomes + + +class CustomBiome(val name: String) \ No newline at end of file diff --git a/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesIntegration.kt b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesIntegration.kt new file mode 100644 index 000000000..ad031ac57 --- /dev/null +++ b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesIntegration.kt @@ -0,0 +1,14 @@ +package com.willfp.libreforge.integrations.custombiomes + +import com.willfp.libreforge.integrations.LoadableIntegration +import org.bukkit.Location + +interface CustomBiomesIntegration: LoadableIntegration { + /** + * Get a biome at given location. (Supports vanilla biomes as well) + * + * @param location The location to get the biome at. + * @return The found biome, null otherwise + */ + fun getBiome(location: Location?): CustomBiome? +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesManager.kt b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesManager.kt new file mode 100644 index 000000000..1c65950bb --- /dev/null +++ b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesManager.kt @@ -0,0 +1,41 @@ +package com.willfp.libreforge.integrations.custombiomes + +import com.willfp.eco.core.integrations.IntegrationRegistry +import com.willfp.libreforge.plugin +import org.bukkit.Location +import org.bukkit.event.Listener + +object CustomBiomesManager { + /** + * A set of all registered biomes. + */ + private val REGISTRY = IntegrationRegistry() + + /** + * Register a new biomes integration. + * + * @param biomesIntegration The biomes integration to register. + */ + fun register(biomesIntegration: CustomBiomesIntegration) { + if (biomesIntegration is Listener) { + plugin.eventManager.registerListener((biomesIntegration as Listener)) + } + REGISTRY.register(biomesIntegration) + } + + fun getBiomeAt(location: Location): CustomBiome? { + val world = location.world ?: return null + val vanilla = world.getBiome(location) + return if (vanilla.name.equals("custom", ignoreCase = true)) { + for (integration in REGISTRY) { + val biome = integration.getBiome(location) + if (biome != null) { + return biome + } + } + null + } else { + CustomBiome(vanilla.name) + } + } +} \ No newline at end of file diff --git a/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/impl/CustomBiomesTerra.kt b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/impl/CustomBiomesTerra.kt new file mode 100644 index 000000000..bc2773b93 --- /dev/null +++ b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/impl/CustomBiomesTerra.kt @@ -0,0 +1,31 @@ +package com.willfp.libreforge.integrations.custombiomes.impl + +import com.dfsek.terra.bukkit.world.BukkitAdapter +import com.willfp.eco.core.EcoPlugin +import com.willfp.libreforge.integrations.custombiomes.CustomBiome +import com.willfp.libreforge.integrations.custombiomes.CustomBiomesIntegration +import com.willfp.libreforge.integrations.custombiomes.CustomBiomesManager +import org.bukkit.Location + +object CustomBiomesTerra: CustomBiomesIntegration { + override fun getPluginName(): String { + return "Terra" + } + + override fun getBiome(location: Location?): CustomBiome? { + if (location == null || location.world == null) { + return null + } + + val terraLocation = BukkitAdapter.adapt(location) ?: return null + val terraWorld = BukkitAdapter.adapt(location.world!!) ?: return null + val biomeProvider = terraWorld.biomeProvider ?: return null + val biome = biomeProvider.getBiome(terraLocation, terraWorld.seed) ?: return null + + return CustomBiome(biome.id) + } + + override fun load(plugin: EcoPlugin) { + CustomBiomesManager.register(this) + } +} \ No newline at end of file diff --git a/core/src/main/resources/plugin.yml b/core/src/main/resources/plugin.yml index 42378a36e..e57e24102 100644 --- a/core/src/main/resources/plugin.yml +++ b/core/src/main/resources/plugin.yml @@ -23,6 +23,7 @@ softdepend: - WorldGuard - Citizens - TAB + - Terra commands: lrcdb: From 1ea3241ba31b8f7ad488c64305716d18c683d2b0 Mon Sep 17 00:00:00 2001 From: _OfTeN_ Date: Wed, 6 Dec 2023 01:19:20 +0300 Subject: [PATCH 2/4] - Added LocationToDrop mutator - Added a location parameter to Drop Item trigger --- .../willfp/libreforge/mutators/Mutators.kt | 17 ++---------- .../mutators/impl/MutatorLocationToDrop.kt | 27 +++++++++++++++++++ .../triggers/impl/TriggerDropItem.kt | 6 +++-- 3 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 core/src/main/kotlin/com/willfp/libreforge/mutators/impl/MutatorLocationToDrop.kt diff --git a/core/src/main/kotlin/com/willfp/libreforge/mutators/Mutators.kt b/core/src/main/kotlin/com/willfp/libreforge/mutators/Mutators.kt index ed7ffe5b6..ce56f71ab 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/mutators/Mutators.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/mutators/Mutators.kt @@ -4,21 +4,7 @@ import com.willfp.eco.core.config.interfaces.Config import com.willfp.eco.core.registry.Registry import com.willfp.libreforge.ConfigViolation import com.willfp.libreforge.ViolationContext -import com.willfp.libreforge.mutators.impl.MutatorBlockToLocation -import com.willfp.libreforge.mutators.impl.MutatorDispatcherAsPlayer -import com.willfp.libreforge.mutators.impl.MutatorDispatcherAsVictim -import com.willfp.libreforge.mutators.impl.MutatorLocationToBlock -import com.willfp.libreforge.mutators.impl.MutatorLocationToCursor -import com.willfp.libreforge.mutators.impl.MutatorLocationToPlayer -import com.willfp.libreforge.mutators.impl.MutatorLocationToProjectile -import com.willfp.libreforge.mutators.impl.MutatorLocationToVictim -import com.willfp.libreforge.mutators.impl.MutatorPlayerAsVictim -import com.willfp.libreforge.mutators.impl.MutatorSpinLocation -import com.willfp.libreforge.mutators.impl.MutatorSpinVelocity -import com.willfp.libreforge.mutators.impl.MutatorTranslateLocation -import com.willfp.libreforge.mutators.impl.MutatorVictimAsDispatcher -import com.willfp.libreforge.mutators.impl.MutatorVictimAsPlayer -import com.willfp.libreforge.mutators.impl.MutatorVictimToOwner +import com.willfp.libreforge.mutators.impl.* object Mutators: Registry>() { /** @@ -76,5 +62,6 @@ object Mutators: Registry>() { register(MutatorVictimAsDispatcher) register(MutatorDispatcherAsPlayer) register(MutatorDispatcherAsVictim) + register(MutatorLocationToDrop) } } diff --git a/core/src/main/kotlin/com/willfp/libreforge/mutators/impl/MutatorLocationToDrop.kt b/core/src/main/kotlin/com/willfp/libreforge/mutators/impl/MutatorLocationToDrop.kt new file mode 100644 index 000000000..aa7935a8c --- /dev/null +++ b/core/src/main/kotlin/com/willfp/libreforge/mutators/impl/MutatorLocationToDrop.kt @@ -0,0 +1,27 @@ +package com.willfp.libreforge.mutators.impl + +import com.willfp.eco.core.config.interfaces.Config +import com.willfp.libreforge.NoCompileData +import com.willfp.libreforge.arguments +import com.willfp.libreforge.mutators.Mutator +import com.willfp.libreforge.mutators.parameterTransformers +import com.willfp.libreforge.plugin +import com.willfp.libreforge.triggers.TriggerData +import com.willfp.libreforge.triggers.TriggerParameter +import org.bukkit.FluidCollisionMode +import org.bukkit.event.player.PlayerDropItemEvent + +object MutatorLocationToDrop : Mutator("location_to_drop") { + override val parameterTransformers = parameterTransformers { + TriggerParameter.EVENT becomes TriggerParameter.LOCATION + } + + override fun mutate(data: TriggerData, config: Config, compileData: NoCompileData): TriggerData { + val event = data.event as? PlayerDropItemEvent ?: return data + + + return data.copy( + location = event.itemDrop.location + ) + } +} diff --git a/core/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerDropItem.kt b/core/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerDropItem.kt index eb4998606..6cb702297 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerDropItem.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/triggers/impl/TriggerDropItem.kt @@ -11,7 +11,8 @@ object TriggerDropItem : Trigger("drop_item") { override val parameters = setOf( TriggerParameter.PLAYER, TriggerParameter.ITEM, - TriggerParameter.EVENT + TriggerParameter.EVENT, + TriggerParameter.LOCATION ) @EventHandler(ignoreCancelled = true) @@ -24,7 +25,8 @@ object TriggerDropItem : Trigger("drop_item") { player = player, item = event.itemDrop.itemStack, value = event.itemDrop.itemStack.amount.toDouble(), - event = event + event = event, + location = event.itemDrop.location ) ) } From 0e6b5aac1686c9688ac24d7b71763aec95d83082 Mon Sep 17 00:00:00 2001 From: Will FP Date: Mon, 11 Dec 2023 11:48:30 +0000 Subject: [PATCH 3/4] Improved custom biomes code --- .../conditions/impl/ConditionInBiome.kt | 8 ++-- .../integrations/custombiomes/CustomBiome.kt | 4 -- .../custombiomes/CustomBiomesIntegration.kt | 2 +- .../custombiomes/CustomBiomesManager.kt | 39 +++++-------------- .../integrations/custombiomes/NamedBiome.kt | 13 +++++++ .../custombiomes/impl/CustomBiomesTerra.kt | 21 ++++++---- 6 files changed, 42 insertions(+), 45 deletions(-) delete mode 100644 core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiome.kt create mode 100644 core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/NamedBiome.kt diff --git a/core/src/main/kotlin/com/willfp/libreforge/conditions/impl/ConditionInBiome.kt b/core/src/main/kotlin/com/willfp/libreforge/conditions/impl/ConditionInBiome.kt index 234a82d1f..d634bfa1f 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/conditions/impl/ConditionInBiome.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/conditions/impl/ConditionInBiome.kt @@ -7,7 +7,7 @@ import com.willfp.libreforge.NoCompileData import com.willfp.libreforge.ProvidedHolder import com.willfp.libreforge.arguments import com.willfp.libreforge.conditions.Condition -import com.willfp.libreforge.integrations.custombiomes.CustomBiomesManager +import com.willfp.libreforge.integrations.custombiomes.namedBiome object ConditionInBiome : Condition("in_biome") { override val arguments = arguments { @@ -21,8 +21,8 @@ object ConditionInBiome : Condition("in_biome") { compileData: NoCompileData ): Boolean { val location = dispatcher.location ?: return false - return config.getStrings("biomes").containsIgnoreCase( - CustomBiomesManager.getBiomeAt(location)?.name ?: return false - ) + + return config.getStrings("biomes") + .containsIgnoreCase(location.namedBiome?.name ?: return false) } } diff --git a/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiome.kt b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiome.kt deleted file mode 100644 index 44d423fea..000000000 --- a/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiome.kt +++ /dev/null @@ -1,4 +0,0 @@ -package com.willfp.libreforge.integrations.custombiomes - - -class CustomBiome(val name: String) \ No newline at end of file diff --git a/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesIntegration.kt b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesIntegration.kt index ad031ac57..ad7cd510b 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesIntegration.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesIntegration.kt @@ -10,5 +10,5 @@ interface CustomBiomesIntegration: LoadableIntegration { * @param location The location to get the biome at. * @return The found biome, null otherwise */ - fun getBiome(location: Location?): CustomBiome? + fun getBiome(location: Location?): NamedBiome? } \ No newline at end of file diff --git a/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesManager.kt b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesManager.kt index 1c65950bb..3de0b5ad3 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesManager.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/CustomBiomesManager.kt @@ -5,37 +5,18 @@ import com.willfp.libreforge.plugin import org.bukkit.Location import org.bukkit.event.Listener -object CustomBiomesManager { - /** - * A set of all registered biomes. - */ - private val REGISTRY = IntegrationRegistry() +val customBiomesIntegrations = IntegrationRegistry() - /** - * Register a new biomes integration. - * - * @param biomesIntegration The biomes integration to register. - */ - fun register(biomesIntegration: CustomBiomesIntegration) { - if (biomesIntegration is Listener) { - plugin.eventManager.registerListener((biomesIntegration as Listener)) - } - REGISTRY.register(biomesIntegration) - } +val Location.namedBiome: NamedBiome? + get() { + val world = this.world ?: return null + val vanilla = world.getBiome(this) - fun getBiomeAt(location: Location): CustomBiome? { - val world = location.world ?: return null - val vanilla = world.getBiome(location) - return if (vanilla.name.equals("custom", ignoreCase = true)) { - for (integration in REGISTRY) { - val biome = integration.getBiome(location) - if (biome != null) { - return biome - } - } - null + return if (vanilla.name.lowercase() == "biome") { + customBiomesIntegrations + .firstOrNull { it.getBiome(this) != null } + ?.getBiome(this) } else { - CustomBiome(vanilla.name) + VanillaNamedBiome(vanilla) } } -} \ No newline at end of file diff --git a/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/NamedBiome.kt b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/NamedBiome.kt new file mode 100644 index 000000000..0a235951c --- /dev/null +++ b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/NamedBiome.kt @@ -0,0 +1,13 @@ +package com.willfp.libreforge.integrations.custombiomes + +import org.bukkit.block.Biome + +interface NamedBiome { + val name: String +} + +class VanillaNamedBiome( + biome: Biome +) : NamedBiome { + override val name = biome.name +} diff --git a/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/impl/CustomBiomesTerra.kt b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/impl/CustomBiomesTerra.kt index bc2773b93..425c8f22d 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/impl/CustomBiomesTerra.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/integrations/custombiomes/impl/CustomBiomesTerra.kt @@ -1,18 +1,19 @@ package com.willfp.libreforge.integrations.custombiomes.impl +import com.dfsek.terra.api.world.biome.Biome import com.dfsek.terra.bukkit.world.BukkitAdapter import com.willfp.eco.core.EcoPlugin -import com.willfp.libreforge.integrations.custombiomes.CustomBiome import com.willfp.libreforge.integrations.custombiomes.CustomBiomesIntegration -import com.willfp.libreforge.integrations.custombiomes.CustomBiomesManager +import com.willfp.libreforge.integrations.custombiomes.NamedBiome +import com.willfp.libreforge.integrations.custombiomes.customBiomesIntegrations import org.bukkit.Location -object CustomBiomesTerra: CustomBiomesIntegration { +object CustomBiomesTerra : CustomBiomesIntegration { override fun getPluginName(): String { return "Terra" } - override fun getBiome(location: Location?): CustomBiome? { + override fun getBiome(location: Location?): NamedBiome? { if (location == null || location.world == null) { return null } @@ -22,10 +23,16 @@ object CustomBiomesTerra: CustomBiomesIntegration { val biomeProvider = terraWorld.biomeProvider ?: return null val biome = biomeProvider.getBiome(terraLocation, terraWorld.seed) ?: return null - return CustomBiome(biome.id) + return TerraNamedBiome(biome) } override fun load(plugin: EcoPlugin) { - CustomBiomesManager.register(this) + customBiomesIntegrations.register(this) } -} \ No newline at end of file + + private class TerraNamedBiome( + biome: Biome + ) : NamedBiome { + override val name: String = biome.id + } +} From c696d342f8d3258e4bb8ee5ff5c9c3fb69057043 Mon Sep 17 00:00:00 2001 From: Will FP Date: Mon, 11 Dec 2023 11:50:45 +0000 Subject: [PATCH 4/4] Improved location_to_drop --- .../mutators/impl/MutatorLocationToDrop.kt | 10 +++------- .../libreforge/triggers/event/EditableDropEvent.kt | 12 ++++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/src/main/kotlin/com/willfp/libreforge/mutators/impl/MutatorLocationToDrop.kt b/core/src/main/kotlin/com/willfp/libreforge/mutators/impl/MutatorLocationToDrop.kt index aa7935a8c..ba745076a 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/mutators/impl/MutatorLocationToDrop.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/mutators/impl/MutatorLocationToDrop.kt @@ -2,14 +2,11 @@ package com.willfp.libreforge.mutators.impl import com.willfp.eco.core.config.interfaces.Config import com.willfp.libreforge.NoCompileData -import com.willfp.libreforge.arguments import com.willfp.libreforge.mutators.Mutator import com.willfp.libreforge.mutators.parameterTransformers -import com.willfp.libreforge.plugin import com.willfp.libreforge.triggers.TriggerData import com.willfp.libreforge.triggers.TriggerParameter -import org.bukkit.FluidCollisionMode -import org.bukkit.event.player.PlayerDropItemEvent +import com.willfp.libreforge.triggers.event.EditableDropEvent object MutatorLocationToDrop : Mutator("location_to_drop") { override val parameterTransformers = parameterTransformers { @@ -17,11 +14,10 @@ object MutatorLocationToDrop : Mutator("location_to_drop") { } override fun mutate(data: TriggerData, config: Config, compileData: NoCompileData): TriggerData { - val event = data.event as? PlayerDropItemEvent ?: return data - + val event = data.event as? EditableDropEvent ?: return data return data.copy( - location = event.itemDrop.location + location = event.dropLocation ) } } diff --git a/core/src/main/kotlin/com/willfp/libreforge/triggers/event/EditableDropEvent.kt b/core/src/main/kotlin/com/willfp/libreforge/triggers/event/EditableDropEvent.kt index 07e641420..a0e09509c 100644 --- a/core/src/main/kotlin/com/willfp/libreforge/triggers/event/EditableDropEvent.kt +++ b/core/src/main/kotlin/com/willfp/libreforge/triggers/event/EditableDropEvent.kt @@ -1,5 +1,6 @@ package com.willfp.libreforge.triggers.event +import org.bukkit.Location import org.bukkit.event.Cancellable import org.bukkit.event.Event import org.bukkit.event.HandlerList @@ -50,6 +51,11 @@ abstract class EditableDropEvent : Event(), Cancellable { */ abstract val items: List + /** + * The location of the drops. + */ + abstract val dropLocation: Location + /** * Remove an item. */ @@ -85,6 +91,9 @@ class EditableEntityDropEvent( override val items: List get() = originalItems.map { modifiers.modify(it) } + override val dropLocation: Location + get() = event.entity.location + override fun removeItem(item: ItemStack) { event.drops.remove(item) } @@ -113,6 +122,9 @@ class EditableBlockDropEvent( override val items: List get() = originalItems.map { modifiers.modify(it) } + override val dropLocation: Location + get() = event.items.first().location + override fun removeItem(item: ItemStack) { event.items.removeIf { it.itemStack == item } }