Skip to content

Commit

Permalink
Reload supports placeholders
Browse files Browse the repository at this point in the history
  • Loading branch information
ToberoCat committed Oct 8, 2023
1 parent dbdbcb5 commit d11081e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<commons.text.version>1.10.0</commons.text.version>
<jetbrains.annotations.version>23.0.0</jetbrains.annotations.version>
<spigot.api.version>1.18.1-R0.1-SNAPSHOT</spigot.api.version>
<toberocore.version>0f2d094899</toberocore.version>
<toberocore.version>d5978b5eec</toberocore.version>
<kotlin.version>1.9.10</kotlin.version>
<org.slf4j.version>1.7.5</org.slf4j.version>

Expand Down
12 changes: 8 additions & 4 deletions src/main/kotlin/io/github/toberocat/guiengine/GuiEngineApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,15 @@ class GuiEngineApi(
* @throws GuiIORuntimeException If there is an I/O error while loading or validating GUIs.
*/
@Throws(GuiIORuntimeException::class)
fun reload(logger: GuiLogger) {
fun reload(logger: GuiLogger, guiPlaceholders: Map<String, Map<String, String>> = mapOf()) {
availableGuis =
listGuis(guiFolder).stream().map { file: File -> guiIdFromFile(file) }.collect(Collectors.toSet())

val totals = LongArray(availableGuis.size)
val guisCopy = ArrayList(availableGuis)

for (i in guisCopy.indices) totals[i] = validateGui(logger, guisCopy[i])
for (i in guisCopy.indices) totals[i] =
validateGui(logger, guisCopy[i], guiPlaceholders[guisCopy[i]] ?: emptyMap())

val avg = Arrays.stream(totals).average().orElse(Double.NaN)
val sumSquaredDifferences =
Expand Down Expand Up @@ -230,14 +231,17 @@ class GuiEngineApi(
}

@Throws(GuiIORuntimeException::class)
private fun validateGui(logger: GuiLogger, gui: String): Long {
private fun validateGui(logger: GuiLogger, gui: String, placeholders: Map<String, String>): Long {
var total: Long = 0
var delta: Long
try {
logger.debug("Validating $gui.gui")
val virtualPlayer = VirtualPlayer()
var now = System.currentTimeMillis()
val xmlGui = loadXmlGui(getGuiPlaceholders(virtualPlayer), gui)
val xmlGui = loadXmlGui(
getGuiPlaceholders(virtualPlayer).toMutableMap().also { it.putAll(placeholders) },
gui
)
delta = System.currentTimeMillis() - now
logger.debug("Took ${delta}ms parsing $gui")
total += delta
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import io.github.toberocat.guiengine.utils.BStatsCollector
import io.github.toberocat.guiengine.utils.Utils
import io.github.toberocat.guiengine.utils.logger.PluginLogger
import io.github.toberocat.guiengine.view.DefaultGuiViewManager
import io.github.toberocat.guiengine.webeditor.WebEditorServer
import io.github.toberocat.toberocore.action.ActionCore
import org.bukkit.Bukkit
import org.bukkit.plugin.java.JavaPlugin
Expand Down Expand Up @@ -93,8 +92,6 @@ class GuiEngineApiPlugin : JavaPlugin() {
registerCommands()
checkForUpdate()
BStatsCollector(this)

WebEditorServer(4567)
}

override fun onDisable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ data class InputFunction(

class Factory : GuiFunctionFactory<InputFunction>() {
override fun build(node: ParserContext): InputFunction {
println(node.node)
return InputFunction(
node.enum(InputType::class.java, "input-type").require(TYPE, javaClass),
node.string("variable").require(TYPE, javaClass),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -791,9 +791,7 @@ class VirtualPlayer : Player {
return null!!
}

override fun getName(): String {
return null!!
}
override fun getName() = "Tobero"

override fun getInventory(): PlayerInventory {
return null!!
Expand Down

0 comments on commit d11081e

Please sign in to comment.