Skip to content

Commit

Permalink
remove redundant Optional#ifPresent check
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakubk15 committed Feb 21, 2025
1 parent ef0e226 commit 6028a6c
Showing 1 changed file with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,29 +64,27 @@ public void collectParcel(Player player, Parcel parcel) {
return;
}

optional.ifPresent(content -> {
List<ItemStack> items = content.items();
if (items.size() > freeSlotsInInventory(player)) {
player.playSound(player.getLocation(), Sound.ITEM_CHORUS_FRUIT_TELEPORT, 0.5F, 1);
this.announcer.sendMessage(player, this.config.messages.notEnoughInventorySpace);
return;
}
List<ItemStack> items = optional.get().items();
if (items.size() > freeSlotsInInventory(player)) {
player.playSound(player.getLocation(), Sound.ITEM_CHORUS_FRUIT_TELEPORT, 0.5F, 1);
this.announcer.sendMessage(player, this.config.messages.notEnoughInventorySpace);
return;
}

items.forEach(item ->
this.scheduler.run(() -> ItemUtil.giveItem(player, item))
);
this.parcelRepository.remove(parcel)
.thenCompose(v -> this.parcelContentRepository.remove(content.uniqueId()))
.whenComplete(SentryExceptionHandler.handler().andThen((v, throwable) -> {
if (throwable != null) {
this.announcer.sendMessage(player, this.config.messages.failedToCollectParcel);
return;
}
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.5F, 1);
this.announcer.sendMessage(player, this.config.messages.parcelSuccessfullyCollected);
items.forEach(item ->
this.scheduler.run(() -> ItemUtil.giveItem(player, item))
);
this.parcelRepository.remove(parcel)
.thenCompose(v -> this.parcelContentRepository.remove(content.uniqueId()))
.whenComplete(SentryExceptionHandler.handler().andThen((v, throwable) -> {
if (throwable != null) {
this.announcer.sendMessage(player, this.config.messages.failedToCollectParcel);
return;
}
));
});
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 0.5F, 1);
this.announcer.sendMessage(player, this.config.messages.parcelSuccessfullyCollected);
}
));
});
}
}

0 comments on commit 6028a6c

Please sign in to comment.