Skip to content

Commit

Permalink
scoreboard scores for entity/gameprofile
Browse files Browse the repository at this point in the history
  • Loading branch information
Faithcaio committed Feb 11, 2024
1 parent 0b265ac commit 0bce6b8
Showing 1 changed file with 91 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

import net.kyori.adventure.text.Component;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.entity.Entity;
import org.spongepowered.api.profile.GameProfile;
import org.spongepowered.api.scoreboard.Score;
import org.spongepowered.api.scoreboard.Scoreboard;
import org.spongepowered.api.scoreboard.criteria.Criterion;
Expand All @@ -35,6 +37,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.Supplier;

/**
Expand Down Expand Up @@ -113,6 +116,24 @@ static Builder builder() {
*/
boolean hasScore(String name);


/**
* Returns whether this objective has a {@link Score} with the given entity.
*
* @param entity The entity of the {@link Score} to check for.
* @return Whether this objective has a {@link Score} with the given entity.
*/
boolean hasScore(Entity entity);


/**
* Returns whether this objective has a {@link Score} with the given profile.
*
* @param profile The profile of the {@link Score} to check for.
* @return Whether this objective has a {@link Score} with the given profile.
*/
boolean hasScore(GameProfile profile);

/**
* Adds the specified {@link Score} to this objective.
*
Expand All @@ -121,13 +142,11 @@ static Builder builder() {
*/
void addScore(Score score) throws IllegalArgumentException;

// TODO findScore for player/entity?

/**
* Gets an entry's {@link Score} for this objective, if it exists.
*
* @param name The name of the {@link Score} to get.
* @return The {@link Score} for te specified {@link Component}, if it exists.
* @return The {@link Score} for the specified name, if it exists.
*/
default Optional<Score> findScore(final String name) {
if (!this.hasScore(name)) {
Expand All @@ -142,25 +161,87 @@ default Optional<Score> findScore(final String name) {
* <p>If the {@link Score} does not exist, it will be created.</p>
*
* @param name The name of the {@link Score} to get
* @return The {@link Score} for the specified {@link Component}
* @return The {@link Score} for the specified name
*/
Score findOrCreateScore(String name);

/**
* Removes the specified {@link Score} from this objective, if present.
* Removes the {@link Score} with the specified name from this objective, if present.
*
* @param score The {@link Score} to remove
* @param name The name of the {@link Score} to remove.
* @return Whether the score existed on this objective
*/
boolean removeScore(Score score);
boolean removeScore(String name);

/**
* Removes the {@link Score} with the specified name from this objective, if present.
* Gets an entry's {@link Score} for this objective, if it exists.
*
* @param name The name of the {@link Score} to remove.
* @param entity The entity of the {@link Score} to get.
* @return The {@link Score} for the specified entity, if it exists.
*/
default Optional<Score> findScore(final Entity entity) {
if (!this.hasScore(entity)) {
return Optional.empty();
}
return Optional.of(this.findOrCreateScore(entity));
}

/**
* Gets an entry's {@link Score} for this objective.
*
* <p>If the {@link Score} does not exist, it will be created.</p>
*
* @param entity The name of the {@link Score} to get
* @return The {@link Score} for the specified entity
*/
Score findOrCreateScore(Entity entity);

/**
* Removes the {@link Score} with the specified entity from this objective, if present.
*
* @param entity The entity of the {@link Score} to remove.
* @return Whether the score existed on this objective
*/
boolean removeScore(String name);
boolean removeScore(Entity entity);

/**
* Gets an entry's {@link Score} for this objective, if it exists.
*
* @param profile The profile of the {@link Score} to get.
* @return The {@link Score} for the specified profile, if it exists.
*/
default Optional<Score> findScore(final GameProfile profile) {
if (!this.hasScore(profile)) {
return Optional.empty();
}
return Optional.of(this.findOrCreateScore(profile));
}

/**
* Gets an entry's {@link Score} for this objective.
*
* <p>If the {@link Score} does not exist, it will be created.</p>
*
* @param profile The profile of the {@link Score} to get
* @return The {@link Score} for the specified profile
*/
Score findOrCreateScore(GameProfile profile);

/**
* Removes the {@link Score} with the specified profile from this objective, if present.
*
* @param profile The profile of the {@link Score} to remove.
* @return Whether the score existed on this objective
*/
boolean removeScore(GameProfile profile);

/**
* Removes the specified {@link Score} from this objective, if present.
*
* @param score The {@link Score} to remove
* @return Whether the score existed on this objective
*/
boolean removeScore(Score score);

/**
* Returns a {@link Set} of parent {@link Scoreboard}s this
Expand Down

0 comments on commit 0bce6b8

Please sign in to comment.