Fix: LuckPerms prefix in placeholders, add /lochat reload
This commit is contained in:
parent
52037bc99c
commit
4d21241150
5 changed files with 144 additions and 14 deletions
|
|
@ -104,6 +104,10 @@ public final class LoChat extends JavaPlugin {
|
|||
getCommand("clearchat").setExecutor(new ClearChatCommand(this));
|
||||
getCommand("mute").setExecutor(new MuteCommand(this));
|
||||
getCommand("unmute").setExecutor(new UnmuteCommand(this));
|
||||
|
||||
LoChatCommand loChatCommand = new LoChatCommand(this);
|
||||
getCommand("lochat").setExecutor(loChatCommand);
|
||||
getCommand("lochat").setTabCompleter(loChatCommand);
|
||||
}
|
||||
|
||||
public void reload() {
|
||||
|
|
|
|||
55
src/main/java/com/loki/lochat/commands/LoChatCommand.java
Normal file
55
src/main/java/com/loki/lochat/commands/LoChatCommand.java
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
package com.loki.lochat.commands;
|
||||
|
||||
import com.loki.lochat.LoChat;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class LoChatCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
private final LoChat plugin;
|
||||
|
||||
public LoChatCommand(LoChat plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command,
|
||||
@NotNull String label, @NotNull String[] args) {
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage("§e=== LoChat v" + plugin.getDescription().getVersion() + " ===");
|
||||
sender.sendMessage("§e/lochat reload §7— перезагрузить конфиги");
|
||||
return true;
|
||||
}
|
||||
|
||||
if (args[0].equalsIgnoreCase("reload")) {
|
||||
if (!sender.hasPermission("lochat.admin")) {
|
||||
sender.sendMessage(plugin.getMessageConfig().get("errors.no-permission"));
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.reload();
|
||||
sender.sendMessage("§aLoChat перезагружен!");
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage("§cНеизвестная команда. Используй /lochat reload");
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command,
|
||||
@NotNull String alias, @NotNull String[] args) {
|
||||
if (args.length == 1 && sender.hasPermission("lochat.admin")) {
|
||||
return List.of("reload").stream()
|
||||
.filter(s -> s.startsWith(args[0].toLowerCase()))
|
||||
.toList();
|
||||
}
|
||||
return List.of();
|
||||
}
|
||||
}
|
||||
|
|
@ -114,11 +114,40 @@ public class GradientModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* Получает отформатированное имя игрока с градиентом
|
||||
* Получает отформатированное имя игрока с градиентом и LuckPerms префиксом
|
||||
*/
|
||||
public String getFormattedName(Player player) {
|
||||
if (!enabled) return player.getName();
|
||||
return DisplayNameUtil.getFullDisplayName(this, player);
|
||||
|
||||
GradientPlayerData data = dataManager.getPlayerData(player.getUniqueId());
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
// Сначала LuckPerms префикс (если нет кастомного)
|
||||
String lpPrefix = null;
|
||||
if (luckPermsHook.isEnabled()) {
|
||||
lpPrefix = luckPermsHook.getActivePrefix(player);
|
||||
}
|
||||
|
||||
// Кастомный префикс имеет приоритет
|
||||
if (data.hasPrefix() && data.isPrefixEnabled()) {
|
||||
String customPrefix = config.getPrefixFormat().replace("{prefix}", data.getPrefix());
|
||||
if (data.hasColors() && data.isColorEnabled() && config.isGradientOnPrefix()) {
|
||||
result.append(GradientUtil.applyGradient(customPrefix, data.getColors(), config.isUseLegacyRgbFormat()));
|
||||
} else {
|
||||
result.append(customPrefix);
|
||||
}
|
||||
} else if (lpPrefix != null && !lpPrefix.isEmpty()) {
|
||||
result.append(lpPrefix);
|
||||
}
|
||||
|
||||
// Ник с градиентом
|
||||
if (data.hasColors() && data.isColorEnabled()) {
|
||||
result.append(GradientUtil.applyGradient(player.getName(), data.getColors(), config.isUseLegacyRgbFormat()));
|
||||
} else {
|
||||
result.append(player.getName());
|
||||
}
|
||||
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -136,21 +165,40 @@ public class GradientModule {
|
|||
}
|
||||
|
||||
/**
|
||||
* Получает только префикс игрока
|
||||
* Получает префикс игрока (кастомный или LuckPerms)
|
||||
*/
|
||||
public String getPrefix(Player player) {
|
||||
if (!enabled) return "";
|
||||
|
||||
GradientPlayerData data = dataManager.getPlayerData(player.getUniqueId());
|
||||
if (!data.hasPrefix() || !data.isPrefixEnabled()) {
|
||||
return "";
|
||||
|
||||
// Кастомный префикс
|
||||
if (data.hasPrefix() && data.isPrefixEnabled()) {
|
||||
String prefix = config.getPrefixFormat().replace("{prefix}", data.getPrefix());
|
||||
if (data.hasColors() && data.isColorEnabled() && config.isGradientOnPrefix()) {
|
||||
return GradientUtil.applyGradient(prefix, data.getColors(), config.isUseLegacyRgbFormat());
|
||||
}
|
||||
return prefix;
|
||||
}
|
||||
|
||||
String prefix = config.getPrefixFormat().replace("{prefix}", data.getPrefix());
|
||||
if (data.hasColors() && data.isColorEnabled() && config.isGradientOnPrefix()) {
|
||||
return GradientUtil.applyGradient(prefix, data.getColors(), config.isUseLegacyRgbFormat());
|
||||
// LuckPerms префикс
|
||||
if (luckPermsHook.isEnabled()) {
|
||||
String lpPrefix = luckPermsHook.getActivePrefix(player);
|
||||
if (lpPrefix != null && !lpPrefix.isEmpty()) {
|
||||
return lpPrefix;
|
||||
}
|
||||
}
|
||||
return prefix;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает только LuckPerms префикс
|
||||
*/
|
||||
public String getLuckPermsPrefix(Player player) {
|
||||
if (!enabled || !luckPermsHook.isEnabled()) return "";
|
||||
String prefix = luckPermsHook.getActivePrefix(player);
|
||||
return prefix != null ? prefix : "";
|
||||
}
|
||||
|
||||
// Геттеры
|
||||
|
|
|
|||
|
|
@ -68,23 +68,39 @@ public class PlaceholderAPIHook extends PlaceholderExpansion {
|
|||
|
||||
// Gradient placeholders (совместимость с LoPreff)
|
||||
case "gradient_full", "full" -> {
|
||||
if (gradient == null || !gradient.isEnabled()) yield player.getName();
|
||||
Player onlinePlayer = player.getPlayer();
|
||||
if (onlinePlayer == null) yield player.getName();
|
||||
if (onlinePlayer == null) yield player.getName() != null ? player.getName() : "";
|
||||
|
||||
// Если gradient модуль выключен — берём только LuckPerms префикс + ник
|
||||
if (gradient == null || !gradient.isEnabled()) {
|
||||
yield player.getName() != null ? player.getName() : "";
|
||||
}
|
||||
|
||||
yield gradient.getFormattedName(onlinePlayer);
|
||||
}
|
||||
case "gradient_name", "name" -> {
|
||||
if (gradient == null || !gradient.isEnabled()) yield player.getName();
|
||||
Player onlinePlayer = player.getPlayer();
|
||||
if (onlinePlayer == null) yield player.getName();
|
||||
if (onlinePlayer == null) yield player.getName() != null ? player.getName() : "";
|
||||
|
||||
if (gradient == null || !gradient.isEnabled()) {
|
||||
yield player.getName();
|
||||
}
|
||||
yield gradient.getGradientNick(onlinePlayer);
|
||||
}
|
||||
case "gradient_prefix", "prefix" -> {
|
||||
if (gradient == null || !gradient.isEnabled()) yield "";
|
||||
Player onlinePlayer = player.getPlayer();
|
||||
if (onlinePlayer == null) yield "";
|
||||
|
||||
if (gradient == null || !gradient.isEnabled()) yield "";
|
||||
yield gradient.getPrefix(onlinePlayer);
|
||||
}
|
||||
case "lp_prefix" -> {
|
||||
Player onlinePlayer = player.getPlayer();
|
||||
if (onlinePlayer == null) yield "";
|
||||
|
||||
if (gradient == null || !gradient.isEnabled()) yield "";
|
||||
yield gradient.getLuckPermsPrefix(onlinePlayer);
|
||||
}
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,6 +76,11 @@ commands:
|
|||
usage: /unmute <player>
|
||||
permission: chat.mute
|
||||
|
||||
lochat:
|
||||
description: LoChat admin command
|
||||
usage: /lochat [reload]
|
||||
permission: lochat.admin
|
||||
|
||||
color:
|
||||
description: Set gradient nick color
|
||||
usage: /color <hex1> [hex2] ...
|
||||
|
|
@ -136,3 +141,5 @@ permissions:
|
|||
default: op
|
||||
gradient.bypass.cost:
|
||||
default: op
|
||||
lochat.admin:
|
||||
default: op
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue