1111import net .minecraft .gametest .framework .GameTestInstance ;
1212import net .minecraft .resources .FileToIdConverter ;
1313import net .minecraft .resources .ResourceKey ;
14- import net .minecraft .resources .ResourceLocation ;
14+ import net .minecraft .resources .Identifier ;
1515import net .minecraft .server .packs .resources .PreparableReloadListener ;
1616import net .minecraft .server .packs .resources .Resource ;
17+ import net .minecraft .server .permissions .LevelBasedPermissionSet ;
18+ import net .minecraft .server .permissions .PermissionSet ;
1719import org .jetbrains .annotations .NotNull ;
1820
1921import java .io .BufferedReader ;
2628import java .util .function .Consumer ;
2729
2830public class PackTestLibrary implements PreparableReloadListener {
29- public static final PackTestLibrary INSTANCE = new PackTestLibrary (null ,2 );
31+ public static final PackTestLibrary INSTANCE = new PackTestLibrary (null , LevelBasedPermissionSet . GAMEMASTER );
3032 private static final FileToIdConverter LISTER = new FileToIdConverter ("test" , ".mcfunction" );
3133
3234 private HolderGetter .Provider registries ;
33- private int permissionLevel ;
35+ private PermissionSet permissionSet ;
3436
35- public PackTestLibrary (HolderGetter .Provider registries , int permissionLevel ) {
37+ public PackTestLibrary (HolderGetter .Provider registries , PermissionSet permissionSet ) {
3638 this .registries = registries ;
37- this .permissionLevel = permissionLevel ;
39+ this .permissionSet = permissionSet ;
3840 }
3941
4042 public void setRegistries (HolderLookup .Provider registries ) {
4143 this .registries = registries ;
4244 }
4345
44- public void setPermissionLevel ( int permissionLevel ) {
45- this .permissionLevel = permissionLevel ;
46+ public void setPermissionSet ( PermissionSet permissionSet ) {
47+ this .permissionSet = permissionSet ;
4648 }
4749
4850 @ Override
4951 public @ NotNull CompletableFuture <Void > reload (PreparableReloadListener .SharedState sharedState , Executor executor1 , PreparableReloadListener .PreparationBarrier barrier , Executor executor2 ) {
50- CompletableFuture <Map <ResourceLocation , CompletableFuture <PackTestFunction >>> prep = CompletableFuture .supplyAsync (
52+ CompletableFuture <Map <Identifier , CompletableFuture <PackTestFunction >>> prep = CompletableFuture .supplyAsync (
5153 () -> LISTER .listMatchingResources (sharedState .resourceManager ()), executor1
5254 ).thenComposeAsync (map -> {
53- Map <ResourceLocation , CompletableFuture <PackTestFunction >> result = Maps .newHashMap ();
54- for (Map .Entry <ResourceLocation , Resource > entry : map .entrySet ()) {
55- ResourceLocation id = LISTER .fileToId (entry .getKey ());
55+ Map <Identifier , CompletableFuture <PackTestFunction >> result = Maps .newHashMap ();
56+ for (Map .Entry <Identifier , Resource > entry : map .entrySet ()) {
57+ Identifier id = LISTER .fileToId (entry .getKey ());
5658 result .put (id , CompletableFuture .supplyAsync (() -> {
5759 List <String > lines = readLines (entry .getValue ());
58- return PackTestFunction .fromLines (lines , this .permissionLevel );
60+ return PackTestFunction .fromLines (lines , this .permissionSet );
5961 }));
6062 }
6163 CompletableFuture <?>[] futures = result .values ().toArray (new CompletableFuture [0 ]);
6264 return CompletableFuture .allOf (futures ).handle ((a , b ) -> result );
6365 });
6466
6567 return prep .thenCompose (barrier ::wait ).thenAcceptAsync (functions -> {
66- ImmutableMap .Builder <ResourceLocation , PackTestFunction > testsBuilder = ImmutableMap .builder ();
68+ ImmutableMap .Builder <Identifier , PackTestFunction > testsBuilder = ImmutableMap .builder ();
6769 functions .forEach ((id , future ) -> future .handle ((val , err ) -> {
6870 if (err != null ) {
6971 PackTest .LOGGER .error ("Failed to load test {}" , id , err );
@@ -72,7 +74,7 @@ public void setPermissionLevel(int permissionLevel) {
7274 }
7375 return null ;
7476 }).join ());
75- ImmutableMap <ResourceLocation , PackTestFunction > tests = testsBuilder .build ();
77+ ImmutableMap <Identifier , PackTestFunction > tests = testsBuilder .build ();
7678 HolderGetter <GameTestInstance > testInstanceRegistry = this .registries .lookup (Registries .TEST_INSTANCE ).orElseThrow ();
7779 HolderGetter <Consumer <GameTestHelper >> testFunctionRegistry = this .registries .lookup (Registries .TEST_FUNCTION ).orElseThrow ();
7880 ((PackTestRegistry )testInstanceRegistry ).packtest$setFrozen (false );
0 commit comments