adamk33n3r / runelite-watchdog

Custom notification plugin for RuneLite
BSD 2-Clause "Simplified" License
6 stars 24 forks source link

fix: refactor to not use lombok builders #152

Closed adamk33n3r closed 6 months ago

adamk33n3r commented 6 months ago

Summary by CodeRabbit

coderabbitai[bot] commented 6 months ago

Walkthrough

The recent changes primarily focus on code refactoring and formatting adjustments across multiple Java files. The build.gradle file has undergone indentation corrections, while the Java classes have shifted from using the builder pattern to constructor initialization. Additionally, annotations like @SuperBuilder and @Builder.Default have been removed or replaced with @Accessors(chain = true), simplifying the code structure and enhancing readability.

Changes

File Path Summary of Changes
build.gradle Indentation and formatting adjustments. No changes to logic or functionality.
.../AlertManager.java Refactored to use constructor initialization instead of builder pattern for several alert instances.
.../alerts/Alert.java Replaced @SuperBuilder with @Accessors(chain = true), removed @Builder.Default, and added methods addNotification and addNotifications.
.../alerts/AlertGroup.java Removed @SuperBuilder and @Builder.Default annotations.
.../alerts/ChatAlert.java Replaced @SuperBuilder with @Accessors(chain = true), removed @Builder.Default annotations.
.../alerts/InventoryAlert.java Replaced @SuperBuilder with @Accessors(chain = true), removed @Builder.Default annotations.
.../alerts/LocationAlert.java Removed @SuperBuilder and @Builder.Default annotations, commented out showTileMarker field.
.../alerts/NotificationFiredAlert.java Replaced @SuperBuilder with @Accessors(chain = true), removed @Builder.Default annotations.
.../alerts/PlayerChatAlert.java Replaced @SuperBuilder with @Accessors(chain = true), removed @Builder.Default annotations.
.../alerts/RegexMatcher.java Changed setRegexEnabled return type from void to Alert.
.../alerts/SoundFiredAlert.java Removed @SuperBuilder, @Builder.Default, and field initialization for soundID.
.../alerts/SpawnedAlert.java Replaced @SuperBuilder with @Accessors(chain = true), removed @Builder.Default annotations.
.../alerts/StatChangedAlert.java Removed @SuperBuilder and @Builder.Default annotations.
.../alerts/XPDropAlert.java Removed @SuperBuilder and @Builder.Default annotations.

Recent Review Details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
Commits Files that changed from the base of the PR and between 8b5830064856b371b9fbfbfcf82a8fadd01aab7c and 797ef7cf4d6abe41fddc21fc5e5ded9e474b8e86.
Files ignored due to path filters (1) * `src/main/resources/com/adamk33n3r/runelite/watchdog/version.properties` is excluded by `!**/version.properties`
Files selected for processing (14) * build.gradle (2 hunks) * src/main/java/com/adamk33n3r/runelite/watchdog/AlertManager.java (4 hunks) * src/main/java/com/adamk33n3r/runelite/watchdog/alerts/Alert.java (3 hunks) * src/main/java/com/adamk33n3r/runelite/watchdog/alerts/AlertGroup.java (1 hunks) * src/main/java/com/adamk33n3r/runelite/watchdog/alerts/ChatAlert.java (1 hunks) * src/main/java/com/adamk33n3r/runelite/watchdog/alerts/InventoryAlert.java (1 hunks) * src/main/java/com/adamk33n3r/runelite/watchdog/alerts/LocationAlert.java (1 hunks) * src/main/java/com/adamk33n3r/runelite/watchdog/alerts/NotificationFiredAlert.java (1 hunks) * src/main/java/com/adamk33n3r/runelite/watchdog/alerts/PlayerChatAlert.java (1 hunks) * src/main/java/com/adamk33n3r/runelite/watchdog/alerts/RegexMatcher.java (1 hunks) * src/main/java/com/adamk33n3r/runelite/watchdog/alerts/SoundFiredAlert.java (1 hunks) * src/main/java/com/adamk33n3r/runelite/watchdog/alerts/SpawnedAlert.java (1 hunks) * src/main/java/com/adamk33n3r/runelite/watchdog/alerts/StatChangedAlert.java (1 hunks) * src/main/java/com/adamk33n3r/runelite/watchdog/alerts/XPDropAlert.java (1 hunks)
Files skipped from review due to trivial changes (1) * build.gradle
Additional comments not posted (12)
src/main/java/com/adamk33n3r/runelite/watchdog/alerts/SoundFiredAlert.java (1)
`7-7`: Simplification by direct field initialization in constructor enhances readability but reduces flexibility compared to the builder pattern.
src/main/java/com/adamk33n3r/runelite/watchdog/alerts/XPDropAlert.java (1)
`10-10`: Direct field initialization in the constructor simplifies the code and is appropriate for the specific context of XP drop alerts.
src/main/java/com/adamk33n3r/runelite/watchdog/alerts/StatChangedAlert.java (1)
`10-10`: Consistent approach with direct field initialization in the constructor across alert types simplifies the code and enhances maintainability.
src/main/java/com/adamk33n3r/runelite/watchdog/alerts/NotificationFiredAlert.java (1)
`9-9`: Addition of `@Accessors(chain = true)` enhances method chaining capabilities, aligning with the refactoring efforts across the project to improve API fluency.
src/main/java/com/adamk33n3r/runelite/watchdog/alerts/ChatAlert.java (1)
`7-7`: The addition of `@Accessors(chain = true)` is a good practice for enabling method chaining, enhancing readability and maintainability. Also applies to: 11-11
src/main/java/com/adamk33n3r/runelite/watchdog/alerts/PlayerChatAlert.java (1)
`7-7`: The use of `@Accessors(chain = true)` here, as in other alert classes, standardizes the approach across the codebase, improving maintainability. Also applies to: 11-11
src/main/java/com/adamk33n3r/runelite/watchdog/alerts/InventoryAlert.java (1)
`8-8`: The addition of `@Accessors(chain = true)` is a good practice for enabling method chaining, enhancing readability and maintainability. Also applies to: 12-12
src/main/java/com/adamk33n3r/runelite/watchdog/alerts/SpawnedAlert.java (1)
`9-9`: The use of `@Accessors(chain = true)` here, as in other alert classes, standardizes the approach across the codebase, improving maintainability. Also applies to: 13-13
src/main/java/com/adamk33n3r/runelite/watchdog/alerts/Alert.java (1)
`8-9`: The addition of `@Accessors(chain = true)` and new methods `addNotification` and `addNotifications` enhance the functionality and maintainability of the `Alert` class. Also applies to: 20-20, 45-53
src/main/java/com/adamk33n3r/runelite/watchdog/AlertManager.java (3)
`230-255`: Refactored to use direct instantiation instead of builders. Ensure all necessary properties are correctly set.
Verification successful --- The search results confirm the instantiation of `ChatAlert` objects in the specified lines. The properties for `cannonReload` and `readyToHarvest` appear to be correctly set as per the provided code snippet. - `cannonReload` sets the message, game message type, and adds notifications. - `readyToHarvest` sets the message, debounce time, and adds a notification.
Scripts Executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify that all properties are correctly set for Alert instances. # Test: Search for the instantiation of Alert. Expect: Properties set correctly. rg --type java $'new Alert\(' ``` Length of output: 30 --- --- Script: ```shell #!/bin/bash # Description: Verify that all properties are correctly set for ChatAlert instances. # Test: Search for the instantiation of ChatAlert. Expect: Properties set correctly. rg --type java $'new ChatAlert\(' ``` Length of output: 299
--- `165-229`: Refactored to use direct instantiation instead of builders. Ensure all necessary properties are correctly set. --- `116-164`: Refactored to use direct instantiation instead of builders. Ensure all necessary properties are correctly set.
Verification successful The initial script identified `AlertGroup` instances but did not find any `Alert` instances. To ensure all properties are correctly set, we need to search for subclasses or related classes of `Alert` and verify their properties. --- The script identified instances of `SpawnedAlert` and `InventoryAlert` in `AlertManager.java`. Let's review the properties set for these instances to ensure they are correctly configured. ### SpawnedAlert Instances 1. **Kraken Dies** - `setSpawnedDespawned(SpawnedAlert.SpawnedDespawned.DESPAWNED)` - `setSpawnedType(SpawnedAlert.SpawnedType.NPC)` - `setSpawnedName("Kraken")` - Notifications: - `Overhead`: `setDisplayTime(3)`, `setTextColor(Color.CYAN)`, `setMessage("Sit Krak")` - `ScreenMarker`: `setDisplayTime(8)`, `setScreenMarkerProperties("Get Fishing Explosive Ready", Color.MAGENTA, Color.BLUE, 2)` - `RequestFocus`: `setForceFocus(true)` 2. **Whirlpool Appears** - `setSpawnedDespawned(SpawnedAlert.SpawnedDespawned.DESPAWNED)` - `setSpawnedType(SpawnedAlert.SpawnedType.NPC)` - `setSpawnedName("Whirlpool")` - `setDebounceTime(15000)` - Notifications: - `ScreenFlash`: `setColor(ColorUtil.fromHex("#6D0030"))`, `setFlashMode(FlashMode.SMOOTH_FLASH)`, `setFlashDuration(1)` - `Overhead`: `setDisplayTime(3)`, `setTextColor(Color.GREEN)`, `setMessage("Throw Explosive!")` ### InventoryAlert Instance 1. **Fishing Explosive Used** - `setInventoryAlertType(InventoryAlert.InventoryAlertType.ITEM_CHANGE)` - `setItemName("Fishing explosive")` - `setItemQuantity(-1)` - `setQuantityComparator(ComparableNumber.Comparator.EQUALS)` - Notifications: - `Overhead`: `setDisplayTime(2)`, `setTextColor(Color.RED)`, `setMessage("Attack!")` - `ScreenFlash`: `setColor(ColorUtil.fromHex("#46FF00"))`, `setFlashMode(FlashMode.FLASH)`, `setFlashDuration(2)` All necessary properties for `SpawnedAlert` and `InventoryAlert` instances appear to be correctly set. Refactored to use direct instantiation instead of builders. All necessary properties are correctly set.
Scripts Executed The following scripts were executed for the analysis: --- Script: ```shell #!/bin/bash # Description: Verify that all properties are correctly set for Alert and AlertGroup instances. # Test: Search for the instantiation of Alert and AlertGroup. Expect: Properties set correctly. rg --type java $'new AlertGroup\(' rg --type java $'new Alert\(' ``` Length of output: 447 --- --- Script: ```shell #!/bin/bash # Description: Verify that all properties are correctly set for Alert subclasses and related classes. # Test: Search for subclasses of Alert and their instantiation. Expect: Properties set correctly. ast-grep --lang java --pattern 'class $_ extends Alert { $$$ }' rg --type java 'new SpawnedAlert\(' rg --type java 'new InventoryAlert\(' ``` Length of output: 489
--- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit .` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai generate interesting stats about this repository and render them as a table.` - `@coderabbitai show all the console.log statements in this repository.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (invoked as PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger a review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai help` to get help. Additionally, you can add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. ### CodeRabbit Configration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](https://discord.com/invite/GsXnASn26c) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.