Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/main/kotlin/pl/syntaxdevteam/plotsx/loader/SemanticVersion.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package pl.syntaxdevteam.plotsx.loader

data class SemanticVersion(
val major: Int,
val minor: Int,
val patch: Int
) : Comparable<SemanticVersion> {
override fun compareTo(other: SemanticVersion): Int {
return compareValuesBy(
this,
other,
SemanticVersion::major,
SemanticVersion::minor,
SemanticVersion::patch
)
}

override fun toString(): String = "$major.$minor.$patch"

companion object {
private val VERSION_PATTERN = Regex("\\d+(?:\\.\\d+){0,2}")

fun parse(raw: String): SemanticVersion {
val clean = VERSION_PATTERN.find(raw)?.value ?: "0.0.0"
val parts = clean.split('.')
val major = parts.getOrNull(0)?.toIntOrNull() ?: 0
val minor = parts.getOrNull(1)?.toIntOrNull() ?: 0
val patch = parts.getOrNull(2)?.toIntOrNull() ?: 0
return SemanticVersion(major, minor, patch)
}
}
}

fun SemanticVersion.isBetween(start: SemanticVersion, endInclusive: SemanticVersion?): Boolean {
if (this < start) return false
if (endInclusive == null) return true
return this <= endInclusive
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package pl.syntaxdevteam.plotsx.loader

import org.bukkit.Bukkit
import pl.syntaxdevteam.core.platform.ServerEnvironment
import pl.syntaxdevteam.plotsx.PlotsX

class VersionChecker(private val plugin: PlotsX) {

companion object {
Expand All @@ -22,7 +24,7 @@ class VersionChecker(private val plugin: PlotsX) {
SemanticVersion(26, 1, 0),
SemanticVersion(26, 1, 1),
SemanticVersion(26, 1, 2),
SemanticVersion(26,2,0)
SemanticVersion(26, 2, 0)
)

fun isVersionSupported(version: String): Boolean =
Expand Down Expand Up @@ -58,5 +60,3 @@ class VersionChecker(private val plugin: PlotsX) {
return current >= required
}
}


Loading