Skip to content

Commit

Permalink
fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei1058 committed Oct 14, 2023
1 parent 74a8ca1 commit 864db17
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,19 @@ public interface ISidebar {
*
* @param player format given player on current holder's sidebar.
* @param skipStateCheck will skip checking if tab formatting is disabled.
* @param spectator when you already know the player is a spectator. E.g. on join. Null will let the plugin whether the player is spectator or not.
*/
void giveUpdateTabFormat(@NotNull Player player, boolean skipStateCheck);
void giveUpdateTabFormat(@NotNull Player player, boolean skipStateCheck, @Nullable Boolean spectator);

/**
* Will update tab prefix and suffix for the given player on current sidebar.
*
* @param player format given player on current holder's sidebar.
* @param skipStateCheck will skip checking if tab formatting is disabled.
*/
default void giveUpdateTabFormat(@NotNull Player player, boolean skipStateCheck) {
giveUpdateTabFormat(player, skipStateCheck, null);
}


/**
Expand Down
18 changes: 9 additions & 9 deletions bedwars-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,55 +242,55 @@
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-base</artifactId>
<version>23.10-SNAPSHOT</version>
<version>23.10.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_8_R3</artifactId>
<version>23.10-SNAPSHOT</version>
<version>23.10.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_12_R1</artifactId>
<version>23.10-SNAPSHOT</version>
<version>23.10.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_16_R1</artifactId>
<version>23.10-SNAPSHOT</version>
<version>23.10.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_17_R1</artifactId>
<version>23.10-SNAPSHOT</version>
<version>23.10.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_18_R2</artifactId>
<version>23.10-SNAPSHOT</version>
<version>23.10.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_19_R2</artifactId>
<version>23.10-SNAPSHOT</version>
<version>23.10.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_19_R3</artifactId>
<version>23.10-SNAPSHOT</version>
<version>23.10.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.andrei1058.spigot.sidebar</groupId>
<artifactId>sidebar-v1_20_R1</artifactId>
<version>23.10-SNAPSHOT</version>
<version>23.10.2-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- End of Sidebar LIB-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentLinkedQueue;

import static com.andrei1058.bedwars.BedWars.*;
import static com.andrei1058.bedwars.api.language.Language.getMsg;
Expand All @@ -43,7 +44,7 @@ public class BwSidebar implements ISidebar {
private final SimpleDateFormat dateFormat;
private final SimpleDateFormat nextEventDateFormat;

private final List<PlaceholderProvider> persistentProviders = new ArrayList<>();
private final ConcurrentLinkedQueue<PlaceholderProvider> persistentProviders = new ConcurrentLinkedQueue<>();

private final BwTabList tabList;

Expand Down Expand Up @@ -83,7 +84,7 @@ public void setContent(List<String> titleArray, List<String> lineArray, @Nullabl
setTopStatistics(null);
}

List<PlaceholderProvider> placeholders = this.getPlaceholders(this.getPlayer());
ConcurrentLinkedQueue<PlaceholderProvider> placeholders = this.getPlaceholders(this.getPlayer());
placeholders.addAll(this.persistentProviders);

// if it is the first time setting content we create the handle
Expand Down Expand Up @@ -235,8 +236,8 @@ public SidebarLine normalizeTitle(@Nullable List<String> titleArray) {
}

@Override
public void giveUpdateTabFormat(@NotNull Player player, boolean skipStateCheck) {
tabList.giveUpdateTabFormat(player, skipStateCheck);
public void giveUpdateTabFormat(@NotNull Player player, boolean skipStateCheck, @Nullable Boolean spectator) {
tabList.giveUpdateTabFormat(player, skipStateCheck, spectator);
}

@SuppressWarnings("removal")
Expand All @@ -252,8 +253,8 @@ public boolean isTabFormattingDisabled() {
* @return placeholders.
*/
@Contract(pure = true)
@NotNull LinkedList<PlaceholderProvider> getPlaceholders(@NotNull Player player) {
LinkedList<PlaceholderProvider> providers = new LinkedList<>();
@NotNull ConcurrentLinkedQueue<PlaceholderProvider> getPlaceholders(@NotNull Player player) {
ConcurrentLinkedQueue<PlaceholderProvider> providers = new ConcurrentLinkedQueue<>();
providers.add(new PlaceholderProvider("{player}", player::getDisplayName));
providers.add(new PlaceholderProvider("{money}", () -> String.valueOf(getEconomy().getMoney(player))));
providers.add(new PlaceholderProvider("{playerName}", player::getCustomName));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ void handlePlayerList() {
if (null == lobby) {
return;
}
lobby.getPlayers().forEach(inLobby -> giveUpdateTabFormat(inLobby, true));
lobby.getPlayers().forEach(inLobby -> giveUpdateTabFormat(inLobby, true, null));
}
return;
}

handleHealthIcon();

sidebar.getArena().getPlayers().forEach(playing -> giveUpdateTabFormat(playing, true));
sidebar.getArena().getSpectators().forEach(spectating -> giveUpdateTabFormat(spectating, true));
sidebar.getArena().getPlayers().forEach(playing -> giveUpdateTabFormat(playing, true, null));
sidebar.getArena().getSpectators().forEach(spectating -> giveUpdateTabFormat(spectating, true, null));
}

public void handleHealthIcon() {
Expand Down Expand Up @@ -196,7 +196,7 @@ public boolean isTabFormattingDisabled() {
* Will remove existing tab and give a new one based on game conditions list like spectator, team red, etc.
* Will handle invisibility potion as well.
*/
public void giveUpdateTabFormat(@NotNull Player player, boolean skipStateCheck) {
public void giveUpdateTabFormat(@NotNull Player player, boolean skipStateCheck, @Nullable Boolean spectator) {
// if sidebar was not created
if (sidebar.getHandle() == null) {
return;
Expand Down Expand Up @@ -236,7 +236,7 @@ public void giveUpdateTabFormat(@NotNull Player player, boolean skipStateCheck)
}

// in-game tab has a special treatment
if (arena.isSpectator(player)) {
if (arena.isSpectator(player) || (spectator != null && spectator)) {

// if has been eliminated from a team
ITeam exTeam = arena.getExTeam(player.getUniqueId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void reJoin(@NotNull PlayerReJoinEvent e) {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void arenaJoin(@NotNull PlayerJoinArenaEvent e) {
// add player to scoreboard tab list
SidebarService.getInstance().handleJoin(e.getArena(), e.getPlayer());
SidebarService.getInstance().handleJoin(e.getArena(), e.getPlayer(), e.isSpectator());
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ public void handleReJoin(IArena arena, Player player) {
});
}

public void handleJoin(IArena arena, Player player) {
public void handleJoin(IArena arena, Player player, @Nullable Boolean spectator) {
this.sidebars.forEach((k, v) -> {
if (null != v.getArena() && v.getArena().equals(arena)) {
if (!v.getPlayer().equals(player)) {
v.giveUpdateTabFormat(player, false);
v.giveUpdateTabFormat(player, false, spectator);
}
}
});
Expand Down

0 comments on commit 864db17

Please sign in to comment.