init
This commit is contained in:
parent
834f535304
commit
57252679b0
|
@ -4,8 +4,8 @@
|
|||
<facet type="minecraft" name="Minecraft">
|
||||
<configuration>
|
||||
<autoDetectTypes>
|
||||
<platformType>SPIGOT</platformType>
|
||||
<platformType>BUNGEECORD</platformType>
|
||||
<platformType>SPIGOT</platformType>
|
||||
</autoDetectTypes>
|
||||
</configuration>
|
||||
</facet>
|
||||
|
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
BIN
lib/PixelLivePlugin.jar
Normal file
BIN
lib/PixelLivePlugin.jar
Normal file
Binary file not shown.
Binary file not shown.
|
@ -1,11 +0,0 @@
|
|||
package com.io.yutian.livemutually.liveroom;
|
||||
|
||||
public interface Gift {
|
||||
|
||||
User user();
|
||||
|
||||
String name();
|
||||
|
||||
long count();
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
package com.io.yutian.livemutually.liveroom;
|
||||
|
||||
import com.io.yutian.livemutually.wss.KSWebSocketClient;
|
||||
import com.io.yutian.mclive.Main;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
public class KSLiveRoomClient {
|
||||
|
||||
private static final String URL = "ws://localhost:8765";
|
||||
private String roomId;
|
||||
private Map<String, String> headMap = new HashMap<>();
|
||||
private KSWebSocketClient socketClient;
|
||||
private ExecutorService executor = Executors.newCachedThreadPool();
|
||||
|
||||
public KSLiveRoomClient(String roomId) {
|
||||
this.roomId = roomId;
|
||||
headMap.put("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1");
|
||||
headMap.put("Content-Type", "text/plain;charset=UTF-8");
|
||||
headMap.put("accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9");
|
||||
headMap.put("cookie", "__ac_nonce=0638733a400869171be51");
|
||||
}
|
||||
|
||||
public KSWebSocketClient getSocketClient() {
|
||||
return socketClient;
|
||||
}
|
||||
|
||||
public void openRoom(Player player) throws Exception {
|
||||
URI uri = new URI(URL);
|
||||
KSWebSocketClient ksWebSocketClient = new KSWebSocketClient(player, uri, headMap);
|
||||
socketClient = ksWebSocketClient;
|
||||
Main.LiveRoomClientList.add(ksWebSocketClient);
|
||||
executor.submit(() -> socketClient.run());
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (socketClient == null || socketClient.isClosed() || socketClient.isClosing()) {
|
||||
return;
|
||||
}
|
||||
socketClient.setForcedClose(true);
|
||||
socketClient.close();
|
||||
}
|
||||
|
||||
public String getRoomId() {
|
||||
return roomId;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,7 @@
|
|||
package com.io.yutian.livemutually.liveroom;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
|
@ -9,7 +11,6 @@ public class LiveRoomWatcher {
|
|||
protected Consumer<User> userHandler;
|
||||
protected Consumer<Like> likeHandler;
|
||||
protected Consumer<Follow> followHandler;
|
||||
protected Consumer<Gift> giftHandler;
|
||||
|
||||
public final LiveRoomWatcher onChat(Consumer<Chat> handler) {
|
||||
Objects.requireNonNull(handler);
|
||||
|
@ -35,12 +36,6 @@ public class LiveRoomWatcher {
|
|||
return this;
|
||||
}
|
||||
|
||||
public final LiveRoomWatcher onGift(Consumer<Gift> handler) {
|
||||
Objects.requireNonNull(handler);
|
||||
this.giftHandler = handler;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void callChat(Chat chat) {
|
||||
if (chatHandler != null) {
|
||||
chatHandler.accept(chat);
|
||||
|
@ -65,10 +60,4 @@ public class LiveRoomWatcher {
|
|||
}
|
||||
}
|
||||
|
||||
public void callGift(Gift gift) {
|
||||
if (giftHandler != null) {
|
||||
giftHandler.accept(gift);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,157 +0,0 @@
|
|||
package com.io.yutian.livemutually.wss;
|
||||
|
||||
import com.io.yutian.livemutually.liveroom.KSLiveRoomClient;
|
||||
import com.io.yutian.livemutually.liveroom.LiveRoomWatcher;
|
||||
import com.io.yutian.livemutually.liveroom.User;
|
||||
import com.io.yutian.mclive.Main;
|
||||
import json.JSONObject;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
import org.java_websocket.drafts.Draft_6455;
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class KSWebSocketClient extends WebSocketClient {
|
||||
|
||||
private Player player;
|
||||
private LiveRoomWatcher liveRoomWatcher;
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public KSWebSocketClient(Player player, URI uri, Map<String, String> httpHeaders) {
|
||||
super(uri, new Draft_6455(), httpHeaders);
|
||||
this.player = player;
|
||||
this.liveRoomWatcher = new KSAPILiveRoomWatcher(player);
|
||||
Bukkit.getConsoleSender().sendMessage("#WebSocketClient 已创建.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(ServerHandshake serverHandshake) {
|
||||
this.send();
|
||||
}
|
||||
|
||||
public HashMap<String,String> hashMap = new HashMap<>();
|
||||
@Override
|
||||
public void onMessage(String s) {
|
||||
//if(s.isEmpty()){return;}
|
||||
Bukkit.getConsoleSender().sendMessage("TEST = "+s);
|
||||
Bukkit.getConsoleSender().sendMessage("TEST = "+new JSONObject(s));
|
||||
JSONObject jsonObject = new JSONObject(s);
|
||||
/*String type = jsonObject.getString("type");
|
||||
if (!type.equalsIgnoreCase("liudui")) {
|
||||
if (type.equalsIgnoreCase("礼物")) {
|
||||
String username = jsonObject.getString("昵称");
|
||||
String userpng = jsonObject.getString("头像");
|
||||
if(hashMap.get(userpng) != null){
|
||||
username = hashMap.get(userpng);
|
||||
}
|
||||
String giftname = jsonObject.getString("礼物名称");
|
||||
int amount = jsonObject.getInt("礼物增量");
|
||||
if (amount >= 1){
|
||||
liveRoomWatcher.callGift(new KuaiShouGift(username, giftname, amount));
|
||||
}
|
||||
}else if (type.equalsIgnoreCase("muyu")) {
|
||||
String user = jsonObject.getString("user");
|
||||
int zan = jsonObject.getInt("zan");
|
||||
liveRoomWatcher.callLike(new KuaiShouLike(user, zan));
|
||||
} else if (type.equalsIgnoreCase("点赞")) {
|
||||
String user = jsonObject.getString("昵称");
|
||||
int zan = jsonObject.getInt("点赞次数");
|
||||
liveRoomWatcher.callLike(new KuaiShouLike(user, zan));
|
||||
} else if (type.equalsIgnoreCase("fayan")) {
|
||||
String nickname = jsonObject.getString("nickname");
|
||||
String headurl = jsonObject.getString("headurl");
|
||||
String nr = jsonObject.getString("nr");
|
||||
liveRoomWatcher.callChat(new KuaiShouChat(nickname, nr));
|
||||
} else if (type.equalsIgnoreCase("gift")) {
|
||||
String username = jsonObject.getString("giftusername");
|
||||
String giftpic = jsonObject.getString("giftpic");
|
||||
hashMap.put(giftpic,username);
|
||||
int amount = jsonObject.getInt("liwushuliang");
|
||||
String giftPic2 = jsonObject.getString("liwutupian");
|
||||
String nr = jsonObject.getString("giftnr");
|
||||
String giftname = nr.split("个")[1];
|
||||
} else if (type.equalsIgnoreCase("others")) {
|
||||
String qian = jsonObject.getString("qian");
|
||||
if(qian.contains("欢迎")){
|
||||
String nr = jsonObject.getString("othernr");
|
||||
String userName = nr.split(" 进入")[0];
|
||||
liveRoomWatcher.callUser(new KuaiShouUser(userName));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(int i, String s, boolean b) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
private void sendVerify() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("type", "register");
|
||||
KSWebSocketClient.this.send(jsonObject.toString().getBytes());
|
||||
}
|
||||
|
||||
public void send() {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!KSWebSocketClient.this.isOpen()) {
|
||||
// Bukkit.getConsoleSender().sendMessage("[直播互动] 心跳检测失败,已自动重连.");
|
||||
// restartReconnectionTimer();
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("type", "heartbeat");
|
||||
KSWebSocketClient.this.send(jsonObject.toString().getBytes());
|
||||
}
|
||||
}.runTaskTimerAsynchronously(Main.plugin, 0L, 10 * 20L);
|
||||
}
|
||||
|
||||
private boolean forcedClose = false;
|
||||
private volatile boolean isReconnecting = false;
|
||||
|
||||
public void setForcedClose(boolean forcedClose) {
|
||||
this.forcedClose = forcedClose;
|
||||
}
|
||||
|
||||
private void restartReconnectionTimer() {
|
||||
new BukkitRunnable() {
|
||||
private int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (reconnectBlocking()) {
|
||||
cancel();
|
||||
isReconnecting = false;
|
||||
return;
|
||||
}
|
||||
if (i >= 100) {
|
||||
if (player != null) {
|
||||
player.sendMessage("§c[系统]§a直播间自动重连失败...");
|
||||
}
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(Main.plugin, 0L, 5L);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.io.yutian.livemutually.manager;
|
||||
|
||||
public class GiftData {
|
||||
|
||||
private String name;
|
||||
|
||||
private long amount;
|
||||
|
||||
private long sendTime;
|
||||
|
||||
public GiftData(String name,long amount,long sendTime){
|
||||
this.name = name;
|
||||
this.amount = amount;
|
||||
this.sendTime = sendTime;
|
||||
}
|
||||
|
||||
public long getAmount() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public long getSendTime() {
|
||||
return sendTime;
|
||||
}
|
||||
|
||||
public void setSendTime(long sendTime) {
|
||||
this.sendTime = sendTime;
|
||||
}
|
||||
}
|
|
@ -1,63 +1,33 @@
|
|||
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.pixelliveplugin.PixelLiveAPI;
|
||||
import com.io.yutian.verify.AESUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
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 List<Player> livepluginList = new ArrayList<>();
|
||||
|
||||
public static boolean isConnected(Player player) {
|
||||
KSLiveRoomClient liveRoomClient = getLiveRoomClient(player);
|
||||
return liveRoomClient != null && liveRoomClient.getSocketClient() != null && liveRoomClient.getSocketClient().isOpen();
|
||||
if(livepluginList.contains(player)){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
livepluginList.remove(player);
|
||||
PixelLiveAPI.disconnect(player);
|
||||
player.sendMessage("§c[系统]§b已断开直播间连接...");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package com.io.yutian.livemutually.manager;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class UserData {
|
||||
|
||||
private String userName;
|
||||
// 礼物 礼物数据
|
||||
private HashMap<String,GiftData> giftData = new HashMap<>();
|
||||
|
||||
public UserData(String userName){
|
||||
this.userName = userName;
|
||||
this.giftData = new HashMap<>();
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
// 判断本次赠送礼物是否已送过
|
||||
public boolean isExitGift(String giftName){
|
||||
if(giftData.get(giftName) != null){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public GiftData getGiftsData(String giftName){
|
||||
if(giftData.get(giftName) != null){
|
||||
return giftData.get(giftName);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void createGiftsData(String giftName,long giftAmount){
|
||||
long sendTime = System.currentTimeMillis();
|
||||
giftData.put(giftName,new GiftData(giftName,giftAmount,sendTime));
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ import com.io.yutian.livemutually.liveroom.LiveRoomWatcher;
|
|||
import com.io.yutian.mclive.Main;
|
||||
import com.io.yutian.mclive.event.LiveChatEvents;
|
||||
import com.io.yutian.mclive.event.LiveEnterEvents;
|
||||
import com.io.yutian.mclive.event.LiveGiftEvents;
|
||||
import com.io.yutian.mclive.event.LiveLikeEvents;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -33,26 +32,5 @@ public class KSAPILiveRoomWatcher extends LiveRoomWatcher {
|
|||
Bukkit.getPluginManager().callEvent(event);
|
||||
});
|
||||
});
|
||||
onGift(gift -> {
|
||||
String giftName = gift.name();
|
||||
long count = gift.count();
|
||||
String count_color = "§a";
|
||||
if (count >= 1314) {
|
||||
count_color = "§c";
|
||||
} else if (count >= 520) {
|
||||
count_color = "§d";
|
||||
} else if (count >= 188) {
|
||||
count_color = "§e";
|
||||
} else if (count >= 66) {
|
||||
count_color = "§b";
|
||||
}
|
||||
String message = "§6[日志 - 礼物触发] §f"+player.getName()+ " >>> " + gift.user().nickName() + " = §a" + giftName + " 数量: "+count_color + count;
|
||||
Bukkit.getConsoleSender().sendMessage(message);
|
||||
Bukkit.getScheduler().runTask(Main.plugin, () -> {
|
||||
LiveGiftEvents event = new LiveGiftEvents(player, gift.user(), gift.name(), gift.count());
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,157 +0,0 @@
|
|||
package com.io.yutian.livemutually.wss;
|
||||
|
||||
import com.io.yutian.livemutually.liveroom.KSLiveRoomClient;
|
||||
import com.io.yutian.livemutually.liveroom.LiveRoomWatcher;
|
||||
import com.io.yutian.livemutually.liveroom.User;
|
||||
import com.io.yutian.mclive.Main;
|
||||
import json.JSONObject;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.java_websocket.client.WebSocketClient;
|
||||
import org.java_websocket.drafts.Draft_6455;
|
||||
import org.java_websocket.handshake.ServerHandshake;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class KSWebSocketClient extends WebSocketClient {
|
||||
|
||||
private Player player;
|
||||
private LiveRoomWatcher liveRoomWatcher;
|
||||
|
||||
public Player getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
||||
public KSWebSocketClient(Player player, URI uri, Map<String, String> httpHeaders) {
|
||||
super(uri, new Draft_6455(), httpHeaders);
|
||||
this.player = player;
|
||||
this.liveRoomWatcher = new KSAPILiveRoomWatcher(player);
|
||||
Bukkit.getConsoleSender().sendMessage("#WebSocketClient 已创建.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOpen(ServerHandshake serverHandshake) {
|
||||
this.send();
|
||||
}
|
||||
|
||||
public HashMap<String,String> hashMap = new HashMap<>();
|
||||
@Override
|
||||
public void onMessage(String s) {
|
||||
//if(s.isEmpty()){return;}
|
||||
Bukkit.getConsoleSender().sendMessage("TEST = "+s);
|
||||
Bukkit.getConsoleSender().sendMessage("TEST = "+new JSONObject(s));
|
||||
JSONObject jsonObject = new JSONObject(s);
|
||||
/*String type = jsonObject.getString("type");
|
||||
if (!type.equalsIgnoreCase("liudui")) {
|
||||
if (type.equalsIgnoreCase("礼物")) {
|
||||
String username = jsonObject.getString("昵称");
|
||||
String userpng = jsonObject.getString("头像");
|
||||
if(hashMap.get(userpng) != null){
|
||||
username = hashMap.get(userpng);
|
||||
}
|
||||
String giftname = jsonObject.getString("礼物名称");
|
||||
int amount = jsonObject.getInt("礼物增量");
|
||||
if (amount >= 1){
|
||||
liveRoomWatcher.callGift(new KuaiShouGift(username, giftname, amount));
|
||||
}
|
||||
}else if (type.equalsIgnoreCase("muyu")) {
|
||||
String user = jsonObject.getString("user");
|
||||
int zan = jsonObject.getInt("zan");
|
||||
liveRoomWatcher.callLike(new KuaiShouLike(user, zan));
|
||||
} else if (type.equalsIgnoreCase("点赞")) {
|
||||
String user = jsonObject.getString("昵称");
|
||||
int zan = jsonObject.getInt("点赞次数");
|
||||
liveRoomWatcher.callLike(new KuaiShouLike(user, zan));
|
||||
} else if (type.equalsIgnoreCase("fayan")) {
|
||||
String nickname = jsonObject.getString("nickname");
|
||||
String headurl = jsonObject.getString("headurl");
|
||||
String nr = jsonObject.getString("nr");
|
||||
liveRoomWatcher.callChat(new KuaiShouChat(nickname, nr));
|
||||
} else if (type.equalsIgnoreCase("gift")) {
|
||||
String username = jsonObject.getString("giftusername");
|
||||
String giftpic = jsonObject.getString("giftpic");
|
||||
hashMap.put(giftpic,username);
|
||||
int amount = jsonObject.getInt("liwushuliang");
|
||||
String giftPic2 = jsonObject.getString("liwutupian");
|
||||
String nr = jsonObject.getString("giftnr");
|
||||
String giftname = nr.split("个")[1];
|
||||
} else if (type.equalsIgnoreCase("others")) {
|
||||
String qian = jsonObject.getString("qian");
|
||||
if(qian.contains("欢迎")){
|
||||
String nr = jsonObject.getString("othernr");
|
||||
String userName = nr.split(" 进入")[0];
|
||||
liveRoomWatcher.callUser(new KuaiShouUser(userName));
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose(int i, String s, boolean b) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
private void sendVerify() {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("type", "register");
|
||||
KSWebSocketClient.this.send(jsonObject.toString().getBytes());
|
||||
}
|
||||
|
||||
public void send() {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!KSWebSocketClient.this.isOpen()) {
|
||||
// Bukkit.getConsoleSender().sendMessage("[直播互动] 心跳检测失败,已自动重连.");
|
||||
// restartReconnectionTimer();
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("type", "heartbeat");
|
||||
KSWebSocketClient.this.send(jsonObject.toString().getBytes());
|
||||
}
|
||||
}.runTaskTimerAsynchronously(Main.plugin, 0L, 10 * 20L);
|
||||
}
|
||||
|
||||
private boolean forcedClose = false;
|
||||
private volatile boolean isReconnecting = false;
|
||||
|
||||
public void setForcedClose(boolean forcedClose) {
|
||||
this.forcedClose = forcedClose;
|
||||
}
|
||||
|
||||
private void restartReconnectionTimer() {
|
||||
new BukkitRunnable() {
|
||||
private int i = 0;
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (reconnectBlocking()) {
|
||||
cancel();
|
||||
isReconnecting = false;
|
||||
return;
|
||||
}
|
||||
if (i >= 100) {
|
||||
if (player != null) {
|
||||
player.sendMessage("§c[系统]§a直播间自动重连失败...");
|
||||
}
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.runTaskTimerAsynchronously(Main.plugin, 0L, 5L);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,36 +0,0 @@
|
|||
package com.io.yutian.livemutually.wss;
|
||||
|
||||
import com.io.yutian.livemutually.liveroom.Gift;
|
||||
import com.io.yutian.livemutually.liveroom.User;
|
||||
|
||||
public class KuaiShouGift implements Gift {
|
||||
|
||||
private String userName;
|
||||
private String giftName;
|
||||
private int amount;
|
||||
|
||||
private User user;
|
||||
|
||||
public KuaiShouGift(String userName, String giftName, int amount) {
|
||||
this.userName = userName;
|
||||
this.giftName = giftName;
|
||||
this.amount = amount;
|
||||
this.user = new KuaiShouUser(userName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User user() {
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return giftName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long count() {
|
||||
return amount;
|
||||
}
|
||||
|
||||
}
|
|
@ -8,10 +8,15 @@ import java.util.HashMap;
|
|||
public class ConfigYml {
|
||||
|
||||
private String GameMode;
|
||||
private long gifts_delay;
|
||||
private boolean MainDebug;
|
||||
private HashMap<String, String> RoomId_Map = new HashMap<>();
|
||||
|
||||
public ConfigYml(FileConfiguration yml) {
|
||||
this.gifts_delay = 3500;
|
||||
if (yml.getLong("GiftDelay") >= 1000) {
|
||||
this.gifts_delay = yml.getLong("GiftDelay");
|
||||
}
|
||||
this.MainDebug = yml.getBoolean("MainDebug");
|
||||
this.GameMode = yml.getString("GameMode");
|
||||
Bukkit.getConsoleSender().sendMessage("§b[整蛊MC直播] §7对接游戏: §e"+ this.GameMode);
|
||||
|
@ -55,6 +60,13 @@ public class ConfigYml {
|
|||
MainDebug = butt;
|
||||
}
|
||||
|
||||
public long getGifts_delay() {return gifts_delay;}
|
||||
public void setGifts_delay(long gifts_delay) {
|
||||
FileConfiguration yml = Main.plugin.getConfig();
|
||||
yml.set("GiftDelay",gifts_delay);
|
||||
Main.plugin.saveConfig();
|
||||
this.gifts_delay = gifts_delay;
|
||||
}
|
||||
public String getGameMode() {
|
||||
return this.GameMode;
|
||||
}
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
package com.io.yutian.mclive;
|
||||
|
||||
import net.md_5.bungee.api.chat.ClickEvent;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
||||
|
@ -24,6 +29,33 @@ public class LinkRoom implements Listener {
|
|||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e){
|
||||
Player p = e.getPlayer();
|
||||
e.setJoinMessage(null);
|
||||
if (!Main.check_plugin) {
|
||||
return;
|
||||
}
|
||||
String playName = p.getName();
|
||||
String roomId = Main.configYml.getRoomId(playName);
|
||||
if(Main.configYml.getRoomId(playName) != null) {
|
||||
String message = "§7[§6提示§7] §f当前账号: §a§n" + playName + "§r §f抖音号: §b" + roomId + " §c【点击复制链接】";
|
||||
SendClickMessage(p, message, roomId);
|
||||
SendClickMessage(p, message, roomId);
|
||||
SendClickMessage(p, message, roomId);
|
||||
}else{
|
||||
String message = "§7[§6提示§7] §f当前账号: §c§n" + playName + "§r §f并未绑定抖音ID";
|
||||
p.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendClickMessage(Player player,String message,String roomId){
|
||||
TextComponent tomessage = new TextComponent(message);
|
||||
tomessage.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://live.douyin.com/"+roomId));
|
||||
tomessage.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder("§9By.极光像素工作室").create()));
|
||||
player.spigot().sendMessage(tomessage);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onQuit(PlayerQuitEvent e){
|
||||
Player player = e.getPlayer();
|
||||
|
|
|
@ -2,8 +2,15 @@ package com.io.yutian.mclive;
|
|||
|
||||
import cn.hamster3.cdapi.CDTimeAPI;
|
||||
import com.io.yutian.livemutually.manager.KSLiveRoomManager;
|
||||
import com.io.yutian.livemutually.wss.KSWebSocketClient;
|
||||
import com.io.yutian.livemutually.wss.KuaiShouUser;
|
||||
import com.io.yutian.mclive.Util.MessageUtil;
|
||||
import com.io.yutian.mclive.event.LiveConnectEvents;
|
||||
import com.io.yutian.mclive.event.LiveGiftEvents;
|
||||
import com.io.yutian.mclive.event.ZhuboAPI;
|
||||
import com.io.yutian.pixelliveplugin.PixelLiveAPI;
|
||||
import com.io.yutian.pixelliveplugin.PixelLivePlugin;
|
||||
import com.io.yutian.pixelliveplugin.event.KeyInputEvent;
|
||||
import com.io.yutian.pixelliveplugin.event.WSMessageEvent;
|
||||
import com.io.yutian.verify.AESUtil;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -14,6 +21,7 @@ import org.bukkit.inventory.Inventory;
|
|||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
@ -22,7 +30,6 @@ import java.util.List;
|
|||
public class LiveAdminGui implements Listener {
|
||||
|
||||
public static String invTitle = "我的世界整蛊玩法操作界面";
|
||||
|
||||
@EventHandler
|
||||
public void onclick(InventoryClickEvent e){
|
||||
int rawSlot = e.getRawSlot();
|
||||
|
@ -44,19 +51,48 @@ public class LiveAdminGui implements Listener {
|
|||
if (ZhuboAPI.isRoomisConnected(player)) {
|
||||
return;
|
||||
}
|
||||
if(Main.LiveRoomClientList.size() >= 1) {
|
||||
for (KSWebSocketClient socketClient : Main.LiveRoomClientList) {
|
||||
if (socketClient.getPlayer().equals(player)) {
|
||||
if (socketClient.isOpen()) {
|
||||
socketClient.setForcedClose(true);
|
||||
}
|
||||
socketClient.close();
|
||||
KSLiveRoomManager.liveRoomClientMap.remove(player);
|
||||
}
|
||||
}
|
||||
if(System.currentTimeMillis() >= 1723680000000L){ // 2024年8月15日 此插件将过期
|
||||
player.sendMessage("§c[系统]§a当前插件版本太老,请联系作者更新。");
|
||||
player.sendMessage("§c[系统]§a当前插件版本太老,请联系作者更新。");
|
||||
player.sendMessage("§c[系统]§a当前插件版本太老,请联系作者更新。");
|
||||
return;
|
||||
}
|
||||
String pluginName = Main.configYml.getGameMode();
|
||||
String roomId = Main.configYml.getRoomId(playName);
|
||||
KSLiveRoomManager.connect(player,roomId);
|
||||
if (AESUtil.isVerifyCheck(player,pluginName,roomId)) {
|
||||
return;
|
||||
}
|
||||
LiveConnectEvents event = new LiveConnectEvents(player,roomId,pluginName);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(ZhuboAPI.getRoomLiveName().equalsIgnoreCase("KuaiShou")) {
|
||||
new BukkitRunnable() {
|
||||
private int i = 0;
|
||||
private int link = 1;
|
||||
@Override
|
||||
public void run() {
|
||||
if (i >= 4) {
|
||||
long cdTime = CDTimeAPI.getCD(player.getUniqueId(),"tingcloud_cd");
|
||||
if(cdTime > 0){
|
||||
player.sendMessage("§c[系统]§a听云整蛊连接成功.");
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
PixelLiveAPI.connect(player, "127.0.0.1", 8765);
|
||||
player.sendMessage("§c[系统]§a正在尝试§e[第"+link+"次]§a连接.");
|
||||
link++;
|
||||
i -= 4;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}.runTaskTimerAsynchronously(Main.plugin, 0L, 5L);
|
||||
player.sendMessage("§c[系统]§a已在为你连接听云整蛊,请不要再次点击.");
|
||||
} else {
|
||||
PixelLiveAPI.connect(player,"127.0.0.1",9018);
|
||||
}
|
||||
if(Main.giftStatistics){
|
||||
Main.giftManage.getSqlManager().createAnchorProfile(roomId);
|
||||
}
|
||||
Bukkit.getConsoleSender().sendMessage("######CONNECT#####");
|
||||
Location loc = player.getLocation();
|
||||
loc.getWorld().playEffect(loc, Effect.MOBSPAWNER_FLAMES, 20);
|
||||
player.playSound(player.getLocation(), Sound.BLOCK_NOTE_BLOCK_BASS,1,1);
|
||||
|
@ -109,6 +145,7 @@ public class LiveAdminGui implements Listener {
|
|||
inv.setItem(5,Games_Edit());
|
||||
inv.setItem(18,Stop_LiveLink());
|
||||
inv.setItem(20,test_Verify(p));
|
||||
//inv.setItem(22,getLiveRoomId(p));
|
||||
p.openInventory(inv);
|
||||
}
|
||||
|
||||
|
@ -228,4 +265,24 @@ public class LiveAdminGui implements Listener {
|
|||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
|
||||
public static ItemStack getLiveRoomId(Player p){
|
||||
ItemStack item = new ItemStack(Material.DIAMOND);
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName("§d★ §e点击获取直播间Id");
|
||||
List<String> lore = new ArrayList<>();
|
||||
if(Main.configYml.getRoomId(p.getName()) == null) {
|
||||
lore.add("§7您的直播间号: §9尚未设置");
|
||||
lore.add(" ");
|
||||
lore.add("§b★ §6鼠标点击 §7获取直播间Id");
|
||||
}else{
|
||||
String roomId = Main.configYml.getRoomId(p.getName());
|
||||
lore.add("§7您的直播间号: §a"+roomId);
|
||||
lore.add(" ");
|
||||
lore.add("§b★ §6鼠标点击 §7获取直播间Id");
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.io.yutian.mclive;
|
||||
|
||||
import com.io.yutian.mclive.data.GiftManage;
|
||||
import com.io.yutian.mclive.event.*;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import net.md_5.bungee.api.chat.TextComponent;
|
||||
|
@ -21,6 +22,16 @@ public class LiveEvent implements Listener {
|
|||
String audience = e.getUser().nickName();
|
||||
String gift_name = e.getName();
|
||||
long gift_amount = e.getAmount();
|
||||
if (Main.giftStatistics) {
|
||||
GiftManage giftManage = Main.giftManage;
|
||||
String name = e.getPlayer().getName();
|
||||
int trillGift = giftManage.getGiftMoney(gift_name);
|
||||
if (gift_amount >= 2) {
|
||||
giftManage.addTotalMoney(name,trillGift, gift_amount);
|
||||
} else {
|
||||
giftManage.addTotalMoney(name,trillGift);
|
||||
}
|
||||
}
|
||||
// Bukkit.getConsoleSender().sendMessage("[直播互动 " + e.getPlayer().getName() + "] 类型: " + type + " 用户: " + audience + " 礼物: " + gift_name + "x" + gift_amount);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
package com.io.yutian.mclive;
|
||||
|
||||
import cn.hamster3.cdapi.CDTimeAPI;
|
||||
import com.io.yutian.livemutually.manager.KSLiveRoomManager;
|
||||
import com.io.yutian.livemutually.wss.KSWebSocketClient;
|
||||
import com.io.yutian.mclive.data.GiftManage;
|
||||
import com.io.yutian.mclive.event.ZhuboAPI;
|
||||
import com.io.yutian.pixelliveplugin.PixelLiveAPI;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
@ -25,22 +26,37 @@ public class Main extends JavaPlugin {
|
|||
public static Main plugin;
|
||||
public static boolean check_plugin = false;
|
||||
public static ConfigYml configYml;
|
||||
public static List<KSWebSocketClient> LiveRoomClientList = new ArrayList<>();
|
||||
public static GiftManage giftManage;
|
||||
public static boolean giftStatistics = false;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
SendPluginsAuthorMessage(Bukkit.getConsoleSender());
|
||||
saveDefaultConfig();
|
||||
if (giftStatistics){
|
||||
giftManage = new GiftManage();
|
||||
}
|
||||
configYml = new ConfigYml(getConfig());
|
||||
getServer().getPluginManager().registerEvents(new LiveAdminGui(),this);
|
||||
getServer().getPluginManager().registerEvents(new LinkRoom(),this);
|
||||
getServer().getPluginManager().registerEvents(new ModEvent(),this);
|
||||
getServer().getPluginManager().registerEvents(new LiveEvent(configYml),this);
|
||||
Bukkit.getConsoleSender().sendMessage("§b[整蛊MC直播] §7当前版本: §ev"+plugin.getDescription().getVersion());
|
||||
Plugin plugin = getServer().getPluginManager().getPlugin(configYml.getGameMode());
|
||||
if (plugin != null) {
|
||||
check_plugin = true;
|
||||
Bukkit.getConsoleSender().sendMessage("§b[整蛊MC直播] §a已激活游戏模式");
|
||||
if(giftStatistics) {
|
||||
Bukkit.getScheduler().runTaskTimerAsynchronously(this, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
giftManage.SaveZhuboData(player.getName());
|
||||
}
|
||||
}
|
||||
}, 0L, 24000L);
|
||||
}
|
||||
} else {
|
||||
Bukkit.getConsoleSender().sendMessage("§b[整蛊MC直播] §c未检测到§a<"+configYml.getGameMode()+">§c游戏插件.");
|
||||
}
|
||||
|
@ -58,6 +74,7 @@ public class Main extends JavaPlugin {
|
|||
sender.sendMessage("§2/mclive §e[主播名] §2<直播间ID> §f- §2设置直播间");
|
||||
}
|
||||
sender.sendMessage("§2/mclive debug §f- §2开启调试模式");
|
||||
sender.sendMessage("§2/mclive giftlong §e[时间] §f- §2叠刷计时");
|
||||
sender.sendMessage("§2/mclive reload §f- §2重新载入配置文件");
|
||||
sender.sendMessage("§e------ ====== §6直播弹幕互动 §e====== ------");
|
||||
sender.sendMessage("");
|
||||
|
@ -68,13 +85,29 @@ public class Main extends JavaPlugin {
|
|||
sender.sendMessage("§c[系统]§a配置文件已重载");
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("save")) {
|
||||
for (Player player : Bukkit.getOnlinePlayers()){
|
||||
giftManage.SaveZhuboData(player.getName());
|
||||
}
|
||||
sender.sendMessage("§c[系统]§a数据已提交至云数据库.");
|
||||
return true;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("giftlong")) {
|
||||
if (args.length == 1) {
|
||||
sender.sendMessage("§c[系统]§a正确用法: §e/mclive giftlong [时间戳]");
|
||||
return true;
|
||||
}
|
||||
if (args.length == 2) {
|
||||
long delay = Long.parseLong(args[1]);
|
||||
Main.configYml.setGifts_delay(delay);
|
||||
sender.sendMessage("§c[系统]§a礼物叠刷计算周期: §e§l" + delay);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (args.length == 1 && args[0].equalsIgnoreCase("stop")) {
|
||||
KSLiveRoomManager.liveRoomClientMap.clear();
|
||||
for (KSWebSocketClient socketClient : LiveRoomClientList) {
|
||||
if (socketClient.isOpen()) {
|
||||
socketClient.setForcedClose(true);
|
||||
}
|
||||
socketClient.close();
|
||||
ZhuboAPI.wsRoomIdSame.clear();
|
||||
for (Player player : KSLiveRoomManager.livepluginList) {
|
||||
KSLiveRoomManager.disconnect(player);
|
||||
}
|
||||
Bukkit.broadcastMessage("§c[系统]§a已断开所有主播的连接.");
|
||||
return true;
|
||||
|
|
25
src/main/java/com/io/yutian/mclive/ModEvent.java
Normal file
25
src/main/java/com/io/yutian/mclive/ModEvent.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package com.io.yutian.mclive;
|
||||
|
||||
import com.io.yutian.mclive.Util.MessageUtil;
|
||||
import com.io.yutian.pixelliveplugin.event.KeyInputEvent;
|
||||
import com.io.yutian.pixelliveplugin.event.WSMessageEvent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class ModEvent implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onWsMessage(WSMessageEvent e){
|
||||
Player player = e.getPlayer();
|
||||
String s = e.getMessage();
|
||||
MessageUtil.parse(player,s);
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onKey(KeyInputEvent e){
|
||||
Player player = e.getPlayer();
|
||||
}
|
||||
}
|
210
src/main/java/com/io/yutian/mclive/Util/MessageUtil.java
Normal file
210
src/main/java/com/io/yutian/mclive/Util/MessageUtil.java
Normal file
|
@ -0,0 +1,210 @@
|
|||
package com.io.yutian.mclive.Util;
|
||||
|
||||
import cn.hamster3.cdapi.CDTimeAPI;
|
||||
import com.io.yutian.livemutually.manager.GiftData;
|
||||
import com.io.yutian.livemutually.manager.UserData;
|
||||
import com.io.yutian.livemutually.wss.*;
|
||||
import com.io.yutian.mclive.Main;
|
||||
import com.io.yutian.mclive.event.LiveGiftEvents;
|
||||
import com.io.yutian.mclive.event.ZhuboAPI;
|
||||
import json.JSONObject;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MessageUtil {
|
||||
|
||||
public static void parse(Player player,String py_data){
|
||||
if(py_data.isEmpty()){return;}
|
||||
if(ZhuboAPI.getRoomLiveName().equalsIgnoreCase("KuaiShou")){
|
||||
JSONObject jsonObject = new JSONObject(py_data);
|
||||
if (py_data.contains("type")) {
|
||||
long cdTime = CDTimeAPI.getCD(player.getUniqueId(),"tingcloud_cd");
|
||||
if(cdTime < 0) {
|
||||
CDTimeAPI.setPlayerCD(player.getUniqueId(),"tingcloud_cd",1000 * 10);
|
||||
Bukkit.getConsoleSender().sendMessage("§a[直播连接助手] 听云整蛊弹幕正常抓取中...");
|
||||
}
|
||||
String type = jsonObject.getString("type");
|
||||
if(type.equalsIgnoreCase("礼物")){
|
||||
String nickName = jsonObject.getString("昵称");
|
||||
String giftName = jsonObject.getString("礼物名称");
|
||||
int newCount = jsonObject.getInt("礼物数量");
|
||||
if (newCount >= 1) {
|
||||
String count_color = "§a";
|
||||
if (newCount >= 1314) {
|
||||
count_color = "§c";
|
||||
} else if (newCount >= 520) {
|
||||
count_color = "§d";
|
||||
} else if (newCount >= 188) {
|
||||
count_color = "§e";
|
||||
} else if (newCount >= 66) {
|
||||
count_color = "§b";
|
||||
}
|
||||
String message = "§6[日志 - 礼物触发] §f" + player.getName() + " >>> " + nickName + " = §a" + giftName + " 数量: " + count_color + newCount;
|
||||
Bukkit.getConsoleSender().sendMessage(message);
|
||||
LiveGiftEvents event = new LiveGiftEvents(player, new KuaiShouUser(nickName), giftName, newCount);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
}else if(type.equalsIgnoreCase("发言")){
|
||||
String userName = jsonObject.getString("昵称");
|
||||
String message = jsonObject.getString("弹幕");
|
||||
KSAPILiveRoomWatcher ksapiLiveRoomWatcher = new KSAPILiveRoomWatcher(player);
|
||||
ksapiLiveRoomWatcher.callChat(new KuaiShouChat(userName, message));
|
||||
}else if(type.equalsIgnoreCase("点赞")){
|
||||
String userName = jsonObject.getString("昵称");
|
||||
KSAPILiveRoomWatcher ksapiLiveRoomWatcher = new KSAPILiveRoomWatcher(player);
|
||||
ksapiLiveRoomWatcher.callLike(new KuaiShouLike(userName, 1));
|
||||
}
|
||||
} else {
|
||||
long cdTime = CDTimeAPI.getCD(player.getUniqueId(),"tingcloud_cd");
|
||||
if(cdTime < 0) {
|
||||
CDTimeAPI.setPlayerCD(player.getUniqueId(),"tingcloud_cd",1000 * 10);
|
||||
Bukkit.getConsoleSender().sendMessage("§a[直播连接助手] 听云整蛊弹幕正常抓取中...");
|
||||
}
|
||||
}
|
||||
}else {
|
||||
String s;
|
||||
try {
|
||||
s = decrypt_ecb(py_data);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
JSONObject jsonObject = new JSONObject(s);
|
||||
String type = jsonObject.getString("broadcast");
|
||||
if (type.equalsIgnoreCase("gift_message")) {
|
||||
if (!ZhuboAPI.isWsRoomIdSame(player)) {
|
||||
player.sendMessage("§c[系统]§a当前软件获取的直播间尚未进行授权.");
|
||||
return;
|
||||
}
|
||||
JSONObject dataObject = new JSONObject(jsonObject.getString("data"));
|
||||
String nickName = dataObject.getJSONObject("user").getString("nickName");
|
||||
// 礼物名
|
||||
String giftName = dataObject.getJSONObject("gift").getString("name");
|
||||
// 礼物数量
|
||||
int giftAmount = 0;
|
||||
int repeatCount = dataObject.getInt("repeatCount");
|
||||
int comboCount = dataObject.getInt("comboCount");
|
||||
if (repeatCount > comboCount) {
|
||||
giftAmount = repeatCount;
|
||||
} else {
|
||||
giftAmount = comboCount;
|
||||
}
|
||||
if (userDataMap.get(nickName) == null) {
|
||||
userDataMap.put(nickName, new UserData(nickName));
|
||||
}
|
||||
// 默认礼物赠送数量
|
||||
long count = giftAmount;
|
||||
long newCount = giftAmount;
|
||||
UserData userData = userDataMap.get(nickName);
|
||||
//判断这个礼物是否已赠送过
|
||||
if (userData.isExitGift(giftName)) {
|
||||
GiftData giftData = userData.getGiftsData(giftName);
|
||||
// 判断礼物上次刷的时间
|
||||
long sendTime = System.currentTimeMillis();
|
||||
// 公式 本次刷礼物时间 - 记录时间
|
||||
// player.sendMessage("SendTime = "+(sendTime - giftData.getSendTime()));
|
||||
if (sendTime - giftData.getSendTime() < Main.configYml.getGifts_delay()) {
|
||||
newCount = count - giftData.getAmount();
|
||||
sendConsoleMessage("§f用户: " + nickName + " §d叠刷礼物缓存数据 §f礼物: " + giftName + " 记录数量: " + count + " 触发数量: " + newCount);
|
||||
if (newCount >= 1) {
|
||||
userData.createGiftsData(giftName, giftAmount);
|
||||
}
|
||||
} else {
|
||||
userData.createGiftsData(giftName, giftAmount);
|
||||
sendConsoleMessage("§f用户: " + nickName + " §c超时覆盖礼物缓存数据 §f礼物: " + giftName + " 记录数量: " + count + " 触发数量: " + newCount);
|
||||
}
|
||||
} else {
|
||||
// 若从未赠送则需创建新的缓存数据
|
||||
sendConsoleMessage("§f用户: " + nickName + " §a创建礼物缓存数据 §f礼物: " + giftName + " 记录数量: " + count + " 触发数量: " + newCount);
|
||||
userData.createGiftsData(giftName, giftAmount);
|
||||
}
|
||||
if (newCount >= 1) {
|
||||
String count_color = "§a";
|
||||
if (newCount >= 1314) {
|
||||
count_color = "§c";
|
||||
} else if (newCount >= 520) {
|
||||
count_color = "§d";
|
||||
} else if (newCount >= 188) {
|
||||
count_color = "§e";
|
||||
} else if (newCount >= 66) {
|
||||
count_color = "§b";
|
||||
}
|
||||
String message = "§6[日志 - 礼物触发] §f" + player.getName() + " >>> " + nickName + " = §a" + giftName + " 数量: " + count_color + newCount;
|
||||
Bukkit.getConsoleSender().sendMessage(message);
|
||||
LiveGiftEvents event = new LiveGiftEvents(player, new KuaiShouUser(nickName), giftName, newCount);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
}
|
||||
} else if (type.equalsIgnoreCase("chat_message")) {
|
||||
if (!ZhuboAPI.isWsRoomIdSame(player)) {
|
||||
player.sendMessage("§c[系统]§a当前软件获取的直播间尚未进行授权.");
|
||||
return;
|
||||
}
|
||||
JSONObject dataObject = new JSONObject(jsonObject.getString("data"));
|
||||
String nickName = dataObject.getJSONObject("user").getString("nickName");
|
||||
String message = dataObject.getString("content");
|
||||
KSAPILiveRoomWatcher ksapiLiveRoomWatcher = new KSAPILiveRoomWatcher(player);
|
||||
ksapiLiveRoomWatcher.callChat(new KuaiShouChat(nickName, message));
|
||||
} else if (type.equalsIgnoreCase("like_message")) {
|
||||
if (!ZhuboAPI.isWsRoomIdSame(player)) {
|
||||
player.sendMessage("§c[系统]§a当前软件获取的直播间尚未进行授权.");
|
||||
return;
|
||||
}
|
||||
JSONObject dataObject = new JSONObject(jsonObject.getString("data"));
|
||||
String nickName = dataObject.getJSONObject("user").getString("nickName");
|
||||
int count = dataObject.getInt("count");
|
||||
String total = dataObject.getString("total");
|
||||
KSAPILiveRoomWatcher ksapiLiveRoomWatcher = new KSAPILiveRoomWatcher(player);
|
||||
ksapiLiveRoomWatcher.callLike(new KuaiShouLike(nickName, count));
|
||||
} else if (type.equalsIgnoreCase("member_message")) {
|
||||
if (!ZhuboAPI.isWsRoomIdSame(player)) {
|
||||
player.sendMessage("§c[系统]§a当前软件获取的直播间尚未进行授权.");
|
||||
return;
|
||||
}
|
||||
JSONObject dataObject = new JSONObject(jsonObject.getString("data"));
|
||||
String nickName = dataObject.getJSONObject("user").getString("nickName");
|
||||
KSAPILiveRoomWatcher ksapiLiveRoomWatcher = new KSAPILiveRoomWatcher(player);
|
||||
ksapiLiveRoomWatcher.callUser(new KuaiShouUser(nickName));
|
||||
} else if (type.equalsIgnoreCase("live_id")) {
|
||||
JSONObject dataObject = jsonObject.getJSONObject("data");
|
||||
String wsRoomId = dataObject.getString("id");
|
||||
if (ZhuboAPI.wsRoomIdSame.get(player) == null) {
|
||||
String roomId = Main.configYml.getRoomId(player.getName());
|
||||
if (!wsRoomId.equalsIgnoreCase(roomId)) {
|
||||
ZhuboAPI.wsRoomIdSame.put(player, false);
|
||||
} else {
|
||||
ZhuboAPI.wsRoomIdSame.put(player, true);
|
||||
}
|
||||
} else {
|
||||
String roomId = Main.configYml.getRoomId(player.getName());
|
||||
if (!wsRoomId.equalsIgnoreCase(roomId)) {
|
||||
ZhuboAPI.wsRoomIdSame.put(player, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void sendConsoleMessage(String message) {
|
||||
// Bukkit.getConsoleSender().sendMessage("§6[弹幕监听] " + message);
|
||||
}
|
||||
public static HashMap<String, UserData> userDataMap = new HashMap<>();
|
||||
private static final String AES_KEY = "H8dyaR95ZJwZ6PikZ1qmoIY1"; // 与Python中相同的密钥
|
||||
|
||||
public static String decrypt_ecb(String encryptedMessage) throws Exception {
|
||||
// Base64解码
|
||||
byte[] decodedMessage = Base64.getDecoder().decode(encryptedMessage);
|
||||
|
||||
// AES解密
|
||||
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
|
||||
SecretKeySpec secretKeySpec = new SecretKeySpec(AES_KEY.getBytes(), "AES");
|
||||
cipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
|
||||
byte[] decryptedBytes = cipher.doFinal(decodedMessage);
|
||||
|
||||
// 转换为字符串
|
||||
return new String(decryptedBytes, "UTF-8");
|
||||
}
|
||||
}
|
102
src/main/java/com/io/yutian/mclive/Util/SqlUtil.java
Normal file
102
src/main/java/com/io/yutian/mclive/Util/SqlUtil.java
Normal file
|
@ -0,0 +1,102 @@
|
|||
package com.io.yutian.mclive.Util;
|
||||
|
||||
import com.io.yutian.mclive.data.database.MegumiSQL;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
public class SqlUtil extends MegumiSQL {
|
||||
private final String hostname;
|
||||
private final String port;
|
||||
private final String database;
|
||||
private final String username;
|
||||
private final String password;
|
||||
private Connection connection;
|
||||
|
||||
public SqlUtil(String hostname, String port, String database, String username, String password) {
|
||||
this.hostname = hostname;
|
||||
this.port = port;
|
||||
this.database = database;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.connection = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openConnection() {
|
||||
try {
|
||||
Class.forName("com.mysql.jdbc.Driver");
|
||||
this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database + "?useSSL=false", this.username, this.password);
|
||||
} catch (SQLException e) {
|
||||
System.out.println("[日志 - 错误] 连接数据库失败!");
|
||||
this.connection = null;
|
||||
} catch (ClassNotFoundException e) {
|
||||
System.out.println("[日志 - 错误] 未找到JDBC驱动程序");
|
||||
this.connection = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkConnection() {
|
||||
return this.connection != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() {
|
||||
return this.connection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeConnection() {
|
||||
if (this.connection != null) {
|
||||
try {
|
||||
this.connection.close();
|
||||
this.connection = null;
|
||||
} catch (SQLException e) {
|
||||
System.out.println("[日志 - 错误] 关闭数据库连接失败!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ResultSet querySQL(String query) {
|
||||
Connection conn;
|
||||
if (checkConnection())
|
||||
conn = getConnection();
|
||||
else
|
||||
return null;
|
||||
Statement stat = null;
|
||||
try {
|
||||
stat = conn.createStatement();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ResultSet result = null;
|
||||
try {
|
||||
if (stat != null)
|
||||
result = stat.executeQuery(query);
|
||||
else
|
||||
return null;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean updateSQL(String data) {
|
||||
Connection conn;
|
||||
if (checkConnection())
|
||||
conn = getConnection();
|
||||
else
|
||||
return false;
|
||||
Statement stat = null;
|
||||
try {
|
||||
stat = conn.createStatement();
|
||||
stat.executeUpdate(data);
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
191
src/main/java/com/io/yutian/mclive/data/GiftManage.java
Normal file
191
src/main/java/com/io/yutian/mclive/data/GiftManage.java
Normal file
|
@ -0,0 +1,191 @@
|
|||
package com.io.yutian.mclive.data;
|
||||
|
||||
import com.io.yutian.mclive.Main;
|
||||
import com.io.yutian.mclive.Util.SqlUtil;
|
||||
import com.io.yutian.mclive.data.database.SqlManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GiftManage {
|
||||
|
||||
private int totalMoney;
|
||||
private HashMap<String,Integer> giftMap = new HashMap<>();
|
||||
|
||||
public GiftManage(){
|
||||
totalMoney = 0;
|
||||
giftMap.put("玫瑰",1);
|
||||
giftMap.put("抖音",1);
|
||||
giftMap.put("称心如意",1);
|
||||
giftMap.put("你最好看",2);
|
||||
giftMap.put("亲吻",99);
|
||||
giftMap.put("跑车",1200);
|
||||
giftMap.put("礼花筒",199);
|
||||
giftMap.put("捏捏小脸",99);
|
||||
giftMap.put("鹿仙子",99);
|
||||
giftMap.put("夏威夷花环",99);
|
||||
giftMap.put("爱的纸鹤",99);
|
||||
giftMap.put("送你花花",49);
|
||||
giftMap.put("女神花环",99);
|
||||
giftMap.put("粘人小狗",1);
|
||||
giftMap.put("鱼你一起",99);
|
||||
giftMap.put("真爱玫瑰",366);
|
||||
giftMap.put("为你举牌",199);
|
||||
giftMap.put("兔耳朵",99);
|
||||
giftMap.put("龙抬头",99);
|
||||
giftMap.put("花开烂漫",466);
|
||||
giftMap.put("比心",199);
|
||||
giftMap.put("真的爱你",520);
|
||||
giftMap.put("万象烟花",688);
|
||||
giftMap.put("私人飞机",3000);
|
||||
giftMap.put("浪漫烟花",599);
|
||||
giftMap.put("闪亮登场",460);
|
||||
giftMap.put("多喝热水",126);
|
||||
giftMap.put("一点心意",266);
|
||||
giftMap.put("荧光棒",99);
|
||||
giftMap.put("娶你回家",599);
|
||||
giftMap.put("掌上明珠",888);
|
||||
giftMap.put("摧残舞台",899);
|
||||
giftMap.put("星星点灯",268);
|
||||
giftMap.put("一束花开",366);
|
||||
giftMap.put("小傻猪",299);
|
||||
giftMap.put("环球旅行车",650);
|
||||
giftMap.put("爱的守护",299);
|
||||
giftMap.put("好运莲莲鸭",299);
|
||||
giftMap.put("日出相伴",726);
|
||||
giftMap.put("永生花",520);
|
||||
giftMap.put("纸短情长",921);
|
||||
giftMap.put("直升机",2999);
|
||||
giftMap.put("蝶·连理枝",280);
|
||||
giftMap.put("爱情树下",599);
|
||||
giftMap.put("灵龙现世",600);
|
||||
giftMap.put("爱心煎蛋",99);
|
||||
giftMap.put("夏日回忆",1000);
|
||||
giftMap.put("抖音1号",10001);
|
||||
giftMap.put("繁花秘语",1314);
|
||||
giftMap.put("ONE礼挑一",299);
|
||||
giftMap.put("重拳出击",199);
|
||||
giftMap.put("花落长亭",1588);
|
||||
giftMap.put("浪漫恋人",1999);
|
||||
giftMap.put("花海泛舟",2800);
|
||||
giftMap.put("豪华邮轮",6000);
|
||||
giftMap.put("环游世界",3000);
|
||||
giftMap.put("蝶·书中情",750);
|
||||
giftMap.put("带你去海边",4500);
|
||||
giftMap.put("蜜蜂叮叮",1000);
|
||||
giftMap.put("奇幻八音盒",2399);
|
||||
giftMap.put("光之祝福",1999);
|
||||
giftMap.put("消暑罐头车",1500);
|
||||
giftMap.put("月色山茶花",1999);
|
||||
giftMap.put("为你而来",1688);
|
||||
giftMap.put("点亮孤单",1800);
|
||||
giftMap.put("浪漫营地",1699);
|
||||
giftMap.put("薰衣草庄园",3300);
|
||||
giftMap.put("红墙白雪",1688);
|
||||
giftMap.put("华灯初上",5000);
|
||||
giftMap.put("嘉年华",30000);
|
||||
giftMap.put("单车恋人",1899);
|
||||
giftMap.put("为爱启航",10001);
|
||||
giftMap.put("镜中奇缘",1500);
|
||||
giftMap.put("仲夏夜之梦",8999);
|
||||
giftMap.put("龙珠纳福",2388);
|
||||
giftMap.put("蝶·比翼鸟",1700);
|
||||
giftMap.put("无畏守护",10168);
|
||||
giftMap.put("壁上飞仙",4999);
|
||||
giftMap.put("海上生明月",4166);
|
||||
giftMap.put("铁甲柔情",3800);
|
||||
giftMap.put("心动丘比特",4321);
|
||||
giftMap.put("变形战车",5500);
|
||||
giftMap.put("抖音飞艇",20000);
|
||||
giftMap.put("冰冻战车",3000);
|
||||
giftMap.put("星际玫瑰",7500);
|
||||
giftMap.put("奏响人生",3666);
|
||||
giftMap.put("摩天大厦",8222);
|
||||
giftMap.put("传送门",2999);
|
||||
giftMap.put("云中秘境",13140);
|
||||
giftMap.put("火龙爆发",5000);
|
||||
giftMap.put("福佑万家",4888);
|
||||
giftMap.put("天空之镜",6399);
|
||||
giftMap.put("情定三生",9666);
|
||||
giftMap.put("月下瀑布",6666);
|
||||
giftMap.put("金鳞化龙",9000);
|
||||
giftMap.put("蝶·化蝶飞",10999);
|
||||
giftMap.put("无尽浪漫",19999);
|
||||
giftMap.put("云霄大厦",7888);
|
||||
giftMap.put("梦幻城堡",28888);
|
||||
giftMap.put("真爱永恒",8999);
|
||||
giftMap.put("跨时空之恋",9000);
|
||||
giftMap.put("炫彩射击",1888);
|
||||
giftMap.put("一路有你",17999);
|
||||
giftMap.put("浪漫马车",28888);
|
||||
giftMap.put("蝶·寄相思",6800);
|
||||
giftMap.put("梦回紫禁城",8666);
|
||||
giftMap.put("小纸条",399);
|
||||
giftMap.put("如意锦囊",99);
|
||||
giftMap.put("星光瓶",900);
|
||||
giftMap.put("粉丝团灯牌",1);
|
||||
giftMap.put("为你闪耀",9);
|
||||
giftMap.put("一直陪伴你",520);
|
||||
giftMap.put("动次打次",2999);
|
||||
giftMap.put("宇宙之心",18888);
|
||||
LinkMySqlData();
|
||||
}
|
||||
|
||||
private SqlUtil sqlUtil;
|
||||
private SqlManager sqlManager;
|
||||
|
||||
public SqlUtil getSqlUtil() {
|
||||
return sqlUtil;
|
||||
}
|
||||
|
||||
public SqlManager getSqlManager() {
|
||||
return sqlManager;
|
||||
}
|
||||
|
||||
public void LinkMySqlData(){
|
||||
String SQL_Host = "gz-cdb-r9koldtt.sql.tencentcdb.com";
|
||||
String SQL_Port = "29320";
|
||||
String SQL_Users = "root";
|
||||
String SQL_Password = "Pixel@123456";
|
||||
String SQL_Database = "autogunstats";
|
||||
sqlUtil = new SqlUtil(SQL_Host,SQL_Port,SQL_Database,SQL_Users,SQL_Password);
|
||||
sqlManager.createTable();
|
||||
Bukkit.getConsoleSender().sendMessage("[直播数据] 数据库已连接.");
|
||||
}
|
||||
|
||||
public int getGiftMoney(String giftName){
|
||||
if(giftMap.get(giftName) == null){
|
||||
return 1;
|
||||
}
|
||||
return giftMap.get(giftName);
|
||||
}
|
||||
|
||||
public int getTotalMoney() {
|
||||
return totalMoney;
|
||||
}
|
||||
|
||||
public void addTotalMoney(String name,int money){
|
||||
if(money >= 5000){
|
||||
SaveZhuboData(name);
|
||||
}
|
||||
this.totalMoney += money;
|
||||
}
|
||||
|
||||
public void addTotalMoney(String name,int money, long amount){
|
||||
int newMoney = (int) (money * amount);
|
||||
if(newMoney >= 5000){
|
||||
SaveZhuboData(name);
|
||||
}
|
||||
this.totalMoney += newMoney;
|
||||
}
|
||||
|
||||
public void SaveZhuboData(String name){
|
||||
if(Main.configYml.getRoomId(name) == null){
|
||||
return;
|
||||
}
|
||||
String tiktok = Main.configYml.getRoomId(name);
|
||||
sqlManager.SavePlayerData(tiktok);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.io.yutian.mclive.data.database;
|
||||
|
||||
import java.sql.Connection;
|
||||
|
||||
public abstract class MegumiSQL {
|
||||
public abstract void openConnection();
|
||||
|
||||
public abstract boolean checkConnection();
|
||||
|
||||
public abstract Connection getConnection();
|
||||
|
||||
public abstract void closeConnection();
|
||||
}
|
114
src/main/java/com/io/yutian/mclive/data/database/SqlManager.java
Normal file
114
src/main/java/com/io/yutian/mclive/data/database/SqlManager.java
Normal file
|
@ -0,0 +1,114 @@
|
|||
package com.io.yutian.mclive.data.database;
|
||||
|
||||
import com.io.yutian.mclive.Main;
|
||||
import com.io.yutian.mclive.Util.SqlUtil;
|
||||
import com.io.yutian.mclive.data.GiftManage;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class SqlManager {
|
||||
|
||||
|
||||
public String table = "zhubo_income";
|
||||
|
||||
// 创建数据库表格格式
|
||||
public void createTable() {
|
||||
// 数据库结构组成
|
||||
// 抖音号(VARCHAR) 直播流水(VARCHAR)
|
||||
String s = "CREATE TABLE IF NOT EXISTS "+table+"(" +
|
||||
" id INT NOT NULL AUTO_INCREMENT," +
|
||||
" tiktok VARCHAR(32) NOT NULL," +
|
||||
" income INT NOT NULL," +
|
||||
" livetime VARCHAR(256) NOT NULL," +
|
||||
" PRIMARY KEY(id)" +
|
||||
") ENGINE = InnoDB";
|
||||
getSQL().openConnection();
|
||||
getSQL().updateSQL(s);
|
||||
getSQL().closeConnection();
|
||||
}
|
||||
|
||||
// 创建主播档案数据
|
||||
public void createAnchorProfile(String tiktok){
|
||||
String set = "INSERT INTO "+table+" (`tiktok`, `income`, `livetime`) VALUES ('%tiktok%', '%income%', '%livetime%')";
|
||||
getSQL().openConnection();
|
||||
set = set.replace("%tiktok%", tiktok);
|
||||
set = set.replace("%income%", String.valueOf(0));
|
||||
set = set.replace("%livetime%", getNowTimeString());
|
||||
getSQL().updateSQL(set);
|
||||
getSQL().closeConnection();
|
||||
Bukkit.getConsoleSender().sendMessage("§6[主播数据] §a主播档案创建。");
|
||||
}
|
||||
|
||||
public String getNowTimeString(){
|
||||
// 获取当前时间戳
|
||||
Instant now = Instant.now();
|
||||
// 将时间戳转换为本地日期时间
|
||||
LocalDateTime dateTime = LocalDateTime.ofInstant(now, ZoneId.systemDefault());
|
||||
// 定义日期时间格式
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm");
|
||||
return dateTime.format(formatter);
|
||||
}
|
||||
|
||||
public int getZhuboIncome(String tiktok) {
|
||||
String select = "SELECT * FROM "+table+" WHERE tiktok = '%tiktok%'";
|
||||
try {
|
||||
getSQL().openConnection();
|
||||
ResultSet resultSet = getSQL().querySQL(select.replace("%tiktok%", tiktok));
|
||||
while (resultSet.next()) {
|
||||
return resultSet.getInt("income");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
getSQL().closeConnection();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getAllZhuboData() {
|
||||
HashMap<String, Integer> map = new HashMap<>();
|
||||
String select = "SELECT * FROM "+table;
|
||||
try {
|
||||
getSQL().openConnection();
|
||||
ResultSet set = getSQL().querySQL(select);
|
||||
while (set.next()) {
|
||||
String tiktok = set.getString("tiktok");
|
||||
int income = set.getInt("income");
|
||||
map.put(tiktok, income);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
getSQL().closeConnection();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public void SavePlayerData(String tiktok){
|
||||
if(!Main.giftStatistics){return;}
|
||||
GiftManage giftManage = Main.giftManage;
|
||||
int money = (int) (giftManage.getTotalMoney() * 0.1);
|
||||
String set = "UPDATE `"+table+"` SET " +
|
||||
"`income` = '%income%'," +
|
||||
"`livetime` = '%livetime%' WHERE `"+table+"`.`tiktok` = '%tiktok%'";
|
||||
getSQL().openConnection();
|
||||
getSQL().updateSQL(set.replace("%tiktok%", tiktok).
|
||||
replace("%income%", String.valueOf(money)).
|
||||
replace("%livetime%",getNowTimeString()));
|
||||
getSQL().closeConnection();
|
||||
}
|
||||
|
||||
private SqlUtil getSQL() {
|
||||
GiftManage giftManage = Main.giftManage;
|
||||
return giftManage.getSqlUtil();
|
||||
}
|
||||
}
|
|
@ -4,9 +4,21 @@ import com.io.yutian.livemutually.manager.KSLiveRoomManager;
|
|||
import com.io.yutian.mclive.Main;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public abstract class ZhuboAPI {
|
||||
// 存储Wss主播的直播间id
|
||||
public static HashMap<Player,Boolean> wsRoomIdSame = new HashMap<>();
|
||||
public static boolean isWsRoomIdSame(Player player){
|
||||
if(wsRoomIdSame.get(player) == null){
|
||||
return false;
|
||||
}
|
||||
return wsRoomIdSame.get(player);
|
||||
}
|
||||
// 获取主播的连接状态
|
||||
public static boolean isRoomisConnected(Player zhubo){
|
||||
return KSLiveRoomManager.isConnected(zhubo);
|
||||
}
|
||||
public static String getRoomLiveName(){return "DouYin";}
|
||||
//public static String getRoomLiveName(){return "KuaiShou";}
|
||||
}
|
||||
|
|
|
@ -3,22 +3,5 @@ GameMode: BlockWars
|
|||
# 调试模式
|
||||
MainDebug: false
|
||||
# 请勿调动此参数
|
||||
GiftDelay: 6000
|
||||
# 直播平台
|
||||
LivePlatform: DouYin
|
||||
# 后台输出信息
|
||||
Settings:
|
||||
# 礼物
|
||||
debug_gifts: false
|
||||
# 点赞
|
||||
debug_dianzan: false
|
||||
# 关注
|
||||
debug_guanzhu: false
|
||||
# 进入
|
||||
debug_join: true
|
||||
# 聊天消息
|
||||
debug_message: true
|
||||
# 进入提示信息
|
||||
join_show: true
|
||||
AutoLink: false
|
||||
GiftDelay: 3500
|
||||
LiveId: {}
|
|
@ -1,8 +1,10 @@
|
|||
name: McLiveAPI
|
||||
version: 1.3
|
||||
version: 1.3.2
|
||||
main: com.io.yutian.mclive.Main
|
||||
api-version: 1.18
|
||||
author: yutian
|
||||
|
||||
softdepend:
|
||||
- CDTimeAPI
|
||||
- PixelLivePlugin
|
||||
commands:
|
||||
mclive:
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -3,22 +3,5 @@ GameMode: BlockWars
|
|||
# 调试模式
|
||||
MainDebug: false
|
||||
# 请勿调动此参数
|
||||
GiftDelay: 6000
|
||||
# 直播平台
|
||||
LivePlatform: DouYin
|
||||
# 后台输出信息
|
||||
Settings:
|
||||
# 礼物
|
||||
debug_gifts: false
|
||||
# 点赞
|
||||
debug_dianzan: false
|
||||
# 关注
|
||||
debug_guanzhu: false
|
||||
# 进入
|
||||
debug_join: true
|
||||
# 聊天消息
|
||||
debug_message: true
|
||||
# 进入提示信息
|
||||
join_show: true
|
||||
AutoLink: false
|
||||
GiftDelay: 3500
|
||||
LiveId: {}
|
|
@ -1,8 +1,10 @@
|
|||
name: McLiveAPI
|
||||
version: 1.3
|
||||
version: 1.3.2
|
||||
main: com.io.yutian.mclive.Main
|
||||
api-version: 1.18
|
||||
author: yutian
|
||||
|
||||
softdepend:
|
||||
- CDTimeAPI
|
||||
- PixelLivePlugin
|
||||
commands:
|
||||
mclive:
|
Loading…
Reference in New Issue
Block a user