Skip to content
This repository was archived by the owner on May 23, 2025. It is now read-only.

Commit 013bd1e

Browse files
committed
Update finally
1 parent c71f1cc commit 013bd1e

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

src/main/java/io/github/minecraftchampions/dodoopenjava/message/card/CardMessage.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,14 @@ public CardMessage.Builder insert(int index, @NonNull CardComponent component) {
198198
}
199199

200200
public CardMessage build() {
201-
JSONObject json = new JSONObject(Map.of("type", "card", "components", new JSONArray(),
201+
JSONArray jsonArray = new JSONArray();
202+
JSONObject json = new JSONObject(Map.of("type", "card", "components", jsonArray,
202203
"theme", theme.toString()));
203204
if (title != null) {
204205
json.put("title", title);
205206
}
206-
synchronized (this.components) {
207-
components.forEach(component -> json.getJSONArray("components").put(component.toJsonObject()));
207+
synchronized (components) {
208+
components.forEach(component -> jsonArray.put(component.toJsonObject()));
208209
}
209210
JSONObject jsonObject = new JSONObject(Map.of("card", json));
210211
if (content != null) {

src/main/java/io/github/minecraftchampions/dodoopenjava/message/card/component/ButtonGroupComponent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ public class ButtonGroupComponent implements CardComponent {
2525

2626
@Override
2727
public JSONObject toJsonObject() {
28-
JSONObject jsonObject = new JSONObject(Map.of("type", type, "elements", new JSONArray()));
28+
JSONArray jsonArray = new JSONArray();
29+
JSONObject jsonObject = new JSONObject(Map.of("type", type, "elements", jsonArray));
2930
synchronized (elementList) {
3031
for (AbstractElement element : elementList) {
31-
jsonObject.getJSONArray("elements").put(element.toJsonObject());
32+
jsonArray.put(element.toJsonObject());
3233
}
3334
}
3435
return jsonObject;

src/main/java/io/github/minecraftchampions/dodoopenjava/message/card/component/ListSelectorComponent.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ public static ListSelectorComponent of(int min, int max, @NonNull String interac
6464

6565
@Override
6666
public JSONObject toJsonObject() {
67-
JSONObject jsonObject = new JSONObject(Map.of("type", type, "min", min, "max", max, "elements", new JSONArray()));
67+
JSONArray jsonArray = new JSONArray();
68+
JSONObject jsonObject = new JSONObject(Map.of("type", type, "min", min, "max", max, "elements", jsonArray));
6869
if (placeholder != null) {
6970
jsonObject.put("placeholder", placeholder);
7071
}
7172
if (interactCustomId != null) {
7273
jsonObject.put("interactCustomId", interactCustomId);
7374
}
7475
for (OptionElement element : elementList) {
75-
jsonObject.getJSONArray("elements").put(element.toJsonObject());
76+
jsonArray.put(element.toJsonObject());
7677
}
7778
return jsonObject;
7879
}

src/main/java/io/github/minecraftchampions/dodoopenjava/message/card/component/RemarkComponent.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ public class RemarkComponent implements CardComponent {
2626

2727
@Override
2828
public JSONObject toJsonObject() {
29-
JSONObject jsonObject = new JSONObject(Map.of("type", type, "elements", new JSONArray()));
29+
JSONArray jsonArray = new JSONArray();
30+
JSONObject jsonObject = new JSONObject(Map.of("type", type, "elements", jsonArray));
3031
synchronized (elementList) {
3132
for (AbstractElement element : elementList) {
3233
if (element instanceof TextElement.ParagraphText paragraphText) {
33-
paragraphText.forEach((text) -> jsonObject.getJSONArray("elements").put(text.toJsonObject()));
34+
paragraphText.forEach((text) -> jsonArray.put(text.toJsonObject()));
3435
} else {
35-
jsonObject.getJSONArray("elements").put(element.toJsonObject());
36+
jsonArray.put(element.toJsonObject());
3637
}
3738
}
3839
}
@@ -41,21 +42,21 @@ public JSONObject toJsonObject() {
4142

4243
public RemarkComponent append(@NonNull AbstractElement.AbstractDataElement element) {
4344
synchronized (elementList) {
44-
this.elementList.add(element);
45+
elementList.add(element);
4546
return this;
4647
}
4748
}
4849

4950
public RemarkComponent insert(int index, @NonNull AbstractElement.AbstractDataElement element) {
5051
synchronized (elementList) {
51-
this.elementList.add(index, element);
52+
elementList.add(index, element);
5253
return this;
5354
}
5455
}
5556

5657
public RemarkComponent prepend(int index, @NonNull AbstractElement.AbstractDataElement element) {
5758
synchronized (elementList) {
58-
this.elementList.add(0, element);
59+
elementList.add(0, element);
5960
return this;
6061
}
6162
}

0 commit comments

Comments
 (0)