-
-
Notifications
You must be signed in to change notification settings - Fork 0
GH-143 Add 'max parcels per locker' option #143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d454560
Add 'max parcels per locker' option
Jakubk15 a082ab8
Update src/main/java/com/eternalcode/parcellockers/parcel/repository/…
Jakubk15 0f7f46e
adjust to copilot's suggestions
Jakubk15 9395829
thenRun -> thenAccept
Jakubk15 f942ddf
[ci skip] delete redundant comment
Jakubk15 9d61b1b
Adjust to Mike's suggestion, simplify code, bump MC version to 1.21.10
Jakubk15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,10 @@ | ||
| package com.eternalcode.parcellockers.locker; | ||
|
|
||
| import com.eternalcode.parcellockers.configuration.implementation.PluginConfig; | ||
| import com.eternalcode.parcellockers.locker.repository.LockerRepository; | ||
| import com.eternalcode.parcellockers.locker.validation.LockerValidationService; | ||
| import com.eternalcode.parcellockers.notification.NoticeService; | ||
| import com.eternalcode.parcellockers.parcel.repository.ParcelRepository; | ||
| import com.eternalcode.parcellockers.shared.Page; | ||
| import com.eternalcode.parcellockers.shared.PageResult; | ||
| import com.eternalcode.parcellockers.shared.Position; | ||
|
|
@@ -19,15 +21,24 @@ | |
|
|
||
| public class LockerManager { | ||
|
|
||
| private final PluginConfig config; | ||
| private final LockerRepository lockerRepository; | ||
| private final LockerValidationService validationService; | ||
| private final ParcelRepository parcelRepository; | ||
|
|
||
| private final Cache<UUID, Locker> lockersByUUID; | ||
| private final Cache<Position, Locker> lockersByPosition; | ||
|
|
||
| public LockerManager(LockerRepository lockerRepository, LockerValidationService validationService) { | ||
| public LockerManager( | ||
| PluginConfig config, | ||
| LockerRepository lockerRepository, | ||
| LockerValidationService validationService, | ||
| ParcelRepository parcelRepository | ||
| ) { | ||
| this.config = config; | ||
| this.lockerRepository = lockerRepository; | ||
| this.validationService = validationService; | ||
| this.parcelRepository = parcelRepository; | ||
|
|
||
| this.lockersByUUID = Caffeine.newBuilder() | ||
| .expireAfterAccess(Duration.ofHours(2)) | ||
|
|
@@ -148,6 +159,11 @@ public CompletableFuture<Void> deleteAll(CommandSender sender, NoticeService not | |
| }); | ||
| } | ||
|
|
||
| public CompletableFuture<Boolean> isLockerFull(UUID lockerUuid) { | ||
| return this.parcelRepository.countByDestinationLocker(lockerUuid) | ||
| .thenApply(count -> count >= this.config.settings.maxParcelsPerLocker); | ||
|
||
| } | ||
|
|
||
| private void cacheAll() { | ||
| this.lockerRepository.fetchAll() | ||
| .thenAccept(optionalLockers -> optionalLockers.ifPresent(lockers -> lockers.forEach(locker -> { | ||
|
|
@@ -156,3 +172,4 @@ private void cacheAll() { | |
| }))); | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.