use of cn.nukkit.form.response.FormResponseData in project Nukkit by Nukkit.
the class FormWindowCustom method setResponse.
public void setResponse(String data) {
if (data.equals("null")) {
this.closed = true;
return;
}
List<String> elementResponses = new Gson().fromJson(data, new TypeToken<List<String>>() {
}.getType());
// elementResponses.remove(elementResponses.size() - 1); //submit button //maybe mojang removed that?
int i = 0;
HashMap<Integer, FormResponseData> dropdownResponses = new HashMap<>();
HashMap<Integer, String> inputResponses = new HashMap<>();
HashMap<Integer, Float> sliderResponses = new HashMap<>();
HashMap<Integer, FormResponseData> stepSliderResponses = new HashMap<>();
HashMap<Integer, Boolean> toggleResponses = new HashMap<>();
HashMap<Integer, Object> responses = new HashMap<>();
for (String elementData : elementResponses) {
if (i >= content.size()) {
break;
}
Element e = content.get(i);
if (e == null)
break;
if (e instanceof ElementLabel) {
i++;
continue;
}
if (e instanceof ElementDropdown) {
String answer = ((ElementDropdown) e).getOptions().get(Integer.parseInt(elementData));
dropdownResponses.put(i, new FormResponseData(Integer.parseInt(elementData), answer));
responses.put(i, answer);
} else if (e instanceof ElementInput) {
inputResponses.put(i, elementData);
responses.put(i, elementData);
} else if (e instanceof ElementSlider) {
Float answer = Float.parseFloat(elementData);
sliderResponses.put(i, answer);
responses.put(i, answer);
} else if (e instanceof ElementStepSlider) {
String answer = ((ElementStepSlider) e).getSteps().get(Integer.parseInt(elementData));
stepSliderResponses.put(i, new FormResponseData(Integer.parseInt(elementData), answer));
responses.put(i, answer);
} else if (e instanceof ElementToggle) {
Boolean answer = Boolean.parseBoolean(elementData);
toggleResponses.put(i, answer);
responses.put(i, answer);
}
i++;
}
this.response = new FormResponseCustom(responses, dropdownResponses, inputResponses, sliderResponses, stepSliderResponses, toggleResponses);
}
Aggregations