mirror of
https://github.com/Coloryr/AllMusic.git
synced 2026-11-12 17:47:35 +00:00
配置文件检查
This commit is contained in:
1 parent
780f5ca19e
commit
6ea391cc9d
4 files changed
+141
-31
No files matched your search
+1
-1
@@ -3,7 +3,7 @@ plugins {
|
||||
id 'maven-publish'
|
||||
id 'com.github.johnrengelman.shadow' version '6.1.0'
|
||||
}
|
||||
version = "2.10.3"
|
||||
version = "2.10.4"
|
||||
|
||||
repositories {
|
||||
jcenter()
|
||||
|
||||
@@ -2,11 +2,12 @@ package Color_yr.AllMusic;
|
||||
|
||||
import Color_yr.AllMusic.API.IMusicAPI;
|
||||
import Color_yr.AllMusic.API.ISide;
|
||||
import Color_yr.AllMusic.Message.MessageOBJ;
|
||||
import Color_yr.AllMusic.Message.*;
|
||||
import Color_yr.AllMusic.MusicAPI.MusicAPI1.API1;
|
||||
import Color_yr.AllMusic.MusicAPI.MusicAPI2.API2;
|
||||
import Color_yr.AllMusic.MusicAPI.SongSearch.SearchPage;
|
||||
import Color_yr.AllMusic.MusicPlay.PlayMusic;
|
||||
import Color_yr.AllMusic.MusicPlay.SendHud.SaveOBJ;
|
||||
import Color_yr.AllMusic.Side.SideBukkit.VaultHook;
|
||||
import Color_yr.AllMusic.Utils.RunApi;
|
||||
import Color_yr.AllMusic.Utils.logs;
|
||||
@@ -20,10 +21,11 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class AllMusic {
|
||||
public static final String channel = "allmusic:channel";
|
||||
public static final String Version = "2.10.0";
|
||||
public static final String Version = "2.10.4";
|
||||
|
||||
private static final Map<String, SearchPage> SearchSave = new HashMap<>();
|
||||
private static final List<String> VotePlayer = new ArrayList<>();
|
||||
@@ -40,6 +42,29 @@ public class AllMusic {
|
||||
private static File MessageFile;
|
||||
private static File DataFolder;
|
||||
|
||||
public static void configCheck() {
|
||||
if (Config == null) {
|
||||
Config = new ConfigOBJ();
|
||||
log.warning("§d[AllMusic]§c配置文件Config.json错误,已覆盖");
|
||||
save();
|
||||
}
|
||||
else if (Config.check()) {
|
||||
log.warning("§d[AllMusic]§c配置文件Config.json错误,已覆盖");
|
||||
save();
|
||||
}
|
||||
}
|
||||
private static void messageCheck() {
|
||||
if (Message == null) {
|
||||
Message = new MessageOBJ();
|
||||
log.warning("§d[AllMusic]§c配置文件Message.json错误,已覆盖");
|
||||
save();
|
||||
}
|
||||
else if (Message.check()) {
|
||||
log.warning("§d[AllMusic]§c配置文件Message.json错误,已覆盖");
|
||||
save();
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean containNowPlay(String player) {
|
||||
return NowPlayPlayer.contains(player);
|
||||
}
|
||||
@@ -97,11 +122,19 @@ public class AllMusic {
|
||||
public static void save() {
|
||||
try {
|
||||
String data = new GsonBuilder().setPrettyPrinting().create().toJson(Config);
|
||||
Writer out = new FileWriter(ConfigFile);
|
||||
out.write(data);
|
||||
out.close();
|
||||
FileOutputStream out = new FileOutputStream(ConfigFile);
|
||||
OutputStreamWriter write = new OutputStreamWriter(
|
||||
out, StandardCharsets.UTF_8);
|
||||
write.write(data);
|
||||
write.close();
|
||||
data = new GsonBuilder().setPrettyPrinting().create().toJson(Message);
|
||||
out = new FileOutputStream(MessageFile);
|
||||
write = new OutputStreamWriter(
|
||||
out, StandardCharsets.UTF_8);
|
||||
write.write(data);
|
||||
write.close();
|
||||
} catch (Exception e) {
|
||||
log.warning("§d[AllMusic]§c配置文件错误");
|
||||
log.warning("§d[AllMusic]§c配置文件保存错误");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@@ -119,9 +152,9 @@ public class AllMusic {
|
||||
Side.Send("[Stop]", false);
|
||||
SearchTask.stop();
|
||||
PlayMusic.stop();
|
||||
if (AllMusic.Config.isAutoApi()) {
|
||||
RunApi.stop();
|
||||
}
|
||||
// if (AllMusic.Config.AutoApi) {
|
||||
// RunApi.stop();
|
||||
// }
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -136,11 +169,11 @@ public class AllMusic {
|
||||
}
|
||||
|
||||
private static void initAPI() {
|
||||
if (AllMusic.Config.isAutoApi()) {
|
||||
if (!RunApi.runAPI(DataFolder)) {
|
||||
log.warning("§d[AllMusic]§c外置API启动失败");
|
||||
}
|
||||
}
|
||||
// if (AllMusic.Config.AutoApi) {
|
||||
// if (!RunApi.runAPI(DataFolder)) {
|
||||
// log.warning("§d[AllMusic]§c外置API启动失败");
|
||||
// }
|
||||
// }
|
||||
switch (AllMusic.Config.getMusic_Api()) {
|
||||
case 2: {
|
||||
AllMusic.Music = new API1();
|
||||
@@ -162,20 +195,14 @@ public class AllMusic {
|
||||
Config = new Gson().fromJson(bf, ConfigOBJ.class);
|
||||
bf.close();
|
||||
reader.close();
|
||||
if (Config == null) {
|
||||
log.warning("§d[AllMusic]§c配置文件错误");
|
||||
Config = new ConfigOBJ();
|
||||
}
|
||||
configCheck();
|
||||
|
||||
reader = new InputStreamReader(new FileInputStream(AllMusic.MessageFile), StandardCharsets.UTF_8);
|
||||
bf = new BufferedReader(reader);
|
||||
Message = new Gson().fromJson(bf, MessageOBJ.class);
|
||||
bf.close();
|
||||
reader.close();
|
||||
if (Config == null) {
|
||||
log.warning("§d[AllMusic]§c语言文件错误");
|
||||
Message = new MessageOBJ();
|
||||
}
|
||||
messageCheck();
|
||||
|
||||
log.info("§d[AllMusic]§e当前插件版本为:" + AllMusic.Version
|
||||
+ ",你的配置文件版本为:" + AllMusic.Config.getVersion());
|
||||
@@ -183,14 +210,6 @@ public class AllMusic {
|
||||
if (!AllMusic.Version.equalsIgnoreCase(AllMusic.Config.getVersion())) {
|
||||
log.warning("§d[AllMusic]§c请及时更新配置文件");
|
||||
}
|
||||
|
||||
for (String item : AllMusic.Config.getNoMusicPlayer()) {
|
||||
AllMusic.log.info("玩家:" + item + "不参与点歌");
|
||||
}
|
||||
|
||||
for (String item : AllMusic.Config.getNoMusicServer()) {
|
||||
AllMusic.log.info("服务器:" + item + "不参与点歌");
|
||||
}
|
||||
initAPI();
|
||||
} catch (Exception e) {
|
||||
log.warning("§d[AllMusic]§c读取配置文件错误");
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class ConfigOBJ {
|
||||
private String Music_Url;
|
||||
@@ -198,4 +199,37 @@ public class ConfigOBJ {
|
||||
public void setAutoApi(boolean autoApi) {
|
||||
AutoApi = autoApi;
|
||||
}
|
||||
|
||||
public boolean check() {
|
||||
boolean saveConfig = false;
|
||||
if (PlayList == null) {
|
||||
saveConfig = true;
|
||||
PlayList = new ArrayList<>();
|
||||
}
|
||||
if (Admin == null) {
|
||||
saveConfig = true;
|
||||
Admin = new ArrayList<>();
|
||||
}
|
||||
if (BanMusic == null) {
|
||||
saveConfig = true;
|
||||
BanMusic = new ArrayList<>();
|
||||
}
|
||||
if (DefaultHud == null) {
|
||||
saveConfig = true;
|
||||
DefaultHud = new SaveOBJ();
|
||||
}
|
||||
if (HudSave == null) {
|
||||
saveConfig = true;
|
||||
HudSave = new ConcurrentHashMap<>();
|
||||
}
|
||||
if (NoMusicPlayer == null) {
|
||||
saveConfig = true;
|
||||
NoMusicPlayer = new ArrayList<>();
|
||||
}
|
||||
if (NoMusicServer == null) {
|
||||
saveConfig = true;
|
||||
NoMusicServer = new ArrayList<>();
|
||||
}
|
||||
return saveConfig;
|
||||
}
|
||||
}
|
||||
@@ -82,4 +82,61 @@ public class MessageOBJ {
|
||||
public AddMusicOBJ getAddMusic() {
|
||||
return AddMusic;
|
||||
}
|
||||
|
||||
public boolean check() {
|
||||
boolean saveConfig = false;
|
||||
if (MusicPlay == null) {
|
||||
saveConfig = true;
|
||||
MusicPlay = new MusicPlayOBJ();
|
||||
}
|
||||
if (AddMusic == null) {
|
||||
saveConfig = true;
|
||||
AddMusic = new AddMusicOBJ();
|
||||
}
|
||||
if (Page == null) {
|
||||
saveConfig = true;
|
||||
Page = new PageOBJ();
|
||||
}
|
||||
if (Lyric == null) {
|
||||
saveConfig = true;
|
||||
Lyric = new LyricOBJ();
|
||||
}
|
||||
if (Vote == null) {
|
||||
saveConfig = true;
|
||||
Vote = new VoteOBJ();
|
||||
}
|
||||
if (Search == null) {
|
||||
saveConfig = true;
|
||||
Search = new SearchOBJ();
|
||||
}
|
||||
if (Hud == null) {
|
||||
saveConfig = true;
|
||||
Hud = new HudOBJ();
|
||||
}
|
||||
if (HudList == null) {
|
||||
saveConfig = true;
|
||||
HudList = new HudListOBJ();
|
||||
}
|
||||
if (Command == null) {
|
||||
saveConfig = true;
|
||||
Command = new CommandOBJ();
|
||||
}
|
||||
if (Custom == null) {
|
||||
saveConfig = true;
|
||||
Custom = new CustomOBJ();
|
||||
}
|
||||
if (PAPI == null) {
|
||||
saveConfig = true;
|
||||
PAPI = new PAPIOBJ();
|
||||
}
|
||||
if (Cost == null) {
|
||||
saveConfig = true;
|
||||
Cost = new CostObj();
|
||||
}
|
||||
if (Click == null) {
|
||||
saveConfig = true;
|
||||
Click = new ClickObj();
|
||||
}
|
||||
return saveConfig;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user