Skip to content

Commit

Permalink
Refactored all Logging
Browse files Browse the repository at this point in the history
* Need to go thru all Files Fixing the Logging and Comments
  • Loading branch information
MeAlam1 committed Sep 26, 2024
1 parent 6f5fc5f commit 8003e54
Show file tree
Hide file tree
Showing 24 changed files with 173 additions and 254 deletions.
5 changes: 3 additions & 2 deletions NeoForge/src/main/java/software/bluelib/BlueLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.neoforged.fml.loading.FMLEnvironment;
import software.bluelib.example.event.ClientEvents;
import software.bluelib.example.init.ModEntities;
import software.bluelib.utils.logging.BaseLogLevel;
import software.bluelib.utils.logging.BaseLogger;

import java.util.concurrent.Executors;
Expand Down Expand Up @@ -120,9 +121,9 @@ public void onLoadComplete(FMLLoadCompleteEvent pEvent) {
static boolean isDeveloperMode() {
boolean isDevMode = !FMLEnvironment.production;
if (isDevMode) {
BaseLogger.bluelibLogSuccess("Running in Developer mode.");
BaseLogger.log(BaseLogLevel.INFO ,"Running in Developer mode.", true);
} else {
BaseLogger.bluelibLogSuccess("Running in Production mode.");
BaseLogger.log(BaseLogLevel.INFO ,"Running in Production mode.", true);
}
return isDevMode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.packs.resources.ResourceManager;
import software.bluelib.BlueLib;
import software.bluelib.interfaces.variant.base.IVariantEntityBase;
import software.bluelib.json.JSONLoader;
import software.bluelib.json.JSONMerger;
Expand Down Expand Up @@ -77,7 +76,7 @@ public class VariantLoader implements IVariantEntityBase {
* @param pEntityName {@link String} - The name of the entity whose variants should be cleared before loading new ones.
*/
public static void loadVariants(String folderPath, MinecraftServer pServer, String pEntityName) {
BaseLogger.bluelibLogInfo("Starting to load variants for entity: " + pEntityName);
BaseLogger.log("Starting to load variants for entity: " + pEntityName);

clearVariantsForEntity(pEntityName);

Expand All @@ -86,19 +85,19 @@ public static void loadVariants(String folderPath, MinecraftServer pServer, Stri

Collection<ResourceLocation> collection = resourceManager.listResources(folderPath, pFiles -> pFiles.getPath().endsWith(".json")).keySet();

BaseLogger.bluelibLogSuccess("Found resources: " + collection);
BaseLogger.log("Found resources: " + collection);

for (ResourceLocation resourceLocation : collection) {
try {
BaseLogger.bluelibLogInfo("Loading JSON data from resource: " + resourceLocation.toString());
BaseLogger.log("Loading JSON data from resource: " + resourceLocation.toString());
JsonObject jsonObject = jsonLoader.loadJson(resourceLocation, resourceManager);
jsonMerger.mergeJsonObjects(mergedJsonObject, jsonObject);
} catch (Exception pException) {
BaseLogger.logError("Failed to load JSON data from resource: " + resourceLocation.toString(), pException);
BaseLogger.log("Failed to load JSON data from resource: " + resourceLocation.toString(), pException);
}
}

BaseLogger.bluelibLogSuccess("Successfully loaded and merged JSON data for entity: " + pEntityName);
BaseLogger.log("Successfully loaded and merged JSON data for entity: " + pEntityName);
parseVariants(mergedJsonObject);
}

Expand All @@ -110,7 +109,7 @@ public static void loadVariants(String folderPath, MinecraftServer pServer, Stri
* @param pEntityName {@link String} - The name of the entity whose variants should be cleared.
*/
private static void clearVariantsForEntity(String pEntityName) {
BaseLogger.bluelibLogInfo("Clearing variants for entity: " + pEntityName);
BaseLogger.log("Clearing variants for entity: " + pEntityName);
entityVariantsMap.remove(pEntityName);
}

Expand All @@ -126,7 +125,7 @@ private static void parseVariants(JsonObject pJsonObject) {
String entityName = entry.getKey();
JsonArray textureArray = entry.getValue().getAsJsonArray();

BaseLogger.bluelibLogInfo("Parsing variants for entity: " + entityName);
BaseLogger.log("Parsing variants for entity: " + entityName);
List<VariantParameter> variantList = entityVariantsMap.computeIfAbsent(entityName, k -> new ArrayList<>());

for (JsonElement variant : textureArray) {
Expand Down Expand Up @@ -164,7 +163,7 @@ private static VariantParameter getEntityVariant(String pJsonKey, JsonObject pJs
* @return {@link List<VariantParameter>} - A {@link List<VariantParameter>} of {@link VariantParameter} instances for the specified entity.
*/
public static List<VariantParameter> getVariantsFromEntity(String pEntityName) {
BaseLogger.bluelibLogInfo("Retrieving variants for entity: " + pEntityName);
BaseLogger.log("Retrieving variants for entity: " + pEntityName);
return entityVariantsMap.getOrDefault(pEntityName, new ArrayList<>());
}

Expand All @@ -178,14 +177,14 @@ public static List<VariantParameter> getVariantsFromEntity(String pEntityName) {
* @return {@link VariantParameter} - The {@link VariantParameter} with the specified name, or {@code null} if not found.
*/
public static VariantParameter getVariantByName(String pEntityName, String pVariantName) {
BaseLogger.bluelibLogInfo("Retrieving variant by name: " + pVariantName + " for entity: " + pEntityName);
BaseLogger.log("Retrieving variant by name: " + pVariantName + " for entity: " + pEntityName);
List<VariantParameter> variants = getVariantsFromEntity(pEntityName);
for (VariantParameter variant : variants) {
if (variant.getVariantName().equals(pVariantName)) {
return variant;
}
}
BaseLogger.logWarning("Variant with name: " + pVariantName + " not found for entity: " + pEntityName);
BaseLogger.log("Variant with name: " + pVariantName + " not found for entity: " + pEntityName);
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,31 +62,31 @@ public VariantParameter(String pJsonKey, JsonObject pJsonObject) {
if (pJsonKey == null || pJsonObject == null) {
Throwable throwable = new Throwable("JSON key or JSON object is null");
IllegalArgumentException exception = new IllegalArgumentException("JSON key and object must not be null");
BaseLogger.logError(exception.toString(), throwable);
BaseLogger.log(exception.toString(), throwable);
throw exception;
}
this.jsonKey = pJsonKey;
BaseLogger.bluelibLogInfo("Creating VariantParameter with JSON key: " + pJsonKey);
BaseLogger.log("Creating VariantParameter with JSON key: " + pJsonKey);
Set<Map.Entry<String, JsonElement>> entryMap = pJsonObject.entrySet();
for (Map.Entry<String, JsonElement> entry : entryMap) {
JsonElement element = entry.getValue();
if (element.isJsonPrimitive()) {
addParameter(entry.getKey(), element.getAsString());
BaseLogger.bluelibLogInfo("Added primitive parameter: " + entry.getKey() + " = " + element.getAsString());
BaseLogger.log("Added primitive parameter: " + entry.getKey() + " = " + element.getAsString());
} else if (element.isJsonArray()) {
StringBuilder arrayValues = new StringBuilder();
element.getAsJsonArray().forEach(e -> arrayValues.append(e.getAsString()).append(","));
if (arrayValues.length() > 0) {
arrayValues.setLength(arrayValues.length() - 1); // Remove trailing comma
}
addParameter(entry.getKey(), arrayValues.toString());
BaseLogger.bluelibLogInfo("Added array parameter: " + entry.getKey() + " = " + arrayValues.toString());
BaseLogger.log("Added array parameter: " + entry.getKey() + " = " + arrayValues.toString());
} else if (element.isJsonObject()) {
addParameter(entry.getKey(), element.toString());
BaseLogger.bluelibLogInfo("Added object parameter: " + entry.getKey() + " = " + element.toString());
BaseLogger.log("Added object parameter: " + entry.getKey() + " = " + element.toString());
} else {
addParameter(entry.getKey(), "null");
BaseLogger.bluelibLogInfo("Added null parameter for key: " + entry.getKey());
BaseLogger.log("Added null parameter for key: " + entry.getKey());
}
}
}
Expand All @@ -106,10 +106,10 @@ public String getJsonKey() {
if (this.jsonKey == null) {
Throwable throwable = new Throwable("JSON key should not be null");
IllegalStateException exception = new IllegalStateException("JSON key is unexpectedly null when retrieving from VariantParameter.");
BaseLogger.logError(exception.toString(), throwable);
BaseLogger.log(exception.toString(), throwable);
throw exception;
}
BaseLogger.bluelibLogSuccess("Retrieved JSON key: " + this.jsonKey);
BaseLogger.log("Retrieved JSON key: " + this.jsonKey);
return this.jsonKey;
}

Expand All @@ -125,7 +125,7 @@ public String getJsonKey() {
*/
public String getVariantName() {
String variantName = getParameter("variantName");
BaseLogger.bluelibLogSuccess("Retrieved variant name: " + variantName);
BaseLogger.log("Retrieved variant name: " + variantName);
return variantName;
}

Expand All @@ -142,7 +142,7 @@ public String getVariantName() {
*/
public String getParameter(String pKey) {
String value = (String) super.getParameter(pKey);
BaseLogger.bluelibLogSuccess("Retrieved parameter for key " + pKey + ": " + value);
BaseLogger.log("Retrieved parameter for key " + pKey + ": " + value);
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

package software.bluelib.entity.variant.base;

import software.bluelib.utils.logging.BaseLogLevel;
import software.bluelib.utils.logging.BaseLogger;

import java.util.Collection;
Expand Down Expand Up @@ -57,7 +58,7 @@ public abstract class ParameterBase {
*/
protected void addParameter(String pKey, Object pValue) {
parameters.put(pKey, pValue);
BaseLogger.bluelibLogSuccess(String.format("Parameter added: Key = %s, Value = %s", pKey, pValue));
BaseLogger.log(BaseLogLevel.SUCCESS, String.format("Parameter added: Key = %s, Value = %s", pKey, pValue), true);
}

/**
Expand All @@ -73,7 +74,7 @@ protected void addParameter(String pKey, Object pValue) {
*/
protected Object getParameter(String pKey) {
Object value = parameters.get(pKey);
BaseLogger.bluelibLogSuccess(String.format("Parameter retrieved: Key = %s, Value = %s", pKey, value));
BaseLogger.log(BaseLogLevel.INFO, String.format("Parameter retrieved: Key = %s, Value = %s", pKey, value), true);
return value;
}

Expand All @@ -89,9 +90,9 @@ protected Object getParameter(String pKey) {
*/
protected void removeParameter(String pKey) {
if (parameters.remove(pKey) != null) {
BaseLogger.bluelibLogSuccess(String.format("Parameter removed: Key = %s", pKey));
BaseLogger.log(BaseLogLevel.SUCCESS, String.format("Parameter removed: Key = %s", pKey), true);
} else {
BaseLogger.logWarning(String.format("Attempted to remove non-existent parameter: Key = %s", pKey));
BaseLogger.log(BaseLogLevel.WARNING, String.format("Attempted to remove non-existent parameter: Key = %s", pKey), true);
}
}

Expand All @@ -106,7 +107,7 @@ protected void removeParameter(String pKey) {
* @since 1.0.0
*/
protected Map<String, Object> getAllParameters() {
BaseLogger.bluelibLogSuccess("Retrieved all parameters.");
BaseLogger.log(BaseLogLevel.INFO, "Retrieved all parameters.", true);
return new HashMap<>(parameters);
}

Expand All @@ -123,7 +124,7 @@ protected Map<String, Object> getAllParameters() {
*/
protected boolean containsParameter(String pKey) {
boolean exists = parameters.containsKey(pKey);
BaseLogger.bluelibLogInfo(String.format("Parameter existence check: Key = %s, Exists = %b", pKey, exists));
BaseLogger.log(BaseLogLevel.INFO, String.format("Parameter existence check: Key = %s, Exists = %b", pKey, exists), true);
return exists;
}

Expand All @@ -139,7 +140,7 @@ protected boolean containsParameter(String pKey) {
*/
protected boolean isEmpty() {
boolean empty = parameters.isEmpty();
BaseLogger.bluelibLogInfo("Checked if parameters are empty: " + empty);
BaseLogger.log(BaseLogLevel.INFO, "Checked if parameters are empty: " + empty, true);
return empty;
}

Expand All @@ -154,7 +155,7 @@ protected boolean isEmpty() {
*/
protected void clearParameters() {
parameters.clear();
BaseLogger.bluelibLogSuccess("Cleared all parameters.");
BaseLogger.log(BaseLogLevel.SUCCESS, "Cleared all parameters.", true);
}

/**
Expand All @@ -169,7 +170,7 @@ protected void clearParameters() {
*/
protected int getParameterCount() {
int count = parameters.size();
BaseLogger.bluelibLogSuccess("Retrieved parameter count: " + count);
BaseLogger.log(BaseLogLevel.INFO, "Retrieved parameter count: " + count, true);
return count;
}

Expand All @@ -184,7 +185,7 @@ protected int getParameterCount() {
* @since 1.0.0
*/
protected Set<String> getParameterKeys() {
BaseLogger.bluelibLogSuccess("Retrieved parameter keys.");
BaseLogger.log(BaseLogLevel.INFO, "Retrieved parameter keys.", true);
return parameters.keySet();
}

Expand All @@ -199,7 +200,7 @@ protected Set<String> getParameterKeys() {
* @since 1.0.0
*/
protected Collection<Object> getParameterValues() {
BaseLogger.bluelibLogSuccess("Retrieved parameter values.");
BaseLogger.log(BaseLogLevel.INFO, "Retrieved parameter values.", true);
return parameters.values();
}

Expand All @@ -218,11 +219,11 @@ protected Collection<Object> getParameterValues() {
protected void updateParameter(String pKey, Object pNewValue) {
if (parameters.containsKey(pKey)) {
parameters.put(pKey, pNewValue);
BaseLogger.bluelibLogInfo(String.format("Parameter updated: Key = %s, New Value = %s", pKey, pNewValue));
BaseLogger.log(BaseLogLevel.SUCCESS, String.format("Parameter updated: Key = %s, New Value = %s", pKey, pNewValue), true);
} else {
Throwable throwable = new Throwable("Key does not exist: " + pKey);
IllegalArgumentException exception = new IllegalArgumentException("Key does not exist: " + pKey);
BaseLogger.logError(String.format("Attempted to update non-existent parameter: Key = %s", pKey), throwable);
BaseLogger.log(BaseLogLevel.ERROR, String.format("Attempted to update non-existent parameter: Key = %s", pKey), throwable, true);
throw exception;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ public class ReloadEventHandler {
*/
protected static void registerEntityVariants(String pFolderPath, MinecraftServer pServer, String pModID, String pEntityName) {

BaseLogger.bluelibLogInfo("Attempting to register entity variants for " + pEntityName + " with ModID: " + pModID);
BaseLogger.log("Attempting to register entity variants for " + pEntityName + " with ModID: " + pModID);

try {
VariantLoader.loadVariants(pFolderPath, pServer, pEntityName);
BaseLogger.bluelibLogSuccess("Successfully registered entity variants for " + pEntityName + " from ModID: " + pModID);
BaseLogger.log("Successfully registered entity variants for " + pEntityName + " from ModID: " + pModID);
} catch (JsonParseException pException) {
BaseLogger.logError("Failed to parse JSON(s) while registering entity variants for " + pEntityName + " from ModID: " + pModID, pException);
BaseLogger.log("Failed to parse JSON(s) while registering entity variants for " + pEntityName + " from ModID: " + pModID, pException);
throw pException;
} catch (Exception pException) {
BaseLogger.logError("Unexpected error occurred while registering entity variants for " + pEntityName + " from ModID: " + pModID, pException);
BaseLogger.log("Unexpected error occurred while registering entity variants for " + pEntityName + " from ModID: " + pModID, pException);
throw pException;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@
import net.minecraft.world.entity.ai.attributes.AttributeSupplier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.block.entity.BlockEntity;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import software.bernie.geckolib.animatable.GeoEntity;
Expand All @@ -24,12 +22,8 @@
import software.bernie.geckolib.util.GeckoLibUtil;
import software.bluelib.interfaces.variant.IVariantEntity;
import software.bluelib.utils.logging.BaseLogger;
import software.bluelib.utils.minecraft.ChunkUtils;
import software.bluelib.utils.variant.ParameterUtils;

import java.util.Arrays;
import java.util.Collection;

/**
* A {@code DragonEntity} class representing a dragon entity in the game, which extends {@link TamableAnimal}
* and implements {@link IVariantEntity} and {@link GeoEntity}.
Expand Down Expand Up @@ -165,7 +159,7 @@ public SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor pLevel, @NotNul
.withParameter("array")
.connect();
}
BaseLogger.logSuccess("Dragon Spawned with Variant: " + getVariantName());
BaseLogger.log("Dragon Spawned with Variant: " + getVariantName());
return super.finalizeSpawn(pLevel, pDifficulty, pReason, pSpawnData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ public interface IVariantEntity extends IVariantEntityBase {
*/
default String getRandomVariant(List<String> pVariantNamesList, String pDefaultVariant) {
if (pVariantNamesList.isEmpty()) {
BaseLogger.logWarning("Variant names list is empty. Returning default variant: " + pDefaultVariant);
BaseLogger.log("Variant names list is empty. Returning default variant: " + pDefaultVariant);
return pDefaultVariant;
}
int index = random.nextInt(pVariantNamesList.size());
String selectedVariant = pVariantNamesList.get(index);
BaseLogger.bluelibLogSuccess("Selected random variant: " + selectedVariant + " from list of size: " + pVariantNamesList.size());
BaseLogger.log("Selected random variant: " + selectedVariant + " from list of size: " + pVariantNamesList.size());
return selectedVariant;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ default List<String> getEntityVariants(String pEntityName) {
List<String> variantNames = variants.stream()
.map(VariantParameter::getVariantName)
.collect(Collectors.toList());
BaseLogger.bluelibLogSuccess("Retrieved " + variantNames.size() + " variants for entity: " + pEntityName);
BaseLogger.log("Retrieved " + variantNames.size() + " variants for entity: " + pEntityName);
return variantNames;
}
}
Loading

0 comments on commit 8003e54

Please sign in to comment.