Skip to content

Commit

Permalink
Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
MeAlam1 committed Dec 20, 2024
1 parent 612c1b7 commit 665df50
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.server.MinecraftServer;
import software.bluelib.json.JSONParser;
import software.bluelib.utils.logging.BaseLogLevel;
import software.bluelib.utils.logging.BaseLogger;
import software.bluelib.utils.variant.ParameterUtils;

import java.util.HashMap;
import java.util.Map;

/**
* A class for loading and managing entity variants.
* <p>
Expand All @@ -35,6 +34,7 @@
* @since 1.0.0
*/
public class VariantLoader extends JSONParser {

/**
* A map to store all loaded variants.
* <p>
Expand Down Expand Up @@ -115,4 +115,4 @@ private static void parseVariants(String pEntityName, JsonObject pJsonObject) {
BaseLogger.log(BaseLogLevel.INFO, "All Entities: " + ParameterUtils.getAllEntities(), true);
BaseLogger.log(BaseLogLevel.INFO, "Variants of " + pEntityName + ": " + ParameterUtils.getVariantsOfEntity(pEntityName), true);
}
}
}
21 changes: 10 additions & 11 deletions common/src/main/java/software/bluelib/json/JSONParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
package software.bluelib.json;

import com.google.gson.JsonObject;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.packs.resources.ResourceManager;
import software.bluelib.utils.logging.BaseLogLevel;
import software.bluelib.utils.logging.BaseLogger;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
* An abstract class for parsing JSON data.
* <p>
Expand Down Expand Up @@ -40,6 +39,7 @@
* @author MeAlam
*/
public abstract class JSONParser {

/**
* A map to store JSON data with their corresponding keys.
* <p>
Expand Down Expand Up @@ -104,7 +104,7 @@ public abstract class JSONParser {
* </p>
*
* @param pFolderPath The folder path to load JSON data from.
* @param pServer The Minecraft server instance.
* @param pServer The Minecraft server instance.
* @since 1.7.0
* @author MeAlam
* @see JSONLoader
Expand All @@ -119,18 +119,17 @@ public void loadData(String pFolderPath, MinecraftServer pServer) {
ResourceManager resourceManager = pServer.getResourceManager();
mergedJsonObject = new JsonObject();

Collection<ResourceLocation> resources =
resourceManager.listResources(pFolderPath, path -> path.getPath().endsWith(".json")).keySet();
Collection<ResourceLocation> resources = resourceManager.listResources(pFolderPath, path -> path.getPath().endsWith(".json")).keySet();

BaseLogger.log(BaseLogLevel.INFO, "Found resources: " + resources + " at: " + pFolderPath);
BaseLogger.log(BaseLogLevel.INFO, "Found resources: " + resources + " at: " + pFolderPath, true);

for (ResourceLocation resourceLocation : resources) {
try {
BaseLogger.log(BaseLogLevel.INFO, "Loading JSON data from resource: " + resourceLocation);
BaseLogger.log(BaseLogLevel.INFO, "Loading JSON data from resource: " + resourceLocation, true);
JsonObject jsonObject = jsonLoader.loadJson(resourceLocation, resourceManager);
jsonMerger.mergeJsonObjects(mergedJsonObject, jsonObject);
} catch (Exception exception) {
BaseLogger.log(BaseLogLevel.ERROR, "Failed to load JSON data from resource: " + resourceLocation, exception);
BaseLogger.log(BaseLogLevel.ERROR, "Failed to load JSON data from resource: " + resourceLocation, exception, true);
}
}
}
Expand Down Expand Up @@ -171,4 +170,4 @@ public Map<String, JsonObject> getDataMap() {
public JsonObject getMergedJsonObject() {
return mergedJsonObject;
}
}
}

0 comments on commit 665df50

Please sign in to comment.