Skip to content

Commit

Permalink
Add public map getters to data managers
Browse files Browse the repository at this point in the history
  • Loading branch information
Commoble committed Jan 26, 2022
1 parent 4440b63 commit 42f3952
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/commoble/databuddy/data/CodecJsonDataManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ of this software and associated documentation files (the "Software"), to deal

package commoble.databuddy.data;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -110,12 +111,22 @@ public CodecJsonDataManager(String folderName, Codec<T> codec, Logger logger, Gs
* Get the data object for the given key
* @param id A resourcelocation identifying a json; e.g. a json at data/some_modid/folderName/some_json.json has id "some_modid:some_json"
* @return The java object that was deserializd from the json with the given ID, or null if no such object is associated with that ID
* @deprecated Prefer using the other getData to get the data entries
*/
@Deprecated(forRemoval=true)
@Nullable
public T getData(ResourceLocation id)
{
return this.data.get(id);
}

/**
* @return The data entries
*/
public Map<ResourceLocation, T> getData()
{
return this.data;
}

@Override
protected void apply(Map<ResourceLocation, JsonElement> jsons, ResourceManager resourceManager, ProfilerFiller profiler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ public class MergeableCodecDataManager<RAW, FINE> extends SimplePreparableReload
protected static final int JSON_EXTENSION_LENGTH = JSON_EXTENSION.length();
protected static final Gson STANDARD_GSON = new Gson();

/**
* @deprecated prefer using the getter, will be made protected later
*/
@Deprecated
@Nonnull
/** Mutable, non-null map containing whatever data was loaded last time server datapacks were loaded **/
public Map<ResourceLocation, FINE> data = new HashMap<>();
Expand Down Expand Up @@ -132,6 +136,14 @@ public MergeableCodecDataManager(final String folderName, final Logger logger, C
this.merger = merger;
this.gson = gson;
}

/**
* @return The map of data entries
*/
public Map<ResourceLocation, FINE> getData()
{
return this.data;
}

/** Off-thread processing (can include reading files from hard drive) **/
@Override
Expand Down

0 comments on commit 42f3952

Please sign in to comment.