File tree Expand file tree Collapse file tree
api/receptacle/src/main/kotlin/trplugins/menu/api/receptacle/dialog
plugin/src/main/kotlin/trplugins/menu/module Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -274,6 +274,7 @@ class DialogNMSImpl : DialogNMS() {
274274 }
275275
276276 private fun buildSingleOptionInput (element : DialogElementPayload ): Any {
277+ require(element.options.isNotEmpty()) { " Dialog single_option ${element.id} requires at least one option." }
277278 val entryClass = singleOptionEntryClass()
278279 val defaultValue = element.value
279280 val entries = element.options.map { option ->
Original file line number Diff line number Diff line change @@ -656,12 +656,13 @@ object MenuSerializer : ISerializer {
656656 }
657657
658658 private fun serializeDialogOptions (section : ConfigurationSection ): List <DialogOptionSpec > {
659- return section.getMapList(" Options" ).mapIndexed { index, optionMap ->
659+ val optionMaps = section.getMapList(" Options" ).ifEmpty { section.getMapList(" options" ) }
660+ return optionMaps.mapIndexed { index, optionMap ->
660661 val option = Property .asSection(optionMap) ? : Configuration .empty()
661662 DialogOptionSpec (
662- id = option.getString(" Id" ) ? : " option_$index " ,
663- title = option.getString(" Title" ) ? : option.getString(" Name" ) ? : " Option-$index " ,
664- description = option.getString(" Description" )
663+ id = option.getString(" id " ) ? : option.getString( " Id" ) ? : " option_$index " ,
664+ title = option.getString(" title " ) ? : option.getString( " Title" ) ? : option.getString( " name " ) ? : option.getString(" Name" ) ? : " Option-$index " ,
665+ description = option.getString(" description " ) ? : option.getString( " Description" )
665666 )
666667 }
667668 }
Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ object DialogCompiler {
5555 booleanIds + = bodySpec.id
5656 }
5757 is DialogSingleOptionSpec -> {
58+ requireOptions(bodySpec.id, bodySpec.options, " single_option" )
5859 body + = compileBody(session, bodySpec)
5960 optionIds + = bodySpec.id
6061 }
@@ -63,6 +64,7 @@ object DialogCompiler {
6364 optionIds + = bodySpec.id
6465 }
6566 is DialogMultiOptionSpec -> {
67+ requireOptions(bodySpec.id, bodySpec.options, " multi_option" )
6668 val expansion = compileMultiOption(session, bodySpec)
6769 body + = expansion.elements
6870 booleanIds + = expansion.syntheticIds.keys
@@ -207,6 +209,12 @@ object DialogCompiler {
207209 return ((colSpan.toDouble() / compiler.gridColumns.toDouble()) * compiler.contentMaxWidth.toDouble()).toInt().coerceAtLeast(80 )
208210 }
209211
212+ private fun requireOptions (id : String , options : List <DialogOptionSpec >, type : String ) {
213+ if (options.isEmpty()) {
214+ throw DialogCompileException (" Dialog $type widget $id requires at least one option." )
215+ }
216+ }
217+
210218 private fun compileAction (session : MenuSession , spec : DialogActionSpec ): DialogActionPayload {
211219 return DialogActionPayload (
212220 id = spec.id,
You can’t perform that action at this time.
0 commit comments