Skip to content

Commit

Permalink
[plugin] add constants for requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
iGabyTM committed Jan 12, 2023
1 parent 7b70f8b commit fad6fcf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ object Constant {

}

object Requirement {

const val TYPE: String = "type"
const val OPTIONAL: String = "optional"
const val NEGATION: Char = '!'
const val FAIL_ACTIONS: String = "failActions"

}

object Separator {

val COLON = Regex(":")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.number

import me.gabytm.minecraft.arcanevouchers.Constant.Requirement
import me.gabytm.minecraft.arcanevouchers.actions.ArcaneActionManager
import me.gabytm.minecraft.arcanevouchers.voucher.requirements.ArcaneRequirementFactory
import me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.common.DoubleVariable
import me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.common.variable.DoubleVariable
import org.bukkit.configuration.ConfigurationSection

class NumberRequirementFactory : ArcaneRequirementFactory<NumberRequirement>() {

override fun matches(source: ConfigurationSection): Boolean {
var type = source.getString("type")?.trim() ?: return false
var type = source.getString(Requirement.TYPE)?.trim() ?: return false

if (type.startsWith('!')) {
if (type.startsWith(Requirement.NEGATION)) {
type = type.substring(1)
}

return NumberRequirement.Operation.find(type) != null
}

override fun create(source: ConfigurationSection, actionManager: ArcaneActionManager): NumberRequirement? {
var type = source.getString("type")?.trim() ?: return null
val negated = type.startsWith('!')
val optional = source.getBoolean("optional")
var type = source.getString(Requirement.TYPE)?.trim() ?: return null
val negated = type.startsWith(Requirement.NEGATION)
val optional = source.getBoolean(Requirement.OPTIONAL)

if (negated) {
type = type.substring(1)
Expand All @@ -29,7 +30,7 @@ class NumberRequirementFactory : ArcaneRequirementFactory<NumberRequirement>() {
val operation = NumberRequirement.Operation.find(type) ?: return null
val left = DoubleVariable(source.getString("left") ?: return null)
val right = DoubleVariable(source.getString("right") ?: return null)
val failActions = actionManager.parseActions(source.getStringList("failActions"))
val failActions = actionManager.parseActions(source.getStringList(Requirement.FAIL_ACTIONS))
return NumberRequirement(source.name, optional, negated, failActions, actionManager, left, right, operation)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
package me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.string

import me.gabytm.minecraft.arcanevouchers.Constant.Requirement
import me.gabytm.minecraft.arcanevouchers.actions.ArcaneActionManager
import me.gabytm.minecraft.arcanevouchers.voucher.requirements.ArcaneRequirementFactory
import org.bukkit.configuration.ConfigurationSection

class StringRequirementFactory : ArcaneRequirementFactory<StringRequirement>() {

override fun matches(source: ConfigurationSection): Boolean {
var type = source.getString("type")?.trim() ?: return false
var type = source.getString(Requirement.TYPE)?.trim() ?: return false

if (type.startsWith('!')) {
if (type.startsWith(Requirement.NEGATION)) {
type = type.substring(1)
}

return StringRequirement.Operation.find(type) != null
}

override fun create(source: ConfigurationSection, actionManager: ArcaneActionManager): StringRequirement? {
var type = source.getString("type")?.trim() ?: return null
val negated = type.startsWith('!')
val optional = source.getBoolean("optional")
var type = source.getString(Requirement.TYPE)?.trim() ?: return null
val negated = type.startsWith(Requirement.TYPE)
val optional = source.getBoolean(Requirement.OPTIONAL)

if (negated) {
type = type.substring(1)
Expand All @@ -28,7 +29,7 @@ class StringRequirementFactory : ArcaneRequirementFactory<StringRequirement>() {
val operation = StringRequirement.Operation.find(type) ?: return null
val left = source.getString("left") ?: return null
val right = source.getString("right") ?: return null
val failActions = actionManager.parseActions(source.getStringList("failActions"))
val failActions = actionManager.parseActions(source.getStringList(Requirement.FAIL_ACTIONS))
return StringRequirement(source.name, optional, negated, failActions, actionManager, left, right, operation)
}

Expand Down

0 comments on commit fad6fcf

Please sign in to comment.