Skip to content

Commit

Permalink
Optimizations and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
WillFP committed Nov 26, 2021
1 parent 03151ad commit be7350d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 56 deletions.
6 changes: 5 additions & 1 deletion eco-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
}
}
}
102 changes: 50 additions & 52 deletions eco-api/src/main/kotlin/com/willfp/libreforge/LibReforge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<HolderProvider>()
Expand Down Expand Up @@ -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<Holder>()
val removed = mutableListOf<Holder>()
val added = mutableListOf<Holder>()
val removed = mutableListOf<Holder>()

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)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = 1.2.0
version = 1.2.1
plugin-name = libreforge

0 comments on commit be7350d

Please sign in to comment.