Skip to content

Commit

Permalink
[plugin] add warnings to factories for missing properties
Browse files Browse the repository at this point in the history
  • Loading branch information
iGabyTM committed Jan 14, 2023
1 parent 849a5f1 commit 2ad103f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.

import me.gabytm.minecraft.arcanevouchers.Constant.Requirement
import me.gabytm.minecraft.arcanevouchers.actions.ArcaneActionManager
import me.gabytm.minecraft.arcanevouchers.functions.warning
import me.gabytm.minecraft.arcanevouchers.voucher.requirements.ArcaneRequirementFactory
import me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.common.variable.DoubleVariable
import me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.common.variable.LocationVariable
Expand All @@ -24,8 +25,18 @@ class DistanceRequirementFactory : ArcaneRequirementFactory<DistanceRequirement>
val negated = type.startsWith(Requirement.NEGATION)
val optional = source.getBoolean(Requirement.OPTIONAL)

val location = LocationVariable(source.getString("location") ?: return null)
val distance = DoubleVariable(source.getString("distance") ?: return null)
val location = LocationVariable(
source.getString("location") ?: kotlin.run {
warning("Could not load 'distance' requirement from ${source.currentPath}: missing required property 'location'")
return null
}
)
val distance = DoubleVariable(
source.getString("distance") ?: kotlin.run {
warning("Could not load 'distance' requirement from ${source.currentPath}: missing required property 'distance'")
return null
}
)
val failActions = actionManager.parseActions(source.getStringList(Requirement.FAIL_ACTIONS))
return DistanceRequirement(source.name, optional, negated, failActions, actionManager, location, distance)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class NumberRequirement(
}

@Suppress("unused")
enum class Operation(private val identifier: String) {
enum class Operation(val identifier: String) {

EQUAL("==") {
override fun check(left: Double, right: Double, negated: Boolean): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.

import me.gabytm.minecraft.arcanevouchers.Constant.Requirement
import me.gabytm.minecraft.arcanevouchers.actions.ArcaneActionManager
import me.gabytm.minecraft.arcanevouchers.functions.warning
import me.gabytm.minecraft.arcanevouchers.voucher.requirements.ArcaneRequirementFactory
import me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.common.variable.DoubleVariable
import org.bukkit.configuration.ConfigurationSection
Expand All @@ -27,9 +28,20 @@ class NumberRequirementFactory : ArcaneRequirementFactory<NumberRequirement>() {
type = type.substring(1)
}

// Not adding a warning for this because it won't get to this point if the factory couldn't find an Operation
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 left = DoubleVariable(
source.getString("left") ?: kotlin.run {
warning("Could not load '${operation.identifier}' requirement from ${source.currentPath}: missing required property 'left'")
return null
}
)
val right = DoubleVariable(
source.getString("right") ?: kotlin.run {
warning("Could not load '${operation.identifier}' requirement from ${source.currentPath}: missing required property 'right'")
return null
}
)
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
Expand Up @@ -26,7 +26,7 @@ class StringRequirement(
}

@Suppress("unused")
enum class Operation(private val identifier: String) {
enum class Operation(val identifier: String) {

EQUALS("string equals") {
override fun check(left: String?, right: String?, negated: Boolean): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package me.gabytm.minecraft.arcanevouchers.voucher.requirements.implementations.

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

Expand All @@ -27,8 +28,14 @@ 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 left = source.getString("left") ?: kotlin.run {
warning("Could not load '${operation.identifier}' requirement from ${source.currentPath}: missing required property 'left'")
return null
}
val right = source.getString("right") ?: kotlin.run {
warning("Could not load '${operation.identifier}' requirement from ${source.currentPath}: missing required property 'right'")
return null
}
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 2ad103f

Please sign in to comment.