From 376d1a2c3b0975f8a2cae4e8746093fcc51653b5 Mon Sep 17 00:00:00 2001 From: loki5512344 Date: Mon, 11 May 2026 16:58:31 +0200 Subject: [PATCH] docs: add task to refactor if-else forests in rating commands, fix GayCommand package --- TODO.md | 69 +++++++++++++++++++ .../games/rating/GayCommand.java | 2 +- .../core/registry/PrefixCommandRegistrar.java | 1 + 3 files changed, 71 insertions(+), 1 deletion(-) diff --git a/TODO.md b/TODO.md index 63f5bd2..2453e12 100644 --- a/TODO.md +++ b/TODO.md @@ -402,6 +402,75 @@ src/main/java/creator/loki/ --- +## Рефакторинг кода (Code Quality) + +### Убрать if-else леса в rating командах + +**Проблема:** +Все rating команды (MustacheCommand, IqCommand, FatCommand, GayCommand, PpCommand, BoykisserCommand) содержат огромные if-else цепочки для определения уровня/комментария/цвета. + +**Пример плохого кода (MustacheCommand):** +```java +String comment; +Color color; +if (mustacheLevel >= 1000) { + comment = "🎩 ЛЕГЕНДАРНЫЕ УСИЩИ!"; + color = new Color(255, 215, 0); +} else if (mustacheLevel >= 80) { + comment = "🧔 Роскошные усы!"; + color = new Color(139, 69, 19); +} else if (mustacheLevel >= 60) { + comment = "👨 Хорошие усы"; + color = new Color(160, 82, 45); +} else if (mustacheLevel >= 40) { + comment = "😊 Усики растут"; + color = new Color(205, 133, 63); +} else if (mustacheLevel >= 20) { + comment = "🙂 Лёгкая щетина"; + color = new Color(210, 180, 140); +} else if (mustacheLevel > 0) { + comment = "😐 Почти нет усов"; + color = new Color(128, 128, 128); +} else { + comment = "🪒 Гладко выбрит"; + color = new Color(200, 200, 200); +} +``` + +**Решение:** +Создать общий класс `RatingLevel` с конфигурацией уровней: + +```java +public class RatingLevel { + private final int threshold; + private final String comment; + private final Color color; + + public static RatingLevel findLevel(int value, List levels) { + return levels.stream() + .filter(level -> value >= level.threshold) + .findFirst() + .orElse(levels.get(levels.size() - 1)); + } +} +``` + +**План действий:** +- [ ] Создать `command/impl/entertainment/games/rating/RatingLevel.java` +- [ ] Создать `command/impl/entertainment/games/rating/RatingConfig.java` с предустановленными конфигурациями +- [ ] Рефакторить MustacheCommand - использовать RatingLevel +- [ ] Рефакторить IqCommand - использовать RatingLevel +- [ ] Рефакторить FatCommand - использовать RatingLevel +- [ ] Рефакторить GayCommand - использовать RatingLevel (без уровней, только прогресс-бар) +- [ ] Рефакторить PpCommand - использовать RatingLevel +- [ ] Рефакторить BoykisserCommand - использовать RatingLevel +- [ ] Проверить что все команды работают корректно +- [ ] Удалить дублирующийся код + +**Приоритет:** Средний (улучшение качества кода) + +--- + ## Основные задачи ### 1. ⚡ Переделать систему опыта (XP System Rework) diff --git a/src/main/java/creator/loki/command/impl/entertainment/games/rating/GayCommand.java b/src/main/java/creator/loki/command/impl/entertainment/games/rating/GayCommand.java index 9cdd212..7198f8c 100644 --- a/src/main/java/creator/loki/command/impl/entertainment/games/rating/GayCommand.java +++ b/src/main/java/creator/loki/command/impl/entertainment/games/rating/GayCommand.java @@ -1,4 +1,4 @@ -package creator.loki.command.impl.entertainment.games; +package creator.loki.command.impl.entertainment.games.rating; import creator.loki.command.Command; import creator.loki.command.CommandContext; diff --git a/src/main/java/creator/loki/core/registry/PrefixCommandRegistrar.java b/src/main/java/creator/loki/core/registry/PrefixCommandRegistrar.java index 71b6d14..2c56f31 100644 --- a/src/main/java/creator/loki/core/registry/PrefixCommandRegistrar.java +++ b/src/main/java/creator/loki/core/registry/PrefixCommandRegistrar.java @@ -8,6 +8,7 @@ import creator.loki.command.impl.entertainment.games.random.MemeCommand; import creator.loki.command.impl.entertainment.games.random.RateCommand; import creator.loki.command.impl.entertainment.games.rating.BoykisserCommand; import creator.loki.command.impl.entertainment.games.rating.FatCommand; +import creator.loki.command.impl.entertainment.games.rating.GayCommand; import creator.loki.command.impl.entertainment.games.rating.IqCommand; import creator.loki.command.impl.entertainment.games.rating.MustacheCommand; import creator.loki.command.impl.entertainment.games.rating.PpCommand;