-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
261 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectSwarm.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.willfp.libreforge.effects.impl | ||
|
||
import com.willfp.eco.core.config.interfaces.Config | ||
import com.willfp.eco.core.entities.Entities | ||
import com.willfp.eco.core.entities.TestableEntity | ||
import com.willfp.eco.core.lookup.matches | ||
import com.willfp.libreforge.ConfigArguments | ||
import com.willfp.libreforge.NoCompileData | ||
import com.willfp.libreforge.ViolationContext | ||
import com.willfp.libreforge.arguments | ||
import com.willfp.libreforge.effects.Effect | ||
import com.willfp.libreforge.getDoubleFromExpression | ||
import com.willfp.libreforge.triggers.TriggerData | ||
import com.willfp.libreforge.triggers.TriggerParameter | ||
import org.bukkit.entity.Monster | ||
import org.checkerframework.checker.units.qual.t | ||
|
||
object EffectSwarm : Effect<List<TestableEntity>?>("swarm") { | ||
override val parameters = setOf( | ||
TriggerParameter.VICTIM | ||
) | ||
|
||
override val arguments = arguments { | ||
require("radius", "You must specify the maximum distance to swarm the victim from!") | ||
} | ||
|
||
override fun onTrigger(config: Config, data: TriggerData, compileData: List<TestableEntity>?): Boolean { | ||
val victim = data.victim ?: return false | ||
|
||
val radius = config.getDoubleFromExpression("radius", data) | ||
|
||
victim.getNearbyEntities(radius, radius, radius) | ||
.filterIsInstance<Monster>() | ||
.filter { compileData?.any { t -> t.matches(it) } ?: true } | ||
.forEach { it.target = victim } | ||
|
||
return true | ||
} | ||
|
||
override fun makeCompileData(config: Config, context: ViolationContext): List<TestableEntity>? { | ||
return config.getStringsOrNull("entities") | ||
?.mapNotNull { Entities.lookup(it) } | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
core/src/main/kotlin/com/willfp/libreforge/effects/impl/EffectTargetPlayer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.willfp.libreforge.effects.impl | ||
|
||
import com.willfp.eco.core.config.interfaces.Config | ||
import com.willfp.libreforge.NoCompileData | ||
import com.willfp.libreforge.effects.Effect | ||
import com.willfp.libreforge.triggers.TriggerData | ||
import com.willfp.libreforge.triggers.TriggerParameter | ||
import org.bukkit.entity.Monster | ||
|
||
object EffectTargetPlayer : Effect<NoCompileData>("target_player") { | ||
override val parameters = setOf( | ||
TriggerParameter.PLAYER, | ||
TriggerParameter.VICTIM | ||
) | ||
|
||
override fun onTrigger(config: Config, data: TriggerData, compileData: NoCompileData): Boolean { | ||
val player = data.player ?: return false | ||
val victim = data.victim as? Monster ?: return false | ||
|
||
victim.target = player | ||
|
||
return true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
core/src/main/kotlin/com/willfp/libreforge/mutators/TriggerParameterTransformer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.willfp.libreforge.mutators | ||
|
||
import com.willfp.libreforge.triggers.TriggerParameter | ||
|
||
data class TriggerParameterTransformer( | ||
val parameterIn: TriggerParameter, | ||
val parameterOut: TriggerParameter | ||
) { | ||
fun transform(parameters: Set<TriggerParameter>): Set<TriggerParameter> { | ||
return parameters.fold(mutableSetOf()) { acc, parameter -> | ||
if (parameter == parameterIn) { | ||
acc.apply { | ||
add(parameterIn) | ||
add(parameterOut) | ||
} | ||
} else { | ||
acc.apply { add(parameter) } | ||
} | ||
} | ||
} | ||
} | ||
|
||
class TriggerParameterBuilder { | ||
private val set = mutableSetOf<TriggerParameterTransformer>() | ||
|
||
infix fun TriggerParameter.becomes(other: TriggerParameter) { | ||
set += TriggerParameterTransformer(this, other) | ||
} | ||
|
||
internal fun toSet(): Set<TriggerParameterTransformer> { | ||
return set | ||
} | ||
} | ||
|
||
fun parameterTransformers(block: TriggerParameterBuilder.() -> Unit): Set<TriggerParameterTransformer> = | ||
TriggerParameterBuilder().apply(block).toSet() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.