-
-
Notifications
You must be signed in to change notification settings - Fork 0
GH-121 Enhanced delivery logic #121
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 22 commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
0a8ee3e
Begin coding enhanced delivery logic
Jakubk15 3a530b4
Remove delivery object from repo after task completion
Jakubk15 ea9ed8e
use ParcelSendTask
Jakubk15 51d55f5
add DurationComposer
Jakubk15 a850247
Reorder methods
Jakubk15 5a963fd
Bump cdn, fix composer registration
Jakubk15 c7e4d38
Use DeliveryWrapper class in database instead of Delivery
Jakubk15 c3765cb
Remove duplicate code, bump deps, downgrade spigot-api to 1.21.4 due …
Jakubk15 7a3d50f
Temporarily change default parcel delivery delay
Jakubk15 00d68c3
Do not return immutable list if optional is empty
Jakubk15 555800d
Make debug commands executable from console
Jakubk15 fc3170f
Remove Vault left-overs
Jakubk15 23657ed
changes in gradle config
Jakubk15 0c03083
Adjust colors in debug messages
Jakubk15 9a5c0dc
Remove unnecessary messages, fix GUI items propagation
Jakubk15 d2c8673
Merge branch 'master' into enhanced-delivery-logic
Jakubk15 abbe0f3
Update build.gradle.kts
Jakubk15 2cd7bac
Update src/main/java/com/eternalcode/parcellockers/configuration/comp…
Jakubk15 29c6081
Refactor sendParcel to Result
Jakubk15 5466356
Merge remote-tracking branch 'origin/enhanced-delivery-logic' into en…
Jakubk15 eb918f6
More robust result handling, fix GUI slot painting
Jakubk15 65f6ed4
Rewrite DurationComposer
Jakubk15 e1f16b1
Add Copilot-generated unit test
Jakubk15 1561d73
Enhance serialize() method
Jakubk15 0043483
Disallow negative durations
Jakubk15 c092a5c
Delete redundant DurationUtil, remove debug breadcrumbs, properly par…
Jakubk15 a134365
Fix unit test
Jakubk15 f7d0f63
Fix unit test
Jakubk15 7c1f572
Merge remote-tracking branch 'origin/enhanced-delivery-logic' into en…
Jakubk15 798d7e9
Remove debug main method
Jakubk15 de3c6b8
Merge branch 'master' into enhanced-delivery-logic
Jakubk15 b8224e6
Update src/main/java/com/eternalcode/parcellockers/command/debug/Debu…
Jakubk15 2b4f9d5
Update src/main/java/com/eternalcode/parcellockers/parcel/task/Parcel…
Jakubk15 1784c5b
Update src/main/java/com/eternalcode/parcellockers/parcel/task/Parcel…
Jakubk15 67a9b70
Update src/main/java/com/eternalcode/parcellockers/command/debug/Debu…
Jakubk15 519191a
Update src/main/java/com/eternalcode/parcellockers/command/debug/Debu…
Jakubk15 8f901cc
Update src/main/java/com/eternalcode/parcellockers/command/debug/Debu…
Jakubk15 9c31a0e
Update src/main/java/com/eternalcode/parcellockers/command/debug/Debu…
Jakubk15 5d1c24e
Update src/main/java/com/eternalcode/parcellockers/gui/implementation…
Jakubk15 08a58a9
Apply DMK's suggestions
Jakubk15 3011663
Fix build, don't use deprecated methods in SkullAPI
Jakubk15 9bd4b6a
Merge branch 'master' into enhanced-delivery-logic
Jakubk15 040478b
Fix unit tests loading
Jakubk15 5f2d275
bump minecraft to 1.21.7 and update papermc repo url
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
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
88 changes: 88 additions & 0 deletions
88
src/main/java/com/eternalcode/parcellockers/configuration/composer/DurationComposer.java
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 |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| package com.eternalcode.parcellockers.configuration.composer; | ||
|
|
||
| import panda.std.Result; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| public class DurationComposer implements SimpleComposer<Duration> { | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Regex to match each time component individually | ||
| private static final Pattern TIME_PATTERN = Pattern.compile( | ||
| "(-?\\d+(?:\\.\\d+)?)\\s*([dhms])", | ||
| Pattern.CASE_INSENSITIVE); | ||
|
|
||
| @Override | ||
| public Result<String, Exception> serialize(Duration duration) { | ||
| if (duration == null) { | ||
| return Result.error(new IllegalArgumentException("Duration cannot be null")); | ||
| } | ||
| return Result.ok(duration.toString() | ||
| .substring(2) // Remove the PT prefix | ||
| .replaceAll("(\\d[HMS])(?!$)", "$1 ") // Add spaces between components | ||
| .toLowerCase()); | ||
| } | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public Result<Duration, Exception> deserialize(String input) { | ||
| try { | ||
| if (input == null || input.isBlank()) { | ||
| return Result.error(new IllegalArgumentException("Input cannot be null or blank")); | ||
| } | ||
|
|
||
| // If input is already in ISO-8601 format | ||
| if (input.toUpperCase().startsWith("P")) { | ||
| return Result.ok(Duration.parse(input)); | ||
| } | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // For simple case: just a number (assume seconds) | ||
| if (input.matches("-?\\d+(\\.\\d+)?")) { | ||
| return Result.ok(Duration.ofSeconds(Long.parseLong(input))); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| // Parse custom format (e.g., "1d 2h 3m 4.5s") | ||
| Duration duration = Duration.ZERO; | ||
| Matcher matcher = TIME_PATTERN.matcher(input); | ||
|
|
||
| boolean foundMatch = false; | ||
| while (matcher.find()) { | ||
| foundMatch = true; | ||
| String value = matcher.group(1); | ||
| String unit = matcher.group(2).toLowerCase(); | ||
|
|
||
| switch (unit) { | ||
| case "d": | ||
| duration = duration.plusDays(Long.parseLong(value)); | ||
| break; | ||
| case "h": | ||
| duration = duration.plusHours(Long.parseLong(value)); | ||
| break; | ||
| case "m": | ||
| duration = duration.plusMinutes(Long.parseLong(value)); | ||
| break; | ||
| case "s": | ||
| if (value.contains(".")) { | ||
| double seconds = Double.parseDouble(value); | ||
| long wholeSeconds = (long) seconds; | ||
| long nanos = (long) ((seconds - wholeSeconds) * 1_000_000_000); | ||
| duration = duration.plusSeconds(wholeSeconds).plusNanos(nanos); | ||
| } else { | ||
| duration = duration.plusSeconds(Long.parseLong(value)); | ||
| } | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!foundMatch) { | ||
| return Result.error(new IllegalArgumentException( | ||
| "Invalid duration format. Expected format like '1d 2h 3m 4s' or ISO-8601 duration.")); | ||
| } | ||
|
|
||
| return Result.ok(duration); | ||
|
|
||
| } catch (Exception e) { | ||
| return Result.error(new IllegalArgumentException("Failed to parse duration: " + e.getMessage(), e)); | ||
| } | ||
| } | ||
| } | ||
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.