Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-24 23:30:15 +01:00
Save boss bars to BungeeCord which are made by Withers / Enderdragons
Dieser Commit ist enthalten in:
Ursprung
e8039e158f
Commit
a52552dcb4
@ -9,11 +9,13 @@ import us.myles.ViaVersion.bungee.handlers.BungeeServerHandler;
|
|||||||
import us.myles.ViaVersion.bungee.listeners.ElytraPatch;
|
import us.myles.ViaVersion.bungee.listeners.ElytraPatch;
|
||||||
import us.myles.ViaVersion.bungee.listeners.MainHandPatch;
|
import us.myles.ViaVersion.bungee.listeners.MainHandPatch;
|
||||||
import us.myles.ViaVersion.bungee.listeners.UpdateListener;
|
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.BungeeEntityIdProvider;
|
||||||
import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter;
|
import us.myles.ViaVersion.bungee.providers.BungeeMovementTransmitter;
|
||||||
import us.myles.ViaVersion.bungee.providers.BungeeVersionProvider;
|
import us.myles.ViaVersion.bungee.providers.BungeeVersionProvider;
|
||||||
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
|
import us.myles.ViaVersion.bungee.service.ProtocolDetectorService;
|
||||||
import us.myles.ViaVersion.protocols.base.VersionProvider;
|
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.EntityIdProvider;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
|
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(MovementTransmitterProvider.class, new BungeeMovementTransmitter());
|
||||||
Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider());
|
Via.getManager().getProviders().use(VersionProvider.class, new BungeeVersionProvider());
|
||||||
Via.getManager().getProviders().use(EntityIdProvider.class, new BungeeEntityIdProvider());
|
Via.getManager().getProviders().use(EntityIdProvider.class, new BungeeEntityIdProvider());
|
||||||
|
Via.getManager().getProviders().use(BossBarProvider.class, new BungeeBossBarProvider());
|
||||||
|
|
||||||
if (plugin.getConf().getBungeePingInterval() > 0) {
|
if (plugin.getConf().getBungeePingInterval() > 0) {
|
||||||
plugin.getProxy().getScheduler().schedule(plugin, new ProtocolDetectorService(plugin), 0, plugin.getConf().getBungeePingInterval(), TimeUnit.SECONDS);
|
plugin.getProxy().getScheduler().schedule(plugin, new ProtocolDetectorService(plugin), 0, plugin.getConf().getBungeePingInterval(), TimeUnit.SECONDS);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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.StoredObject;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public class BungeeStorage extends StoredObject {
|
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 ProxiedPlayer player;
|
||||||
private String currentServer;
|
private String currentServer;
|
||||||
|
private Set<UUID> bossbar;
|
||||||
|
|
||||||
public BungeeStorage(UserConnection user, ProxiedPlayer player) {
|
public BungeeStorage(UserConnection user, ProxiedPlayer player) {
|
||||||
super(user);
|
super(user);
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.currentServer = "";
|
this.currentServer = "";
|
||||||
|
|
||||||
|
// Get bossbar list if it's supported
|
||||||
|
if (bossField != null) {
|
||||||
|
try {
|
||||||
|
bossbar = (Set<UUID>) bossField.get(player);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -167,4 +167,11 @@ public abstract class BossBar<T> {
|
|||||||
* @return visibility changable with show() and hide()
|
* @return visibility changable with show() and hide()
|
||||||
*/
|
*/
|
||||||
public abstract boolean isVisible();
|
public abstract boolean isVisible();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the UUID of this bossbar
|
||||||
|
*
|
||||||
|
* @return Unique Id for this bossbar
|
||||||
|
*/
|
||||||
|
public abstract UUID getId();
|
||||||
}
|
}
|
||||||
|
@ -138,6 +138,11 @@ public abstract class CommonBoss<T> extends BossBar<T> {
|
|||||||
return visible;
|
return visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public UUID getId() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
private void setVisible(boolean value) {
|
private void setVisible(boolean value) {
|
||||||
if (visible != value) {
|
if (visible != value) {
|
||||||
visible = value;
|
visible = value;
|
||||||
|
@ -94,6 +94,7 @@ public class Protocol1_9TO1_8 extends Protocol {
|
|||||||
providers.register(BulkChunkTranslatorProvider.class, new BulkChunkTranslatorProvider());
|
providers.register(BulkChunkTranslatorProvider.class, new BulkChunkTranslatorProvider());
|
||||||
providers.register(CommandBlockProvider.class, new CommandBlockProvider());
|
providers.register(CommandBlockProvider.class, new CommandBlockProvider());
|
||||||
providers.register(EntityIdProvider.class, new EntityIdProvider());
|
providers.register(EntityIdProvider.class, new EntityIdProvider());
|
||||||
|
providers.register(BossBarProvider.class, new BossBarProvider());
|
||||||
providers.require(MovementTransmitterProvider.class);
|
providers.require(MovementTransmitterProvider.class);
|
||||||
if (Via.getConfig().isStimulatePlayerTick()) {
|
if (Via.getConfig().isStimulatePlayerTick()) {
|
||||||
Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L);
|
Via.getPlatform().runRepeatingSync(new ViaIdleThread(), 1L);
|
||||||
|
@ -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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -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.Protocol1_9TO1_8;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.chat.GameMode;
|
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.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 us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.EntityIdProvider;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -95,6 +97,8 @@ public class EntityTracker extends StoredObject {
|
|||||||
BossBar bar = bossBarMap.remove(entityID);
|
BossBar bar = bossBarMap.remove(entityID);
|
||||||
if (bar != null) {
|
if (bar != null) {
|
||||||
bar.hide();
|
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);
|
bossBarMap.put(entityID, bar);
|
||||||
bar.addPlayer(uuid);
|
bar.addPlayer(uuid);
|
||||||
bar.show();
|
bar.show();
|
||||||
|
|
||||||
|
// Send to provider
|
||||||
|
Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(getUser(), bar.getId());
|
||||||
} else {
|
} else {
|
||||||
bar.setTitle(title);
|
bar.setTitle(title);
|
||||||
}
|
}
|
||||||
@ -217,6 +224,8 @@ public class EntityTracker extends StoredObject {
|
|||||||
bossBarMap.put(entityID, bar);
|
bossBarMap.put(entityID, bar);
|
||||||
bar.addPlayer(uuid);
|
bar.addPlayer(uuid);
|
||||||
bar.show();
|
bar.show();
|
||||||
|
// Send to provider
|
||||||
|
Via.getManager().getProviders().get(BossBarProvider.class).handleAdd(getUser(), bar.getId());
|
||||||
} else {
|
} else {
|
||||||
bar.setHealth(health);
|
bar.setHealth(health);
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren