Added BadIPDetection
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package net.axay.kspigot.languageextensions
|
||||
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.JsonObject
|
||||
import java.net.URL
|
||||
|
||||
internal fun JsonObject.getStringOrNull(key: String): String? {
|
||||
return try {
|
||||
this[key].toString()
|
||||
} catch (exc: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
internal fun Gson.fromUrlJson(url: String): JsonObject? {
|
||||
return fromJson(
|
||||
URL(url).readText(),
|
||||
JsonObject::class.java
|
||||
) ?: return null
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package net.axay.kspigot.languageextensions
|
||||
|
||||
import org.json.JSONObject
|
||||
|
||||
internal fun JSONObject.getStringOrNull(key: String): String? {
|
||||
return try {
|
||||
this[key].toString()
|
||||
} catch (exc: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package net.axay.kspigot.languageextensions.kotlinextensions
|
||||
|
||||
import java.io.File
|
||||
|
||||
internal fun File.createIfNotExists(): Boolean {
|
||||
return if (!exists()) {
|
||||
if (!parentFile.exists())
|
||||
parentFile.mkdirs()
|
||||
createNewFile()
|
||||
} else true
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package net.axay.kspigot.languageextensions.kotlinextensions
|
||||
|
||||
internal fun <T> T.applyIfNotNull(block: (T.() -> Unit)?): T {
|
||||
if (block != null)
|
||||
apply(block)
|
||||
return this
|
||||
}
|
@@ -0,0 +1,7 @@
|
||||
package net.axay.kspigot.languageextensions.kotlinextensions
|
||||
|
||||
internal inline fun <T, R> Lazy<T>.ifInitialized(block: (T) -> R) = if (isInitialized()) block(value) else null
|
||||
|
||||
internal val <T> Lazy<T>.valueIfInitialized get() = ifInitialized { value }
|
||||
|
||||
internal fun Lazy<AutoCloseable>.closeIfInitialized() = ifInitialized { value.close() }
|
@@ -0,0 +1,18 @@
|
||||
@file:Suppress("MemberVisibilityCanBePrivate")
|
||||
|
||||
package net.axay.kspigot.languageextensions.kotlinextensions
|
||||
|
||||
internal class MinMaxPair<T : Comparable<T>>(a: T, b: T) {
|
||||
|
||||
val min: T;
|
||||
val max: T
|
||||
|
||||
init {
|
||||
if (a >= b) {
|
||||
min = b; max = a
|
||||
} else {
|
||||
min = a; max = b
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user