aboutsummaryrefslogtreecommitdiff
path: root/spark-fabric/src
diff options
context:
space:
mode:
authorLuck <git@lucko.me>2024-09-05 20:37:25 +0100
committerLuck <git@lucko.me>2024-09-05 20:37:37 +0100
commit8986c711cef445650ceef832a3ac999819cd06a0 (patch)
tree3a53b128d88ad5f3028c0651e1c2b03a0cbd5288 /spark-fabric/src
parented33fd51cefabfd04df4376dc2118f31ce93a90d (diff)
downloadspark-8986c711cef445650ceef832a3ac999819cd06a0.tar.gz
spark-8986c711cef445650ceef832a3ac999819cd06a0.tar.bz2
spark-8986c711cef445650ceef832a3ac999819cd06a0.zip
Include datapacks info in sampler proto
Diffstat (limited to 'spark-fabric/src')
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java73
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/FabricWorldInfoProvider.java41
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java7
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java7
-rw-r--r--spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java3
5 files changed, 43 insertions, 88 deletions
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java
deleted file mode 100644
index a6f70a6..0000000
--- a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricExtraMetadataProvider.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * This file is part of spark.
- *
- * Copyright (c) lucko (Luck) <luck@lucko.me>
- * Copyright (c) contributors
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-package me.lucko.spark.fabric;
-
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import me.lucko.spark.common.platform.MetadataProvider;
-import net.minecraft.resource.ResourcePackManager;
-import net.minecraft.resource.ResourcePackProfile;
-import net.minecraft.resource.ResourcePackSource;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-public class FabricExtraMetadataProvider implements MetadataProvider {
-
- private final ResourcePackManager resourcePackManager;
-
- public FabricExtraMetadataProvider(ResourcePackManager resourcePackManager) {
- this.resourcePackManager = resourcePackManager;
- }
-
- @Override
- public Map<String, JsonElement> get() {
- Map<String, JsonElement> metadata = new LinkedHashMap<>();
- metadata.put("datapacks", datapackMetadata());
- return metadata;
- }
-
- private JsonElement datapackMetadata() {
- JsonObject datapacks = new JsonObject();
- for (ResourcePackProfile profile : this.resourcePackManager.getEnabledProfiles()) {
- JsonObject obj = new JsonObject();
- obj.addProperty("name", profile.getDisplayName().getString());
- obj.addProperty("description", profile.getDescription().getString());
- obj.addProperty("source", resourcePackSource(profile.getSource()));
- datapacks.add(profile.getId(), obj);
- }
- return datapacks;
- }
-
- private static String resourcePackSource(ResourcePackSource source) {
- if (source == ResourcePackSource.NONE) {
- return "none";
- } else if (source == ResourcePackSource.BUILTIN) {
- return "builtin";
- } else if (source == ResourcePackSource.WORLD) {
- return "world";
- } else if (source == ResourcePackSource.SERVER) {
- return "server";
- } else {
- return "unknown";
- }
- }
-}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricWorldInfoProvider.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricWorldInfoProvider.java
index 5486cc2..514be5b 100644
--- a/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricWorldInfoProvider.java
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/FabricWorldInfoProvider.java
@@ -34,6 +34,8 @@ import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
+import net.minecraft.resource.ResourcePackManager;
+import net.minecraft.resource.ResourcePackSource;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerEntityManager;
import net.minecraft.server.world.ServerWorld;
@@ -44,11 +46,40 @@ import net.minecraft.world.entity.EntityIndex;
import net.minecraft.world.entity.EntityLookup;
import java.lang.reflect.Method;
+import java.util.Collection;
import java.util.HashMap;
import java.util.List;
+import java.util.stream.Collectors;
public abstract class FabricWorldInfoProvider implements WorldInfoProvider {
+ protected abstract ResourcePackManager getResourcePackManager();
+
+ @Override
+ public Collection<DataPackInfo> pollDataPacks() {
+ return getResourcePackManager().getEnabledProfiles().stream()
+ .map(pack -> new DataPackInfo(
+ pack.getId(),
+ pack.getDescription().getString(),
+ resourcePackSource(pack.getSource())
+ ))
+ .collect(Collectors.toList());
+ }
+
+ private static String resourcePackSource(ResourcePackSource source) {
+ if (source == ResourcePackSource.NONE) {
+ return "none";
+ } else if (source == ResourcePackSource.BUILTIN) {
+ return "builtin";
+ } else if (source == ResourcePackSource.WORLD) {
+ return "world";
+ } else if (source == ResourcePackSource.SERVER) {
+ return "server";
+ } else {
+ return "unknown";
+ }
+ }
+
public static final class Server extends FabricWorldInfoProvider {
private final MinecraftServer server;
@@ -118,6 +149,11 @@ public abstract class FabricWorldInfoProvider implements WorldInfoProvider {
});
return data;
}
+
+ @Override
+ protected ResourcePackManager getResourcePackManager() {
+ return this.server.getDataPackManager();
+ }
}
public static final class Client extends FabricWorldInfoProvider {
@@ -195,6 +231,11 @@ public abstract class FabricWorldInfoProvider implements WorldInfoProvider {
return data;
}
+
+ @Override
+ protected ResourcePackManager getResourcePackManager() {
+ return this.client.getResourcePackManager();
+ }
}
static final class FabricChunkInfo extends AbstractChunkInfo<EntityType<?>> {
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java
index 0a17bd7..d80e026 100644
--- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricClientSparkPlugin.java
@@ -27,14 +27,12 @@ import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.SuggestionProvider;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
-import me.lucko.spark.common.platform.MetadataProvider;
import me.lucko.spark.common.platform.PlatformInfo;
import me.lucko.spark.common.platform.world.WorldInfoProvider;
import me.lucko.spark.common.sampler.ThreadDumper;
import me.lucko.spark.common.tick.TickHook;
import me.lucko.spark.common.tick.TickReporter;
import me.lucko.spark.fabric.FabricCommandSender;
-import me.lucko.spark.fabric.FabricExtraMetadataProvider;
import me.lucko.spark.fabric.FabricPlatformInfo;
import me.lucko.spark.fabric.FabricSparkMod;
import me.lucko.spark.fabric.FabricTickHook;
@@ -138,11 +136,6 @@ public class FabricClientSparkPlugin extends FabricSparkPlugin implements Comman
}
@Override
- public MetadataProvider createExtraMetadataProvider() {
- return new FabricExtraMetadataProvider(this.minecraft.getResourcePackManager());
- }
-
- @Override
public WorldInfoProvider createWorldInfoProvider() {
return new FabricWorldInfoProvider.Client(this.minecraft);
}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java
index bd937af..04bbdf0 100644
--- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricServerSparkPlugin.java
@@ -29,7 +29,6 @@ import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import me.lucko.fabric.api.permissions.v0.Permissions;
import me.lucko.spark.common.monitor.ping.PlayerPingProvider;
-import me.lucko.spark.common.platform.MetadataProvider;
import me.lucko.spark.common.platform.PlatformInfo;
import me.lucko.spark.common.platform.serverconfig.ServerConfigProvider;
import me.lucko.spark.common.platform.world.WorldInfoProvider;
@@ -37,7 +36,6 @@ import me.lucko.spark.common.sampler.ThreadDumper;
import me.lucko.spark.common.tick.TickHook;
import me.lucko.spark.common.tick.TickReporter;
import me.lucko.spark.fabric.FabricCommandSender;
-import me.lucko.spark.fabric.FabricExtraMetadataProvider;
import me.lucko.spark.fabric.FabricPlatformInfo;
import me.lucko.spark.fabric.FabricPlayerPingProvider;
import me.lucko.spark.fabric.FabricServerConfigProvider;
@@ -170,11 +168,6 @@ public class FabricServerSparkPlugin extends FabricSparkPlugin implements Comman
}
@Override
- public MetadataProvider createExtraMetadataProvider() {
- return new FabricExtraMetadataProvider(this.server.getDataPackManager());
- }
-
- @Override
public WorldInfoProvider createWorldInfoProvider() {
return new FabricWorldInfoProvider.Server(this.server);
}
diff --git a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java
index 1569bf8..8f0c14d 100644
--- a/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java
+++ b/spark-fabric/src/main/java/me/lucko/spark/fabric/plugin/FabricSparkPlugin.java
@@ -120,7 +120,8 @@ public abstract class FabricSparkPlugin implements SparkPlugin {
mod -> mod.getMetadata().getVersion().getFriendlyString(),
mod -> mod.getMetadata().getAuthors().stream()
.map(Person::getName)
- .collect(Collectors.joining(", "))
+ .collect(Collectors.joining(", ")),
+ mod -> mod.getMetadata().getDescription()
);
}