Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/dev/1.20' into api-11
Browse files Browse the repository at this point in the history
  • Loading branch information
ImMorpheus committed Feb 24, 2024
2 parents 92619ec + ef584a5 commit 7f5b7d0
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.spongepowered.api.Engine;
import org.spongepowered.api.ResourceKey;
import org.spongepowered.api.event.GenericEvent;
import org.spongepowered.api.registry.DefaultedRegistryValue;
import org.spongepowered.api.registry.RegistryType;

public interface RegisterRegistryValueEvent extends LifecycleEvent {
Expand All @@ -38,6 +39,11 @@ interface RegistryStep<T> {
RegistryStep<T> register(ResourceKey key, T value);
}

interface BuiltIn<T extends DefaultedRegistryValue> extends LifecycleEvent {

RegistryStep<T> registry(RegistryType<T> registryType);
}

interface GameScoped extends RegisterRegistryValueEvent {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
* <p>All registrations through the API will generate into the Vanilla data pack system</p>
*/
public interface RecipeRegistration extends DataPackEntry<RecipeRegistration> {

Recipe recipe();
}
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ public final class RegistryTypes {

public static final DefaultedRegistryType<StructureType> STRUCTURE_TYPE = RegistryTypes.minecraftKeyInGame("worldgen/structure_type");

public static final DefaultedRegistryType<Trigger<@NonNull ?>> TRIGGER = RegistryTypes.minecraftKeyInGame("trigger_type");

public static final DefaultedRegistryType<VillagerType> VILLAGER_TYPE = RegistryTypes.minecraftKeyInGame("villager_type");

public static final DefaultedRegistryType<WorldType> WORLD_TYPE = RegistryTypes.minecraftKeyInServer("dimension_type");
Expand Down Expand Up @@ -490,8 +492,6 @@ public final class RegistryTypes {

public static final DefaultedRegistryType<TransactionType> TRANSACTION_TYPE = RegistryTypes.spongeKeyInGame("transaction_type");

public static final DefaultedRegistryType<Trigger<@NonNull ?>> TRIGGER = RegistryTypes.spongeKeyInGame("trigger");

public static final DefaultedRegistryType<TropicalFishShape> TROPICAL_FISH_SHAPE = RegistryTypes.spongeKeyInGame("tropical_fish_shape");

public static final DefaultedRegistryType<Tilt> TILT = RegistryTypes.spongeKeyInGame("tilt");
Expand Down
34 changes: 33 additions & 1 deletion src/main/java/org/spongepowered/api/scoreboard/Score.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
package org.spongepowered.api.scoreboard;

import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.api.scoreboard.objective.Objective;

import java.util.Optional;
import java.util.Set;

/**
Expand All @@ -39,7 +41,7 @@ public interface Score {
*
* @return The name of this score
*/
Component name();
String name();

/**
* Gets the current score value.
Expand Down Expand Up @@ -69,6 +71,36 @@ public interface Score {
*/
void setLocked(boolean locked);

// TODO javadocs

/**
* Sets this score display
*
* @param display the display
*/
void setDisplay(@Nullable Component display);

/**
* Returns this score display
*
* @return the display
*/
Optional<Component> display();

/**
* Sets the score number format
*
* @param format the number format
*/
void setNumberFormat(@Nullable ScoreFormat format);

/**
* Returns the score number format
*
* @return the number format
*/
Optional<ScoreFormat> numberFormat();

/**
* Returns a {@link Set} of parent {@link Objective}s this {@link Score} is
* registered to.
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/org/spongepowered/api/scoreboard/ScoreFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package org.spongepowered.api.scoreboard;

import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.Style;
import org.spongepowered.api.Sponge;

/**
* A Score Number Format
*/
public interface ScoreFormat {

static ScoreFormat blank() {
return Sponge.game().factoryProvider().provide(Factory.class).blank();
}

static ScoreFormat fixed(Component component) {
return Sponge.game().factoryProvider().provide(Factory.class).fixed(component);
}

static ScoreFormat styled(Style style) {
return Sponge.game().factoryProvider().provide(Factory.class).styled(style);
}

interface Factory {

/**
* Blank score formatting.
*
* @return the format
*/
ScoreFormat blank();

/**
* Fixed score formatting
*
* @param component the fixed component
*
* @return the format
*/
ScoreFormat fixed(Component component);

/**
* Styled number formatting
*
* @param style the style
*
* @return the format
*/
ScoreFormat styled(Style style);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,15 @@ default Set<Objective> objectivesByCriterion(Supplier<? extends Criterion> crite
* @param name The name whose scores are being retrieved
* @return A set of all scores for the name
*/
Set<Score> scores(Component name);
Set<Score> scores(String name);

/**
* Removes all scores with the specified name on this scoreboard,
* across all objectives.
*
* @param name The name to remove all scores for
*/
void removeScores(Component name);
void removeScores(String name);

/**
* Gets a {@link Team} by name on this scoreboard.
Expand Down
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 Down Expand Up @@ -103,15 +105,33 @@ static Builder builder() {
*
* @return The set of {@link Score}s for this objective
*/
Map<Component, Score> scores();
Map<String, Score> scores();

/**
* Returns whether this objective has a {@link Score} with the given name.
*
* @param name The name of the {@link Score} to check for.
* @return Whether this objective has a {@link Score} with the given name.
*/
boolean hasScore(Component name);
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 @@ -125,9 +145,9 @@ static Builder builder() {
* 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 Component name) {
default Optional<Score> findScore(final String name) {
if (!this.hasScore(name)) {
return Optional.empty();
}
Expand All @@ -140,25 +160,87 @@ default Optional<Score> findScore(final Component 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(Component 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(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(Component name);
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 7f5b7d0

Please sign in to comment.