-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* You can now simply specify something like "no-clear" in `tap:bossbar` without having to add a value to it. * Improved version parsing greatly * Fixed a crash with invalid parameters
- Loading branch information
1 parent
0ff5959
commit 587892f
Showing
3 changed files
with
42 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package live.ixnoah.tapactions.misc | ||
|
||
data class Version(val version: String) { | ||
val domains = version.split('.') | ||
.map { d -> return@map d.toIntOrNull() } | ||
.filterNotNull() | ||
|
||
fun compareTo(other: Version, depth: Int = 3): Int { | ||
if (domains.size < other.domains.size) { | ||
domains.forEachIndexed { i, d -> | ||
if (i > depth) return 0 | ||
if (other.domains[i] == d) return@forEachIndexed | ||
if (other.domains[i] > d) return 1 | ||
if (other.domains[i] < d) return -1 | ||
} | ||
} else { | ||
other.domains.forEachIndexed { i, d -> | ||
if (i > depth) return 0 | ||
if (domains[i] == d) return@forEachIndexed | ||
if (domains[i] > d) return 1 | ||
if (domains[i] < d) return -1 | ||
} | ||
} | ||
|
||
return 0 | ||
} | ||
|
||
fun greaterThan(other: Version, depth: Int = 3): Boolean { | ||
return this.compareTo(other, depth) > 0 | ||
} | ||
|
||
fun lessThan(other: Version, depth: Int = 3): Boolean { | ||
return this.compareTo(other, depth) > 0 | ||
} | ||
} |