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-924 Fix synchronization bug. #924

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

vLuckyyy
Copy link
Member

@vLuckyyy vLuckyyy commented Mar 4, 2025

Initially, the warp GUI wasn’t working properly, so I added CompletableFuture#exceptionally. Using exceptionally isn’t strictly necessary, but including it helps uncover errors that aren’t immediately obvious, as they don’t automatically appear in the console.
After adding exceptionally, I encountered the following error:

[23:56:57 INFO]: com.eternalcode.core.feature.language.Language@cc8
[23:56:57 ERROR]: [com.eternalcode.core.util.CompletableFutureUtil] Caught an exception in future execution: {0}
java.util.concurrent.CompletionException: java.lang.IllegalStateException: InventoryOpenEvent may only be triggered synchronously.
        at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:332) ~[?:?]
        at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:347) ~[?:?]
        at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:874) ~[?:?]
        at java.base/java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:841) ~[?:?]
        at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510) ~[?:?]
        at java.base/java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:2179) ~[?:?]
        at EternalCore v1.6.0 (MC 1.17.x-1.21.x).jar/com.eternalcode.core.database.wrapper.AbstractRepositoryOrmLite.lambda$action$7(AbstractRepositoryOrmLite.java:62) ~[EternalCore v1.6.0 (MC 1.17.x-1.21.x).jar:?]
        at org.bukkit.craftbukkit.scheduler.CraftTask.run(CraftTask.java:78) ~[pufferfish-1.21.3.jar:1.21.3-27-04bc249]
        at org.bukkit.craftbukkit.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:57) ~[pufferfish-1.21.3.jar:1.21.3-27-04bc249]
        at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[pufferfish-1.21.3.jar:?]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144) ~[?:?]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642) ~[?:?]
        at java.base/java.lang.Thread.run(Thread.java:1570) ~[?:?]
Caused by: java.lang.IllegalStateException: InventoryOpenEvent may only be triggered synchronously.
        at io.papermc.paper.plugin.manager.PaperEventManager.callEvent(PaperEventManager.java:42) ~[pufferfish-1.21.3.jar:1.21.3-27-04bc249]
        at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.callEvent(PaperPluginManagerImpl.java:131) ~[pufferfish-1.21.3.jar:1.21.3-27-04bc249]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:630) ~[pufferfish-api-1.21.3-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.event.CraftEventFactory.callInventoryOpenEventWithTitle(CraftEventFactory.java:1443) ~[pufferfish-1.21.3.jar:1.21.3-27-04bc249]
        at org.bukkit.craftbukkit.event.CraftEventFactory.callInventoryOpenEventWithTitle(CraftEventFactory.java:1422) ~[pufferfish-1.21.3.jar:1.21.3-27-04bc249]
        at org.bukkit.craftbukkit.entity.CraftHumanEntity.openCustomInventory(CraftHumanEntity.java:370) ~[pufferfish-1.21.3.jar:1.21.3-27-04bc249]
        at org.bukkit.craftbukkit.entity.CraftHumanEntity.openInventory(CraftHumanEntity.java:354) ~[pufferfish-1.21.3.jar:1.21.3-27-04bc249]
        at EternalCore v1.6.0 (MC 1.17.x-1.21.x).jar/com.eternalcode.core.libs.dev.triumphteam.gui.guis.BaseGui.open(BaseGui.java:436) ~[EternalCore v1.6.0 (MC 1.17.x-1.21.x).jar:?]
        at EternalCore v1.6.0 (MC 1.17.x-1.21.x).jar/com.eternalcode.core.feature.warp.WarpInventory.lambda$openInventory$0(WarpInventory.java:86) ~[EternalCore v1.6.0 (MC 1.17.x-1.21.x).jar:?]
        at java.base/java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:863) ~[?:?]
        ... 10 more
        

My PulRequest fixes this error.

Copy link
Contributor

coderabbitai bot commented Mar 4, 2025

Walkthrough

The changes introduce a new Scheduler dependency to the WarpInventory class, allowing for better management of asynchronous tasks. The openInventory method has been updated to call a new method, createInventoryAsync, which retrieves the player's language asynchronously and defaults to a standard value if none is found. This refactor enhances the structure of the code and includes exception handling through the newly added CompletableFutureUtil class. This utility class provides a static method for logging exceptions that occur during asynchronous operations, ensuring that issues are captured effectively. Additionally, minor formatting adjustments were made in the addWarp method for improved clarity.


📜 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 05d7499 and 0967124.

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

246-258: Improved formatting for readability

The code formatting makes the method call clearer and easier to read.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 35fab52 and 05d7499.

📒 Files selected for processing (2)
  • eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java (5 hunks)
  • eternalcore-core/src/main/java/com/eternalcode/core/util/CompletableFutureUtil.java (1 hunks)
🔇 Additional comments (8)
eternalcore-core/src/main/java/com/eternalcode/core/util/CompletableFutureUtil.java (1)

6-18: Good new utility class for handling async exceptions

This class handles exceptions from CompletableFuture operations nicely. The private constructor prevents mistakes, and the utility method logs issues clearly.

eternalcore-core/src/main/java/com/eternalcode/core/feature/warp/WarpInventory.java (7)

4-4: Added Scheduler import as needed

The Scheduler is required for the fix, so this import is necessary.


17-17: Added required utility import

Adding the CompletableFutureUtil import supports the new exception handling approach.


22-26: Added needed imports for async operations

These imports support the new async inventory creation functionality.


55-55: Added Scheduler field

Adding the Scheduler field allows running GUI opening on the main thread, which is needed for inventory events.


66-67: Added Scheduler to constructor and initialization

The Scheduler is properly added to the constructor and initialized in the field.

Also applies to: 77-77


80-86: Fixed synchronization issue with inventory opening

This change fixes the problem by making sure the inventory opens on the main thread using scheduler.run(). Using exceptionally() helps catch errors that might happen during async operations.


89-98: Created method for async inventory creation

This new method handles getting the player's language asynchronously and falls back to the default language if needed. The exceptionally handler ensures errors are properly logged.

@vLuckyyy vLuckyyy changed the title Fix synchronization bug. GH-924 Fix synchronization bug. Mar 4, 2025
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