-
-
Notifications
You must be signed in to change notification settings - Fork 1
GH-152 feat!: introduce new dependency injection system and rework plugin core #152
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 all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
c365e2f
Start refactoring an injector system.
imDMK 213846a
Add Subscribe Events via Annotations (thanks to EternalCodeTeam).
imDMK 9f10e93
Continue work to writing.
imDMK 3adbe2b
Fix a Dependency Injection and Components system.
imDMK 729dbd3
Enable a gradle configuration cache.
imDMK 27bc325
Continue work.
imDMK 174eda2
Continue work.
imDMK 08318de
Continue work.
imDMK 44baa93
Fix DI processors.
imDMK 53b90eb
Improve API.
imDMK 6e94211
Continue work.
imDMK 9a76ae5
Finish work.
imDMK 673d86a
Fix tests.
imDMK 9e9b220
Fix ComponentManager.
imDMK 31f0d9f
Add NotNull annotation.
imDMK 8206131
Improve AdventureFormatter.
imDMK 29475c6
Add final
imDMK 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
64 changes: 64 additions & 0 deletions
64
playtime-api/src/main/java/com/github/imdmk/playtime/PlayTime.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,64 @@ | ||
| package com.github.imdmk.playtime; | ||
|
|
||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| import java.time.Duration; | ||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| public record PlayTime(long millis) implements Comparable<PlayTime> { | ||
|
|
||
| private static final long MILLIS_PER_TICK = 50L; | ||
|
|
||
| public static final PlayTime ZERO = new PlayTime(0L); | ||
|
|
||
| public PlayTime { | ||
| if (millis < 0L) { | ||
| throw new IllegalArgumentException("PlayTime millis cannot be negative"); | ||
| } | ||
| } | ||
|
|
||
| public static PlayTime of(@NotNull Duration duration) { | ||
| return new PlayTime(duration.toMillis()); | ||
| } | ||
|
|
||
| public static PlayTime ofMillis(long millis) { | ||
| return new PlayTime(millis); | ||
| } | ||
|
|
||
| public static PlayTime ofTicks(long ticks) { | ||
| return new PlayTime(Math.multiplyExact(ticks, MILLIS_PER_TICK)); | ||
| } | ||
|
|
||
| public long toMillis() { | ||
| return millis; | ||
| } | ||
|
|
||
| public Duration toDuration() { | ||
| return Duration.ofMillis(millis); | ||
| } | ||
|
|
||
| public long toSeconds() { | ||
| return TimeUnit.MILLISECONDS.toSeconds(millis); | ||
| } | ||
|
|
||
| public int toTicks() { | ||
| return Math.toIntExact(millis / MILLIS_PER_TICK); | ||
| } | ||
|
|
||
| public boolean isZero() { | ||
| return millis == 0; | ||
| } | ||
|
|
||
| public PlayTime plus(@NotNull PlayTime other) { | ||
| return new PlayTime(Math.addExact(millis, other.millis)); | ||
| } | ||
imDMK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public PlayTime minus(@NotNull PlayTime other) { | ||
| return new PlayTime(Math.subtractExact(millis, other.millis)); | ||
| } | ||
imDMK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| @Override | ||
| public int compareTo(PlayTime o) { | ||
| return Long.compare(millis, o.millis); | ||
| } | ||
| } | ||
60 changes: 9 additions & 51 deletions
60
playtime-api/src/main/java/com/github/imdmk/playtime/PlayTimeApi.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 |
|---|---|---|
| @@ -1,59 +1,17 @@ | ||
| package com.github.imdmk.playtime; | ||
|
|
||
| import com.github.imdmk.playtime.user.UserService; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
| /** | ||
| * Central API contract for interacting with the PlayTime plugin’s core services. | ||
| * | ||
| * <p>This interface provides unified access to the main subsystems of the plugin:</p> | ||
| * | ||
| * <ul> | ||
| * <li>{@link UserService} – manages player data persistence, synchronization, | ||
| * and user-specific statistics.</li> | ||
| * <li>{@link PlaytimeService} – handles retrieval and manipulation of player | ||
| * playtime data.</li> | ||
| * </ul> | ||
| * | ||
| * <p>External plugins can use this interface to integrate with PlayTime features | ||
| * without depending on internal implementation details. The implementation is provided | ||
| * automatically by the PlayTime plugin during runtime initialization.</p> | ||
| * | ||
| * <p><b>Usage Example:</b></p> | ||
| * | ||
| * <pre>{@code | ||
| * PlayTimeApi api = PlayTimeApiProvider.get(); | ||
| * | ||
| * UserService userService = api.userService(); | ||
| * PlaytimeService playtimeService = api.playtimeService(); | ||
| * | ||
| * UUID uuid = player.getUniqueId(); | ||
| * UserTime time = playtimeService.getTime(uuid); | ||
| * }</pre> | ||
| * | ||
| * @see PlaytimeService | ||
| * @see com.github.imdmk.playtime.user.UserService | ||
| * @see com.github.imdmk.playtime.user.UserTime | ||
| */ | ||
| import java.util.UUID; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| public interface PlayTimeApi { | ||
imDMK marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Returns the {@link UserService}, which provides access to user-management operations | ||
| * such as creating, saving, and retrieving user data including playtime, | ||
| * ranks, and metadata. | ||
| * | ||
| * @return non-null {@link UserService} instance | ||
| */ | ||
| @NotNull UserService userService(); | ||
| CompletableFuture<PlayTime> getTime(@NotNull UUID uuid); | ||
|
|
||
| CompletableFuture<Void> setTime(@NotNull UUID uuid, @NotNull PlayTime time); | ||
| CompletableFuture<Void> addTime(@NotNull UUID uuid, @NotNull PlayTime delta); | ||
|
|
||
| CompletableFuture<Void> resetTime(@NotNull UUID uuid); | ||
|
|
||
| /** | ||
| * Returns the {@link PlaytimeService}, which provides high-level operations for | ||
| * retrieving and modifying player playtime data. | ||
| * | ||
| * <p>This service acts as the bridge between the plugin’s internal user model | ||
| * and the underlying storage or platform-specific systems.</p> | ||
| * | ||
| * @return non-null {@link PlaytimeService} instance | ||
| */ | ||
| @NotNull PlaytimeService playtimeService(); | ||
| } | ||
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
59 changes: 0 additions & 59 deletions
59
playtime-api/src/main/java/com/github/imdmk/playtime/PlaytimeService.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.