Skip to content

Commit

Permalink
Fix /statbuild view, closes #603
Browse files Browse the repository at this point in the history
  • Loading branch information
renbinden committed Jul 4, 2022
1 parent 79cdd21 commit 38d666e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2021 Ren Binden
* Copyright 2022 Ren Binden
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand Down Expand Up @@ -94,14 +95,17 @@ class StatBuildAssignPointCommand(private val plugin: RPKStatBuildsBukkit) : Com
sender.sendMessage(plugin.messages["stat-build-assign-point-invalid-points-too-many-in-stat"])
return@getStatPoints
}
statBuildService.setStatPoints(character, statAttribute, assignedStatPoints + points)
sender.sendMessage(plugin.messages["stat-build-assign-point-valid", mapOf(
"character" to character.name,
"stat_attribute" to statAttribute.name.value,
"points" to points.toString(),
"total_points" to statBuildService.getStatPoints(character, statAttribute).toString(),
"max_points" to statBuildService.getMaxStatPoints(character, statAttribute).toString()
)])
statBuildService.setStatPoints(character, statAttribute, assignedStatPoints + points).thenRunAsync {
sender.sendMessage(
plugin.messages["stat-build-assign-point-valid", mapOf(
"character" to character.name,
"stat_attribute" to statAttribute.name.value,
"points" to points.toString(),
"total_points" to statBuildService.getStatPoints(character, statAttribute).join().toString(),
"max_points" to statBuildService.getMaxStatPoints(character, statAttribute).toString()
)]
)
}
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright 2021 Ren Binden
* Copyright 2022 Ren Binden
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -25,6 +26,7 @@ import org.bukkit.command.Command
import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import java.util.concurrent.CompletableFuture

class StatBuildViewCommand(private val plugin: RPKStatBuildsBukkit) : CommandExecutor {
override fun onCommand(sender: CommandSender, command: Command, label: String, args: Array<out String>): Boolean {
Expand Down Expand Up @@ -67,17 +69,28 @@ class StatBuildViewCommand(private val plugin: RPKStatBuildsBukkit) : CommandExe
sender.sendMessage(plugin.messages["no-stat-build-service"])
return true
}
sender.sendMessage(plugin.messages["stat-build-view-points-assignment-count", mapOf(
"total" to statBuildService.getTotalStatPoints(character).toString(),
"assigned" to statBuildService.getAssignedStatPoints(character).toString(),
"unassigned" to statBuildService.getUnassignedStatPoints(character).toString()
)])
statAttributeService.statAttributes.forEach { statAttribute ->
sender.sendMessage(plugin.messages["stat-build-view-item", mapOf(
val totalStatPointsFuture = statBuildService.getTotalStatPoints(character)
val assignedStatPointsFuture = statBuildService.getAssignedStatPoints(character)
val unassignedStatPointsFuture = statBuildService.getUnassignedStatPoints(character)
val statAttributePointsFutures = statAttributeService.statAttributes.associateWith { statAttribute -> statBuildService.getStatPoints(character, statAttribute) }
CompletableFuture.allOf(
totalStatPointsFuture,
assignedStatPointsFuture,
unassignedStatPointsFuture,
CompletableFuture.allOf(*statAttributePointsFutures.values.toTypedArray())
).thenRunAsync {
sender.sendMessage(plugin.messages["stat-build-view-points-assignment-count", mapOf(
"total" to totalStatPointsFuture.join().toString(),
"assigned" to assignedStatPointsFuture.join().toString(),
"unassigned" to unassignedStatPointsFuture.join().toString()
)])
statAttributeService.statAttributes.forEach { statAttribute ->
sender.sendMessage(plugin.messages["stat-build-view-item", mapOf(
"stat_attribute" to statAttribute.name.value,
"points" to statBuildService.getStatPoints(character, statAttribute).toString(),
"points" to statAttributePointsFutures[statAttribute]?.join().toString(),
"max_points" to statBuildService.getMaxStatPoints(character, statAttribute).toString()
)])
)])
}
}
return true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RPKStatBuildServiceImpl(override val plugin: RPKStatBuildsBukkit) : RPKSta

override fun getMaxStatPoints(character: RPKCharacter, statAttribute: RPKStatAttribute): Int {
val expressionService = Services[RPKExpressionService::class.java] ?: return 0
val expression = expressionService.createExpression(plugin.config.getString("stat-attributes.${statAttribute.name}.max-points") ?: return 0)
val expression = expressionService.createExpression(plugin.config.getString("stat-attributes.${statAttribute.name.value}.max-points") ?: return 0)
return expression.parseInt(
mapOf(
"level" to (Services[RPKExperienceService::class.java]?.getLevel(character)?.join()?.toDouble() ?: 1.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ stat-build-usage: '&cUsage: /statbuild [view|assignpoint]'
no-permission-stat-build-view: '&cYou do not have permission to view your stat build.'
stat-build-view-title: '&fStat build:'
stat-build-view-points-assignment-count: '&fTotal stat points: &7${total}&f, Unassigned: &7${unassigned}&f, Assigned: &7${assigned}'
stat-build-view-item: '&f${stat}-attribute &e${points}&7/&f${max_points}'
stat-build-view-item: '&f${stat_attribute} &e${points}&7/&f${max_points}'
stat-attribute-usage: '&cUsage: /statattribute [list]'
no-permission-stat-attribute-list: '&cYou do not have permission to list stat attributes.'
stat-attribute-list-title: '&fStat attributes:'
Expand Down

0 comments on commit 38d666e

Please sign in to comment.