BossBar fix for 1.14+
This commit is contained in:
@@ -0,0 +1,76 @@
|
|||||||
|
package pers.xanadu.enderdragon.nms.BossBar.v1_14_R1;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_14_R1.BossBattle;
|
||||||
|
import net.minecraft.server.v1_14_R1.BossBattleServer;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.craftbukkit.v1_14_R1.util.CraftChatMessage;
|
||||||
|
import pers.xanadu.enderdragon.config.Lang;
|
||||||
|
import pers.xanadu.enderdragon.manager.DragonManager;
|
||||||
|
import pers.xanadu.enderdragon.nms.BossBar.I_BossBarManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
||||||
|
|
||||||
|
public class BossBarManager implements I_BossBarManager {
|
||||||
|
private Field BossBattleServer = null;
|
||||||
|
public void saveBossBarData(List<World> worlds){
|
||||||
|
File file = new File(plugin.getDataFolder(),"world_data.yml");
|
||||||
|
YamlConfiguration yml = new YamlConfiguration();
|
||||||
|
worlds.forEach(world -> {
|
||||||
|
try{
|
||||||
|
Object edb = DragonManager.getEnderDragonBattle(world);
|
||||||
|
assert edb != null;
|
||||||
|
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("bossBattle");
|
||||||
|
BossBattleServer.setAccessible(true);
|
||||||
|
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
||||||
|
String path = world.getName() + yml.options().pathSeparator();
|
||||||
|
yml.set(path+"title",bbs.title.getText());
|
||||||
|
yml.set(path+"color",bbs.color.name());
|
||||||
|
yml.set(path+"style",bbs.style.name());
|
||||||
|
}catch (ReflectiveOperationException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try{
|
||||||
|
yml.save(file);
|
||||||
|
Lang.info("BossBar data has been saved!");
|
||||||
|
}catch (IOException e){
|
||||||
|
Lang.error("Failed to save world_data!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void loadBossBarData(List<World> worlds){
|
||||||
|
File file = new File(plugin.getDataFolder(),"world_data.yml");
|
||||||
|
if(!file.exists()) return;
|
||||||
|
Lang.info("Enabling BossBar fix...");
|
||||||
|
YamlConfiguration yml = new YamlConfiguration();
|
||||||
|
try{
|
||||||
|
yml.load(file);
|
||||||
|
}catch (InvalidConfigurationException | IOException e) {
|
||||||
|
Lang.error("Failed to load world_data!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
worlds.forEach(world -> {
|
||||||
|
try{
|
||||||
|
Object edb = DragonManager.getEnderDragonBattle(world);
|
||||||
|
assert edb != null;
|
||||||
|
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("bossBattle");
|
||||||
|
BossBattleServer.setAccessible(true);
|
||||||
|
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
||||||
|
String path = world.getName() + yml.options().pathSeparator();
|
||||||
|
bbs.title = CraftChatMessage.fromString(yml.getString(path+"title"), true)[0];
|
||||||
|
bbs.color = BossBattle.BarColor.valueOf(yml.getString(path+"color"));
|
||||||
|
bbs.style = BossBattle.BarStyle.valueOf(yml.getString(path+"style"));
|
||||||
|
}catch (ReflectiveOperationException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public void setBossBar(World world,String title,String color,String style){
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package pers.xanadu.enderdragon.nms.BossBar.v1_15_R1;
|
||||||
|
|
||||||
|
import net.minecraft.server.v1_15_R1.BossBattle;
|
||||||
|
import net.minecraft.server.v1_15_R1.BossBattleServer;
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.craftbukkit.v1_15_R1.util.CraftChatMessage;
|
||||||
|
import pers.xanadu.enderdragon.config.Lang;
|
||||||
|
import pers.xanadu.enderdragon.manager.DragonManager;
|
||||||
|
import pers.xanadu.enderdragon.nms.BossBar.I_BossBarManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
||||||
|
|
||||||
|
public class BossBarManager implements I_BossBarManager {
|
||||||
|
private Field BossBattleServer = null;
|
||||||
|
public void saveBossBarData(List<World> worlds){
|
||||||
|
File file = new File(plugin.getDataFolder(),"world_data.yml");
|
||||||
|
YamlConfiguration yml = new YamlConfiguration();
|
||||||
|
worlds.forEach(world -> {
|
||||||
|
try{
|
||||||
|
Object edb = DragonManager.getEnderDragonBattle(world);
|
||||||
|
assert edb != null;
|
||||||
|
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("bossBattle");
|
||||||
|
BossBattleServer.setAccessible(true);
|
||||||
|
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
||||||
|
String path = world.getName() + yml.options().pathSeparator();
|
||||||
|
yml.set(path+"title",bbs.title.getText());
|
||||||
|
yml.set(path+"color",bbs.color.name());
|
||||||
|
yml.set(path+"style",bbs.style.name());
|
||||||
|
}catch (ReflectiveOperationException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try{
|
||||||
|
yml.save(file);
|
||||||
|
Lang.info("BossBar data has been saved!");
|
||||||
|
}catch (IOException e){
|
||||||
|
Lang.error("Failed to save world_data!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void loadBossBarData(List<World> worlds){
|
||||||
|
File file = new File(plugin.getDataFolder(),"world_data.yml");
|
||||||
|
if(!file.exists()) return;
|
||||||
|
Lang.info("Enabling BossBar fix...");
|
||||||
|
YamlConfiguration yml = new YamlConfiguration();
|
||||||
|
try{
|
||||||
|
yml.load(file);
|
||||||
|
}catch (InvalidConfigurationException | IOException e) {
|
||||||
|
Lang.error("Failed to load world_data!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
worlds.forEach(world -> {
|
||||||
|
try{
|
||||||
|
Object edb = DragonManager.getEnderDragonBattle(world);
|
||||||
|
assert edb != null;
|
||||||
|
if(BossBattleServer == null) BossBattleServer = edb.getClass().getDeclaredField("bossBattle");
|
||||||
|
BossBattleServer.setAccessible(true);
|
||||||
|
BossBattleServer bbs = (BossBattleServer) BossBattleServer.get(edb);
|
||||||
|
String path = world.getName() + yml.options().pathSeparator();
|
||||||
|
bbs.title = CraftChatMessage.fromString(yml.getString(path+"title"), true)[0];
|
||||||
|
bbs.color = BossBattle.BarColor.valueOf(yml.getString(path+"color"));
|
||||||
|
bbs.style = BossBattle.BarStyle.valueOf(yml.getString(path+"style"));
|
||||||
|
}catch (ReflectiveOperationException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public void setBossBar(World world,String title,String color,String style){
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package pers.xanadu.enderdragon.nms.BossBar.v1_16_R1_above;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
import org.bukkit.boss.BarColor;
|
||||||
|
import org.bukkit.boss.BarStyle;
|
||||||
|
import org.bukkit.boss.BossBar;
|
||||||
|
import org.bukkit.boss.DragonBattle;
|
||||||
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import pers.xanadu.enderdragon.config.Lang;
|
||||||
|
import pers.xanadu.enderdragon.nms.BossBar.I_BossBarManager;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static pers.xanadu.enderdragon.EnderDragon.plugin;
|
||||||
|
|
||||||
|
public class BossBarManager implements I_BossBarManager {
|
||||||
|
public void saveBossBarData(List<World> worlds){
|
||||||
|
File file = new File(plugin.getDataFolder(),"world_data.yml");
|
||||||
|
YamlConfiguration yml = new YamlConfiguration();
|
||||||
|
worlds.forEach(world -> {
|
||||||
|
DragonBattle battle = world.getEnderDragonBattle();
|
||||||
|
if(battle == null) return;
|
||||||
|
BossBar bossBar = battle.getBossBar();
|
||||||
|
String path = world.getName() + yml.options().pathSeparator();
|
||||||
|
yml.set(path+"title",bossBar.getTitle());
|
||||||
|
yml.set(path+"color",bossBar.getColor().name());
|
||||||
|
yml.set(path+"style",bossBar.getStyle().name());
|
||||||
|
});
|
||||||
|
try{
|
||||||
|
yml.save(file);
|
||||||
|
Lang.info("BossBar data has been saved!");
|
||||||
|
}catch (IOException e){
|
||||||
|
Lang.error("Failed to save world_data!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void loadBossBarData(List<World> worlds){
|
||||||
|
File file = new File(plugin.getDataFolder(),"world_data.yml");
|
||||||
|
if(!file.exists()) return;
|
||||||
|
Lang.info("Enabling BossBar fix...");
|
||||||
|
YamlConfiguration yml = new YamlConfiguration();
|
||||||
|
try{
|
||||||
|
yml.load(file);
|
||||||
|
}catch (InvalidConfigurationException | IOException e) {
|
||||||
|
Lang.error("Failed to load world_data!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
worlds.forEach(world -> {
|
||||||
|
DragonBattle battle = world.getEnderDragonBattle();
|
||||||
|
if(battle == null) return;
|
||||||
|
BossBar bossBar = battle.getBossBar();
|
||||||
|
String path = world.getName() + yml.options().pathSeparator();
|
||||||
|
bossBar.setTitle(yml.getString(path+"title"));
|
||||||
|
bossBar.setColor(BarColor.valueOf(yml.getString(path+"color")));
|
||||||
|
bossBar.setStyle(BarStyle.valueOf(yml.getString(path+"style")));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
public void setBossBar(World world,String title,String color,String style){
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -47,7 +47,9 @@ public class Version {
|
|||||||
case "v1_12_R1" : return new pers.xanadu.enderdragon.nms.BossBar.v1_12_R1.BossBarManager();
|
case "v1_12_R1" : return new pers.xanadu.enderdragon.nms.BossBar.v1_12_R1.BossBarManager();
|
||||||
case "v1_13_R1" : return new pers.xanadu.enderdragon.nms.BossBar.v1_13_R1.BossBarManager();
|
case "v1_13_R1" : return new pers.xanadu.enderdragon.nms.BossBar.v1_13_R1.BossBarManager();
|
||||||
case "v1_13_R2" : return new pers.xanadu.enderdragon.nms.BossBar.v1_13_R2.BossBarManager();
|
case "v1_13_R2" : return new pers.xanadu.enderdragon.nms.BossBar.v1_13_R2.BossBarManager();
|
||||||
default: return null;
|
case "v1_14_R1" : return new pers.xanadu.enderdragon.nms.BossBar.v1_14_R1.BossBarManager();
|
||||||
|
case "v1_15_R1" : return new pers.xanadu.enderdragon.nms.BossBar.v1_15_R1.BossBarManager();
|
||||||
|
default: return new pers.xanadu.enderdragon.nms.BossBar.v1_16_R1_above.BossBarManager();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static I_WorldDataManager getWorldDataManager(){
|
public static I_WorldDataManager getWorldDataManager(){
|
||||||
|
|||||||
Reference in New Issue
Block a user