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

Extract prefix to static variable in notifications. #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

VerniQ
Copy link
Contributor

@VerniQ VerniQ commented Oct 22, 2024

No description provided.

@VerniQ VerniQ linked an issue Oct 22, 2024 that may be closed by this pull request
Copy link

coderabbitai bot commented Oct 22, 2024

📝 Walkthrough

Walkthrough

The pull request introduces several changes to the eternaleconomy-core project, primarily in the build.gradle.kts file and various Java classes related to message handling. A new downloadPlugins configuration is added to the tasks.runServer section, specifying a GitHub repository for the Vault plugin, version "1.7.3". Additionally, the tasks.shadowJar section is updated to set a new output filename format that includes the project version. In the Java classes, message handling is enhanced by introducing a messagesPrefix variable in the MessageConfig class, which is used to standardize message formatting across different Notice instances. This change is reflected in classes such as CommandCooldownConfig, MessageAdminSubSection, and MessagesPlayerSubSection, where existing message strings are modified to prepend the new prefix, improving consistency and maintainability.

Possibly related PRs

Suggested labels

🆕 feature

Suggested reviewers

  • CitralFlo
  • Kamicjusz
  • Rollczi
  • vLuckyyy

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

@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: 2

🧹 Outside diff range and nitpick comments (2)
eternaleconomy-core/src/main/java/com/eternalcode/economy/config/implementation/messages/MessageConfig.java (1)

9-11: Consider making the prefix final

Since this is a constant value that defines your message styling, it would be good to mark it as final to prevent accidental changes.

-    public static String messagesPrefix =
+    public static final String messagesPrefix =
eternaleconomy-core/src/main/java/com/eternalcode/economy/config/implementation/messages/MessageAdminSubSection.java (1)

13-30: Fix inconsistent spacing after prefix

Some messages have extra spaces after the prefix while others don't. Let's make them consistent.

Here's a simpler version:

-        Notice.chat(messagesPrefix + " <white>Removed <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> from "
+        Notice.chat(messagesPrefix + "<white>Removed <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> from "

-        Notice.chat(messagesPrefix + " <white><gradient:#00FFA2:#34AE00>{PLAYER}</gradient>'s balance is "
+        Notice.chat(messagesPrefix + "<white><gradient:#00FFA2:#34AE00>{PLAYER}</gradient>'s balance is "
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 5bc160a and 3839e1d.

📒 Files selected for processing (5)
  • eternaleconomy-core/build.gradle.kts (1 hunks)
  • eternaleconomy-core/src/main/java/com/eternalcode/economy/command/cooldown/CommandCooldownConfig.java (1 hunks)
  • eternaleconomy-core/src/main/java/com/eternalcode/economy/config/implementation/messages/MessageAdminSubSection.java (1 hunks)
  • eternaleconomy-core/src/main/java/com/eternalcode/economy/config/implementation/messages/MessageConfig.java (1 hunks)
  • eternaleconomy-core/src/main/java/com/eternalcode/economy/config/implementation/messages/MessagesPlayerSubSection.java (1 hunks)
🧰 Additional context used
🔇 Additional comments (8)
eternaleconomy-core/src/main/java/com/eternalcode/economy/command/cooldown/CommandCooldownConfig.java (1)

3-3: Nice work on standardizing the message prefix!

The changes consistently implement the new message prefix pattern, making the codebase more maintainable.

Also applies to: 10-10, 18-18

eternaleconomy-core/src/main/java/com/eternalcode/economy/config/implementation/messages/MessageConfig.java (2)

13-17: Nice work on consistent message formatting! 👍

The messages look clean and well-formatted. The white text on all user-facing messages will ensure good readability.


24-25: Good use of gradient for permission display

The permission message looks great with the gradient highlighting. This will help it stand out to users.

eternaleconomy-core/src/main/java/com/eternalcode/economy/config/implementation/messages/MessageAdminSubSection.java (1)

7-8: LGTM!

The static import for MessageConfig is properly used.

eternaleconomy-core/src/main/java/com/eternalcode/economy/config/implementation/messages/MessagesPlayerSubSection.java (1)

6-7: LGTM! Good job centralizing the prefix.

The static import helps keep the code clean while reusing the shared prefix.

eternaleconomy-core/build.gradle.kts (3)

81-83: Nice addition of Vault plugin download configuration!

This ensures the test environment matches the production dependency version.


Line range hint 89-89: Good job on the clear jar naming convention!

Adding the version to the jar name will make it easier to identify different builds.


Line range hint 81-89: Verify if these changes belong in this PR.

The PR title mentions extracting prefix to static variable in notifications, but these build changes seem unrelated. Could you clarify if these changes should be in a separate PR?

Comment on lines +20 to 22
Notice.chat(messagesPrefix + "Correct usage:");
public Notice correctUsageHeader = Notice.chat("<dark_gray>➤</dark_gray> &fCorrect usage:");
public Notice correctUsageEntry = Notice.chat("<dark_gray>➤</dark_gray> &f{USAGE}");
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

🛠️ Refactor suggestion

You're right - the styling needs to be unified

Looking at the code, there are indeed inconsistent styles:

  • The main prefix uses a gradient-styled "ECONOMY" with an arrow
  • Some messages use this full prefix
  • Others use just a simple arrow

The review suggestion to unify the style is valid, and it would be better to stick with the main prefix style for consistency.

🔗 Analysis chain

Consider unifying the styling approach

The usage-related notices mix different styles - some use the prefix while others use a simple arrow. It might be clearer to stick to one approach.

Consider updating all usage messages to use the prefix:

-    public Notice correctUsageHeader = Notice.chat("<dark_gray>➤</dark_gray> &fCorrect usage:");
-    public Notice correctUsageEntry = Notice.chat("<dark_gray>➤</dark_gray> &f{USAGE}");
+    public Notice correctUsageHeader = Notice.chat(messagesPrefix + "Correct usage:");
+    public Notice correctUsageEntry = Notice.chat(messagesPrefix + "{USAGE}");

Let me check the actual usage patterns in these files to make a more informed decision.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if there are other inconsistent styling patterns
rg -l "dark_gray>➤" 

Length of output: 213


Script:

#!/bin/bash
# Check the context of arrow usage in both files
rg "dark_gray>➤" -B 2 -A 2

Length of output: 2510

Comment on lines +10 to +34
public Notice added =
Notice.chat(messagesPrefix + "<white>Added <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient>"
+ "to your account.</white>");
public Notice removed =
Notice.chat(messagesPrefix + " <white>Removed <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient>"
+ "from your account.</white>");
public Notice set =
Notice.chat(messagesPrefix + "<white>Set your balance to <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient>.</white>");
public Notice reset =
Notice.chat(messagesPrefix + "<white>Your balance was reset.</white>");
public Notice balance =
Notice.chat(messagesPrefix + " <white>Your balance is <gradient:#00FFA2:#34AE00>{BALANCE}</gradient>.</white>");
public Notice balanceOther =
Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray>"
+ " <white><gradient:#00FFA2:#34AE00>{PLAYER}</gradient>'s balance is <gradient:#00FFA2:#34AE00>{BALANCE}</gradient>.</white>");
public Notice insufficientBalance = Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> "
+ "<dark_gray>➤</dark_gray> <white>Insufficient funds,"
Notice.chat(messagesPrefix + " <white><gradient:#00FFA2:#34AE00>{PLAYER}</gradient>'s balance is"
+ "<gradient:#00FFA2:#34AE00>{BALANCE}</gradient>.</white>");
public Notice insufficientBalance = Notice.chat(messagesPrefix + "<white>Insufficient funds,"
+ " you are missing <gradient:#00FFA2:#34AE00> {MISSING_BALANCE}</gradient>.</white>");
public Notice transferSuccess = Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray"
+ ">➤</dark_gray> <white>Successfully transferred <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> to "
+ "<gradient:#00FFA2:#34AE00>{PLAYER}</gradient>.</white>");
public Notice transferReceived = Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> "
+ "<dark_gray>➤</dark_gray> <white>Received <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> from "
+ "<gradient:#00FFA2:#34AE00>{PLAYER}</gradient>.</white>");
public Notice transferLimit = Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray>"
+ " <white>Transaction limit is <gradient:#00FFA2:#34AE00>{LIMIT}</gradient>.</white>");
public Notice transferSuccess =
Notice.chat(messagesPrefix + "<white>Successfully transferred <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> to "
+ "<gradient:#00FFA2:#34AE00>{PLAYER}</gradient>.</white>");
public Notice transferReceived =
Notice.chat(messagesPrefix + "<white>Received <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> from "
+ "<gradient:#00FFA2:#34AE00>{PLAYER}</gradient>.</white>");
public Notice transferLimit =
Notice.chat(messagesPrefix + "<white>Transaction limit is <gradient:#00FFA2:#34AE00>{LIMIT}</gradient>.</white>");
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix inconsistent spacing after prefix.

Some messages have an extra space after the prefix while others don't. Let's make this consistent.

Here's a simple fix for the spacing issues:

-    public Notice removed =
-        Notice.chat(messagesPrefix + " <white>Removed <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient>"
+    public Notice removed =
+        Notice.chat(messagesPrefix + "<white>Removed <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient>"

-    public Notice balance =
-        Notice.chat(messagesPrefix + " <white>Your balance is <gradient:#00FFA2:#34AE00>{BALANCE}</gradient>.</white>");
+    public Notice balance =
+        Notice.chat(messagesPrefix + "<white>Your balance is <gradient:#00FFA2:#34AE00>{BALANCE}</gradient>.</white>");

-    public Notice balanceOther =
-        Notice.chat(messagesPrefix + " <white><gradient:#00FFA2:#34AE00>{PLAYER}</gradient>'s balance is"
+    public Notice balanceOther =
+        Notice.chat(messagesPrefix + "<white><gradient:#00FFA2:#34AE00>{PLAYER}</gradient>'s balance is"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
public Notice added =
Notice.chat(messagesPrefix + "<white>Added <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient>"
+ "to your account.</white>");
public Notice removed =
Notice.chat(messagesPrefix + " <white>Removed <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient>"
+ "from your account.</white>");
public Notice set =
Notice.chat(messagesPrefix + "<white>Set your balance to <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient>.</white>");
public Notice reset =
Notice.chat(messagesPrefix + "<white>Your balance was reset.</white>");
public Notice balance =
Notice.chat(messagesPrefix + " <white>Your balance is <gradient:#00FFA2:#34AE00>{BALANCE}</gradient>.</white>");
public Notice balanceOther =
Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray>"
+ " <white><gradient:#00FFA2:#34AE00>{PLAYER}</gradient>'s balance is <gradient:#00FFA2:#34AE00>{BALANCE}</gradient>.</white>");
public Notice insufficientBalance = Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> "
+ "<dark_gray>➤</dark_gray> <white>Insufficient funds,"
Notice.chat(messagesPrefix + " <white><gradient:#00FFA2:#34AE00>{PLAYER}</gradient>'s balance is"
+ "<gradient:#00FFA2:#34AE00>{BALANCE}</gradient>.</white>");
public Notice insufficientBalance = Notice.chat(messagesPrefix + "<white>Insufficient funds,"
+ " you are missing <gradient:#00FFA2:#34AE00> {MISSING_BALANCE}</gradient>.</white>");
public Notice transferSuccess = Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray"
+ ">➤</dark_gray> <white>Successfully transferred <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> to "
+ "<gradient:#00FFA2:#34AE00>{PLAYER}</gradient>.</white>");
public Notice transferReceived = Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> "
+ "<dark_gray>➤</dark_gray> <white>Received <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> from "
+ "<gradient:#00FFA2:#34AE00>{PLAYER}</gradient>.</white>");
public Notice transferLimit = Notice.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray>"
+ " <white>Transaction limit is <gradient:#00FFA2:#34AE00>{LIMIT}</gradient>.</white>");
public Notice transferSuccess =
Notice.chat(messagesPrefix + "<white>Successfully transferred <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> to "
+ "<gradient:#00FFA2:#34AE00>{PLAYER}</gradient>.</white>");
public Notice transferReceived =
Notice.chat(messagesPrefix + "<white>Received <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> from "
+ "<gradient:#00FFA2:#34AE00>{PLAYER}</gradient>.</white>");
public Notice transferLimit =
Notice.chat(messagesPrefix + "<white>Transaction limit is <gradient:#00FFA2:#34AE00>{LIMIT}</gradient>.</white>");
public Notice added =
Notice.chat(messagesPrefix + "<white>Added <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient>"
+ "to your account.</white>");
public Notice removed =
Notice.chat(messagesPrefix + "<white>Removed <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient>"
+ "from your account.</white>");
public Notice set =
Notice.chat(messagesPrefix + "<white>Set your balance to <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient>.</white>");
public Notice reset =
Notice.chat(messagesPrefix + "<white>Your balance was reset.</white>");
public Notice balance =
Notice.chat(messagesPrefix + "<white>Your balance is <gradient:#00FFA2:#34AE00>{BALANCE}</gradient>.</white>");
public Notice balanceOther =
Notice.chat(messagesPrefix + "<white><gradient:#00FFA2:#34AE00>{PLAYER}</gradient>'s balance is"
+ "<gradient:#00FFA2:#34AE00>{BALANCE}</gradient>.</white>");
public Notice insufficientBalance = Notice.chat(messagesPrefix + "<white>Insufficient funds,"
+ " you are missing <gradient:#00FFA2:#34AE00> {MISSING_BALANCE}</gradient>.</white>");
public Notice transferSuccess =
Notice.chat(messagesPrefix + "<white>Successfully transferred <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> to "
+ "<gradient:#00FFA2:#34AE00>{PLAYER}</gradient>.</white>");
public Notice transferReceived =
Notice.chat(messagesPrefix + "<white>Received <gradient:#00FFA2:#34AE00>{AMOUNT}</gradient> from "
+ "<gradient:#00FFA2:#34AE00>{PLAYER}</gradient>.</white>");
public Notice transferLimit =
Notice.chat(messagesPrefix + "<white>Transaction limit is <gradient:#00FFA2:#34AE00>{LIMIT}</gradient>.</white>");

