From a2262860d5bfe44a94b752682d3d1393f0b50e35 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Tue, 7 Apr 2020 14:08:17 +1200 Subject: [PATCH] BossBars are no longer supported in 1.12 due to api restrictions --- pom.xml | 2 +- .../disguise/DisguiseConfig.java | 8 ++++++++ .../disguise/disguisetypes/Disguise.java | 14 ++++++++----- .../disguise/utilities/DisguiseUtilities.java | 20 ++++++++++--------- src/main/resources/config.yml | 1 + 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/pom.xml b/pom.xml index 1961ca91..19075cc7 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ LibsDisguises LibsDisguises - 10.0.1 + 10.0.1-SNAPSHOT exec:java clean install diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java index 8105ddcd..6bc000be 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java @@ -444,6 +444,14 @@ public class DisguiseConfig { try { setNotifyBar(NotifyBar.valueOf(config.getString("NotifyBar").toUpperCase())); + + if (getNotifyBar() == NotifyBar.BOSS_BAR) { + DisguiseUtilities.getLogger().warning( + "BossBars hasn't been implemented properly in 1.12 due to api restrictions, falling back to " + + "ACTION_BAR"); + + setNotifyBar(NotifyBar.ACTION_BAR); + } } catch (Exception ex) { DisguiseUtilities.getLogger() diff --git a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java index 3a046deb..ac117cea 100644 --- a/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java +++ b/src/main/java/me/libraryaddict/disguise/disguisetypes/Disguise.java @@ -20,6 +20,7 @@ import me.libraryaddict.disguise.events.DisguiseEvent; import me.libraryaddict.disguise.events.UndisguiseEvent; import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.LibsPremium; +import me.libraryaddict.disguise.utilities.reflection.NmsVersion; import me.libraryaddict.disguise.utilities.reflection.ReflectionManager; import me.libraryaddict.disguise.utilities.translations.LibsMsg; import net.md_5.bungee.api.ChatMessageType; @@ -186,7 +187,8 @@ public abstract class Disguise { } private void makeBossBar() { - if (getNotifyBar() != DisguiseConfig.NotifyBar.BOSS_BAR || !(getEntity() instanceof Player)) { + if (getNotifyBar() != DisguiseConfig.NotifyBar.BOSS_BAR || !NmsVersion.v1_13.isSupported() || + !(getEntity() instanceof Player)) { return; } @@ -803,11 +805,13 @@ public abstract class Disguise { getEntity().setMetadata("LastDisguise", new FixedMetadataValue(LibsDisguises.getInstance(), System.currentTimeMillis())); - BossBar bar = Bukkit.getBossBar(getBossBar()); + if (NmsVersion.v1_13.isSupported()) { + BossBar bar = Bukkit.getBossBar(getBossBar()); - if (bar != null) { - bar.removeAll(); - Bukkit.removeBossBar(getBossBar()); + if (bar != null) { + bar.removeAll(); + Bukkit.removeBossBar(getBossBar()); + } } return true; diff --git a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java index c3720b95..3e7765e6 100644 --- a/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java +++ b/src/main/java/me/libraryaddict/disguise/utilities/DisguiseUtilities.java @@ -967,17 +967,19 @@ public class DisguiseUtilities { registerNoName(board); } - Iterator bars = Bukkit.getBossBars(); - ArrayList barList = new ArrayList<>(); - bars.forEachRemaining(barList::add); + if (NmsVersion.v1_13.isSupported()) { + Iterator bars = Bukkit.getBossBars(); + ArrayList barList = new ArrayList<>(); + bars.forEachRemaining(barList::add); - for (KeyedBossBar bar : barList) { - if (!bar.getKey().getNamespace().equalsIgnoreCase("libsdisguises")) { - continue; + for (KeyedBossBar bar : barList) { + if (!bar.getKey().getNamespace().equalsIgnoreCase("libsdisguises")) { + continue; + } + + bar.removeAll(); + Bukkit.removeBossBar(bar.getKey()); } - - bar.removeAll(); - Bukkit.removeBossBar(bar.getKey()); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e50ec521..0429e196 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -127,6 +127,7 @@ HearSelfDisguise: true # When disguised, should a message be displayed to the player? If so, where? # The message can be customized in translations +# BOSS_BAR is not supported in 1.12! # NONE, BOSS_BAR, ACTION_BAR NotifyBar: ACTION_BAR # If using boss bar, these two options come into play