|
18 | 18 | import io.github.projectunified.unidialog.adventure.input.AdventureBooleanInput; |
19 | 19 | import io.github.projectunified.unidialog.core.input.BooleanInput; |
20 | 20 | import io.github.projectunified.unidialog.core.input.DialogInputBuilder; |
| 21 | +import io.github.projectunified.unidialog.core.payload.DialogPayload; |
21 | 22 | import me.hsgamer.bettergui.betterdialogs.DialogManagerProvider; |
22 | 23 | import me.hsgamer.bettergui.betterdialogs.builder.DialogComponentBuilder; |
23 | 24 | import me.hsgamer.bettergui.betterdialogs.text.Text; |
|
29 | 30 | import java.util.Optional; |
30 | 31 | import java.util.UUID; |
31 | 32 |
|
32 | | -public class BooleanInputComponent extends InputComponent<String> { |
| 33 | +public class BooleanInputComponent extends InputComponent<Boolean> { |
33 | 34 | private final Text label; |
34 | 35 | private final String initial; |
35 | 36 | private final String onTrue; |
@@ -67,25 +68,16 @@ protected void apply(Player player, DialogInputBuilder builder) { |
67 | 68 | } |
68 | 69 |
|
69 | 70 | @Override |
70 | | - protected String getValue(String value, UUID uuid, String args) { |
71 | | - return value; |
72 | | - } |
73 | | - |
74 | | - @Override |
75 | | - protected String convertValue(UUID uuid, String rawValue) { |
76 | | - try { |
77 | | - float value = Float.parseFloat(rawValue); |
78 | | - rawValue = value == 0 ? "false" : "true"; |
79 | | - } catch (NumberFormatException e) { |
80 | | - // Ignore the exception, keep the raw value as is |
81 | | - } |
82 | | - |
83 | | - if (rawValue.equalsIgnoreCase("true") || rawValue.equalsIgnoreCase("yes")) { |
| 71 | + protected String getValue(Boolean value, UUID uuid, String args) { |
| 72 | + if (value == Boolean.TRUE) { |
84 | 73 | return StringReplacerApplier.replace(onTrue, uuid, this); |
85 | | - } else if (rawValue.equalsIgnoreCase("false") || rawValue.equalsIgnoreCase("no")) { |
86 | | - return StringReplacerApplier.replace(onFalse, uuid, this); |
87 | 74 | } else { |
88 | | - return rawValue; |
| 75 | + return StringReplacerApplier.replace(onFalse, uuid, this); |
89 | 76 | } |
90 | 77 | } |
| 78 | + |
| 79 | + @Override |
| 80 | + protected Boolean getValue(String key, DialogPayload payload) { |
| 81 | + return payload.booleanValue(key); |
| 82 | + } |
91 | 83 | } |
0 commit comments