2013-03-08 00:25:48 +00:00
|
|
|
/*
|
2016-06-23 03:49:47 +00:00
|
|
|
* Minecraft Forge
|
2019-02-10 22:57:03 +00:00
|
|
|
* Copyright (c) 2016-2019.
|
2016-06-23 03:49:47 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation version 2.1
|
|
|
|
* of the License.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2013-03-08 00:25:48 +00:00
|
|
|
*/
|
|
|
|
|
2018-06-19 18:04:05 +00:00
|
|
|
package net.minecraftforge.fml;
|
2012-08-04 15:26:51 +00:00
|
|
|
|
2018-09-29 01:07:46 +00:00
|
|
|
import com.google.common.collect.Streams;
|
|
|
|
import net.minecraftforge.fml.loading.EarlyLoadingException;
|
2019-08-05 00:16:01 +00:00
|
|
|
import net.minecraftforge.forgespi.language.IModInfo;
|
2018-09-29 01:07:46 +00:00
|
|
|
|
|
|
|
import java.util.Arrays;
|
2018-06-19 18:04:05 +00:00
|
|
|
import java.util.List;
|
2018-09-29 01:07:46 +00:00
|
|
|
import java.util.stream.Stream;
|
2012-08-04 15:26:51 +00:00
|
|
|
|
2018-06-19 18:04:05 +00:00
|
|
|
/**
|
2018-09-29 01:07:46 +00:00
|
|
|
* General purpose mod loading error message
|
2018-06-19 18:04:05 +00:00
|
|
|
*/
|
|
|
|
public class ModLoadingException extends RuntimeException
|
2018-06-15 19:03:35 +00:00
|
|
|
{
|
2018-09-29 01:07:46 +00:00
|
|
|
/**
|
|
|
|
* Mod Info for mod with issue
|
|
|
|
*/
|
|
|
|
private final IModInfo modInfo;
|
|
|
|
/**
|
|
|
|
* The stage where this error was encountered
|
|
|
|
*/
|
|
|
|
private final ModLoadingStage errorStage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* I18N message to use for display
|
|
|
|
*/
|
|
|
|
private final String i18nMessage;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context for message display
|
|
|
|
*/
|
|
|
|
private final List<Object> context;
|
|
|
|
|
|
|
|
public ModLoadingException(final IModInfo modInfo, final ModLoadingStage errorStage, final String i18nMessage, final Throwable originalException, Object... context) {
|
2019-08-05 00:16:01 +00:00
|
|
|
super("Mod Loading Exception", originalException);
|
2018-09-29 01:07:46 +00:00
|
|
|
this.modInfo = modInfo;
|
|
|
|
this.errorStage = errorStage;
|
|
|
|
this.i18nMessage = i18nMessage;
|
|
|
|
this.context = Arrays.asList(context);
|
|
|
|
}
|
|
|
|
|
2018-10-04 04:57:08 +00:00
|
|
|
static Stream<ModLoadingException> fromEarlyException(final EarlyLoadingException e) {
|
|
|
|
return e.getAllData().stream().map(ed->new ModLoadingException(null, ModLoadingStage.VALIDATE, ed.getI18message(), e.getCause(), ed.getArgs()));
|
2018-09-29 01:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getI18NMessage() {
|
|
|
|
return i18nMessage;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object[] getContext() {
|
|
|
|
return context.toArray();
|
|
|
|
}
|
2018-06-19 18:04:05 +00:00
|
|
|
|
2018-09-29 01:07:46 +00:00
|
|
|
public String formatToString() {
|
2019-08-03 01:48:46 +00:00
|
|
|
return ForgeI18n.parseMessage(i18nMessage, Streams.concat(Stream.of(modInfo, errorStage, getCause()), context.stream()).toArray());
|
2018-06-19 18:04:05 +00:00
|
|
|
}
|
2019-08-05 00:16:01 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getMessage() {
|
|
|
|
return formatToString();
|
|
|
|
}
|
2012-08-04 15:26:51 +00:00
|
|
|
}
|