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

Sidebar Improvements #139

Merged
merged 1 commit into from
Mar 12, 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 @@ -36,6 +36,8 @@
import io.fairyproject.mc.protocol.MCProtocol;
import io.fairyproject.metadata.MetadataKey;
import io.fairyproject.util.CC;
import lombok.Getter;
import lombok.Setter;
import net.kyori.adventure.text.Component;

import java.util.List;
Expand All @@ -46,9 +48,15 @@ public class Sidebar {
public static final MetadataKey<Sidebar> METADATA_TAG = MetadataKey.create(Fairy.METADATA_PREFIX + "Scoreboard", Sidebar.class);

private final MCPlayer player;
private final Component[] teams;

private Component title;
private final Component[] teams;
@Getter
@Setter
private int ticks;
@Getter
@Setter
private boolean removed;

public Sidebar(MCPlayer player) {
this.player = player;
Expand Down Expand Up @@ -192,6 +200,10 @@ public void clear(int line) {
}

public void remove() {
if (this.isRemoved())
return;
this.setRemoved(true);

for (int line = 1; line < 15; line++) {
this.clear(line);
}
Expand All @@ -202,7 +214,7 @@ private WrapperPlayServerTeams getOrRegisterTeam(int line) {
return new WrapperPlayServerTeams(
"-sb" + line,
WrapperPlayServerTeams.TeamMode.UPDATE,
Optional.empty()
(WrapperPlayServerTeams.ScoreBoardTeamInfo) null
);
} else {
teams[line] = null;
Expand All @@ -218,7 +230,7 @@ private WrapperPlayServerTeams getOrRegisterTeam(int line) {
return new WrapperPlayServerTeams(
"-sb" + line,
WrapperPlayServerTeams.TeamMode.CREATE,
Optional.empty(),
(WrapperPlayServerTeams.ScoreBoardTeamInfo) null,
getEntry(line)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,26 @@ private void tick() {
break;
}

Sidebar board = this.get(player);
if (board == null) {
Sidebar sidebar = this.get(player);
if (sidebar == null)
continue;

sidebar.setTicks(sidebar.getTicks() + 1);
if (sidebar.getTicks() < 20)
continue;
}

SidebarInfo entry = this.findAdapter(player);
if (entry == null) {
board.remove();
sidebar.remove();
continue;
}

board.setTitle(entry.getTitle());

if (entry.getLines() == null || entry.getLines().isEmpty()) {
board.remove();
sidebar.remove();
} else {
board.setLines(entry.getLines());
sidebar.setRemoved(false);
sidebar.setTitle(entry.getTitle());
sidebar.setLines(entry.getLines());
}
}
}
Expand Down
Loading