64 lines
2.0 KiB
Java
64 lines
2.0 KiB
Java
package com.io.yutian.livemutually.manager;
|
|
|
|
import cn.hamster3.cdapi.CDTimeAPI;
|
|
import com.io.yutian.livemutually.liveroom.KSLiveRoomClient;
|
|
import com.io.yutian.mclive.*;
|
|
import com.io.yutian.verify.AESUtil;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.regex.Pattern;
|
|
|
|
public class KSLiveRoomManager {
|
|
|
|
public static Map<Player, KSLiveRoomClient> liveRoomClientMap = new HashMap<>();
|
|
|
|
public static void connect(Player player, String id) {
|
|
if (isConnected(player)) {
|
|
disconnect(player);
|
|
return;
|
|
}
|
|
if(!Pattern.matches("[a-zA-Z0-9_]+", id)) {
|
|
return;
|
|
}
|
|
String pluginName = Main.configYml.getGameMode();
|
|
if (AESUtil.isVerifyCheck(player,pluginName,id)) {
|
|
return;
|
|
}
|
|
CDTimeAPI.setPlayerCD(player.getUniqueId(),"link_live_Cd",1000 * 6);
|
|
KSLiveRoomClient liveRoomClient = new KSLiveRoomClient(id);
|
|
try {
|
|
liveRoomClient.openRoom(player);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
liveRoomClientMap.put(player, liveRoomClient);
|
|
if (player != null) {
|
|
player.sendMessage("§c[系统]§a您的直播间: §e" + id + " §a已连接...");
|
|
}
|
|
}
|
|
|
|
public static KSLiveRoomClient getLiveRoomClient(Player player) {
|
|
return liveRoomClientMap.get(player);
|
|
}
|
|
|
|
public static boolean isConnected(Player player) {
|
|
KSLiveRoomClient liveRoomClient = getLiveRoomClient(player);
|
|
return liveRoomClient != null && liveRoomClient.getSocketClient() != null && liveRoomClient.getSocketClient().isOpen();
|
|
}
|
|
|
|
public static void disconnect(Player player) {
|
|
if (!isConnected(player)) {
|
|
return;
|
|
}
|
|
KSLiveRoomClient liveRoomClient = getLiveRoomClient(player);
|
|
liveRoomClient.close();
|
|
if (player != null) {
|
|
player.sendMessage("§c[系统]§b已断开直播间连接...");
|
|
}
|
|
liveRoomClientMap.remove(player);
|
|
}
|
|
|
|
}
|