Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BungeeCord bossbar support #155

Merged
merged 5 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public abstract class ServerBossbar implements Castable<ServerBossbar> {
protected Style segmentStyle = Style.SOLID;
protected Color color = Color.BLUE;
protected float progress;
protected float progress = 0;
protected ServerComponent title;

public ServerBossbar color(Color color) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,77 +1,31 @@
package me.mastercapexd.auth.bungee.api.bossbar;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import com.bivashy.auth.api.server.bossbar.ServerBossbar;
import com.bivashy.auth.api.server.message.ServerComponent;
import com.bivashy.auth.api.server.player.ServerPlayer;

import me.mastercapexd.auth.bungee.BungeeAuthPluginBootstrap;
import me.mastercapexd.auth.bungee.player.BungeeServerPlayer;
import net.md_5.bungee.protocol.packet.BossBar;

public class BungeeServerBossbar extends ServerBossbar {
private final Set<ServerPlayer> players = new HashSet<>();
private final UUID uuid = UUID.randomUUID();

public BungeeServerBossbar(ServerComponent component) {
this.title(component);
}
import me.mastercapexd.auth.server.adventure.AdventureServerBossbar;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;

@Override
public ServerBossbar removeAll() {
this.players.forEach(this::remove);
this.players.clear();
return this;
}
public class BungeeServerBossbar extends AdventureServerBossbar {

@Override
public ServerBossbar send(ServerPlayer... viewers) {
BossBar bossBar = getAddPacket();
for (ServerPlayer player : viewers) {
player.as(BungeeServerPlayer.class).getBungeePlayer().unsafe().sendPacket(bossBar);
players.add(player);
}
return this;
}
private final BungeeAudiences audiences = BungeeAuthPluginBootstrap.getInstance().getBungeeAudiences();

@Override
public ServerBossbar remove(ServerPlayer... viewers) {
BossBar bossBar = getRemovePacket();
for (ServerPlayer player : viewers) {
player.as(BungeeServerPlayer.class).getBungeePlayer().unsafe().sendPacket(bossBar);
players.remove(player);
}
return this;
public BungeeServerBossbar(ServerComponent component) {
super(component);
}

@Override
public ServerBossbar update() {
BossBar bossBar = getAddPacket();
for (ServerPlayer player : players)
player.as(BungeeServerPlayer.class).getBungeePlayer().unsafe().sendPacket(bossBar);
return this;
public void showBossBar(ServerPlayer player, BossBar bossBar) {
audiences.player(player.as(BungeeServerPlayer.class).getBungeePlayer()).showBossBar(bossBar);
}

@Override
public Collection<ServerPlayer> players() {
return Collections.unmodifiableCollection(players);
}

private BossBar getAddPacket() {
BossBar packet = new BossBar(uuid, 0);

packet.setTitle(title.jsonText());
packet.setColor(this.color.ordinal());
packet.setDivision(this.segmentStyle.ordinal());
packet.setHealth(this.progress);
return packet;
public void hideBossBar(ServerPlayer player, BossBar bossBar) {
audiences.player(player.as(BungeeServerPlayer.class).getBungeePlayer()).hideBossBar(bossBar);
}

private BossBar getRemovePacket() {
return new BossBar(uuid, 1);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package me.mastercapexd.auth.server.adventure;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import com.bivashy.auth.api.server.bossbar.ServerBossbar;
import com.bivashy.auth.api.server.message.AdventureServerComponent;
import com.bivashy.auth.api.server.message.ServerComponent;
import com.bivashy.auth.api.server.player.ServerPlayer;

import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;

public abstract class AdventureServerBossbar extends ServerBossbar {
private static final GsonComponentSerializer GSON_COMPONENT_SERIALIZER = GsonComponentSerializer.gson();
private final List<ServerPlayer> bossBarPlayers = new ArrayList<>();
private final BossBar bossBar;

public AdventureServerBossbar(ServerComponent component) {
this.title = component;
BossBar.Color bossBarColor = BossBar.Color.values()[color.ordinal()];
BossBar.Overlay bossBarOverlay = BossBar.Overlay.values()[segmentStyle.ordinal()];
bossBar = BossBar.bossBar(GSON_COMPONENT_SERIALIZER.deserialize(component.jsonText()), progress, bossBarColor, bossBarOverlay);
}

public abstract void showBossBar(ServerPlayer player, BossBar bossBar);

public abstract void hideBossBar(ServerPlayer player, BossBar bossBar);

@Override
public ServerBossbar send(ServerPlayer... viewers) {
for (ServerPlayer player : viewers) {
showBossBar(player, bossBar);
bossBarPlayers.add(player);
}
return this;
}

@Override
public ServerBossbar remove(ServerPlayer... viewers) {
for (ServerPlayer player : viewers) {
hideBossBar(player, bossBar);
bossBarPlayers.remove(player);
}
return this;
}

@Override
public ServerBossbar update() {
BossBar.Color bossBarColor = BossBar.Color.values()[color.ordinal()];
BossBar.Overlay bossBarOverlay = BossBar.Overlay.values()[segmentStyle.ordinal()];

if (title instanceof AdventureServerComponent) {
bossBar.name(((AdventureServerComponent) title).component());
} else {
bossBar.name(GSON_COMPONENT_SERIALIZER.deserialize(title.jsonText()));
}
bossBar.color(bossBarColor).overlay(bossBarOverlay).progress(progress);
return this;
}

@Override
public ServerBossbar title(ServerComponent component) {
super.title(component);
bossBar.name(GSON_COMPONENT_SERIALIZER.deserialize(component.jsonText()));
return this;
}

@Override
public ServerBossbar color(Color color) {
BossBar.Color bossBarColor = BossBar.Color.values()[color.ordinal()];
super.color(color);
bossBar.color(bossBarColor);
return this;
}

@Override
public ServerBossbar style(Style segmentStyle) {
BossBar.Overlay bossBarOverlay = BossBar.Overlay.values()[segmentStyle.ordinal()];
super.style(segmentStyle);
bossBar.overlay(bossBarOverlay);
return this;
}

@Override
public ServerBossbar progress(float progress) {
super.progress(progress);
bossBar.progress(progress);
return this;
}

@Override
public ServerBossbar removeAll() {
remove(bossBarPlayers.toArray(new ServerPlayer[0]));
return this;
}

@Override
public Collection<ServerPlayer> players() {
return Collections.unmodifiableList(bossBarPlayers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ public AuthenticationProgressBarTask(AuthPlugin plugin) {
}

String formattedDuration = settings.getDurationPlaceholderFormat().format(new Date(timeoutMillis - accountTimeElapsedFromEntryMillis));
progressBar.title(ServerComponent.fromJson(settings.getTitle().jsonText().replace("%duration%", formattedDuration)));
progressBar.progress(progress);
progressBar.update();
progressBar.title(ServerComponent.fromJson(settings.getTitle().jsonText().replace("%duration%", formattedDuration)));
}
}, 0, 1, TimeUnit.SECONDS);
plugin.getEventBus().register(this);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,71 +1,26 @@
package me.mastercapexd.auth.velocity.api.bossbar;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;

import com.bivashy.auth.api.server.bossbar.ServerBossbar;
import com.bivashy.auth.api.server.message.AdventureServerComponent;
import com.bivashy.auth.api.server.message.ServerComponent;
import com.bivashy.auth.api.server.player.ServerPlayer;

import me.mastercapexd.auth.server.adventure.AdventureServerBossbar;
import me.mastercapexd.auth.velocity.player.VelocityServerPlayer;
import net.kyori.adventure.bossbar.BossBar;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;

public class VelocityServerBossbar extends ServerBossbar {
private static final GsonComponentSerializer GSON_COMPONENT_SERIALIZER = GsonComponentSerializer.gson();
private final List<ServerPlayer> bossBarPlayers = new ArrayList<>();
private final BossBar bossBar;
public class VelocityServerBossbar extends AdventureServerBossbar {

public VelocityServerBossbar(ServerComponent component) {
title(component);
BossBar.Color bossBarColor = BossBar.Color.values()[color.ordinal()];
BossBar.Overlay bossBarOverlay = BossBar.Overlay.values()[segmentStyle.ordinal()];
bossBar = BossBar.bossBar(GSON_COMPONENT_SERIALIZER.deserialize(component.jsonText()), progress, bossBarColor, bossBarOverlay).progress(progress);
}

@Override
public ServerBossbar send(ServerPlayer... viewers) {
for (ServerPlayer player : viewers) {
player.as(VelocityServerPlayer.class).getPlayer().showBossBar(bossBar);
bossBarPlayers.add(player);
}
return this;
}

@Override
public ServerBossbar remove(ServerPlayer... viewers) {
for (ServerPlayer player : viewers) {
player.as(VelocityServerPlayer.class).getPlayer().hideBossBar(bossBar);
bossBarPlayers.remove(player);
}
return this;
super(component);
}

@Override
public ServerBossbar update() {
BossBar.Color bossBarColor = BossBar.Color.values()[color.ordinal()];
BossBar.Overlay bossBarOverlay = BossBar.Overlay.values()[segmentStyle.ordinal()];

if (title instanceof AdventureServerComponent) {
bossBar.name(((AdventureServerComponent) title).component());
} else {
bossBar.name(GSON_COMPONENT_SERIALIZER.deserialize(title.jsonText()));
}
bossBar.color(bossBarColor).overlay(bossBarOverlay).progress(progress);
return this;
public void showBossBar(ServerPlayer player, BossBar bossBar) {
player.as(VelocityServerPlayer.class).getPlayer().showBossBar(bossBar);
}

@Override
public ServerBossbar removeAll() {
remove(bossBarPlayers.toArray(new ServerPlayer[0]));
return this;
public void hideBossBar(ServerPlayer player, BossBar bossBar) {
player.as(VelocityServerPlayer.class).getPlayer().hideBossBar(bossBar);
}

@Override
public Collection<ServerPlayer> players() {
return Collections.unmodifiableList(bossBarPlayers);
}
}
Loading