This commit is contained in:
yaohunya 2024-07-29 02:18:12 +08:00
parent 57252679b0
commit dc821de01c
8 changed files with 74 additions and 33 deletions

View File

@ -7,6 +7,7 @@ import java.util.HashMap;
public class ConfigYml {
public static boolean mysqlState = false;
private String GameMode;
private long gifts_delay;
private boolean MainDebug;

View File

@ -1,5 +1,6 @@
package com.io.yutian.mclive;
import cn.hamster3.cdapi.CDTimeAPI;
import com.io.yutian.mclive.data.GiftManage;
import com.io.yutian.mclive.event.*;
import net.md_5.bungee.api.ChatMessageType;
@ -22,7 +23,7 @@ public class LiveEvent implements Listener {
String audience = e.getUser().nickName();
String gift_name = e.getName();
long gift_amount = e.getAmount();
if (Main.giftStatistics) {
if (Main.giftStatistics && ConfigYml.mysqlState) {
GiftManage giftManage = Main.giftManage;
String name = e.getPlayer().getName();
int trillGift = giftManage.getGiftMoney(gift_name);

View File

@ -27,17 +27,18 @@ public class Main extends JavaPlugin {
public static boolean check_plugin = false;
public static ConfigYml configYml;
public static GiftManage giftManage;
public static boolean giftStatistics = false;
public static boolean giftStatistics = true;
@Override
public void onEnable() {
plugin = this;
SendPluginsAuthorMessage(Bukkit.getConsoleSender());
saveDefaultConfig();
SendPluginsAuthorMessage(Bukkit.getConsoleSender());
configYml = new ConfigYml(getConfig());
if (giftStatistics){
giftManage = new GiftManage();
giftManage.LinkMySqlData();
}
configYml = new ConfigYml(getConfig());
getServer().getPluginManager().registerEvents(new LiveAdminGui(),this);
getServer().getPluginManager().registerEvents(new LinkRoom(),this);
getServer().getPluginManager().registerEvents(new ModEvent(),this);
@ -190,9 +191,9 @@ public class Main extends JavaPlugin {
return String.valueOf(firstChar) + maskedString + lastChar;
}
public static String getTime(String format){
Date date = Calendar.getInstance().getTime();
SimpleDateFormat datatime = new SimpleDateFormat(format);
return datatime.format(date);
public static String getMinecraftVersion() {
String packageName = Bukkit.getServer().getClass().getPackage().getName();
String version = packageName.substring(packageName.lastIndexOf('.') + 1);
return version;
}
}

View File

@ -170,7 +170,7 @@ public class MessageUtil {
ksapiLiveRoomWatcher.callUser(new KuaiShouUser(nickName));
} else if (type.equalsIgnoreCase("live_id")) {
JSONObject dataObject = jsonObject.getJSONObject("data");
String wsRoomId = dataObject.getString("id");
String wsRoomId = dataObject.getString("id").replace(" ","").replace("\n","");
if (ZhuboAPI.wsRoomIdSame.get(player) == null) {
String roomId = Main.configYml.getRoomId(player.getName());
if (!wsRoomId.equalsIgnoreCase(roomId)) {

View File

@ -1,6 +1,9 @@
package com.io.yutian.mclive.Util;
import com.io.yutian.mclive.ConfigYml;
import com.io.yutian.mclive.Main;
import com.io.yutian.mclive.data.database.MegumiSQL;
import org.bukkit.Bukkit;
import java.sql.*;
@ -24,8 +27,14 @@ public class SqlUtil extends MegumiSQL {
@Override
public void openConnection() {
try {
Class.forName("com.mysql.jdbc.Driver");
String mcVersion = Main.getMinecraftVersion();
if(mcVersion.contains("1_20")){
Class.forName("com.mysql.cj.jdbc.Driver"); // 1.20.4的mysql路径
}else{
Class.forName("com.mysql.jdbc.Driver"); // 1.18.2的mysql路径
}
this.connection = DriverManager.getConnection("jdbc:mysql://" + this.hostname + ":" + this.port + "/" + this.database + "?useSSL=false", this.username, this.password);
ConfigYml.mysqlState = true;
} catch (SQLException e) {
System.out.println("[日志 - 错误] 连接数据库失败!");
this.connection = null;

View File

@ -1,5 +1,6 @@
package com.io.yutian.mclive.data;
import com.io.yutian.mclive.ConfigYml;
import com.io.yutian.mclive.Main;
import com.io.yutian.mclive.Util.SqlUtil;
import com.io.yutian.mclive.data.database.SqlManager;
@ -10,7 +11,7 @@ import java.util.HashMap;
public class GiftManage {
private int totalMoney;
private double totalMoney;
private HashMap<String,Integer> giftMap = new HashMap<>();
public GiftManage(){
@ -129,7 +130,6 @@ public class GiftManage {
giftMap.put("一直陪伴你",520);
giftMap.put("动次打次",2999);
giftMap.put("宇宙之心",18888);
LinkMySqlData();
}
private SqlUtil sqlUtil;
@ -148,10 +148,10 @@ public class GiftManage {
String SQL_Port = "29320";
String SQL_Users = "root";
String SQL_Password = "Pixel@123456";
String SQL_Database = "autogunstats";
String SQL_Database = "mclivedata";
sqlManager = new SqlManager();
sqlUtil = new SqlUtil(SQL_Host,SQL_Port,SQL_Database,SQL_Users,SQL_Password);
sqlManager.createTable();
Bukkit.getConsoleSender().sendMessage("[直播数据] 数据库已连接.");
}
public int getGiftMoney(String giftName){
@ -161,11 +161,18 @@ public class GiftManage {
return giftMap.get(giftName);
}
public int getTotalMoney() {
public double getTotalMoney() {
return totalMoney;
}
public void addTotalMoney(String name,int money){
if(this.totalMoney <= 0){
if(Main.configYml.getRoomId(name) == null){
return;
}
String tiktok = Main.configYml.getRoomId(name);
this.totalMoney = sqlManager.getZhuboIncome(tiktok);
}
if(money >= 5000){
SaveZhuboData(name);
}
@ -173,6 +180,13 @@ public class GiftManage {
}
public void addTotalMoney(String name,int money, long amount){
if(this.totalMoney <= 0){
if(Main.configYml.getRoomId(name) == null){
return;
}
String tiktok = Main.configYml.getRoomId(name);
this.totalMoney = sqlManager.getZhuboIncome(tiktok);
}
int newMoney = (int) (money * amount);
if(newMoney >= 5000){
SaveZhuboData(name);
@ -180,12 +194,14 @@ public class GiftManage {
this.totalMoney += newMoney;
}
public void SaveZhuboData(String name){
if(Main.configYml.getRoomId(name) == null){
public void SaveZhuboData(String name) {
if (Main.configYml.getRoomId(name) == null) {
return;
}
String tiktok = Main.configYml.getRoomId(name);
sqlManager.SavePlayerData(tiktok);
if (ConfigYml.mysqlState) {
sqlManager.SavePlayerData(tiktok);
}
}
}

View File

@ -18,18 +18,18 @@ import java.util.StringJoiner;
public class SqlManager {
public String table = "zhubo_income";
public String table = "income_"+Main.configYml.getGameMode().toLowerCase();
// 创建数据库表格格式
public void createTable() {
// 数据库结构组成
// 抖音号(VARCHAR) 直播流水(VARCHAR)
// 主播名(VARCHAR) 抖音号(VARCHAR) 直播流水(VARCHAR) 记录时间(VARCHAR) 创建时间(VARCHAR)
String s = "CREATE TABLE IF NOT EXISTS "+table+"(" +
" id INT NOT NULL AUTO_INCREMENT," +
" zhubo VARCHAR(32) NOT NULL," +
" tiktok VARCHAR(32) NOT NULL," +
" income INT NOT NULL," +
" income DOUBLE NOT NULL," +
" livetime VARCHAR(256) NOT NULL," +
" PRIMARY KEY(id)" +
" createtime VARCHAR(256) NOT NULL" +
") ENGINE = InnoDB";
getSQL().openConnection();
getSQL().updateSQL(s);
@ -38,14 +38,27 @@ public class SqlManager {
// 创建主播档案数据
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);
int iconme = -1;
String select = "SELECT * FROM "+table+" WHERE tiktok = '%tiktok%'";
try {
ResultSet resultSet = getSQL().querySQL(select.replace("%tiktok%", tiktok));
while (resultSet.next()) {
iconme = resultSet.getInt("income");
}
} catch (Exception e) {
e.printStackTrace();
}
if(iconme <= -1) {
String set = "INSERT INTO " + table + " (`zhubo`,`tiktok`, `income`, `livetime`, `createtime`) VALUES ('%zhubo%','%tiktok%', '%income%', '%livetime%', '%createtime%')";
set = set.replace("%zhubo%", "默认");
set = set.replace("%tiktok%", tiktok);
set = set.replace("%income%", String.valueOf(0));
set = set.replace("%livetime%", getNowTimeString());
set = set.replace("%createtime%", getNowTimeString());
getSQL().updateSQL(set);
}
getSQL().closeConnection();
Bukkit.getConsoleSender().sendMessage("§6[主播数据] §a主播档案创建。");
}
public String getNowTimeString(){
@ -58,13 +71,13 @@ public class SqlManager {
return dateTime.format(formatter);
}
public int getZhuboIncome(String tiktok) {
public double 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");
return resultSet.getDouble("income");
}
} catch (Exception e) {
e.printStackTrace();
@ -96,13 +109,13 @@ public class SqlManager {
public void SavePlayerData(String tiktok){
if(!Main.giftStatistics){return;}
GiftManage giftManage = Main.giftManage;
int money = (int) (giftManage.getTotalMoney() * 0.1);
double money = 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("%income%", String.format("%.1f",money)).
replace("%livetime%",getNowTimeString()));
getSQL().closeConnection();
}