diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaLoader.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaLoader.java index e721f3eb2..6635d2eca 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaLoader.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/platform/BungeeViaLoader.java @@ -9,11 +9,13 @@ import us.myles.ViaVersion.bungee.handlers.BungeeServerHandler; import us.myles.ViaVersion.bungee.listeners.ElytraPatch; import us.myles.ViaVersion.bungee.listeners.MainHandPatch; import us.myles.ViaVersion.bungee.listeners.UpdateListener; +import us.myles.ViaVersion.bungee.providers.BungeeBossBarProvider; import us.myles.ViaVersion.bungee.providers.BungeeEntityIdProvider; import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter; import us.myles.ViaVersion.bungee.providers.BungeeVersionProvider; import us.myles.ViaVersion.bungee.service.ProtocolDetectorService; import us.myles.ViaVersion.protocols.base.VersionProvider; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider; @@ -36,6 +38,8 @@ public class BungeeViaLoader implements ViaPlatformLoader { Via.getManager().getProviders().use(MovementTransmitterProvider.class, new BungeeMovementTransmitter()); Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider()); Via.getManager().getProviders().use(EntityIdProvider.class, new BungeeEntityIdProvider()); + Via.getManager().getProviders().use(BossBarProvider.class, new BungeeBossBarProvider()); + if (plugin.getConf().getBungeePingInterval() > 0) { plugin.getProxy().getScheduler().schedule(plugin, new ProtocolDetectorService(plugin), 0, plugin.getConf().getBungeePingInterval(), TimeUnit.SECONDS); } diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeBossBarProvider.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeBossBarProvider.java new file mode 100644 index 000000000..e3a2ee8f2 --- /dev/null +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/providers/BungeeBossBarProvider.java @@ -0,0 +1,30 @@ +package us.myles.ViaVersion.bungee.providers; + +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.bungee.storage.BungeeStorage; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider; + +import java.util.UUID; + +public class BungeeBossBarProvider extends BossBarProvider { + @Override + public void handleAdd(UserConnection user, UUID barUUID) { + if (user.has(BungeeStorage.class)) { + BungeeStorage storage = user.get(BungeeStorage.class); + // Check if bossbars are supported by bungee, static maybe + if (storage.getBossbar() != null) { + storage.getBossbar().add(barUUID); + } + } + } + + @Override + public void handleRemove(UserConnection user, UUID barUUID) { + if (user.has(BungeeStorage.class)) { + BungeeStorage storage = user.get(BungeeStorage.class); + if (storage.getBossbar() != null) { + storage.getBossbar().remove(barUUID); + } + } + } +} diff --git a/bungee/src/main/java/us/myles/ViaVersion/bungee/storage/BungeeStorage.java b/bungee/src/main/java/us/myles/ViaVersion/bungee/storage/BungeeStorage.java index 683b8230d..907471e86 100644 --- a/bungee/src/main/java/us/myles/ViaVersion/bungee/storage/BungeeStorage.java +++ b/bungee/src/main/java/us/myles/ViaVersion/bungee/storage/BungeeStorage.java @@ -6,15 +6,43 @@ import net.md_5.bungee.api.connection.ProxiedPlayer; import us.myles.ViaVersion.api.data.StoredObject; import us.myles.ViaVersion.api.data.UserConnection; +import java.lang.reflect.Field; +import java.util.Set; +import java.util.UUID; + @Data @EqualsAndHashCode(callSuper = true) public class BungeeStorage extends StoredObject { + private static Field bossField; + + static { + try { + Class user = Class.forName("net.md_5.bungee.UserConnection"); + bossField = user.getDeclaredField("sentBossBars"); + bossField.setAccessible(true); + } catch (ClassNotFoundException e) { + // Not supported *shrug* probably modified + } catch (NoSuchFieldException e) { + // Not supported, old version probably + } + } + private ProxiedPlayer player; private String currentServer; + private Set bossbar; public BungeeStorage(UserConnection user, ProxiedPlayer player) { super(user); this.player = player; this.currentServer = ""; + + // Get bossbar list if it's supported + if (bossField != null) { + try { + bossbar = (Set) bossField.get(player); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } } } diff --git a/common/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java b/common/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java index 76737c23b..9398e8ed1 100644 --- a/common/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java +++ b/common/src/main/java/us/myles/ViaVersion/api/boss/BossBar.java @@ -167,4 +167,11 @@ public abstract class BossBar { * @return visibility changable with show() and hide() */ public abstract boolean isVisible(); + + /** + * Get the UUID of this bossbar + * + * @return Unique Id for this bossbar + */ + public abstract UUID getId(); } diff --git a/common/src/main/java/us/myles/ViaVersion/boss/CommonBoss.java b/common/src/main/java/us/myles/ViaVersion/boss/CommonBoss.java index 7cc89d0c5..c475c9313 100644 --- a/common/src/main/java/us/myles/ViaVersion/boss/CommonBoss.java +++ b/common/src/main/java/us/myles/ViaVersion/boss/CommonBoss.java @@ -138,6 +138,11 @@ public abstract class CommonBoss extends BossBar { return visible; } + @Override + public UUID getId() { + return uuid; + } + private void setVisible(boolean value) { if (visible != value) { visible = value; diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java index 22b5bf4c0..d15ac6577 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/Protocol1_9TO1_8.java @@ -94,6 +94,7 @@ public class Protocol1_9TO1_8 extends Protocol { providers.register(BulkChunkTranslatorProvider.class, new BulkChunkTranslatorProvider()); providers.register(CommandBlockProvider.class, new CommandBlockProvider()); providers.register(EntityIdProvider.class, new EntityIdProvider()); + providers.register(BossBarProvider.class, new BossBarProvider()); providers.require(MovementTransmitterProvider.class); if (Via.getConfig().isStimulatePlayerTick()) { Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/providers/BossBarProvider.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/providers/BossBarProvider.java new file mode 100644 index 000000000..2890d1d4b --- /dev/null +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/providers/BossBarProvider.java @@ -0,0 +1,16 @@ +package us.myles.ViaVersion.protocols.protocol1_9to1_8.providers; + +import us.myles.ViaVersion.api.data.UserConnection; +import us.myles.ViaVersion.api.platform.providers.Provider; + +import java.util.UUID; + +public class BossBarProvider implements Provider { + public void handleAdd(UserConnection user, UUID barUUID) { + + } + + public void handleRemove(UserConnection user, UUID barUUID) { + + } +} diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java index 0d02b3d06..052f0d70f 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/storage/EntityTracker.java @@ -24,6 +24,8 @@ import us.myles.ViaVersion.protocols.base.ProtocolInfo; import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9TO1_8; import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.GameMode; import us.myles.ViaVersion.protocols.protocol1_9to1_8.metadata.MetadataRewriter; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BossBarProvider; +import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.BulkChunkTranslatorProvider; import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider; import java.util.*; @@ -95,6 +97,8 @@ public class EntityTracker extends StoredObject { BossBar bar = bossBarMap.remove(entityID); if (bar != null) { bar.hide(); + // Send to provider + Via.getManager().getProviders().get(BossBarProvider.class).handleRemove(getUser(), bar.getId()); } } @@ -203,6 +207,9 @@ public class EntityTracker extends StoredObject { bossBarMap.put(entityID, bar); bar.addPlayer(uuid); bar.show(); + + // Send to provider + Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(getUser(), bar.getId()); } else { bar.setTitle(title); } @@ -217,6 +224,8 @@ public class EntityTracker extends StoredObject { bossBarMap.put(entityID, bar); bar.addPlayer(uuid); bar.show(); + // Send to provider + Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(getUser(), bar.getId()); } else { bar.setHealth(health); }