Skip to content

Commit c1d5cc9

Browse files
committed
Refactored copyAll method to reduce NPath complexity
1 parent 1d267ad commit c1d5cc9

File tree

1 file changed

+29
-24
lines changed
  • gui/base/src/main/java/it/fulminazzo/yagl/guis

1 file changed

+29
-24
lines changed

gui/base/src/main/java/it/fulminazzo/yagl/guis/GUI.java

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,31 +1342,36 @@ default int southEast() {
13421342
if (other.size() != size())
13431343
throw new IllegalArgumentException(String.format("Cannot copy from GUI with different size %s != %s",
13441344
size(), other.size()));
1345-
if (other.getTitle() == null || replace) other.setTitle(getTitle());
1346-
copyAll((Metadatable) other, replace);
1347-
for (int i = 0; i < size(); i++) {
1348-
final @NotNull List<GUIContent> contents = getContents(i);
1349-
if (contents.isEmpty()) continue;
1350-
if (other.getContents(i).isEmpty() || replace)
1351-
other.setContents(i, contents.toArray(new GUIContent[0]));
1345+
else {
1346+
if (other.getTitle() == null || replace) other.setTitle(getTitle());
1347+
1348+
copyAll((Metadatable) other, replace);
1349+
1350+
for (int i = 0; i < size(); i++) {
1351+
final @NotNull List<GUIContent> contents = getContents(i);
1352+
if (!contents.isEmpty() && (other.getContents(i).isEmpty() || replace))
1353+
other.setContents(i, contents.toArray(new GUIContent[0]));
1354+
}
1355+
1356+
openGUIAction().ifPresent(a -> {
1357+
@NotNull Optional<GUIAction> open = other.openGUIAction();
1358+
if (!open.isPresent() || replace) other.onOpenGUI(a);
1359+
});
1360+
closeGUIAction().ifPresent(a -> {
1361+
@NotNull Optional<GUIAction> close = other.closeGUIAction();
1362+
if (!close.isPresent() || replace) other.onCloseGUI(a);
1363+
});
1364+
changeGUIAction().ifPresent(a -> {
1365+
@NotNull Optional<BiGUIAction> change = other.changeGUIAction();
1366+
if (!change.isPresent() || replace) other.onChangeGUI(a);
1367+
});
1368+
clickOutsideAction().ifPresent(a -> {
1369+
@NotNull Optional<GUIAction> clickOutside = other.clickOutsideAction();
1370+
if (!clickOutside.isPresent() || replace) other.onClickOutside(a);
1371+
});
1372+
1373+
return this;
13521374
}
1353-
openGUIAction().ifPresent(a -> {
1354-
@NotNull Optional<GUIAction> open = other.openGUIAction();
1355-
if (!open.isPresent() || replace) other.onOpenGUI(a);
1356-
});
1357-
closeGUIAction().ifPresent(a -> {
1358-
@NotNull Optional<GUIAction> close = other.closeGUIAction();
1359-
if (!close.isPresent() || replace) other.onCloseGUI(a);
1360-
});
1361-
changeGUIAction().ifPresent(a -> {
1362-
@NotNull Optional<BiGUIAction> change = other.changeGUIAction();
1363-
if (!change.isPresent() || replace) other.onChangeGUI(a);
1364-
});
1365-
clickOutsideAction().ifPresent(a -> {
1366-
@NotNull Optional<GUIAction> clickOutside = other.clickOutsideAction();
1367-
if (!clickOutside.isPresent() || replace) other.onClickOutside(a);
1368-
});
1369-
return this;
13701375
}
13711376

13721377
/**

0 commit comments

Comments
 (0)