This commit is contained in:
yaohunya 2024-07-16 22:58:42 +08:00
commit e4ca6b4e3b
10 changed files with 290 additions and 0 deletions

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
/.idea/.gitignore
/.idea/misc.xml
/.idea/modules.xml
/.idea/vcs.xml
/.idea/jarRepositories.xml
/.idea/compiler.xml

View File

@ -0,0 +1,8 @@
<component name="ArtifactManager">
<artifact type="jar" name="AuLiveCodeMysql">
<output-path>$PROJECT_DIR$/out/artifacts/AuLiveCodeMysql</output-path>
<root id="archive" name="AuLiveCodeMysql.jar">
<element id="module-output" name="AuLiveCodeMysql" />
</root>
</artifact>
</component>

8
README.md Normal file
View File

@ -0,0 +1,8 @@
# AuLiveCodeMysql
蔚来传媒遂宁公司专用直播监控插件
监听内容:
- 直播间礼物流水
- 观众聊天记录
-

31
pom.xml Normal file
View File

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.yaohun.aulivecode.Main</groupId>
<artifactId>AuLiveCodeMysql</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>public-rpg</id>
<url>https://repo.aurora-pixels.com/repository/public-rpg/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12.2</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,45 @@
package com.yaohun.aulivecode;
import com.yaohun.aulivecode.database.SqlManager;
import com.yaohun.aulivecode.util.SqlUtil;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.java.JavaPlugin;
public class Main extends JavaPlugin {
public static Main plugin;
public static SqlUtil sqlUtil;
public static SqlManager sqlManager;
@Override
public void onEnable() {
plugin = this;
sqlManager = new SqlManager();
LinkMySqlData();
}
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 = "wllivestats";
sqlUtil = new SqlUtil(SQL_Host,SQL_Port,SQL_Database,SQL_Users,SQL_Password);
sqlManager.createTable();
Bukkit.getConsoleSender().sendMessage("[直播数据] 数据库已连接.");
}
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if(args.length == 3 && args[0].equalsIgnoreCase("create") && sender.isOp()){
String zhubo = args[1];
String liveId = args[2];
sqlManager.createAnchorProfile(zhubo,liveId);
sender.sendMessage("[直播数据] 正在创建主播档案.");
}
return false;
}
}

View File

@ -0,0 +1,13 @@
package com.yaohun.aulivecode.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();
}

View File

@ -0,0 +1,72 @@
package com.yaohun.aulivecode.database;
import com.yaohun.aulivecode.Main;
import com.yaohun.aulivecode.util.SqlUtil;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import java.sql.ResultSet;
import java.util.*;
public class SqlManager {
public String table = "zhubo_data";
// 创建数据库表格格式
public void createTable() {
// 数据库结构组成
// 主播名字(VARCHAR) 抖音号(VARCHAR) 直播流水(VARCHAR) 运营礼物(VARCHAR)
String s = "CREATE TABLE IF NOT EXISTS "+table+"(" +
" zhubo VARCHAR(32) NOT NULL," +
" tiktok VARCHAR(32) NOT NULL," +
" giftspectator INT NOT NULL," +
" giftadmini INT NOT NULL," +
" PRIMARY KEY(id)" +
") ENGINE = InnoDB";
getSQL().openConnection();
getSQL().updateSQL(s);
getSQL().closeConnection();
}
// 创建主播档案数据
public void createAnchorProfile(String zhubo,String tiktok){
// MySQL.update("INSERT INTO "+ table+" VALUES ('" + p.getName() + "','" + p.getUniqueId() + "','默认','默认');");
String set = "INSERT INTO "+table+" (`zhubo`, `tiktok`, `giftspectator`, `giftadmini`) VALUES ('%zhubo%', '%tiktok%', '%giftspectator%', '%giftadmini%')";
getSQL().openConnection();
set = set.replace("%zhubo%", zhubo).replace("%tiktok%", tiktok);
List<Integer> integers = new ArrayList<>();
for (int i = 1;i <= 31;i++){
integers.add(i);
}
StringJoiner joiner = new StringJoiner(",");
for (int s : integers) {
joiner.add(String.valueOf(s));
}
set = set.replace("%giftspectator%", joiner.toString());
set = set.replace("%giftadmini%", joiner.toString());
getSQL().updateSQL(set);
getSQL().closeConnection();
Bukkit.getConsoleSender().sendMessage("§6[主播数据] §a主播档案创建。");
}
public int getPlayerData(String playerName) {
String select = "SELECT * FROM recharge WHERE player = '%playerName%'";
try {
getSQL().openConnection();
ResultSet set = getSQL().querySQL(select.replace("%playerName%", playerName));
if (set.next()) {
return set.getInt("point");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
getSQL().closeConnection();
}
return -1;
}
private SqlUtil getSQL() {
return Main.sqlUtil;
}
}

View File

@ -0,0 +1,102 @@
package com.yaohun.aulivecode.util;
import com.yaohun.aulivecode.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;
}
}
}

View File

View File

@ -0,0 +1,5 @@
name: AuLiveCodeMysql
main: com.yaohun.aulivecode.Main
version: 1.0.0
commands:
code: