Remove mute system and add PM format editor with gradient support
This commit is contained in:
parent
c09a3a399f
commit
dfc1c901ab
9 changed files with 0 additions and 329 deletions
|
|
@ -23,7 +23,6 @@ public final class LoChat extends JavaPlugin {
|
|||
private FilterManager filterManager;
|
||||
private AntiSpamManager antiSpamManager;
|
||||
private CooldownManager cooldownManager;
|
||||
private MuteManager muteManager;
|
||||
private MentionManager mentionManager;
|
||||
private SpyManager spyManager;
|
||||
private EmojiManager emojiManager;
|
||||
|
|
@ -44,7 +43,6 @@ public final class LoChat extends JavaPlugin {
|
|||
filterManager = new FilterManager(this);
|
||||
antiSpamManager = new AntiSpamManager(this);
|
||||
cooldownManager = new CooldownManager();
|
||||
muteManager = new MuteManager(this);
|
||||
mentionManager = new MentionManager(this);
|
||||
spyManager = new SpyManager(this);
|
||||
chatManager = new ChatManager(this);
|
||||
|
|
@ -82,9 +80,6 @@ public final class LoChat extends JavaPlugin {
|
|||
if (ignoreManager != null) {
|
||||
ignoreManager.save();
|
||||
}
|
||||
if (muteManager != null) {
|
||||
muteManager.save();
|
||||
}
|
||||
if (gradientModule != null) {
|
||||
gradientModule.shutdown();
|
||||
}
|
||||
|
|
@ -102,8 +97,6 @@ public final class LoChat extends JavaPlugin {
|
|||
getCommand("announce").setExecutor(new AnnounceCommand(this));
|
||||
getCommand("chatspy").setExecutor(new ChatSpyCommand(this));
|
||||
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);
|
||||
|
|
@ -161,10 +154,6 @@ public final class LoChat extends JavaPlugin {
|
|||
return cooldownManager;
|
||||
}
|
||||
|
||||
public MuteManager getMuteManager() {
|
||||
return muteManager;
|
||||
}
|
||||
|
||||
public MentionManager getMentionManager() {
|
||||
return mentionManager;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,56 +0,0 @@
|
|||
package com.loki.lochat.commands;
|
||||
|
||||
import com.loki.lochat.LoChat;
|
||||
import com.loki.lochat.managers.MuteManager;
|
||||
import com.loki.lochat.utils.ChatFormatter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MuteCommand implements CommandExecutor {
|
||||
|
||||
private final LoChat plugin;
|
||||
|
||||
public MuteCommand(LoChat plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 2) {
|
||||
sender.sendMessage(ChatFormatter.parse(plugin.getMessageConfig().getInvalidUsage("/mute <ник> <время> [причина]")));
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendMessage(ChatFormatter.parse(plugin.getMessageConfig().getPlayerNotFound()));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (plugin.getMuteManager().isAlreadyMuted(target.getUniqueId())) {
|
||||
sender.sendMessage(ChatFormatter.parse(plugin.getMessageConfig().get("mute.already-muted")));
|
||||
return true;
|
||||
}
|
||||
|
||||
long duration = MuteManager.parseTime(args[1]);
|
||||
String reason = args.length > 2 ? String.join(" ", java.util.Arrays.copyOfRange(args, 2, args.length)) : null;
|
||||
|
||||
plugin.getMuteManager().mute(target.getUniqueId(), duration, reason);
|
||||
|
||||
String timeStr = duration <= 0 ? "навсегда" : args[1];
|
||||
sender.sendMessage(ChatFormatter.parse(
|
||||
plugin.getMessageConfig().get("mute.muted", "{player}", target.getName(), "{time}", timeStr)
|
||||
));
|
||||
|
||||
// Уведомляем игрока
|
||||
target.sendMessage(ChatFormatter.parse(
|
||||
plugin.getMessageConfig().get("mute.you-muted", "{time}", timeStr)
|
||||
));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,45 +0,0 @@
|
|||
package com.loki.lochat.commands;
|
||||
|
||||
import com.loki.lochat.LoChat;
|
||||
import com.loki.lochat.utils.ChatFormatter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UnmuteCommand implements CommandExecutor {
|
||||
|
||||
private final LoChat plugin;
|
||||
|
||||
public UnmuteCommand(LoChat plugin) {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
||||
if (args.length < 1) {
|
||||
sender.sendMessage(ChatFormatter.parse(plugin.getMessageConfig().getInvalidUsage("/unmute <ник>")));
|
||||
return true;
|
||||
}
|
||||
|
||||
Player target = Bukkit.getPlayer(args[0]);
|
||||
if (target == null) {
|
||||
sender.sendMessage(ChatFormatter.parse(plugin.getMessageConfig().getPlayerNotFound()));
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!plugin.getMuteManager().isMuted(target.getUniqueId())) {
|
||||
sender.sendMessage(ChatFormatter.parse(plugin.getMessageConfig().get("mute.not-muted")));
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.getMuteManager().unmute(target.getUniqueId());
|
||||
sender.sendMessage(ChatFormatter.parse(
|
||||
plugin.getMessageConfig().get("mute.unmuted", "{player}", target.getName())
|
||||
));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -47,15 +47,6 @@ public class PlaceholderAPIHook extends PlaceholderExpansion {
|
|||
GradientModule gradient = plugin.getGradientModule();
|
||||
|
||||
return switch (params.toLowerCase()) {
|
||||
case "muted" -> String.valueOf(plugin.getMuteManager().isMuted(uuid));
|
||||
case "mute_time" -> {
|
||||
String time = plugin.getMuteManager().getRemainingTime(uuid);
|
||||
yield time != null ? time : "0";
|
||||
}
|
||||
case "mute_reason" -> {
|
||||
String reason = plugin.getMuteManager().getReason(uuid);
|
||||
yield reason != null ? reason : "";
|
||||
}
|
||||
case "ignored_count" -> String.valueOf(plugin.getIgnoreManager().getIgnoredCount(uuid));
|
||||
case "global_enabled" -> String.valueOf(!plugin.getChatManager().isGlobalChatDisabled(uuid));
|
||||
case "last_pm" -> {
|
||||
|
|
|
|||
|
|
@ -34,19 +34,6 @@ public class ChatListener implements Listener {
|
|||
}
|
||||
|
||||
private void processChat(Player player, String message) {
|
||||
// Проверка мута
|
||||
if (plugin.getMuteManager().isMuted(player.getUniqueId())) {
|
||||
String remaining = plugin.getMuteManager().getRemainingTime(player.getUniqueId());
|
||||
if (remaining.equals("навсегда")) {
|
||||
player.sendMessage(ChatFormatter.parse(plugin.getMessageConfig().get("mute.permanent")));
|
||||
} else {
|
||||
player.sendMessage(ChatFormatter.parse(
|
||||
plugin.getMessageConfig().get("mute.you-muted", "{time}", remaining)
|
||||
));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
String globalSymbol = plugin.getConfigManager().getGlobalSymbol();
|
||||
boolean isGlobal = message.startsWith(globalSymbol) && player.hasPermission("chat.global.use");
|
||||
String chatType = isGlobal ? "global" : "local";
|
||||
|
|
|
|||
|
|
@ -1,136 +0,0 @@
|
|||
package com.loki.lochat.managers;
|
||||
|
||||
import com.loki.lochat.LoChat;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class MuteManager {
|
||||
|
||||
private final LoChat plugin;
|
||||
private final File muteFile;
|
||||
private final Map<UUID, Long> mutedPlayers = new ConcurrentHashMap<>();
|
||||
private final Map<UUID, String> muteReasons = new ConcurrentHashMap<>();
|
||||
|
||||
public MuteManager(LoChat plugin) {
|
||||
this.plugin = plugin;
|
||||
this.muteFile = new File(plugin.getDataFolder(), "mutes.yml");
|
||||
load();
|
||||
}
|
||||
|
||||
public void load() {
|
||||
if (!muteFile.exists()) return;
|
||||
|
||||
YamlConfiguration config = YamlConfiguration.loadConfiguration(muteFile);
|
||||
for (String key : config.getKeys(false)) {
|
||||
try {
|
||||
UUID uuid = UUID.fromString(key);
|
||||
long muteEnd = config.getLong(key + ".end");
|
||||
String reason = config.getString(key + ".reason");
|
||||
|
||||
// Пропускаем истёкшие муты
|
||||
if (muteEnd != 0 && System.currentTimeMillis() > muteEnd) continue;
|
||||
|
||||
mutedPlayers.put(uuid, muteEnd);
|
||||
if (reason != null) muteReasons.put(uuid, reason);
|
||||
} catch (Exception ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
public void save() {
|
||||
YamlConfiguration config = new YamlConfiguration();
|
||||
|
||||
for (Map.Entry<UUID, Long> entry : mutedPlayers.entrySet()) {
|
||||
String key = entry.getKey().toString();
|
||||
config.set(key + ".end", entry.getValue());
|
||||
String reason = muteReasons.get(entry.getKey());
|
||||
if (reason != null) config.set(key + ".reason", reason);
|
||||
}
|
||||
|
||||
try {
|
||||
config.save(muteFile);
|
||||
} catch (IOException e) {
|
||||
plugin.getLogger().severe("Не удалось сохранить муты: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMuted(UUID player) {
|
||||
Long muteEnd = mutedPlayers.get(player);
|
||||
if (muteEnd == null) return false;
|
||||
|
||||
if (muteEnd == 0) return true;
|
||||
|
||||
if (System.currentTimeMillis() > muteEnd) {
|
||||
mutedPlayers.remove(player);
|
||||
muteReasons.remove(player);
|
||||
save();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void mute(UUID player, long durationSeconds, String reason) {
|
||||
long muteEnd = durationSeconds <= 0 ? 0 : System.currentTimeMillis() + (durationSeconds * 1000);
|
||||
mutedPlayers.put(player, muteEnd);
|
||||
if (reason != null && !reason.isEmpty()) {
|
||||
muteReasons.put(player, reason);
|
||||
}
|
||||
save();
|
||||
}
|
||||
|
||||
public void unmute(UUID player) {
|
||||
mutedPlayers.remove(player);
|
||||
muteReasons.remove(player);
|
||||
save();
|
||||
}
|
||||
|
||||
public String getRemainingTime(UUID player) {
|
||||
Long muteEnd = mutedPlayers.get(player);
|
||||
if (muteEnd == null) return null;
|
||||
if (muteEnd == 0) return "навсегда";
|
||||
|
||||
long remaining = (muteEnd - System.currentTimeMillis()) / 1000;
|
||||
if (remaining <= 0) return null;
|
||||
|
||||
return formatTime(remaining);
|
||||
}
|
||||
|
||||
public String getReason(UUID player) {
|
||||
return muteReasons.get(player);
|
||||
}
|
||||
|
||||
public boolean isAlreadyMuted(UUID player) {
|
||||
return mutedPlayers.containsKey(player);
|
||||
}
|
||||
|
||||
private String formatTime(long seconds) {
|
||||
if (seconds < 60) return seconds + " сек";
|
||||
if (seconds < 3600) return (seconds / 60) + " мин";
|
||||
if (seconds < 86400) return (seconds / 3600) + " ч";
|
||||
return (seconds / 86400) + " д";
|
||||
}
|
||||
|
||||
public static long parseTime(String time) {
|
||||
if (time == null || time.isEmpty()) return -1;
|
||||
|
||||
try {
|
||||
char unit = time.charAt(time.length() - 1);
|
||||
long value = Long.parseLong(time.substring(0, time.length() - 1));
|
||||
|
||||
return switch (Character.toLowerCase(unit)) {
|
||||
case 's' -> value;
|
||||
case 'm' -> value * 60;
|
||||
case 'h' -> value * 3600;
|
||||
case 'd' -> value * 86400;
|
||||
default -> Long.parseLong(time);
|
||||
};
|
||||
} catch (NumberFormatException e) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -35,14 +35,6 @@ ignore:
|
|||
announce:
|
||||
reloaded: "<green>Конфигурация перезагружена</green>"
|
||||
|
||||
mute:
|
||||
muted: "<green>Игрок {player} замучен на {time}</green>"
|
||||
unmuted: "<green>Игрок {player} размучен</green>"
|
||||
already-muted: "<red>Игрок уже замучен</red>"
|
||||
not-muted: "<red>Игрок не замучен</red>"
|
||||
you-muted: "<red>Вы замучены! Осталось: {time}</red>"
|
||||
permanent: "<red>Вы замучены навсегда!</red>"
|
||||
|
||||
spy:
|
||||
enabled: "<green>Шпион режим включен</green>"
|
||||
disabled: "<red>Шпион режим выключен</red>"
|
||||
|
|
|
|||
|
|
@ -66,16 +66,6 @@ commands:
|
|||
permission: chat.clear
|
||||
aliases: [cc]
|
||||
|
||||
mute:
|
||||
description: Mute a player
|
||||
usage: /mute <player> <time> [reason]
|
||||
permission: chat.mute
|
||||
|
||||
unmute:
|
||||
description: Unmute a player
|
||||
usage: /unmute <player>
|
||||
permission: chat.mute
|
||||
|
||||
lochat:
|
||||
description: LoChat admin command
|
||||
usage: /lochat [reload]
|
||||
|
|
@ -121,8 +111,6 @@ permissions:
|
|||
default: op
|
||||
chat.clear:
|
||||
default: op
|
||||
chat.mute:
|
||||
default: op
|
||||
chat.bypass.cooldown:
|
||||
default: op
|
||||
chat.bypass.filter:
|
||||
|
|
|
|||
|
|
@ -1,39 +0,0 @@
|
|||
package com.loki.lochat.managers;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class MuteManagerTest {
|
||||
|
||||
@Test
|
||||
void parseTime_seconds() {
|
||||
assertEquals(30, MuteManager.parseTime("30s"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseTime_minutes() {
|
||||
assertEquals(300, MuteManager.parseTime("5m"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseTime_hours() {
|
||||
assertEquals(3600, MuteManager.parseTime("1h"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseTime_days() {
|
||||
assertEquals(86400, MuteManager.parseTime("1d"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseTime_invalid() {
|
||||
assertEquals(-1, MuteManager.parseTime("abc"));
|
||||
assertEquals(-1, MuteManager.parseTime(""));
|
||||
assertEquals(-1, MuteManager.parseTime(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void parseTime_numberOnly() {
|
||||
assertEquals(60, MuteManager.parseTime("60"));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue