firt
This commit is contained in:
parent
e4ca6b4e3b
commit
2453c8924e
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@
|
|||
/.idea/vcs.xml
|
||||
/.idea/jarRepositories.xml
|
||||
/.idea/compiler.xml
|
||||
/.idea/artifacts/
|
||||
|
|
1
pom.xml
1
pom.xml
|
@ -13,6 +13,7 @@
|
|||
<maven.compiler.target>8</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>public-rpg</id>
|
||||
|
|
|
@ -1,23 +1,34 @@
|
|||
package com.yaohun.aulivecode;
|
||||
|
||||
import com.yaohun.aulivecode.database.SqlManager;
|
||||
import com.yaohun.aulivecode.util.GiftMoney;
|
||||
import com.yaohun.aulivecode.util.SqlUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Main extends JavaPlugin {
|
||||
|
||||
public static Main plugin;
|
||||
public static SqlUtil sqlUtil;
|
||||
public static SqlManager sqlManager;
|
||||
public static GiftMoney giftMoney;
|
||||
public static HashMap<String,ZhuboData> zhuboDataMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
plugin = this;
|
||||
sqlManager = new SqlManager();
|
||||
giftMoney = new GiftMoney();
|
||||
LinkMySqlData();
|
||||
loadLiveIdSendLocal();
|
||||
}
|
||||
|
||||
public void LinkMySqlData(){
|
||||
|
@ -31,8 +42,34 @@ public class Main extends JavaPlugin {
|
|||
Bukkit.getConsoleSender().sendMessage("[直播数据] 数据库已连接.");
|
||||
}
|
||||
|
||||
public void loadLiveIdSendLocal(){
|
||||
File file = new File("./plugins/McLiveAPI","config.yml");
|
||||
FileConfiguration yml = YamlConfiguration.loadConfiguration(file);
|
||||
HashMap<String,String> stringStringHashMap = sqlManager.getAllZhuboData();
|
||||
for (String name : stringStringHashMap.keySet()) {
|
||||
String liveId = stringStringHashMap.get(name);
|
||||
yml.set("LiveId."+name,liveId);
|
||||
Bukkit.getConsoleSender().sendMessage("[日志 - 输出] 主播: "+name+" 抖音号: "+liveId);
|
||||
}
|
||||
// 保存配置文件
|
||||
try {
|
||||
yml.save(file);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||
if(args.length == 1 && args[0].equalsIgnoreCase("load") && sender.isOp()){
|
||||
loadLiveIdSendLocal();
|
||||
sender.sendMessage("[直播数据] 正在下载主播档案.");
|
||||
}
|
||||
if(args.length == 2 && args[0].equalsIgnoreCase("download") && sender.isOp()){
|
||||
String zhubo = args[1];
|
||||
Main.zhuboDataMap.put(zhubo,Main.sqlManager.getZhuboData(zhubo));
|
||||
sender.sendMessage("[直播数据] 正在下载主播档案.");
|
||||
}
|
||||
if(args.length == 3 && args[0].equalsIgnoreCase("create") && sender.isOp()){
|
||||
String zhubo = args[1];
|
||||
String liveId = args[2];
|
||||
|
|
79
src/main/java/com/yaohun/aulivecode/ZhuboData.java
Normal file
79
src/main/java/com/yaohun/aulivecode/ZhuboData.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
package com.yaohun.aulivecode;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
|
||||
public class ZhuboData {
|
||||
|
||||
private String zhuBo;
|
||||
private String liveId;
|
||||
private LinkedHashMap<Integer,Integer> spectatorMap = new LinkedHashMap<>();
|
||||
private LinkedHashMap<Integer,Integer> adminMap = new LinkedHashMap<>();
|
||||
|
||||
public ZhuboData(String zhuBo,ResultSet resultSet){
|
||||
this.zhuBo = zhuBo;
|
||||
System.out.println("[调试 - 输出] 主播名: "+zhuBo);
|
||||
try {
|
||||
this.liveId = resultSet.getString("tiktok");
|
||||
System.out.println("[调试 - 输出] 抖音号: "+liveId);
|
||||
String spectatorString = resultSet.getString("giftspectator");
|
||||
String[] stringList1 = spectatorString.split(",");
|
||||
int a = 1;
|
||||
for (String s : stringList1){
|
||||
int money = Integer.parseInt(s);
|
||||
spectatorMap.put(a,money);
|
||||
System.out.println("[调试 - 输出] "+a+"号 流水: "+money+"音浪");
|
||||
a++;
|
||||
}
|
||||
String giftadminiString = resultSet.getString("giftadmini");
|
||||
String[] stringList2 = giftadminiString.split(",");
|
||||
int b = 1;
|
||||
for (String s : stringList2){
|
||||
int money = Integer.parseInt(s);
|
||||
adminMap.put(b,money);
|
||||
System.out.println("[调试 - 输出] "+b+"号 对抗流水: "+money+"音浪");
|
||||
b++;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public String getZhuBo() {
|
||||
return zhuBo;
|
||||
}
|
||||
|
||||
public String getLiveId() {
|
||||
return liveId;
|
||||
}
|
||||
|
||||
public LinkedHashMap<Integer, Integer> getAdminMap() {
|
||||
return adminMap;
|
||||
}
|
||||
|
||||
public LinkedHashMap<Integer, Integer> getSpectatorMap() {
|
||||
return spectatorMap;
|
||||
}
|
||||
public List<Integer> getSpectatorList(){
|
||||
List<Integer> integerList = new ArrayList<>();
|
||||
LocalDate today = LocalDate.now();
|
||||
int dayOfMonth = today.getDayOfMonth();
|
||||
for (int number : spectatorMap.keySet()){
|
||||
if(number == dayOfMonth){
|
||||
integerList.add(88);
|
||||
}else {
|
||||
integerList.add(spectatorMap.get(number));
|
||||
}
|
||||
}
|
||||
return integerList;
|
||||
}
|
||||
public String getSpectatorConvertList(){
|
||||
StringJoiner joiner = new StringJoiner(",");
|
||||
for (int s : getSpectatorList()) {
|
||||
joiner.add(String.valueOf(s));
|
||||
}
|
||||
return joiner.toString();
|
||||
}
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package com.yaohun.aulivecode.database;
|
||||
|
||||
import com.yaohun.aulivecode.Main;
|
||||
import com.yaohun.aulivecode.ZhuboData;
|
||||
import com.yaohun.aulivecode.util.SqlUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
@ -20,9 +21,8 @@ public class SqlManager {
|
|||
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)" +
|
||||
" giftspectator VARCHAR(256) NOT NULL," +
|
||||
" giftadmini VARCHAR(256) NOT NULL" +
|
||||
") ENGINE = InnoDB";
|
||||
getSQL().openConnection();
|
||||
getSQL().updateSQL(s);
|
||||
|
@ -31,13 +31,12 @@ public class SqlManager {
|
|||
|
||||
// 创建主播档案数据
|
||||
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);
|
||||
for (int i = 1;i <= 30;i++){
|
||||
integers.add(0);
|
||||
}
|
||||
StringJoiner joiner = new StringJoiner(",");
|
||||
for (int s : integers) {
|
||||
|
@ -50,20 +49,55 @@ public class SqlManager {
|
|||
Bukkit.getConsoleSender().sendMessage("§6[主播数据] §a主播档案创建。");
|
||||
}
|
||||
|
||||
public int getPlayerData(String playerName) {
|
||||
String select = "SELECT * FROM recharge WHERE player = '%playerName%'";
|
||||
|
||||
public ZhuboData getZhuboData(String name) {
|
||||
String select = "SELECT * FROM "+table+" WHERE zhubo = '%name%'";
|
||||
try {
|
||||
getSQL().openConnection();
|
||||
ResultSet set = getSQL().querySQL(select.replace("%playerName%", playerName));
|
||||
if (set.next()) {
|
||||
return set.getInt("point");
|
||||
ResultSet resultSet = getSQL().querySQL(select.replace("%name%", name));
|
||||
while (resultSet.next()) {
|
||||
return new ZhuboData(name,resultSet);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
getSQL().closeConnection();
|
||||
}
|
||||
return -1;
|
||||
return null;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getAllZhuboData() {
|
||||
HashMap<String, String> map = new HashMap<>();
|
||||
String select = "SELECT * FROM "+table;
|
||||
try {
|
||||
getSQL().openConnection();
|
||||
ResultSet set = getSQL().querySQL(select);
|
||||
while (set.next()) {
|
||||
String zhubo = set.getString("zhubo");
|
||||
String tiktok = set.getString("tiktok");
|
||||
map.put(zhubo, tiktok);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
getSQL().closeConnection();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public void SavePlayerData(String name){
|
||||
if(Main.zhuboDataMap.get(name) == null){return;}
|
||||
ZhuboData dataAPI = Main.zhuboDataMap.get(name);
|
||||
String liveId = dataAPI.getLiveId();
|
||||
|
||||
String set = "UPDATE `"+table+"` SET " +
|
||||
"`tiktok` = '%tiktok%'," +
|
||||
"`giftspectator` = '%giftspectator%' WHERE `"+table+"`.`zhubo` = '%player%'";
|
||||
getSQL().openConnection();
|
||||
getSQL().updateSQL(set.replace("%player%", name).
|
||||
replace("%tiktok%", liveId)
|
||||
.replace("%giftspectator%", dataAPI.getSpectatorConvertList()));
|
||||
getSQL().closeConnection();
|
||||
}
|
||||
|
||||
private SqlUtil getSQL() {
|
||||
|
|
16
src/main/java/com/yaohun/aulivecode/listener/JoinEvent.java
Normal file
16
src/main/java/com/yaohun/aulivecode/listener/JoinEvent.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package com.yaohun.aulivecode.listener;
|
||||
|
||||
import com.yaohun.aulivecode.Main;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
|
||||
public class JoinEvent implements Listener {
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent e){
|
||||
Player player = e.getPlayer();
|
||||
String name = player.getName();
|
||||
Main.zhuboDataMap.put(name,Main.sqlManager.getZhuboData(name));
|
||||
}
|
||||
}
|
148
src/main/java/com/yaohun/aulivecode/util/GiftMoney.java
Normal file
148
src/main/java/com/yaohun/aulivecode/util/GiftMoney.java
Normal file
|
@ -0,0 +1,148 @@
|
|||
package com.yaohun.aulivecode.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class GiftMoney {
|
||||
|
||||
private LinkedHashMap<String,Integer> giftMap = new LinkedHashMap<>();
|
||||
public GiftMoney(){
|
||||
/*活动新增*/
|
||||
giftMap.put("粘人小狗",1);
|
||||
giftMap.put("西瓜",1);
|
||||
giftMap.put("冰镇西瓜",99);
|
||||
giftMap.put("夏日冰饮",99);
|
||||
/*长期存在的礼物*/
|
||||
giftMap.put("粉丝团灯牌",1);
|
||||
giftMap.put("为你闪耀",9);
|
||||
giftMap.put("人气票",1);
|
||||
giftMap.put("小心心",1);
|
||||
giftMap.put("玫瑰",1);
|
||||
giftMap.put("抖音",1);
|
||||
giftMap.put("称心如意",1);
|
||||
giftMap.put("你最好看",2);
|
||||
giftMap.put("啤酒",2);
|
||||
giftMap.put("棒棒糖",9);
|
||||
giftMap.put("鲜花",10);
|
||||
giftMap.put("加油鸭",15);
|
||||
giftMap.put("爱你哟",52);
|
||||
giftMap.put("Thuglife",99);
|
||||
giftMap.put("闪耀星辰",99);
|
||||
giftMap.put("亲吻",99);
|
||||
giftMap.put("比心兔兔",299);
|
||||
giftMap.put("热气球",520);
|
||||
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("鱼你一起",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("一直陪伴你",520);
|
||||
giftMap.put("动次打次",2999);
|
||||
giftMap.put("宇宙之心",18888);
|
||||
}
|
||||
|
||||
public int getGiftValue(String giftName){
|
||||
if(giftMap.get(giftName) != null){
|
||||
return giftMap.get(giftName);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user