Fix missing features and improve code quality
Features fixed: - Added chat filter functionality (block/warn/censor modes) - Fixed spy command to monitor all chat messages - Added proper spy notifications for global/local chat Code quality improvements: - Created PlayerUtil to eliminate code duplication in player lookup - Refactored ChatListener into smaller, focused methods - Added Constants class to replace magic numbers - Improved SOLID principles compliance - Fixed all compilation warnings All features from README are now implemented and working.
This commit is contained in:
parent
4f7b792633
commit
e616667c78
20 changed files with 250 additions and 99 deletions
70
src/main/java/com/loki/lochat/utils/PlayerUtil.java
Normal file
70
src/main/java/com/loki/lochat/utils/PlayerUtil.java
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
package com.loki.lochat.utils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Утилиты для работы с игроками
|
||||
*/
|
||||
public final class PlayerUtil {
|
||||
|
||||
private PlayerUtil() {}
|
||||
|
||||
/**
|
||||
* Находит игрока по имени (онлайн или оффлайн)
|
||||
* @param name имя игрока
|
||||
* @return UUID игрока или null если не найден
|
||||
*/
|
||||
public static UUID findPlayerUUID(String name) {
|
||||
// Сначала ищем онлайн игрока
|
||||
Player onlinePlayer = Bukkit.getPlayer(name);
|
||||
if (onlinePlayer != null) {
|
||||
return onlinePlayer.getUniqueId();
|
||||
}
|
||||
|
||||
// Затем ищем оффлайн игрока
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(name);
|
||||
if (offlinePlayer.hasPlayedBefore() || offlinePlayer.isOnline()) {
|
||||
return offlinePlayer.getUniqueId();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет, существует ли игрок (играл на сервере)
|
||||
* @param name имя игрока
|
||||
* @return true если игрок существует
|
||||
*/
|
||||
public static boolean playerExists(String name) {
|
||||
return findPlayerUUID(name) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает имя игрока по UUID
|
||||
* @param uuid UUID игрока
|
||||
* @return имя игрока или null
|
||||
*/
|
||||
public static String getPlayerName(UUID uuid) {
|
||||
Player onlinePlayer = Bukkit.getPlayer(uuid);
|
||||
if (onlinePlayer != null) {
|
||||
return onlinePlayer.getName();
|
||||
}
|
||||
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
return offlinePlayer.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Проверяет, онлайн ли игрок
|
||||
* @param uuid UUID игрока
|
||||
* @return true если игрок онлайн
|
||||
*/
|
||||
public static boolean isPlayerOnline(UUID uuid) {
|
||||
Player player = Bukkit.getPlayer(uuid);
|
||||
return player != null && player.isOnline();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue