Skip to content

Commit

Permalink
[plugin] keep the code clean 🤦‍♂️
Browse files Browse the repository at this point in the history
  • Loading branch information
iGabyTM committed Jan 14, 2023
1 parent 2ad103f commit 8f335b9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import org.bukkit.configuration.ConfigurationSection

class DistanceRequirementFactory : ArcaneRequirementFactory<DistanceRequirement>() {

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

Expand All @@ -27,13 +31,13 @@ class DistanceRequirementFactory : ArcaneRequirementFactory<DistanceRequirement>

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
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import org.bukkit.configuration.ConfigurationSection

class NumberRequirementFactory : ArcaneRequirementFactory<NumberRequirement>() {

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

Expand All @@ -32,13 +40,13 @@ class NumberRequirementFactory : ArcaneRequirementFactory<NumberRequirement>() {
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
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import org.bukkit.configuration.ConfigurationSection

class StringRequirementFactory : ArcaneRequirementFactory<StringRequirement>() {

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

Expand All @@ -29,11 +37,11 @@ class StringRequirementFactory : ArcaneRequirementFactory<StringRequirement>() {

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))
Expand Down

0 comments on commit 8f335b9

Please sign in to comment.