-
-
Couldn't load subscription status.
- Fork 21
GH-1221 Reformat placeholder definitions #1221
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request focuses on refactoring the placeholder system to use a new Placeholder interface, replacing the old PlaceholderReplacer. This involves changes in how placeholders are registered and used throughout the codebase, including the AFK and Home features. The changes also include the introduction of PlaceholdersDocs for documenting placeholders.
| import com.eternalcode.annotations.scan.placeholder.PlaceholderDocs; | ||
| import com.eternalcode.annotations.scan.placeholder.PlaceholdersDocs; | ||
| import com.eternalcode.annotations.scan.placeholder.PlaceholdersDocs.Entry; | ||
| import static com.eternalcode.annotations.scan.placeholder.PlaceholdersDocs.Entry.*; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Static imports should typically go to the bottom
|
|
||
| private final Server server; | ||
| private final Set<PlaceholderReplacer> replacerPlayers = new HashSet<>(); | ||
| private final Set<Placeholder> replacerPlayers = new HashSet<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private final Set<Placeholder> replacerPlayers = new HashSet<>(); | |
| private final Set<Placeholder> playerPlaceholders = new HashSet<>(); |
eternalcore-docs-api/src/main/java/com/eternalcode/annotations/scan/reflect/AnnotationUtil.java
Outdated
Show resolved
Hide resolved
| import java.lang.annotation.Annotation; | ||
| import java.util.List; | ||
|
|
||
| public abstract class GroupAnnotationScanResolver<A extends Annotation, G extends Annotation, RESULT> implements EternalScanResolver<RESULT> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think GROUP will do better as a generic name here
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request refactors the placeholder system by introducing a new Placeholder interface and a grouped @PlaceholdersDocs annotation for better organization and documentation. The changes are generally positive, simplifying the code and improving maintainability.
However, I've identified several issues that should be addressed:
- A critical bug in the new annotation processing logic (
GroupAnnotationScanResolver) that will prevent it from functioning correctly. - Logic bugs in the
afk_formattedandhomes_leftplaceholder implementations, which could lead to incorrect behavior for users. - A performance degradation in how configuration-based placeholders are registered.
- Inconsistencies in the new placeholder documentation regarding return types.
I have provided detailed comments with suggestions for fixes. Addressing these points will ensure the refactoring is robust and correct.
...ore-docs-api/src/main/java/com/eternalcode/annotations/scan/GroupAnnotationScanResolver.java
Outdated
Show resolved
Hide resolved
| void setUpPlaceholders(PlaceholderRegistry placeholders, AfkService afkService) { | ||
| placeholders.register(Placeholder.ofBoolean("afk", player -> afkService.isAfk(player.getUniqueId()))); | ||
| placeholders.register(Placeholder.of("afk_formatted", player -> { | ||
| Translation messages = this.translationManager.getMessages(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change from this.translationManager.getMessages(player.getUniqueId()) to this.translationManager.getMessages() appears to be a bug. The placeholder description for afk_formatted states it should be "based on player's language settings". Using getMessages() without a player context will likely result in using a default language for all players, instead of their specific language. This should be reverted to use the player-specific method call.
| Translation messages = this.translationManager.getMessages(); | |
| Translation messages = this.translationManager.getMessages(player.getUniqueId()); |
| placeholders.register(Placeholder.ofInt("homes_left", target -> { | ||
| int homesLimit = this.homeService.getHomeLimit(target); | ||
| int amountOfHomes = this.homeService.getAmountOfHomes(target.getUniqueId()); | ||
|
|
||
| @PlaceholderDocs( | ||
| name = "homes_limit", | ||
| description = "Returns the maximum number of homes the player can have.", | ||
| example = "5", | ||
| returnType = "int", | ||
| category = "Home", | ||
| requiresPlayer = true | ||
| ) | ||
| private PlaceholderReplacer createHomesLimitPlaceholder() { | ||
| return PlaceholderReplacer.of( | ||
| "homes_limit", | ||
| (text, targetPlayer) -> | ||
| String.valueOf(this.homeService.getHomeLimit(targetPlayer)) | ||
| ); | ||
| } | ||
|
|
||
| @PlaceholderDocs( | ||
| name = "homes_left", | ||
| description = "Returns how many more homes the player can create before reaching the limit.", | ||
| example = "2", | ||
| returnType = "int", | ||
| category = "Home", | ||
| requiresPlayer = true | ||
| ) | ||
| private PlaceholderReplacer createHomesLeftPlaceholder() { | ||
| return PlaceholderReplacer.of( | ||
| "homes_left", | ||
| (text, targetPlayer) -> { | ||
| int homesLimit = this.homeService.getHomeLimit(targetPlayer); | ||
| int amountOfHomes = this.homeService.getAmountOfHomes(targetPlayer.getUniqueId()); | ||
|
|
||
| if (homesLimit < -1 || amountOfHomes > homesLimit) { | ||
| return "0"; | ||
| } | ||
|
|
||
| return String.valueOf(homesLimit - amountOfHomes); | ||
| if (homesLimit < -1 || amountOfHomes > homesLimit) { | ||
| return 0; | ||
| } | ||
| ); | ||
|
|
||
| return homesLimit - amountOfHomes; | ||
| })); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic for the homes_left placeholder seems incorrect when a player has an unlimited number of homes (usually represented by homesLimit == -1). The current implementation will return 0, which is misleading. For an unlimited limit, it should indicate that, for example by returning -1 or another special value since this is an integer placeholder.
The proposed suggestion handles the unlimited case and also simplifies the logic for calculating remaining homes.
placeholders.register(Placeholder.ofInt("homes_left", target -> {
int homesLimit = this.homeService.getHomeLimit(target);
if (homesLimit == -1) {
return -1; // Use -1 to indicate unlimited
}
int amountOfHomes = this.homeService.getAmountOfHomes(target.getUniqueId());
return Math.max(0, homesLimit - amountOfHomes);
}));
...ore-core/src/main/java/com/eternalcode/core/feature/afk/placeholder/AfkPlaceholderSetup.java
Show resolved
Hide resolved
| static Placeholder of(String target, Placeholder placeholder) { | ||
| return new PlaceholderRaw(target, player -> placeholder.apply(target, player)); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of of(String target, Placeholder placeholder) seems incorrect or at least very confusing. It calls placeholder.apply(target, player), passing the new target string as the text to be processed. This means it will try to find and replace placeholders within the target string itself, which is likely not the intended behavior for aliasing a placeholder. This method should be reviewed to ensure it behaves as expected.
eternalcore-core/src/main/java/com/eternalcode/core/placeholder/PlaceholdersSetup.java
Show resolved
Hide resolved
eternalcore-core/src/main/java/com/eternalcode/core/placeholder/PlaceholdersSetup.java
Show resolved
Hide resolved
c66db8a to
b3f4d99
Compare
No description provided.