Refactor admin command cooldown handling and update localization
- Updated cooldown handling in AdminCommandHandler to use localized messages. - Added new method in Locales class to retrieve strings based on CommandSender type. - Introduced cooldown messages in English and Russian localization files. - Removed outdated DuelMode section from TODO.md and updated the last modified date.
This commit is contained in:
parent
3100c53229
commit
46f7b794c6
5 changed files with 29 additions and 9 deletions
7
TODO.md
7
TODO.md
|
|
@ -1,6 +1,6 @@
|
|||
# LoParkour — TODO
|
||||
|
||||
> Обновлено: 2026-04-02. Длинный хвост старых аудитов и дублей: **[ARCHIVE_TODO.md](ARCHIVE_TODO.md)**.
|
||||
> Обновлено: 2026-04-01.
|
||||
|
||||
## Легенда
|
||||
|
||||
|
|
@ -62,11 +62,6 @@
|
|||
- **RandomStyle** / **ElytraGenerator**: защита от пустых списков.
|
||||
- **InventoryData**: новые сохранения в **YAML**; legacy binary читается один раз при миграции.
|
||||
|
||||
---
|
||||
|
||||
## DuelMode
|
||||
|
||||
**Отдельная крупная фича** (не багфикс): PvP/дуэльный режим из старых заметок — проектировать и оценивать отдельно (сессии, арена, матчмейкинг, награды). Детали и старые идеи см. в **[ARCHIVE_TODO.md](ARCHIVE_TODO.md)** (поиск по «Duel» / режимам).
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package dev.loki.loparkour.command;
|
|||
|
||||
import dev.loki.loparkour.LoParkour;
|
||||
import dev.loki.loparkour.api.Registry;
|
||||
import dev.loki.loparkour.config.Locales;
|
||||
import dev.loki.loparkour.menu.ParkourOption;
|
||||
import dev.loki.loparkour.mode.Mode;
|
||||
import dev.loki.loparkour.mode.Modes;
|
||||
|
|
@ -56,7 +57,7 @@ public class AdminCommandHandler {
|
|||
// ── forcejoin ──────────────────────────────────────────────────────────────
|
||||
|
||||
private void handleForceJoin(String target, CommandSender sender) {
|
||||
if (!base.cooldown(sender, "forcejoin", 2500, COOLDOWN_HINT)) return;
|
||||
if (!base.cooldown(sender, "forcejoin", 2500, Locales.getString(sender, "admin.cooldown"))) return;
|
||||
|
||||
if (target.equalsIgnoreCase("everyone")) {
|
||||
Bukkit.getOnlinePlayers().forEach(p -> Modes.DEFAULT.create(p));
|
||||
|
|
@ -78,7 +79,7 @@ public class AdminCommandHandler {
|
|||
// ── forceleave ─────────────────────────────────────────────────────────────
|
||||
|
||||
private void handleForceLeave(String target, CommandSender sender) {
|
||||
if (!base.cooldown(sender, "forceleave", 2500, COOLDOWN_HINT)) return;
|
||||
if (!base.cooldown(sender, "forceleave", 2500, Locales.getString(sender, "admin.cooldown"))) return;
|
||||
|
||||
if (target.equalsIgnoreCase("everyone")) {
|
||||
ParkourPlayer.getPlayers().forEach(ParkourUser::leave);
|
||||
|
|
@ -120,7 +121,7 @@ public class AdminCommandHandler {
|
|||
// ── recoverinventory ───────────────────────────────────────────────────────
|
||||
|
||||
private void handleRecoverInventory(String target, CommandSender sender) {
|
||||
if (!base.cooldown(sender, "recoverinventory", 2500, COOLDOWN_HINT)) return;
|
||||
if (!base.cooldown(sender, "recoverinventory", 2500, Locales.getString(sender, "admin.cooldown"))) return;
|
||||
Player other = Bukkit.getPlayer(target);
|
||||
if (other == null) { send(sender, LoParkour.PREFIX + "Player not online!"); return; }
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import org.bukkit.Material;
|
|||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
|
@ -45,6 +46,23 @@ public class Locales {
|
|||
return getString(getPlayerLocale(player), path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Player: that player's locale. Console / command blocks: default language from config ({@link Option#OPTIONS_DEFAULTS}), or {@code en}.
|
||||
*/
|
||||
@NotNull
|
||||
public static String getString(@NotNull CommandSender sender, @NotNull String path) {
|
||||
if (sender instanceof Player player) {
|
||||
return getString(player, path);
|
||||
}
|
||||
String locale = Option.OPTIONS_DEFAULTS != null
|
||||
? Option.OPTIONS_DEFAULTS.get(ParkourOption.LANG)
|
||||
: null;
|
||||
if (locale == null || locale.isBlank()) {
|
||||
locale = "en";
|
||||
}
|
||||
return getString(locale, path);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getString(@NotNull String locale, @NotNull String path) {
|
||||
return cachedValue(locale, c -> c.getString(path), "");
|
||||
|
|
|
|||
|
|
@ -293,3 +293,6 @@ modes:
|
|||
lore: "&#A0A0A0Team up with friends!||&#A0A0A0Shared score and progress"
|
||||
player_joined: "�FF00%s &#A0A0Ajoined the co-op session!"
|
||||
stats: "&#A0A0ATeam score: &#FFFFFF%s &#A0A0A| Your blocks: &#FFFFFF%s &#A0A0A(&#FFFFFF%s%%&#A0A0A)"
|
||||
|
||||
admin:
|
||||
cooldown: "<gray>Please wait before using this again."
|
||||
|
|
|
|||
|
|
@ -293,5 +293,8 @@ modes:
|
|||
player_joined: "�FF00%s &#A0A0Aприсоединился к кооперативной сессии!"
|
||||
stats: "&#A0A0AКомандный счёт: &#FFFFFF%s &#A0A0A| Ваши блоки: &#FFFFFF%s &#A0A0A(&#FFFFFF%s%%&#A0A0A)"
|
||||
|
||||
admin:
|
||||
cooldown: "<gray>Подождите немного перед повторным использованием."
|
||||
|
||||
ghost:
|
||||
saved: "�D4FFВаш призрак сохранён с результатом %s очков!"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue