-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[plugin] add more variables for requirements
- Loading branch information
Showing
6 changed files
with
59 additions
and
15 deletions.
There are no files selected for viewing
14 changes: 0 additions & 14 deletions
14
...tm/minecraft/arcanevouchers/voucher/requirements/implementations/common/DoubleVariable.kt
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
...ft/arcanevouchers/voucher/requirements/implementations/common/variable/BooleanVariable.kt
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,9 @@ | ||
package me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.common.variable | ||
|
||
import me.gabytm.minecraft.arcanevouchers.functions.papi | ||
|
||
data class BooleanVariable( | ||
private val stringValue: String | ||
) : Variable<Boolean>( | ||
{ player -> stringValue.toBooleanStrictOrNull() ?: stringValue.papi(player).toBooleanStrictOrNull() } | ||
) |
9 changes: 9 additions & 0 deletions
9
...aft/arcanevouchers/voucher/requirements/implementations/common/variable/DoubleVariable.kt
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,9 @@ | ||
package me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.common.variable | ||
|
||
import me.gabytm.minecraft.arcanevouchers.functions.papi | ||
|
||
data class DoubleVariable( | ||
private val string: String | ||
) : Variable<Double>( | ||
{ player -> string.toDoubleOrNull() ?: string.papi(player).toDoubleOrNull() } | ||
) |
25 changes: 25 additions & 0 deletions
25
...t/arcanevouchers/voucher/requirements/implementations/common/variable/LocationVariable.kt
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,25 @@ | ||
package me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.common.variable | ||
|
||
import me.gabytm.minecraft.arcanevouchers.Constant | ||
import me.gabytm.minecraft.arcanevouchers.functions.papi | ||
import org.bukkit.Bukkit | ||
import org.bukkit.Location | ||
|
||
data class LocationVariable( | ||
private val string: String | ||
) : Variable<Location>( | ||
transformer@{ player -> | ||
// world;x;y;z | ||
val parts = string.papi(player).split(Constant.Separator.SEMICOLON) | ||
|
||
if (parts.size != 4) { | ||
return@transformer null | ||
} | ||
|
||
val world = Bukkit.getWorld(parts[0]) ?: return@transformer null | ||
val x = parts[1].toDoubleOrNull() ?: return@transformer null | ||
val y = parts[2].toDoubleOrNull() ?: return@transformer null | ||
val z = parts[3].toDoubleOrNull() ?: return@transformer null | ||
return@transformer Location(world, x, y, z) | ||
} | ||
) |
15 changes: 15 additions & 0 deletions
15
...minecraft/arcanevouchers/voucher/requirements/implementations/common/variable/Variable.kt
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,15 @@ | ||
package me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.common.variable | ||
|
||
import org.bukkit.entity.Player | ||
|
||
abstract class Variable<T>( | ||
private val transformer: (player: Player?) -> T? | ||
) { | ||
|
||
@Suppress("unused") | ||
private val variableType = this::class.java.simpleName | ||
private val parsed: T? = transformer(null) | ||
|
||
fun get(player: Player?): T? = parsed ?: transformer(player) | ||
|
||
} |
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