mirror of
https://github.com/xfl03/MCCustomSkinLoader.git
synced 2026-11-28 11:16:08 +00:00
Fix NPE if type is null. (#195)
* Fix NPE if type is null. Signed-off-by: ZekerZhayard <[email protected]> * Forge does not support Java 18 for now. Signed-off-by: ZekerZhayard <[email protected]>
This commit is contained in:
1 parent
c8fb6e216e
commit
cff5846e7f
5 files changed
+60
-41
No files matched your search
@@ -22,7 +22,7 @@ static void provideModrinth0(Project proj) {
|
||||
|
||||
token = System.getenv("MODRINTH_TOKEN")
|
||||
projectId = "idMHQ4n2"
|
||||
versionNumber = proj.ext.getCSLVersion()
|
||||
versionNumber = "${proj.ext.getCSLVersion()}-${proj.name.replace("/", ".")}"
|
||||
versionName = "${proj.archivesBaseName}-${proj.ext.getShortVersion()}"
|
||||
changelog = System.getenv("GIT_COMMIT_DESC") ?: ""
|
||||
uploadFile = proj.tasks.jar
|
||||
|
||||
@@ -115,6 +115,10 @@ public class CustomSkinLoader {
|
||||
for(int i=0;i<config.loadlist.size();i++){
|
||||
SkinSiteProfile ssp=config.loadlist.get(i);
|
||||
logger.info((i+1)+"/"+config.loadlist.size()+" Try to load profile from '"+ssp.name+"'.");
|
||||
if(ssp.type==null){
|
||||
logger.info("The type of '" + ssp.name + "' is null.");
|
||||
continue;
|
||||
}
|
||||
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||
if(loader==null){
|
||||
logger.info("Type '"+ssp.type+"' is not defined.");
|
||||
|
||||
@@ -3,8 +3,10 @@ package customskinloader.config;
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import customskinloader.CustomSkinLoader;
|
||||
import customskinloader.loader.ProfileLoader;
|
||||
@@ -69,6 +71,7 @@ public class Config {
|
||||
|
||||
//Init program
|
||||
config.loadExtraList();
|
||||
config.updateLoadlist();
|
||||
config.initLocalFolder();
|
||||
config.threadPoolSize = Math.max(config.threadPoolSize, 1);
|
||||
config.retryTime = Math.max(config.retryTime, 0);
|
||||
@@ -120,10 +123,7 @@ public class Config {
|
||||
return config;
|
||||
}catch (Exception e) {
|
||||
CustomSkinLoader.logger.info("Failed to load config, use default instead.("+e.toString()+")");
|
||||
File brokenFile=new File(CustomSkinLoader.DATA_DIR,"BROKEN-CustomSkinLoader.json");
|
||||
if(brokenFile.exists())
|
||||
brokenFile.delete();
|
||||
CustomSkinLoader.CONFIG_FILE.renameTo(brokenFile);
|
||||
createBrokenFile(CustomSkinLoader.CONFIG_FILE);
|
||||
return initConfig();
|
||||
}
|
||||
}
|
||||
@@ -144,40 +144,57 @@ public class Config {
|
||||
String json=FileUtils.readFileToString(file, "UTF-8");
|
||||
SkinSiteProfile ssp=CustomSkinLoader.GSON.fromJson(json, SkinSiteProfile.class);
|
||||
CustomSkinLoader.logger.info("Successfully load Extra List.");
|
||||
file.delete();
|
||||
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||
if(loader==null){
|
||||
CustomSkinLoader.logger.info("Extra List will be ignore: Type '"+ssp.type+"' is not defined.");
|
||||
continue;
|
||||
}
|
||||
boolean duplicate=false;
|
||||
for(SkinSiteProfile ssp0:this.loadlist){
|
||||
if(!ssp0.type.equalsIgnoreCase(ssp.type))
|
||||
if (ssp.type != null) {
|
||||
ProfileLoader.IProfileLoader loader = ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||
if (loader == null) {
|
||||
CustomSkinLoader.logger.info("Extra List will be ignored: Type '" + ssp.type + "' is not defined.");
|
||||
continue;
|
||||
if(loader.compare(ssp0, ssp)){
|
||||
duplicate=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!duplicate){
|
||||
adds.add(ssp);
|
||||
CustomSkinLoader.logger.info("Successfully apply Extra List.("+ssp.name+")");
|
||||
}else{
|
||||
CustomSkinLoader.logger.info("Extra List will be ignore: Duplicate.("+ssp.name+")");
|
||||
boolean duplicate = false;
|
||||
for (SkinSiteProfile ssp0 : this.loadlist) {
|
||||
if (!ssp0.type.equalsIgnoreCase(ssp.type))
|
||||
continue;
|
||||
if (loader.compare(ssp0, ssp)) {
|
||||
duplicate = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!duplicate) {
|
||||
adds.add(ssp);
|
||||
CustomSkinLoader.logger.info("Successfully apply Extra List.(" + ssp.name + ")");
|
||||
} else {
|
||||
CustomSkinLoader.logger.info("Extra List will be ignored: Duplicate.(" + ssp.name + ")");
|
||||
}
|
||||
file.delete();
|
||||
} else {
|
||||
CustomSkinLoader.logger.info("Extra List is invalid: Type is not defined.(" + file.getName() + ")");
|
||||
createBrokenFile(file);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
CustomSkinLoader.logger.info("Failed to load Extra List.("+e.toString()+")");
|
||||
createBrokenFile(file);
|
||||
}
|
||||
}
|
||||
if(adds.size()!=0){
|
||||
adds.addAll(this.loadlist);
|
||||
this.loadlist=adds;
|
||||
writeConfig(this,true);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLoadlist() {
|
||||
PluginLoader.PLUGINS.stream()
|
||||
.map(ICustomSkinLoaderPlugin::getDefaultProfiles)
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap(Collection::stream)
|
||||
.forEach(profile -> this.loadlist.stream()
|
||||
.filter(ssp -> profile.getName().equals(ssp.name))
|
||||
.forEach(profile::updateSkinSiteProfile));
|
||||
}
|
||||
|
||||
private void initLocalFolder(){
|
||||
for(SkinSiteProfile ssp:this.loadlist){
|
||||
if(ssp.type==null)
|
||||
continue;
|
||||
ProfileLoader.IProfileLoader loader=ProfileLoader.LOADERS.get(ssp.type.toLowerCase());
|
||||
if(loader==null)
|
||||
continue;
|
||||
@@ -185,6 +202,19 @@ public class Config {
|
||||
}
|
||||
}
|
||||
|
||||
private static void createBrokenFile(File file) {
|
||||
try {
|
||||
File brokenFile = new File(file.getParentFile(), file.getName() + ".broken");
|
||||
if (brokenFile.exists()) {
|
||||
brokenFile.delete();
|
||||
}
|
||||
file.renameTo(brokenFile);
|
||||
} catch (Exception e) {
|
||||
CustomSkinLoader.logger.warning("Failed to create broken file. (" + file.getName() + ")");
|
||||
CustomSkinLoader.logger.warning(e);
|
||||
}
|
||||
}
|
||||
|
||||
// The config file does not exist or was broken.
|
||||
private static Config initConfig() {
|
||||
List<ICustomSkinLoaderPlugin.IDefaultProfile> profiles = new ArrayList<>();
|
||||
@@ -209,21 +239,6 @@ public class Config {
|
||||
return config;
|
||||
}
|
||||
private static void writeConfig(Config config, boolean update){
|
||||
if (update && config.loadlist != null) { // Update loadlist, complete missing elements
|
||||
for (ICustomSkinLoaderPlugin plugin : PluginLoader.PLUGINS) {
|
||||
List<ICustomSkinLoaderPlugin.IDefaultProfile> profiles = plugin.getDefaultProfiles();
|
||||
if (profiles != null) {
|
||||
for (ICustomSkinLoaderPlugin.IDefaultProfile profile : profiles) {
|
||||
for (SkinSiteProfile ssp : config.loadlist) {
|
||||
if (profile.getName().equals(ssp.name)) {
|
||||
profile.updateSkinSiteProfile(ssp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String json=CustomSkinLoader.GSON.toJson(config);
|
||||
if(CustomSkinLoader.CONFIG_FILE.exists())
|
||||
CustomSkinLoader.CONFIG_FILE.delete();
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
minecraft_version=1.17.1
|
||||
minecraft_full_versions=1.17.1
|
||||
java_full_versions=16,17,18
|
||||
java_full_versions=16,17
|
||||
#forge gradle needs forge version
|
||||
forge_mc_version=1.12.2
|
||||
forge_version=14.23.5.2768
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
minecraft_version=1.12.2
|
||||
minecraft_full_versions=1.8,1.8.8,1.8.9,1.9,1.9.4,1.10,1.10.2,1.11,1.11.2,1.12,1.12.1,1.12.2,1.13.2,1.14.2,1.14.3,1.14.4,1.15,1.15.1,1.15.2,1.16.1,1.16.2,1.16.3,1.16.4,1.16.5
|
||||
java_full_versions=8,9,10,11,12,13,14,15,16
|
||||
java_full_versions=8,9,10,11,12,13,14,15,16,17
|
||||
#forge gradle needs forge version
|
||||
forge_mc_version=1.12.2
|
||||
forge_version=14.23.5.2768
|
||||
|
||||
Reference in new issue
Block a user