diff options
Diffstat (limited to 'spark-common/src')
6 files changed, 79 insertions, 8 deletions
diff --git a/spark-common/src/main/java/me/lucko/spark/common/platform/world/AsyncWorldInfoProvider.java b/spark-common/src/main/java/me/lucko/spark/common/platform/world/AsyncWorldInfoProvider.java index 0f48b2e..707097a 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/platform/world/AsyncWorldInfoProvider.java +++ b/spark-common/src/main/java/me/lucko/spark/common/platform/world/AsyncWorldInfoProvider.java @@ -23,6 +23,7 @@ package me.lucko.spark.common.platform.world; import me.lucko.spark.common.SparkPlatform; import me.lucko.spark.common.SparkPlugin; +import java.util.Collection; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; @@ -84,6 +85,10 @@ public class AsyncWorldInfoProvider { return async(WorldInfoProvider::pollGameRules); } + public CompletableFuture<Collection<WorldInfoProvider.DataPackInfo>> pollDataPacks() { + return async(WorldInfoProvider::pollDataPacks); + } + public WorldInfoProvider.CountsResult getCounts() { return get(pollCounts()); } @@ -95,4 +100,8 @@ public class AsyncWorldInfoProvider { public WorldInfoProvider.GameRulesResult getGameRules() { return get(pollGameRules()); } + + public Collection<WorldInfoProvider.DataPackInfo> getDataPacks() { + return get(pollDataPacks()); + } } diff --git a/spark-common/src/main/java/me/lucko/spark/common/platform/world/WorldInfoProvider.java b/spark-common/src/main/java/me/lucko/spark/common/platform/world/WorldInfoProvider.java index e360ea4..457f8c9 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/platform/world/WorldInfoProvider.java +++ b/spark-common/src/main/java/me/lucko/spark/common/platform/world/WorldInfoProvider.java @@ -20,6 +20,7 @@ package me.lucko.spark.common.platform.world; +import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -44,6 +45,11 @@ public interface WorldInfoProvider { public GameRulesResult pollGameRules() { return null; } + + @Override + public Collection<DataPackInfo> pollDataPacks() { + return null; + } }; /** @@ -67,6 +73,13 @@ public interface WorldInfoProvider { */ GameRulesResult pollGameRules(); + /** + * Polls for data packs. + * + * @return the data packs + */ + Collection<DataPackInfo> pollDataPacks(); + default boolean mustCallSync() { return true; } @@ -146,4 +159,28 @@ public interface WorldInfoProvider { } } + final class DataPackInfo { + private final String name; + private final String description; + private final String source; + + public DataPackInfo(String name, String description, String source) { + this.name = name; + this.description = description; + this.source = source; + } + + public String name() { + return this.name; + } + + public String description() { + return this.description; + } + + public String source() { + return this.source; + } + } + } diff --git a/spark-common/src/main/java/me/lucko/spark/common/platform/world/WorldStatisticsProvider.java b/spark-common/src/main/java/me/lucko/spark/common/platform/world/WorldStatisticsProvider.java index 5d00037..58183a0 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/platform/world/WorldStatisticsProvider.java +++ b/spark-common/src/main/java/me/lucko/spark/common/platform/world/WorldStatisticsProvider.java @@ -23,6 +23,7 @@ package me.lucko.spark.common.platform.world; import me.lucko.spark.proto.SparkProtos.WorldStatistics; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; @@ -80,6 +81,16 @@ public class WorldStatisticsProvider { )); } + Collection<WorldInfoProvider.DataPackInfo> dataPacks = this.provider.getDataPacks(); + if (dataPacks != null) { + dataPacks.forEach(dataPack -> stats.addDataPacks(WorldStatistics.DataPack.newBuilder() + .setName(dataPack.name()) + .setDescription(dataPack.description()) + .setSource(dataPack.source()) + .build() + )); + } + return stats.build(); } diff --git a/spark-common/src/main/java/me/lucko/spark/common/sampler/source/SourceMetadata.java b/spark-common/src/main/java/me/lucko/spark/common/sampler/source/SourceMetadata.java index 9410b80..d023a68 100644 --- a/spark-common/src/main/java/me/lucko/spark/common/sampler/source/SourceMetadata.java +++ b/spark-common/src/main/java/me/lucko/spark/common/sampler/source/SourceMetadata.java @@ -33,15 +33,16 @@ import java.util.function.Function; */ public class SourceMetadata { - public static <T> List<SourceMetadata> gather(Collection<T> sources, Function<? super T, String> nameFunction, Function<? super T, String> versionFunction, Function<? super T, String> authorFunction) { + public static <T> List<SourceMetadata> gather(Collection<T> sources, Function<? super T, String> name, Function<? super T, String> version, Function<? super T, String> author, Function<? super T, String> description) { ImmutableList.Builder<SourceMetadata> builder = ImmutableList.builder(); for (T source : sources) { - String name = nameFunction.apply(source); - String version = versionFunction.apply(source); - String author = authorFunction.apply(source); - - SourceMetadata metadata = new SourceMetadata(name, version, author); + SourceMetadata metadata = new SourceMetadata( + name.apply(source), + version.apply(source), + author.apply(source), + description.apply(source) + ); builder.add(metadata); } @@ -51,11 +52,13 @@ public class SourceMetadata { private final String name; private final String version; private final String author; + private final String description; - public SourceMetadata(String name, String version, String author) { + public SourceMetadata(String name, String version, String author, String description) { this.name = name; this.version = version; this.author = author; + this.description = description; } public String getName() { @@ -78,6 +81,9 @@ public class SourceMetadata { if (this.author != null) { builder.setAuthor(this.author); } + if (this.description != null) { + builder.setDescription(this.description); + } return builder.build(); } diff --git a/spark-common/src/main/proto/spark/spark.proto b/spark-common/src/main/proto/spark/spark.proto index 779b3c6..f8d7988 100644 --- a/spark-common/src/main/proto/spark/spark.proto +++ b/spark-common/src/main/proto/spark/spark.proto @@ -158,6 +158,7 @@ message WorldStatistics { map<string, int32> entity_counts = 2; repeated World worlds = 3; repeated GameRule game_rules = 4; + repeated DataPack data_packs = 5; message World { string name = 1; @@ -182,6 +183,12 @@ message WorldStatistics { string default_value = 2; map<string, string> world_values = 3; } + + message DataPack { + string name = 1; + string description = 2; + string source = 3; + } } message WindowStatistics { @@ -227,6 +234,7 @@ message PluginOrModMetadata { string name = 1; string version = 2; string author = 3; + string description = 4; } message HealthData { diff --git a/spark-common/src/test/java/me/lucko/spark/common/sampler/node/NodeTest.java b/spark-common/src/test/java/me/lucko/spark/common/sampler/node/NodeTest.java index f1534a8..52477ce 100644 --- a/spark-common/src/test/java/me/lucko/spark/common/sampler/node/NodeTest.java +++ b/spark-common/src/test/java/me/lucko/spark/common/sampler/node/NodeTest.java @@ -94,7 +94,7 @@ public class NodeTest { } @Test - public void testToProto() { + public void testExport() { ThreadNode threadNode = new ThreadNode("Test Thread"); threadNode.log(STACK_TRACE_DESCRIBER, STACK_1, TimeUnit.SECONDS.toMicros(1), WINDOW); threadNode.log(STACK_TRACE_DESCRIBER, STACK_1, TimeUnit.SECONDS.toMicros(1), WINDOW + 1); |