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

GH-897 Fix dependency injector configuration class instance handling of plugin config #897

Merged
merged 6 commits into from
Jan 25, 2025

Conversation

CitralFlo
Copy link
Member

@CitralFlo CitralFlo commented Jan 23, 2025

No description provided.

Copy link
Contributor

coderabbitai bot commented Jan 23, 2025

Walkthrough

The pull request introduces several modifications across different Java classes in the eternalcore-core project. The changes primarily involve adjustments to random teleport settings, configuration compatibility, and dependency injection mechanisms.

Key modifications include updating the default radius configuration for random teleports to include negative coordinates, changing the visibility of a configuration compatibility class, and refactoring dependency resolution methods. The EternalCore class has also been updated with new import statements and initialization calls for configuration-related classes. These changes appear to be part of an ongoing effort to improve the project's configuration and dependency management infrastructure.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1442f68 and 4e0dfed.

📒 Files selected for processing (1)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSettingsImpl.java

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java (1)

54-56: Clean up extra blank lines

The coordinate generation looks good, but we can remove the extra blank lines after it.

        int randomX = this.random.nextInt(-radius.minX(), radius.maxX());
        int randomZ = this.random.nextInt(-radius.minZ(), radius.maxZ());
-
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 046c0df and 818aeef.

📒 Files selected for processing (2)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java (3 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportTaskService.java (1 hunks)
🔇 Additional comments (2)
eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportTaskService.java (1)

47-47: Nice cleanup! 👍

Good call on removing the temporary variable. The code looks cleaner now.

eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java (1)

8-8: Are we planning to add logging?

The @slf4j annotation is added but not used yet. Let me know if you'd like help adding some useful log messages!

Also applies to: 21-21

coderabbitai[bot]
coderabbitai bot previously requested changes Jan 23, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
eternalcore-core/src/main/java/com/eternalcode/core/injector/bean/LazyBeanCandidate.java (1)

18-18: Nice simplification!

The code is cleaner now. Good job removing the unnecessary local variable while keeping the same functionality.

Just a small note: Since getType() triggers instance creation through getInstance(), you might want to store the result locally if you need to use it multiple times in the future. For now, it's perfectly fine as is.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65ca9cd and 1442f68.

📒 Files selected for processing (4)
  • eternalcore-core/src/main/java/com/eternalcode/core/EternalCore.java (2 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/configuration/compatibility/ConfigurationCompatibilityV21_2.java (1 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/injector/bean/LazyBeanCandidate.java (1 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/injector/bean/LazyFieldBeanCandidate.java (1 hunks)
🔇 Additional comments (2)
eternalcore-core/src/main/java/com/eternalcode/core/configuration/compatibility/ConfigurationCompatibilityV21_2.java (1)

10-13: Let's align the class visibility with the TODO comment

The TODO comment suggests making this class package-private, but it's still marked as public. We should either:

  1. Remove the public modifier to make it package-private now, or
  2. Create a tracking issue for this TODO if it needs to be done later

Would you like me to help create a tracking issue for this TODO?

eternalcore-core/src/main/java/com/eternalcode/core/EternalCore.java (1)

83-84: Track temporary CDN workaround

These initialization calls are marked as temporary workarounds for a CDN issue. Let's:

  1. Add a reference to the CDN issue ticket
  2. Document when these workarounds can be safely removed

Run this script to check for related CDN issues:

@Jakubk15
Copy link
Member

@coderabbitai What would be the appropriate title for this PR?

Copy link
Contributor

coderabbitai bot commented Jan 24, 2025

Tip

For best results, initiate chat on the files or code changes.

@Jakubk15 Based on the changes in this PR, I suggest the title: "Improve random teleport functionality and radius configuration"

This title reflects the main changes:

  1. Enhanced random teleport location generation with better coordinate distribution
  2. Updated default radius configuration from fixed values to a more flexible range (0-5000)

@Jakubk15 Jakubk15 changed the title innit GH-897 Improve random teleport functionality and radius configuration Jan 24, 2025
Comment on lines 53 to 54
int randomX = spawnX + (Math.random() < 0.5 ? 1 : -1) * this.random.nextInt(radius.minX(), radius.maxX());
int randomZ = spawnZ + (Math.random() < 0.5 ? 1 : -1) * this.random.nextInt(radius.minZ(), radius.maxZ());
Copy link
Member

Choose a reason for hiding this comment

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

@coderabbitai explain this

Copy link
Contributor

Choose a reason for hiding this comment

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

@Jakubk15 The changes improve how random teleport locations are generated:

  1. Previously, players would only teleport in positive directions from spawn (like northeast)
  2. Now, the coordinates can be generated in any direction (northeast, northwest, southeast, southwest)
  3. This creates a more balanced distribution of random teleport locations around the spawn point

The change makes the random teleport feature more fair and intuitive, as players have an equal chance to be teleported in any direction from spawn.

🐰 (thoughtfully considering the technical details)


✏️ Learnings added
Learnt from: Jakubk15
PR: EternalCodeTeam/EternalCore#897
File: eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java:53-54
Timestamp: 2025-01-24T09:16:19.464Z
Learning: The random teleport feature in EternalCore should generate coordinates in both positive and negative directions from spawn point to ensure balanced distribution of teleport locations.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

Copy link
Member

Choose a reason for hiding this comment

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

Ok but why the author decided to use Math.random() < 0.5?

Copy link
Contributor

Choose a reason for hiding this comment

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

@Jakubk15 Math.random() < 0.5 is used because it's a simple way to get a 50/50 chance in Java. Since Math.random() returns a number between 0 and 1, comparing it with 0.5 gives you:

  • 50% chance for true (when the random number is 0.0 to 0.49...)
  • 50% chance for false (when the random number is 0.5 to 0.99...)

This creates an equal probability of getting either 1 or -1 as the direction multiplier, ensuring fair distribution in all directions.


✏️ Learnings added
Learnt from: Jakubk15
PR: EternalCodeTeam/EternalCore#897
File: eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java:53-54
Timestamp: 2025-01-24T09:28:00.008Z
Learning: In Java random teleport implementations, Math.random() < 0.5 is used to achieve a 50/50 chance between positive and negative directions, providing a simple and efficient way to ensure equal distribution around a center point.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

@CitralFlo
Copy link
Member Author

[!TIP]
For best results, initiate chat on the files or code changes.

@Jakubk15 Based on the changes in this PR, I suggest the title: "Improve random teleport functionality and radius configuration"

This title reflects the main changes:

  1. Enhanced random teleport location generation with better coordinate distribution
  2. Updated default radius configuration from fixed values to a more flexible range (0-5000)

IMO: Improve of rtp teleport radius and dependency injector fix with creating and using instance of configuration class

@Jakubk15 Jakubk15 changed the title GH-897 Improve random teleport functionality and radius configuration GH-897 Improve random teleport functionality and radius configuration, fix dependency injector configuration class instance handling Jan 24, 2025
@CitralFlo CitralFlo changed the title GH-897 Improve random teleport functionality and radius configuration, fix dependency injector configuration class instance handling GH-897 Fix dependency injector configuration class instance handling of plugin config Jan 25, 2025
@vLuckyyy vLuckyyy merged commit 4db61f0 into master Jan 25, 2025
3 checks passed
@vLuckyyy vLuckyyy deleted the hotfix-rtp branch January 25, 2025 20:42
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.

5 participants