-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main'
- Loading branch information
Showing
49 changed files
with
1,597 additions
and
675 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
api/src/main/java/net/megavex/scoreboardlibrary/api/noop/NoopObjectiveManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package net.megavex.scoreboardlibrary.api.noop; | ||
|
||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveDisplaySlot; | ||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveManager; | ||
import net.megavex.scoreboardlibrary.api.objective.ScoreboardObjective; | ||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.*; | ||
|
||
class NoopObjectiveManager implements ObjectiveManager { | ||
private final Map<String, ScoreboardObjective> objectives = new HashMap<>(); | ||
private final Map<ObjectiveDisplaySlot, ScoreboardObjective> displaySlots = new HashMap<>(); | ||
private final Set<Player> players = new HashSet<>(); | ||
private boolean isClosed = true; | ||
|
||
@Override | ||
public @NotNull ScoreboardObjective create(@NotNull String name) { | ||
return objectives.computeIfAbsent(name, i -> null); | ||
} | ||
|
||
@Override | ||
public void remove(@NotNull ScoreboardObjective objective) { | ||
objectives.values().remove(objective); | ||
} | ||
|
||
@Override | ||
public void display(@NotNull ObjectiveDisplaySlot displaySlot, @NotNull ScoreboardObjective objective) { | ||
displaySlots.put(displaySlot, objective); | ||
} | ||
|
||
@Override | ||
public @NotNull Collection<Player> players() { | ||
return Collections.unmodifiableSet(players); | ||
} | ||
|
||
@Override | ||
public boolean addPlayer(@NotNull Player player) { | ||
return players.add(player); | ||
} | ||
|
||
@Override | ||
public boolean removePlayer(@NotNull Player player) { | ||
return players.remove(player); | ||
} | ||
|
||
@Override | ||
public void close() { | ||
isClosed = true; | ||
} | ||
|
||
@Override | ||
public boolean closed() { | ||
return isClosed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
api/src/main/java/net/megavex/scoreboardlibrary/api/noop/NoopScoreboardObjective.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package net.megavex.scoreboardlibrary.api.noop; | ||
|
||
import net.kyori.adventure.text.Component; | ||
import net.megavex.scoreboardlibrary.api.objective.ObjectiveRenderType; | ||
import net.megavex.scoreboardlibrary.api.objective.ScoreboardObjective; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class NoopScoreboardObjective implements ScoreboardObjective { | ||
private final Map<String, Integer> scores = new HashMap<>(); | ||
private Component value; | ||
private ObjectiveRenderType renderType; | ||
|
||
@Override | ||
public @NotNull Component value() { | ||
return value; | ||
} | ||
|
||
@Override | ||
public @NotNull ScoreboardObjective value(@NotNull Component value) { | ||
this.value = value; | ||
return this; | ||
} | ||
|
||
@Override | ||
public @NotNull ObjectiveRenderType renderType() { | ||
return renderType; | ||
} | ||
|
||
@Override | ||
public @NotNull ScoreboardObjective renderType(@NotNull ObjectiveRenderType renderType) { | ||
this.renderType = renderType; | ||
return this; | ||
} | ||
|
||
@Override | ||
public Integer score(@NotNull String entry) { | ||
return scores.get(entry); | ||
} | ||
|
||
@Override | ||
public @NotNull ScoreboardObjective score(@NotNull String entry, int score) { | ||
scores.put(entry, score); | ||
return this; | ||
} | ||
|
||
@Override | ||
public @NotNull ScoreboardObjective removeScore(@NotNull String entry) { | ||
scores.remove(entry); | ||
return this; | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
api/src/main/java/net/megavex/scoreboardlibrary/api/objective/ObjectiveDisplaySlot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package net.megavex.scoreboardlibrary.api.objective; | ||
|
||
import com.google.common.base.Preconditions; | ||
import net.kyori.adventure.text.format.NamedTextColor; | ||
import org.jetbrains.annotations.ApiStatus; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
/** | ||
* Represents all valid display slots that objectives can be shown in. | ||
* | ||
* @see <a href="https://minecraft.wiki/w/Scoreboard#Display_slots">Minecraft Wiki</a> | ||
*/ | ||
@ApiStatus.NonExtendable | ||
public interface ObjectiveDisplaySlot { | ||
static @NotNull PlayerList playerList() { | ||
return PlayerList.INSTANCE; | ||
} | ||
|
||
static @NotNull Sidebar sidebar() { | ||
return Sidebar.INSTANCE; | ||
} | ||
|
||
static @NotNull BelowName belowName() { | ||
return BelowName.INSTANCE; | ||
} | ||
|
||
static @NotNull TeamSidebar teamSidebar(@NotNull NamedTextColor teamColor) { | ||
Preconditions.checkNotNull(teamColor); | ||
return new TeamSidebar(teamColor); | ||
} | ||
|
||
class PlayerList implements ObjectiveDisplaySlot { | ||
private static final PlayerList INSTANCE = new PlayerList(); | ||
|
||
private PlayerList() { | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "PlayerList"; | ||
} | ||
} | ||
|
||
class Sidebar implements ObjectiveDisplaySlot { | ||
private static final Sidebar INSTANCE = new Sidebar(); | ||
|
||
private Sidebar() { | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Sidebar"; | ||
} | ||
} | ||
|
||
class BelowName implements ObjectiveDisplaySlot { | ||
private static final BelowName INSTANCE = new BelowName(); | ||
|
||
private BelowName() { | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BelowName"; | ||
} | ||
} | ||
|
||
class TeamSidebar implements ObjectiveDisplaySlot { | ||
private final NamedTextColor teamColor; | ||
|
||
private TeamSidebar(@NotNull NamedTextColor teamColor) { | ||
this.teamColor = teamColor; | ||
} | ||
|
||
public @NotNull NamedTextColor teamColor() { | ||
return teamColor; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
TeamSidebar that = (TeamSidebar) o; | ||
return teamColor.equals(that.teamColor); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return teamColor.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "TeamSidebar{teamColor=" + teamColor + "}"; | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
api/src/main/java/net/megavex/scoreboardlibrary/api/objective/ObjectiveManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package net.megavex.scoreboardlibrary.api.objective; | ||
|
||
import org.bukkit.entity.Player; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Collection; | ||
|
||
/** | ||
* Manages a group of {@link ScoreboardObjective}s. | ||
* Note: this class is not thread-safe. | ||
*/ | ||
public interface ObjectiveManager { | ||
/** | ||
* Creates an objective | ||
* | ||
* @param name Name of the objective | ||
* @return A newly created objective, or an existing one if the name was already registered | ||
*/ | ||
@NotNull ScoreboardObjective create(@NotNull String name); | ||
|
||
/** | ||
* Removes an objective. | ||
* | ||
* @param objective Objective to remove | ||
*/ | ||
void remove(@NotNull ScoreboardObjective objective); | ||
|
||
/** | ||
* Updates the objective shown at a display slot | ||
* | ||
* @param displaySlot Display slot value | ||
* @param objective Objective to display at that slot | ||
*/ | ||
void display(@NotNull ObjectiveDisplaySlot displaySlot, @NotNull ScoreboardObjective objective); | ||
|
||
/** | ||
* @return Players in this ObjectiveManager | ||
*/ | ||
@NotNull Collection<Player> players(); | ||
|
||
/** | ||
* Adds a player to this ObjectiveManager | ||
* | ||
* @param player Player to add to ObjectiveManager | ||
* @return Whether the player was added | ||
*/ | ||
boolean addPlayer(@NotNull Player player); | ||
|
||
/** | ||
* Adds multiple players to this ObjectiveManager | ||
* | ||
* @param players Players to add | ||
*/ | ||
default void addPlayers(@NotNull Collection<Player> players) { | ||
for (Player player : players) { | ||
addPlayer(player); | ||
} | ||
} | ||
|
||
/** | ||
* Removes a player from this ObjectiveManager | ||
* | ||
* @param player Player to remove | ||
* @return Whether the player was removed | ||
*/ | ||
boolean removePlayer(@NotNull Player player); | ||
|
||
/** | ||
* Removes multiple players to this ObjectiveManager | ||
* | ||
* @param players Players to add | ||
*/ | ||
default void removePlayers(@NotNull Collection<Player> players) { | ||
for (Player player : players) { | ||
removePlayer(player); | ||
} | ||
} | ||
|
||
/** | ||
* Closes this ObjectiveManager. | ||
*/ | ||
void close(); | ||
|
||
/** | ||
* @return Whether this ObjectiveManager is closed | ||
*/ | ||
boolean closed(); | ||
} |
9 changes: 9 additions & 0 deletions
9
api/src/main/java/net/megavex/scoreboardlibrary/api/objective/ObjectiveRenderType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package net.megavex.scoreboardlibrary.api.objective; | ||
|
||
/** | ||
* Represents all valid render types of an objective. | ||
*/ | ||
public enum ObjectiveRenderType { | ||
INTEGER, | ||
HEARTS | ||
} |
Oops, something went wrong.