adapt bossbar save

This commit is contained in:
Xanadu13
2024-01-05 10:04:39 +08:00
committed by GitHub
parent 7c5be09920
commit f46638c2d4
@@ -23,6 +23,7 @@ public class BossBarManager implements I_BossBarManager {
public void saveBossBarData(List<World> worlds){ public void saveBossBarData(List<World> worlds){
File file = new File(plugin.getDataFolder(),"world_data.yml"); File file = new File(plugin.getDataFolder(),"world_data.yml");
YamlConfiguration yml = new YamlConfiguration(); YamlConfiguration yml = new YamlConfiguration();
char split = yml.options().pathSeparator();
worlds.forEach(world -> { worlds.forEach(world -> {
try{ try{
Object edb = DragonManager.getEnderDragonBattle(world); Object edb = DragonManager.getEnderDragonBattle(world);
@@ -30,10 +31,13 @@ public class BossBarManager implements I_BossBarManager {
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("bossBattle"); if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("bossBattle");
BossBattleServer.setAccessible(true); BossBattleServer.setAccessible(true);
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb); BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
String path = world.getName() + yml.options().pathSeparator(); String path = world.getName() + split;
yml.set(path+"title",bbs.title.getText()); yml.set(path+"title",bbs.title.getText());
yml.set(path+"color",bbs.color.name()); yml.set(path+"color",bbs.color.name());
yml.set(path+"style",bbs.style.name()); yml.set(path+"style",bbs.style.name());
yml.set(path+"create_frog",bbs.isCreateFog());
yml.set(path+"darken_sky",bbs.isDarkenSky());
yml.set(path+"play_boss_music",bbs.isPlayMusic());
}catch (ReflectiveOperationException e){ }catch (ReflectiveOperationException e){
e.printStackTrace(); e.printStackTrace();
} }
@@ -50,6 +54,7 @@ public class BossBarManager implements I_BossBarManager {
if(!file.exists()) return; if(!file.exists()) return;
Lang.info("Enabling BossBar fix..."); Lang.info("Enabling BossBar fix...");
YamlConfiguration yml = new YamlConfiguration(); YamlConfiguration yml = new YamlConfiguration();
char split = yml.options().pathSeparator();
try{ try{
yml.load(file); yml.load(file);
}catch (InvalidConfigurationException | IOException e) { }catch (InvalidConfigurationException | IOException e) {
@@ -63,10 +68,13 @@ public class BossBarManager implements I_BossBarManager {
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("bossBattle"); if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("bossBattle");
BossBattleServer.setAccessible(true); BossBattleServer.setAccessible(true);
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb); BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
String path = world.getName() + yml.options().pathSeparator(); String path = world.getName() + split;
bbs.title = CraftChatMessage.fromString(yml.getString(path+"title"), true)[0]; bbs.title = CraftChatMessage.fromString(yml.getString(path+"title"), true)[0];
bbs.color = BossBattle.BarColor.valueOf(yml.getString(path+"color")); bbs.color = BossBattle.BarColor.valueOf(yml.getString(path+"color"));
bbs.style = BossBattle.BarStyle.valueOf(yml.getString(path+"style")); bbs.style = BossBattle.BarStyle.valueOf(yml.getString(path+"style"));
bbs.setCreateFog(yml.getBoolean(path+"create_frog",true));
bbs.setDarkenSky(yml.getBoolean(path+"darken_sky",true));
bbs.setPlayMusic(yml.getBoolean(path+"play_boss_music",true));
}catch (ReflectiveOperationException e){ }catch (ReflectiveOperationException e){
e.printStackTrace(); e.printStackTrace();
} }
@@ -74,4 +82,4 @@ public class BossBarManager implements I_BossBarManager {
} }
public void setBossBar(World world, final MyDragon myDragon){ public void setBossBar(World world, final MyDragon myDragon){
} }
} }