Comment on lines +10 to +11
public static String messagesPrefix =
"<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray> ";
Copy link
Member

Choose a reason for hiding this comment

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

Remove static

import com.eternalcode.multification.notice.Notice;
import eu.okaeri.configs.OkaeriConfig;
import eu.okaeri.configs.annotation.Comment;

import java.time.Duration;

import static com.eternalcode.economy.config.implementation.messages.MessageConfig.*;
Copy link
Member

Choose a reason for hiding this comment

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

We usually don't use * in imports. Try to apply MessageConfig via constructor in main class

public class CommandCooldownConfig extends OkaeriConfig {
@Comment("Duration of the cooldown (e.g. 5s, 10m, 1h)")
public Duration duration = Duration.ofSeconds(5);
@Comment("Permission for admins to bypass the cooldown")
public String bypassPermission = "eternaleconomy.player.pay.bypass";
public Notice message = Notice.builder()
.chat("<b><gradient:#00FFA2:#34AE00>ECONOMY</gradient></b> <dark_gray>➤</dark_gray> "
+ "<white>You must wait <gradient:#00FFA2:#34AE00>{TIME}</gradient> before using /pay again.")
.chat(messagesPrefix + "<white>You must wait <gradient:#00FFA2:#34AE00>{TIME}</gradient> before using /pay again.")
Copy link
Member

Choose a reason for hiding this comment

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

if this import is needed only for this, maybe try package private and access the variable directly or via method. @Rollczi please think if there is a better way to do it

Copy link
Member

@vLuckyyy vLuckyyy left a comment

Choose a reason for hiding this comment

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

It should be done on the principle of internal placeholder, for example {PREFIX} can be used anywhere in the messages, this will allow a little more flexibility, currently you add everywhere, what if someone will have one message set to actionbar and the other to normal chat? I want to have a prefix in the chat and not in the actionbar, then he won't have a choice because you will add a prefix permanently.

Copy link
Member

@Rollczi Rollczi left a comment

Choose a reason for hiding this comment

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

the solution used is based on incorrect assumptions. You can't expect that the prefix will magically be appended to the configuration, to understand this see what the generated config looks like and what happens if you change the prefix in file and reload it.

Tldr: this doesn't work

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.

Template/prefix for notifcations.
4 participants