Skip to content

Commit

Permalink
[plugin] add more variables for requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
iGabyTM committed Jan 12, 2023
1 parent fad6fcf commit 6ae5b24
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 15 deletions.

This file was deleted.

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() }
)
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() }
)
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)
}
)
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)

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.
import me.gabytm.minecraft.arcanevouchers.actions.ArcaneAction
import me.gabytm.minecraft.arcanevouchers.actions.ArcaneActionManager
import me.gabytm.minecraft.arcanevouchers.voucher.requirements.ArcaneRequirement
import me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.common.DoubleVariable
import me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.common.variable.DoubleVariable
import me.gabytm.minecraft.util.requirements.Arguments
import org.bukkit.entity.Player
import java.util.*
Expand Down

0 comments on commit 6ae5b24

Please sign in to comment.