From be7350d3dd70b9cceb2b0bb9f48dab98e40fd389 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Fri, 26 Nov 2021 20:44:47 +0000 Subject: [PATCH] Optimizations and bug fixes --- eco-api/build.gradle | 6 +- .../com/willfp/libreforge/LibReforge.kt | 102 +++++++++--------- .../conditions/conditions/ConditionAboveY.kt | 2 +- .../conditions/conditions/ConditionBelowY.kt | 2 +- .../conditions/conditions/ConditionInAir.kt | 4 + gradle.properties | 2 +- 6 files changed, 62 insertions(+), 56 deletions(-) diff --git a/eco-api/build.gradle b/eco-api/build.gradle index 476c3ef13..f3093f280 100644 --- a/eco-api/build.gradle +++ b/eco-api/build.gradle @@ -5,12 +5,16 @@ dependencies { compileOnly 'com.github.Archy-X:AureliumSkills:Beta1.2.4' } +group 'com.willfp' +version rootProject.version + build.dependsOn publishToMavenLocal publishing { publications { maven(MavenPublication) { from(components.java) + artifactId 'libreforge' } } -} \ No newline at end of file +} diff --git a/eco-api/src/main/kotlin/com/willfp/libreforge/LibReforge.kt b/eco-api/src/main/kotlin/com/willfp/libreforge/LibReforge.kt index 332c6be02..9792629bd 100644 --- a/eco-api/src/main/kotlin/com/willfp/libreforge/LibReforge.kt +++ b/eco-api/src/main/kotlin/com/willfp/libreforge/LibReforge.kt @@ -13,7 +13,6 @@ import com.willfp.libreforge.triggers.Triggers import org.apache.commons.lang.StringUtils import org.bukkit.Bukkit import org.bukkit.entity.Player -import org.bukkit.event.Listener import java.util.* private val holderProviders = mutableSetOf() @@ -129,73 +128,72 @@ fun Player.updateEffects() { } this.clearEffectCache() - LibReforge.plugin.scheduler.run { - val after = this.getHolders() - previousStates[this.uniqueId] = after + val after = this.getHolders() + previousStates[this.uniqueId] = after - val beforeFreq = ListUtils.listToFrequencyMap(before) - val afterFreq = ListUtils.listToFrequencyMap(after.toList()) + val beforeFreq = ListUtils.listToFrequencyMap(before) + val afterFreq = ListUtils.listToFrequencyMap(after.toList()) - val added = mutableListOf() - val removed = mutableListOf() + val added = mutableListOf() + val removed = mutableListOf() - for ((holder, freq) in afterFreq) { - var amount = freq - amount -= beforeFreq[holder] ?: 0 - if (amount < 1) { - continue - } + for ((holder, freq) in afterFreq) { + var amount = freq + amount -= beforeFreq[holder] ?: 0 + if (amount < 1) { + continue + } - for (i in 0 until amount) { - added.add(holder) - } + for (i in 0 until amount) { + added.add(holder) } + } - for ((holder, freq) in beforeFreq) { - var amount = freq + for ((holder, freq) in beforeFreq) { + var amount = freq - amount -= afterFreq[holder] ?: 0 - if (amount < 1) { - continue - } - for (i in 0 until amount) { - removed.add(holder) - } + amount -= afterFreq[holder] ?: 0 + if (amount < 1) { + continue } + for (i in 0 until amount) { + removed.add(holder) + } + } - for (holder in added) { - var areConditionsMet = true - for ((condition, config) in holder.conditions) { - if (!condition.isConditionMet(this, config)) { - areConditionsMet = false - break - } + for (holder in added) { + var areConditionsMet = true + for ((condition, config) in holder.conditions) { + if (!condition.isConditionMet(this, config)) { + areConditionsMet = false + break } + } - if (areConditionsMet) { - for ((effect, config) in holder.effects) { - effect.enableForPlayer(this, config) - } + if (areConditionsMet) { + for ((effect, config) in holder.effects) { + effect.enableForPlayer(this, config) } } - for (holder in removed) { - for ((effect, _) in holder.effects) { - effect.disableForPlayer(this) - } + } + + for (holder in removed) { + for ((effect, _) in holder.effects) { + effect.disableForPlayer(this) } + } - for (holder in after) { - var areConditionsMet = true - for ((condition, config) in holder.conditions) { - if (!condition.isConditionMet(this, config)) { - areConditionsMet = false - break - } + for (holder in after) { + var areConditionsMet = true + for ((condition, config) in holder.conditions) { + if (!condition.isConditionMet(this, config)) { + areConditionsMet = false + break } - if (!areConditionsMet) { - for ((effect, _) in holder.effects) { - effect.disableForPlayer(this) - } + } + if (!areConditionsMet) { + for ((effect, _) in holder.effects) { + effect.disableForPlayer(this) } } } diff --git a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionAboveY.kt b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionAboveY.kt index ac6faa1f6..09632b2dc 100644 --- a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionAboveY.kt +++ b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionAboveY.kt @@ -16,7 +16,7 @@ class ConditionAboveY: Condition("above_y") { fun handle(event: PlayerMoveEvent) { val player = event.player - if (event.from.y == event.to.y) { + if (event.from.blockY == event.to.blockY) { return } diff --git a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionBelowY.kt b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionBelowY.kt index e328b63f6..9906af6e5 100644 --- a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionBelowY.kt +++ b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionBelowY.kt @@ -16,7 +16,7 @@ class ConditionBelowY: Condition("below_y") { fun handle(event: PlayerMoveEvent) { val player = event.player - if (event.from.y == event.to.y) { + if (event.from.blockY == event.to.blockY) { return } diff --git a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionInAir.kt b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionInAir.kt index 589756bc4..c07582151 100644 --- a/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionInAir.kt +++ b/eco-api/src/main/kotlin/com/willfp/libreforge/conditions/conditions/ConditionInAir.kt @@ -17,6 +17,10 @@ class ConditionInAir: Condition("in_air") { fun handle(event: PlayerMoveEvent) { val player = event.player + if (event.from.world?.getBlockAt(event.from)?.type == event.to.world?.getBlockAt(event.to)?.type) { + return + } + player.updateEffects() } diff --git a/gradle.properties b/gradle.properties index eee6812c4..ba1853e0e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ -version = 1.2.0 +version = 1.2.1 plugin-name = libreforge \ No newline at end of file