#1261: Expand DataPack API with 1.20.2 pack version methods

By: Doc <nachito94@msn.com>
This commit is contained in:
CraftBukkit/Spigot 2023-09-27 07:10:02 +10:00
parent 3b107a0717
commit 1d153bf51a
2 changed files with 23 additions and 3 deletions

View File

@ -32,7 +32,7 @@ public class CraftFeatureFlag implements FeatureFlag {
@Override
public String toString() {
return "CraftDataPack{key=" + this.getKey() + ",keyUniverse=" + this.getHandle().universe.toString() + "}";
return "CraftFeatureFlag{key=" + this.getKey() + ",keyUniverse=" + this.getHandle().universe.toString() + "}";
}
public static Set<CraftFeatureFlag> getFromNMS(FeatureFlagSet featureFlagSet) {

View File

@ -1,9 +1,13 @@
package org.bukkit.craftbukkit.packs;
import java.io.IOException;
import java.util.Set;
import java.util.stream.Collectors;
import net.minecraft.server.packs.IResourcePack;
import net.minecraft.server.packs.metadata.pack.ResourcePackInfo;
import net.minecraft.server.packs.repository.PackSource;
import net.minecraft.server.packs.repository.ResourcePackLoader;
import net.minecraft.util.InclusiveRange;
import org.bukkit.Bukkit;
import org.bukkit.FeatureFlag;
import org.bukkit.NamespacedKey;
@ -15,9 +19,15 @@ import org.bukkit.packs.DataPack;
public class CraftDataPack implements DataPack {
private final ResourcePackLoader handle;
private final ResourcePackInfo resourcePackInfo;
public CraftDataPack(ResourcePackLoader handler) {
this.handle = handler;
try (IResourcePack iresourcepack = this.handle.resources.openPrimary(this.handle.getId())) {
this.resourcePackInfo = iresourcepack.getMetadataSection(ResourcePackInfo.TYPE);
} catch (IOException e) { // This is already called in NMS then if in NMS not happen is secure this not throw here
throw new RuntimeException(e);
}
}
public ResourcePackLoader getHandle() {
@ -40,7 +50,17 @@ public class CraftDataPack implements DataPack {
@Override
public int getPackFormat() {
return 0;
return this.resourcePackInfo.packFormat();
}
@Override
public int getMinSupportedPackFormat() {
return this.resourcePackInfo.supportedFormats().orElse(new InclusiveRange<>(this.getPackFormat())).minInclusive();
}
@Override
public int getMaxSupportedPackFormat() {
return this.resourcePackInfo.supportedFormats().orElse(new InclusiveRange<>(this.getPackFormat())).maxInclusive();
}
@Override
@ -89,6 +109,6 @@ public class CraftDataPack implements DataPack {
@Override
public String toString() {
String requestedFeatures = getRequestedFeatures().stream().map(featureFlag -> featureFlag.getKey().toString()).collect(Collectors.joining(","));
return "CraftDataPack{rawId=" + this.getRawId() + ",id=" + this.getKey() + ",title=" + this.getTitle() + ",description=" + this.getDescription() + ",packformat=" + this.getPackFormat() + ",compatibility=" + this.getCompatibility() + ",source=" + this.getSource() + ",enabled=" + this.isEnabled() + ",requestedFeatures=[" + requestedFeatures + "]}";
return "CraftDataPack{rawId=" + this.getRawId() + ",id=" + this.getKey() + ",title=" + this.getTitle() + ",description=" + this.getDescription() + ",packformat=" + this.getPackFormat() + ",minSupportedPackFormat=" + this.getMinSupportedPackFormat() + ",maxSupportedPackFormat=" + this.getMaxSupportedPackFormat() + ",compatibility=" + this.getCompatibility() + ",source=" + this.getSource() + ",enabled=" + this.isEnabled() + ",requestedFeatures=[" + requestedFeatures + "]}";
}
}