Fix Essentials-OG integration
This commit is contained in:
1 parent
97dffe3dc5
commit
56400749e6
1 file changed
+16
-10
@@ -4,20 +4,26 @@ import net.trueog.questsOG.quests.*
|
||||
import org.bukkit.entity.Player
|
||||
|
||||
object HomesProgression : Progression {
|
||||
private const val HOMES_PERMISSION_PREFIX = "essentials.sethome.multiple.homes-"
|
||||
|
||||
override val quests = arrayOf(HomesTwo(), HomesThree(), HomesFour(), HomesFive(), HomesSix())
|
||||
|
||||
/**
|
||||
* Highest home tier the player currently holds via essentials.sethome.multiple.homes-N, or 1 if none. Takes the max
|
||||
* rather than assuming a single node so a leftover lower node (failed removal, group inheritance) never resets the
|
||||
* ladder.
|
||||
*/
|
||||
fun getCurrentHomeCount(player: Player): Int =
|
||||
player.effectivePermissions
|
||||
.filter { it.value && it.permission.startsWith(HOMES_PERMISSION_PREFIX) }
|
||||
.mapNotNull { it.permission.removePrefix(HOMES_PERMISSION_PREFIX).toIntOrNull() }
|
||||
.maxOrNull() ?: 1
|
||||
|
||||
override fun getNextQuest(player: Player): Quest? {
|
||||
val homePermission =
|
||||
player.effectivePermissions.singleOrNull { permission ->
|
||||
permission.permission.startsWith("essentials.sethome.multiple.homes-")
|
||||
}
|
||||
val nextQuestIndex = homePermission?.permission?.takeLast(1)?.toInt()?.minus(1) ?: 0
|
||||
// Quest at index i grants i + 2 homes, so the next quest lives at index current - 1.
|
||||
val nextQuestIndex = getCurrentHomeCount(player) - 1
|
||||
|
||||
if (nextQuestIndex + 1 > quests.size) {
|
||||
return null
|
||||
}
|
||||
|
||||
return quests[nextQuestIndex]
|
||||
return quests.getOrNull(nextQuestIndex)
|
||||
}
|
||||
|
||||
fun getHomeCount(quest: Quest): Int = quests.indexOf(quest) + 2
|
||||
|
||||
Reference in new issue
Block a user