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
|
|
@ -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), "");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue