Skip to content

Conversation

@Rollczi
Copy link
Member

@Rollczi Rollczi commented Oct 21, 2025

No description provided.

@Rollczi Rollczi requested a review from a team as a code owner October 21, 2025 18:24
@Rollczi Rollczi requested a review from vLuckyyy October 21, 2025 18:24
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

@Rollczi Rollczi changed the title Reformat placeholder definitions GH-1221 Reformat placeholder definitions Oct 21, 2025
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.*;
Copy link
Member

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<>();
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private final Set<Placeholder> replacerPlayers = new HashSet<>();
private final Set<Placeholder> playerPlaceholders = new HashSet<>();

import java.lang.annotation.Annotation;
import java.util.List;

public abstract class GroupAnnotationScanResolver<A extends Annotation, G extends Annotation, RESULT> implements EternalScanResolver<RESULT> {
Copy link
Member

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

@Jakubk15
Copy link
Member

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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_formatted and homes_left placeholder 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.

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();
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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.

Suggested change
Translation messages = this.translationManager.getMessages();
Translation messages = this.translationManager.getMessages(player.getUniqueId());

Comment on lines +73 to +82
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;
}));
Copy link
Contributor

Choose a reason for hiding this comment

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

high

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);
        }));

Comment on lines +31 to +33
static Placeholder of(String target, Placeholder placeholder) {
return new PlaceholderRaw(target, player -> placeholder.apply(target, player));
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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.

@Rollczi Rollczi force-pushed the Reformat-placeholder-definitions branch from c66db8a to b3f4d99 Compare October 26, 2025 20:38
@vLuckyyy vLuckyyy merged commit fc53c69 into master Oct 26, 2025
2 checks passed
@vLuckyyy vLuckyyy deleted the Reformat-placeholder-definitions branch October 26, 2025 21:38
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.

4 participants