Skip to content
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

refactor: Refactor the sentinel logic #201

Merged
merged 2 commits into from
Nov 24, 2024
Merged

Conversation

dm94
Copy link
Owner

@dm94 dm94 commented Nov 23, 2024

Summary by Sourcery

Refactor the sentinel logic by extracting and organizing methods to improve code readability and maintainability. Update the plugin version to 2.3.6 beta 1.

Enhancements:

  • Refactor the sentinel logic by extracting and organizing methods for better readability and maintainability, such as attackLogic, followSameMapLogic, and noSentinelLogic.

Chores:

  • Update plugin version from 2.3.5 to 2.3.6 beta 1 in the plugin.json file.

Copy link

sourcery-ai bot commented Nov 23, 2024

Reviewer's Guide by Sourcery

This PR refactors the sentinel logic in the SentinelModule by breaking down the large onTickModule method into smaller, more focused methods. The changes improve code readability and maintainability by extracting complex logic into separate methods and introducing constants for magic numbers.

Updated class diagram for SentinelModule

classDiagram
    class SentinelModule {
        - Location lastSentinelLocation
        - static double MAX_DISTANCE_LIMIT
        - static int MIN_SENTINEL_HEALTH
        - static double SPEED_MULTIPLIER
        - JLabel label
        + void onTickModule()
        + void attackLogic()
        + void followSameMapLogic()
        + void noSentinelLogic()
        + boolean isAttacking()
        + void changeTarget(Entity target)
        + boolean isOurPet(Entity target)
        + Entity getTargetFromAttackerModules()
        + Entity getSentinelTarget()
        + boolean isSentinelValid()
        + boolean hasSentinel()
        + boolean isPotentialSentinel(Player ship)
        + boolean isTaggedSentinel(Player ship)
        + void goToGroup()
        + boolean isGroupMemberValid(eu.darkbot.api.game.group.GroupMember m)
        + void acceptGroupSentinel()
        + double getRadius(Lockable target)
        + void npcMove()
        + void setNPCConfig(Location direction)
    }
Loading

File-Level Changes

Change Details Files
Extracted complex logic into separate methods
  • Split onTickModule into attackLogic, followSameMapLogic, and noSentinelLogic methods
  • Created changeTarget method to handle target switching logic
  • Extracted target validation into isOurPet and getTargetFromAttackerModules methods
  • Refactored sentinel validation into isSentinelValid and isPotentialSentinel methods
src/main/java/com/deeme/modules/SentinelModule.java
Introduced constants for magic numbers
  • Added MAX_DISTANCE_LIMIT constant for maximum distance checks
  • Added MIN_SENTINEL_HEALTH constant for sentinel health validation
  • Added SPEED_MULTIPLIER constant for movement calculations
src/main/java/com/deeme/modules/SentinelModule.java
Improved group member handling
  • Refactored group member processing to use stream operations
  • Extracted group member validation into isGroupMemberValid method
src/main/java/com/deeme/modules/SentinelModule.java
Version bump and minor improvements
  • Updated version to 2.3.6 beta 1
  • Added randomization to radius calculation for non-NPC targets
  • Fixed boolean comparison in setNPCConfig method
src/main/java/com/deeme/modules/SentinelModule.java
src/main/resources/plugin.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @dm94 - I've reviewed your changes - here's some feedback:

Overall Comments:

  • The Boolean.TRUE.equals(runConfigInCircle.getValue()) check is unnecessarily verbose - a simple boolean comparison would be clearer here since getValue() presumably returns a boolean
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🟢 Security: all looks good
  • 🟢 Review instructions: all looks good
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

src/main/java/com/deeme/modules/SentinelModule.java Outdated Show resolved Hide resolved
@dm94 dm94 merged commit a79de10 into master Nov 24, 2024
3 checks passed
@dm94 dm94 deleted the refactor/sentinel-module branch November 24, 2024 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant