From 8f335b925ffff3d41bb774fb8e314ea87fce0f1a Mon Sep 17 00:00:00 2001 From: Gabriel Dumitru Date: Sat, 14 Jan 2023 12:41:46 +0200 Subject: [PATCH] =?UTF-8?q?[plugin]=20keep=20the=20code=20clean=20?= =?UTF-8?q?=F0=9F=A4=A6=E2=80=8D=E2=99=82=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../location/DistanceRequirementFactory.kt | 8 ++++++-- .../number/NumberRequirementFactory.kt | 12 ++++++++++-- .../string/StringRequirementFactory.kt | 12 ++++++++++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/plugin/src/main/kotlin/me/gabytm/minecraft/arcanevouchers/voucher/requirements/implementations/location/DistanceRequirementFactory.kt b/plugin/src/main/kotlin/me/gabytm/minecraft/arcanevouchers/voucher/requirements/implementations/location/DistanceRequirementFactory.kt index 97e5086..6ff3e6f 100644 --- a/plugin/src/main/kotlin/me/gabytm/minecraft/arcanevouchers/voucher/requirements/implementations/location/DistanceRequirementFactory.kt +++ b/plugin/src/main/kotlin/me/gabytm/minecraft/arcanevouchers/voucher/requirements/implementations/location/DistanceRequirementFactory.kt @@ -10,6 +10,10 @@ import org.bukkit.configuration.ConfigurationSection class DistanceRequirementFactory : ArcaneRequirementFactory() { + private fun warnMissingProperty(source: ConfigurationSection, property: String) { + warning("Could not load '${DistanceRequirement.TYPE}' requirement from ${source.currentPath}: missing required property '${property}'") + } + override fun matches(source: ConfigurationSection): Boolean { var type = source.getString(Requirement.TYPE)?.trim() ?: return false @@ -27,13 +31,13 @@ class DistanceRequirementFactory : ArcaneRequirementFactory val location = LocationVariable( source.getString("location") ?: kotlin.run { - warning("Could not load 'distance' requirement from ${source.currentPath}: missing required property 'location'") + warnMissingProperty(source, "location") return null } ) val distance = DoubleVariable( source.getString("distance") ?: kotlin.run { - warning("Could not load 'distance' requirement from ${source.currentPath}: missing required property 'distance'") + warnMissingProperty(source, "distance") return null } ) diff --git a/plugin/src/main/kotlin/me/gabytm/minecraft/arcanevouchers/voucher/requirements/implementations/number/NumberRequirementFactory.kt b/plugin/src/main/kotlin/me/gabytm/minecraft/arcanevouchers/voucher/requirements/implementations/number/NumberRequirementFactory.kt index 9eee23e..870da5b 100644 --- a/plugin/src/main/kotlin/me/gabytm/minecraft/arcanevouchers/voucher/requirements/implementations/number/NumberRequirementFactory.kt +++ b/plugin/src/main/kotlin/me/gabytm/minecraft/arcanevouchers/voucher/requirements/implementations/number/NumberRequirementFactory.kt @@ -9,6 +9,14 @@ import org.bukkit.configuration.ConfigurationSection class NumberRequirementFactory : ArcaneRequirementFactory() { + private fun warnMissingProperty( + operation: NumberRequirement.Operation, + source: ConfigurationSection, + property: String + ) { + warning("Could not load '${operation.identifier}' requirement from ${source.currentPath}: missing required property '${property}'") + } + override fun matches(source: ConfigurationSection): Boolean { var type = source.getString(Requirement.TYPE)?.trim() ?: return false @@ -32,13 +40,13 @@ class NumberRequirementFactory : ArcaneRequirementFactory() { val operation = NumberRequirement.Operation.find(type) ?: return null val left = DoubleVariable( source.getString("left") ?: kotlin.run { - warning("Could not load '${operation.identifier}' requirement from ${source.currentPath}: missing required property 'left'") + warnMissingProperty(operation, source, "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'") + warnMissingProperty(operation, source, "right") return null } ) diff --git a/plugin/src/main/kotlin/me/gabytm/minecraft/arcanevouchers/voucher/requirements/implementations/string/StringRequirementFactory.kt b/plugin/src/main/kotlin/me/gabytm/minecraft/arcanevouchers/voucher/requirements/implementations/string/StringRequirementFactory.kt index f31ff08..92b4e6d 100644 --- a/plugin/src/main/kotlin/me/gabytm/minecraft/arcanevouchers/voucher/requirements/implementations/string/StringRequirementFactory.kt +++ b/plugin/src/main/kotlin/me/gabytm/minecraft/arcanevouchers/voucher/requirements/implementations/string/StringRequirementFactory.kt @@ -8,6 +8,14 @@ import org.bukkit.configuration.ConfigurationSection class StringRequirementFactory : ArcaneRequirementFactory() { + private fun warnMissingProperty( + operation: StringRequirement.Operation, + source: ConfigurationSection, + property: String + ) { + warning("Could not load '${operation.identifier}' requirement from ${source.currentPath}: missing required property '${property}'") + } + override fun matches(source: ConfigurationSection): Boolean { var type = source.getString(Requirement.TYPE)?.trim() ?: return false @@ -29,11 +37,11 @@ class StringRequirementFactory : ArcaneRequirementFactory() { val operation = StringRequirement.Operation.find(type) ?: return null val left = source.getString("left") ?: kotlin.run { - warning("Could not load '${operation.identifier}' requirement from ${source.currentPath}: missing required property 'left'") + warnMissingProperty(operation, source, "left") return null } val right = source.getString("right") ?: kotlin.run { - warning("Could not load '${operation.identifier}' requirement from ${source.currentPath}: missing required property 'right'") + warnMissingProperty(operation, source, "right") return null } val failActions = actionManager.parseActions(source.getStringList(Requirement.FAIL_ACTIONS))