Synchronized Reload Listener

How-To use the Synchronized Reload Listener

Creating an example

This example implementation of the SynchronizedJsonReloadListener will just print every found data in the log.

public class ImplListener extends SynchronizedJsonReloadListener {
   public static final Gson GSON = new GsonBuilder().registerTypeAdapter(ResourceLocation.class, new ResourceLocation.Serializer()).create();

   public ImplListener() {
        // replace "directory" with something of your choice
      super(GSON, "directory");
   }
   
   // this will be called on the server once the datapack is  loaded and on the client once it receives the datapack
   @Override
   protected void onApply(Map<ResourceLocation, JsonElement> dataMap) {
       // iterate over found data
      for (Map.Entry<ResourceLocation, JsonElement> mapEntry : dataMap.entrySet()) {
          LOGGER.debug(mapEntry.getKey().getPath() + "contains the following data: " + mapEntry.getValue());
      }
   }
}

Registering the Listener

In order for the ReloadListener to work properly, you need to register it. The most efficent way is to use the SynchronizedReloadListenerRegistry:

SynchronizedReloadListenerRegistry.register(new ImplListener(), listenerId);

Continue with Miscellaneous