Skip to content

Conversation

@vLuckyyy
Copy link
Member

image

@vLuckyyy vLuckyyy added the 💾 code-only This is just a code problem, it doesn't affect the plugin functionality itself label Oct 17, 2025
@vLuckyyy vLuckyyy requested a review from a team as a code owner October 17, 2025 22:35
@vLuckyyy vLuckyyy changed the title Remove usage of panda-utilities and panda expressible. GH-1213 Remove usage of panda-utilities and panda expressible. Oct 17, 2025
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 removes the usage of panda-utilities and panda-expressible libraries from the project. The changes involve updating the Versions.kt file, removing dependencies in build.gradle.kts files, and replacing usages of panda-utilities with standard Java/Bukkit alternatives in several Java files. The code has been reviewed and suggestions have been made to improve code clarity and maintainability.

@noyzys
Copy link
Member

noyzys commented Oct 18, 2025

Dodam jeszcze od siebie male co nieco odnosnie organizacji i kodu shared ktory moze potem sie przydac:

Mozna zarysowac takie flow tzw. PARSER PIPELINE pod parsera jezeli wiecej niz jedno uzycie jest poza GameMode..

final class ParserPipeline<INPUT, OUTPUT> {

    private final Function<INPUT, ParseResult<OUTPUT>> parser;

    private ParserPipeline(Function<INPUT, ParseResult<OUTPUT>> parser) {
        this.parser = parser;
    }

    public static <INPUT, OUTPUT> ParserPipeline<INPUT, OUTPUT> of() {
        return new ParserPipeline<>(input -> ParseResult.failure(null));
    }

    public ParserPipeline<INPUT, OUTPUT> thenTry(Function<INPUT, ParseResult<OUTPUT>> nextParser) {
        return new ParserPipeline<>(input -> {

            ParseResult<OUTPUT> currentResult = this.parser.apply(input);
            if (currentResult.isSuccess()) {
                return currentResult;
            }

            return nextParser.apply(input);
        });
    }

    public ParserPipeline<INPUT, OUTPUT> thenTryIf(Predicate<INPUT> condition, Function<INPUT, ParseResult<OUTPUT>> nextParser) {
        return new ParserPipeline<>(input -> {

            ParseResult<OUTPUT> currentResult = this.parser.apply(input);
            if (currentResult.isSuccess()) {
                return currentResult;
            }

            if (condition.test(input)) {
                return nextParser.apply(input);
            }

            return ParseResult.failure(null);
        });
    }

    public ParserPipeline<INPUT, OUTPUT> thenMap(Function<INPUT, OUTPUT> mapper) {
        return new ParserPipeline<>(input -> {

            ParseResult<OUTPUT> currentResult = this.parser.apply(input);
            if (currentResult.isSuccess()) {
                return currentResult;
            }

            try {
                OUTPUT result = mapper.apply(input);
                return ParseResult.success(result);
            } catch (Exception e) {
                return ParseResult.failure(null);
            }
        });
    }

    public Function<INPUT, ParseResult<OUTPUT>> build() {
        return this.parser;
    }

    public Function<INPUT, ParseResult<OUTPUT>> buildWithFinalFailure(Function<INPUT, ParseResult<OUTPUT>> finalFailure) {
        return input -> {

            ParseResult<OUTPUT> result = this.parser.apply(input);
            if (result.isSuccess()) {
                return result;
            }

            return finalFailure.apply(input);
        };
    }

    public Function<INPUT, ParseResult<OUTPUT>> buildWithFinalFailure(Supplier<ParseResult<OUTPUT>> finalFailure) {
        return input -> {

            ParseResult<OUTPUT> result = this.parser.apply(input);
            if (result.isSuccess()) {
                return result;
            }

            return finalFailure.get();
        };
    }
}

Finalna klasa:

@LiteArgument(type = GameMode.class)
class GameModeArgument extends AbstractViewerArgument<GameMode> {

    private final GameModeArgumentSettings gameModeArgumentSettings;
    private final Function<String, ParseResult<GameMode>> gameModeParser;

    @Inject
    GameModeArgument(TranslationManager translationManager, GameModeArgumentSettings gameModeArgumentSettings) {
        super(translationManager);
        this.gameModeArgumentSettings = gameModeArgumentSettings;
        this.gameModeParser = createGameModeParser();
    }

    @Override
    public ParseResult<GameMode> parse(Invocation<CommandSender> invocation, String argument, Translation translation) {
        // walidacja jezeli lc robi to zbedne
        if (argument == null || argument.trim().isEmpty()) {
            return ParseResult.failure(translation.player().gameModeNotCorrect());
        }
        
        String normalizedInput = argument.trim().toUpperCase(Locale.ROOT);
        return gameModeParser.apply(normalizedInput);
    }

    @Override
    public SuggestionResult suggest(
        Invocation<CommandSender> invocation,
        Argument<GameMode> argument,
        SuggestionContext context
    ) {
        return this.gameModeArgumentSettings.getAvailableAliases()
               .stream()
               .collect(SuggestionResult.collector());
    }

    private Function<String, ParseResult<GameMode>> createGameModeParser() {
        return ParserPipeline.of()
               .thenTry(this::parseDirectGameMode)
               .thenTry(this::parseFromAliases)
               .buildWithFinalFailure(input -> ParseResult.failure(translation.player().gameModeNotCorrect()));
    }

    private ParseResult<GameMode> parseDirectGameMode(String normalizedInput) {
        try {
            GameMode gameMode = GameMode.valueOf(normalizedInput);
            return ParseResult.success(gameMode);
        
        } catch (IllegalArgumentException exception) {
            return ParseResult.failure(null);
        }
    }

    private ParseResult<GameMode> parseFromAliases(String normalizedInput) {
        // naprawa case inconsistency
        GameMode gameMode = this.gameModeArgumentSettings.getByAlias(normalizedInput);
        if (gameMode != null) {
            return ParseResult.success(gameMode);
        }

        return ParseResult.failure(null);
    }
}

@vLuckyyy vLuckyyy requested a review from P1otrulla October 18, 2025 19:33
# Conflicts:
#	eternalcore-core/src/main/java/com/eternalcode/core/feature/fullserverbypass/FullServerBypassController.java
#	eternalcore-core/src/main/java/com/eternalcode/core/litecommand/argument/GameModeArgument.java
@SfenKer
Copy link

SfenKer commented Oct 20, 2025

image

@vLuckyyy
Copy link
Member Author

Proof of working.

2025-10-20.20-25-48.mp4

@vLuckyyy vLuckyyy merged commit 12c6c9a into master Oct 20, 2025
2 checks passed
@vLuckyyy vLuckyyy deleted the remove-pandas branch October 20, 2025 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💾 code-only This is just a code problem, it doesn't affect the plugin functionality itself hacktoberfest hacktoberfest-accepted

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants