aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java
diff options
context:
space:
mode:
authorSHsuperCM <shsupercm@gmail.com>2021-09-27 10:36:51 +0300
committerSHsuperCM <shsupercm@gmail.com>2021-09-27 10:36:51 +0300
commit4e0a4605c51cb523a367daf0549958d37feeb133 (patch)
tree55432e4b93787a23804444342cefcd81ab238f05 /src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java
parentbf9ac15fa28e5c8eac6fb3e3ea3c6ca187b3e1d2 (diff)
downloadCITResewn-4e0a4605c51cb523a367daf0549958d37feeb133.tar.gz
CITResewn-4e0a4605c51cb523a367daf0549958d37feeb133.tar.bz2
CITResewn-4e0a4605c51cb523a367daf0549958d37feeb133.zip
Fixed some issues with global properties parsing
Diffstat (limited to 'src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java')
-rw-r--r--src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java
index 7313301..03ea512 100644
--- a/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java
+++ b/src/main/java/shcm/shsupercm/fabric/citresewn/pack/CITParser.java
@@ -5,9 +5,8 @@ import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.resource.ResourcePack;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
-import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
import shcm.shsupercm.fabric.citresewn.CITResewn;
-import shcm.shsupercm.fabric.citresewn.ex.CITLoadException;
import shcm.shsupercm.fabric.citresewn.ex.CITParseException;
import shcm.shsupercm.fabric.citresewn.mixin.core.GroupResourcePackAccessor;
import shcm.shsupercm.fabric.citresewn.pack.cits.*;
@@ -62,25 +61,34 @@ public final class CITParser { private CITParser() {}
Collection<Identifier> packProperties = new ArrayList<>();
for (String namespace : resourcePack.getNamespaces(ResourceType.CLIENT_RESOURCES)) {
packProperties.addAll(resourcePack.findResources(ResourceType.CLIENT_RESOURCES, namespace, "citresewn/cit", Integer.MAX_VALUE - 53, s -> s.endsWith(".properties")));
+ if (resourcePack.contains(ResourceType.CLIENT_RESOURCES, new Identifier(namespace, "citresewn/cit.properties")))
+ packProperties.add(new Identifier(namespace, "citresewn/cit.properties"));
+
packProperties.addAll(resourcePack.findResources(ResourceType.CLIENT_RESOURCES, namespace, "optifine/cit", Integer.MAX_VALUE - 53, s -> s.endsWith(".properties")));
+ if (resourcePack.contains(ResourceType.CLIENT_RESOURCES, new Identifier(namespace, "optifine/cit.properties")))
+ packProperties.add(new Identifier(namespace, "optifine/cit.properties"));
+
packProperties.addAll(resourcePack.findResources(ResourceType.CLIENT_RESOURCES, namespace, "mcpatcher/cit", Integer.MAX_VALUE - 53, s -> s.endsWith(".properties")));
+ if (resourcePack.contains(ResourceType.CLIENT_RESOURCES, new Identifier(namespace, "mcpatcher/cit.properties")))
+ packProperties.add(new Identifier(namespace, "mcpatcher/cit.properties"));
}
- boolean readCitProperties = false;
+ boolean readGlobalProperties = false;
for (Iterator<Identifier> iterator = packProperties.iterator(); iterator.hasNext(); ) {
Identifier propertiesIdentifier = iterator.next();
- if (propertiesIdentifier.getPath().substring(propertiesIdentifier.getPath().indexOf("cit/") + 4).equals("cit.properties")) {
- if (!readCitProperties) {
- Properties citProperties = new Properties();
- try (InputStream is = resourcePack.open(ResourceType.CLIENT_RESOURCES, propertiesIdentifier)) {
- citProperties.load(is);
- citPack.loadProperties(citProperties);
- readCitProperties = true;
- } catch (Exception e) {
- CITResewn.logErrorLoading(new CITLoadException(resourcePack, propertiesIdentifier, e.getMessage()).getMessage());
- }
+ try {
+ if (StringUtils.countMatches(propertiesIdentifier.getPath(), '/') <= 2 && propertiesIdentifier.getPath().endsWith("cit.properties")) {
+ iterator.remove();
+ if (!readGlobalProperties)
+ try (InputStream is = resourcePack.open(ResourceType.CLIENT_RESOURCES, propertiesIdentifier)) {
+ Properties citProperties = new Properties();
+ citProperties.load(is);
+ citPack.loadGlobalProperties(citProperties);
+ readGlobalProperties = true;
+ }
}
- iterator.remove();
+ } catch (Exception e) {
+ CITResewn.logErrorLoading("Skipped global properties: " + e.getMessage() + " in " + resourcePack.getName() + " -> " + propertiesIdentifier);
}
}