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-911 Fix typo in afk config, fix permission check order, add constant for permission for afk permission. #911

Merged
merged 4 commits into from
Feb 14, 2025

Conversation

vLuckyyy
Copy link
Member

No description provided.

Copy link
Contributor

coderabbitai bot commented Feb 12, 2025

Walkthrough

The pull request updates the AFK functionality across several components. A new constant for bypass permission is introduced in the command handler, and the logic is restructured to check this permission earlier, thus bypassing any delay if applicable. In addition, a typo in the method description has been corrected. A class responsible for placeholder setup has undergone a renaming to fix a spelling error in both its class name and constructor. Minor adjustments to import statements in some files have been made without affecting their overall functionality. Lastly, a new message field is added to signal when a player is no longer AFK.


📜 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 3ca9dff and 3c624c8.

📒 Files selected for processing (1)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkServiceImpl.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkServiceImpl.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.

@vLuckyyy vLuckyyy changed the title Fix typo, permission check order, add constant for permission. GH-911 Fix typo, permission check order, add constant for permission. Feb 12, 2025
@vLuckyyy vLuckyyy requested review from Rollczi, CitralFlo and imDMK and removed request for eripe14 February 12, 2025 23:10
@vLuckyyy
Copy link
Member Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Feb 13, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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 (2)
eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportServiceImpl.java (1)

94-98: Consider precision in coordinate calculations.

The integer casting might cause slight precision loss at the borders. While this is usually fine for Minecraft coordinates, you might want to round instead of truncating.

-        int minX = (int) (centerX - size/2);
-        int maxX = (int) (centerX + size/2);
-        int minZ = (int) (centerZ - size/2);
-        int maxZ = (int) (centerZ + size/2);
+        int minX = (int) Math.round(centerX - size/2);
+        int maxX = (int) Math.round(centerX + size/2);
+        int minZ = (int) Math.round(centerZ - size/2);
+        int maxZ = (int) Math.round(centerZ + size/2);
eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java (1)

48-49: Consider improving coordinate distribution around spawn.

Based on previous feedback, the random teleport should generate coordinates in both positive and negative directions from spawn for better balance.

Here's a simple way to achieve this:

-        int randomX = spawnX + this.random.nextInt(radius.maxX() - radius.minX() + 1) + radius.minX();
-        int randomZ = spawnZ + this.random.nextInt(radius.maxZ() - radius.minZ() + 1) + radius.minZ();
+        int randomX = spawnX + (this.random.nextBoolean() ? 1 : -1) * this.random.nextInt(radius.maxX() - radius.minX() + 1);
+        int randomZ = spawnZ + (this.random.nextBoolean() ? 1 : -1) * this.random.nextInt(radius.maxZ() - radius.minZ() + 1);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 34aa32c and 3ca9dff.

📒 Files selected for processing (7)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkCommand.java (2 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkPlaceholderSetup.java (1 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkServiceImpl.java (2 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkTask.java (1 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/messages/PLAfkMessages.java (1 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java (2 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportServiceImpl.java (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkTask.java
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkPlaceholderSetup.java
🧰 Additional context used
🧠 Learnings (1)
eternalcore-core/src/main/java/com/eternalcode/core/feature/randomteleport/RandomTeleportSafeLocationService.java (2)
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.806Z
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.
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.144Z
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.
🔇 Additional comments (10)
eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/messages/PLAfkMessages.java (2)

16-18: Nice addition of the AFK status message!

The new message for when players return from AFK matches well with the existing AFK announcement style.


24-24: Clean formatting adjustments!

The consistent spacing and formatting make the code easier to read.

Also applies to: 29-29

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

90-93: LGTM! Nice improvement to world border handling.

The code now properly accounts for world borders with different center points, making it more accurate for all server configurations.

eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkCommand.java (3)

27-28: Nice work extracting the permission to a constant!

This makes the code more maintainable and helps prevent typos.


43-43: Description reads much better now!

The updated description clearly explains the AFK delay bypass behavior.


47-50: Great improvement in code flow!

Moving the bypass check to the start and using early return makes the code easier to follow.

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

39-41: Nice improvement to the attempt count check!

The condition now correctly handles the case when attempts reach zero, making the code more logical.


69-80: Great job extracting spawn location logic!

The new method cleanly handles both configured and default spawn locations, making the code easier to understand and maintain.

eternalcore-core/src/main/java/com/eternalcode/core/feature/afk/AfkServiceImpl.java (2)

15-15: LGTM! Good addition of concurrent utilities.

The import of ConcurrentHashMap aligns well with the thread-safe implementation.


27-29:

✅ Verification successful

Great improvement to thread safety!

Switching to ConcurrentHashMap is a smart choice here. It makes the code safer when multiple threads are accessing the AFK state, interaction counts, and timestamps.

However, let's verify that we're using these maps correctly throughout the codebase:


🏁 Script executed:

#!/bin/bash
# Search for any direct synchronization on these maps that might now be redundant
rg -A 2 "synchronized.*afkByPlayer|synchronized.*interactionsCount|synchronized.*lastInteraction"

# Look for any bulk operations that might need special handling with ConcurrentHashMap
ast-grep --pattern 'putAll($_, $_) | clear() | containsAll($_, $_)'

Length of output: 169


Below is an additional verification step to ensure that no hidden synchronized blocks or wrapping using Collections.synchronizedMap are still interacting with these maps. Please run these extra commands and share the results before we finalize the review comment:

Once you've run these commands and confirmed that there are no unexpected synchronizations or bulk operations involving these maps, we can update the review comment accordingly.


🏁 Script executed:

[run_scripts]
#!/bin/bash
# Look for any synchronized blocks involving our map variables across the codebase
rg -n "synchronized\s*\(.*(afkByPlayer|interactionsCount|lastInteraction)" .

# Also check for any usage of Collections.synchronizedMap around these variables
rg -n "Collections\.synchronizedMap" .

Length of output: 241


Thread Safety Verified: Good Job!

I've double-checked the codebase for any leftover synchronization blocks or bulk operations involving the AFK maps. The search commands returned no unwanted references, confirming that the shift to ConcurrentHashMap is correctly implemented and no redundant synchronization exists.

No further changes are needed.

@vLuckyyy vLuckyyy changed the title GH-911 Fix typo, permission check order, add constant for permission. GH-911 Fix typo in afk config, fix permission check order, add constant for permission for afk permission. Feb 13, 2025
@vLuckyyy vLuckyyy merged commit 2de51a9 into master Feb 14, 2025
3 checks passed
@vLuckyyy vLuckyyy deleted the fix-bugs-in-afk branch February 14, 2025 21:47
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.

3 participants