mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-01 20:52:12 -07:00
Add keyStream() API to registries (#12479)
This commit is contained in:
@@ -525,6 +525,13 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
||||
*/
|
||||
Stream<T> stream();
|
||||
|
||||
/**
|
||||
* Returns a new stream, which contains all registry keys, which are registered to the registry.
|
||||
*
|
||||
* @return a stream of all registry keys
|
||||
*/
|
||||
Stream<NamespacedKey> keyStream();
|
||||
|
||||
/**
|
||||
* Attempts to match the registered object with the given key.
|
||||
* <p>
|
||||
@@ -591,6 +598,11 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
||||
return this.map.values().iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<NamespacedKey> keyStream() {
|
||||
return this.map.keySet().stream();
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
@Deprecated(since = "1.20.6", forRemoval = true)
|
||||
public Class<T> getType() {
|
||||
@@ -606,6 +618,11 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
|
||||
return StreamSupport.stream(this.spliterator(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<NamespacedKey> keyStream() {
|
||||
return stream().map(this::getKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return Iterables.size(this);
|
||||
|
@@ -49,6 +49,11 @@ public final class DelayedRegistry<T extends Keyed, R extends Registry<T>> imple
|
||||
return this.delegate().stream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<NamespacedKey> keyStream() {
|
||||
return this.delegate().keyStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return this.delegate().size();
|
||||
|
@@ -233,6 +233,12 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
|
||||
return this.minecraftRegistry.keySet().stream().map(minecraftKey -> this.get(CraftNamespacedKey.fromMinecraft(minecraftKey)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Stream<NamespacedKey> keyStream() {
|
||||
return this.minecraftRegistry.keySet().stream().map(CraftNamespacedKey::fromMinecraft);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return this.minecraftRegistry.size();
|
||||
|
Reference in New Issue
Block a user