Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Dec 11, 2023
2 parents 08c9b81 + c696d34 commit 689e583
Show file tree
Hide file tree
Showing 13 changed files with 138 additions and 24 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) }
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.namedBiome

object ConditionInBiome : Condition<NoCompileData>("in_biome") {
override val arguments = arguments {
Expand All @@ -19,12 +21,8 @@ object ConditionInBiome : Condition<NoCompileData>("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(location.namedBiome?.name ?: return false)
}
}
Original file line number Diff line number Diff line change
@@ -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?): NamedBiome?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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

val customBiomesIntegrations = IntegrationRegistry<CustomBiomesIntegration>()

val Location.namedBiome: NamedBiome?
get() {
val world = this.world ?: return null
val vanilla = world.getBiome(this)

return if (vanilla.name.lowercase() == "biome") {
customBiomesIntegrations
.firstOrNull { it.getBiome(this) != null }
?.getBiome(this)
} else {
VanillaNamedBiome(vanilla)
}
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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.CustomBiomesIntegration
import com.willfp.libreforge.integrations.custombiomes.NamedBiome
import com.willfp.libreforge.integrations.custombiomes.customBiomesIntegrations
import org.bukkit.Location

object CustomBiomesTerra : CustomBiomesIntegration {
override fun getPluginName(): String {
return "Terra"
}

override fun getBiome(location: Location?): NamedBiome? {
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 TerraNamedBiome(biome)
}

override fun load(plugin: EcoPlugin) {
customBiomesIntegrations.register(this)
}

private class TerraNamedBiome(
biome: Biome
) : NamedBiome {
override val name: String = biome.id
}
}
17 changes: 2 additions & 15 deletions core/src/main/kotlin/com/willfp/libreforge/mutators/Mutators.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutator<*>>() {
/**
Expand Down Expand Up @@ -76,5 +62,6 @@ object Mutators: Registry<Mutator<*>>() {
register(MutatorVictimAsDispatcher)
register(MutatorDispatcherAsPlayer)
register(MutatorDispatcherAsVictim)
register(MutatorLocationToDrop)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.willfp.libreforge.mutators.impl

import com.willfp.eco.core.config.interfaces.Config
import com.willfp.libreforge.NoCompileData
import com.willfp.libreforge.mutators.Mutator
import com.willfp.libreforge.mutators.parameterTransformers
import com.willfp.libreforge.triggers.TriggerData
import com.willfp.libreforge.triggers.TriggerParameter
import com.willfp.libreforge.triggers.event.EditableDropEvent

object MutatorLocationToDrop : Mutator<NoCompileData>("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? EditableDropEvent ?: return data

return data.copy(
location = event.dropLocation
)
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -50,6 +51,11 @@ abstract class EditableDropEvent : Event(), Cancellable {
*/
abstract val items: List<DropResult>

/**
* The location of the drops.
*/
abstract val dropLocation: Location

/**
* Remove an item.
*/
Expand Down Expand Up @@ -85,6 +91,9 @@ class EditableEntityDropEvent(
override val items: List<DropResult>
get() = originalItems.map { modifiers.modify(it) }

override val dropLocation: Location
get() = event.entity.location

override fun removeItem(item: ItemStack) {
event.drops.remove(item)
}
Expand Down Expand Up @@ -113,6 +122,9 @@ class EditableBlockDropEvent(
override val items: List<DropResult>
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 }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
)
)
}
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ softdepend:
- WorldGuard
- Citizens
- TAB
- Terra

commands:
lrcdb:
Expand Down

0 comments on commit 689e583

Please sign in to comment.