Skip to content

Commit

Permalink
Fix Sonar issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Crystal-Spider committed Jun 5, 2024
1 parent f606a5b commit 82ab85b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,17 @@ public static FireBuilder fireBuilder(ResourceLocation fireType) {
* @return whether the registration is successful.
*/
public static synchronized boolean registerFire(Fire fire) {
ResourceLocation fireType = fire.getFireType();
if (!fires.containsKey(fireType)) {
fires.put(fireType, fire);
fire.getSource().flatMap(BuiltInRegistries.BLOCK::getOptional).ifPresent(block -> ((FireTypeChanger) block).setFireType(fireType));
fire.getCampfire().flatMap(BuiltInRegistries.BLOCK::getOptional).ifPresent(block -> ((FireTypeChanger) block).setFireType(fireType));
return true;
Fire previous = fires.computeIfAbsent(fire.getFireType(), key -> {
fire.getSource().flatMap(BuiltInRegistries.BLOCK::getOptional).ifPresent(block -> ((FireTypeChanger) block).setFireType(key));
fire.getCampfire().flatMap(BuiltInRegistries.BLOCK::getOptional).ifPresent(block -> ((FireTypeChanger) block).setFireType(key));
return fire;
});
if (previous != fire) {
ResourceLocation fireType = fire.getFireType();
Constants.LOGGER.error("Fire [{}] was already registered with the following value: {}", fireType, fires.get(fireType));
return false;
}
Constants.LOGGER.error("Fire [{}] was already registered with the following value: {}", fireType, fires.get(fireType));
return false;
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,12 @@ public static synchronized boolean unregisterFire(ResourceLocation fireType) {
* @return whether the registration is successful.
*/
private static synchronized boolean registerFire(FireClient fire) {
ResourceLocation fireType = fire.getFireType();
if (!fires.containsKey(fireType)) {
fires.put(fireType, fire);
return true;
if (fires.putIfAbsent(fire.getFireType(), fire) != fire) {
ResourceLocation fireType = fire.getFireType();
Constants.LOGGER.error("FireClient [{}] was already registered by mod with the following value: {}", fireType, fires.get(fireType));
return false;
}
Constants.LOGGER.error("FireClient [{}] was already registered by mod with the following value: {}", fireType, fires.get(fireType));
return false;
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private static JsonObject getJsonObject(String identifier, JsonElement element)
* @param identifier identifier of the json file.
* @param field field to parse.
* @param data {@link JsonObject} with data to parse.
* @param parser function to use to retrive parse a json field.
* @param parser function to use to retrieve parse a json field.
* @return value of the field.
* @throws NullPointerException if there's no such field.
* @throws UnsupportedOperationException if this element is not a {@link JsonPrimitive} or {@link JsonArray}.
Expand All @@ -108,7 +108,7 @@ private static <T> T parse(String identifier, String field, JsonObject data, Fun
* @param identifier identifier of the json file.
* @param field field to parse.
* @param data {@link JsonObject} with data to parse.
* @param parser function to use to retrive parse a json field.
* @param parser function to use to retrieve parse a json field.
* @param fallback default value if no field named {@code field} exists.
* @return value of the field or default.
* @throws UnsupportedOperationException if this element is not a {@link JsonPrimitive} or {@link JsonArray}.
Expand Down

0 comments on commit 82ab85b

Please sign in to comment.