Fix some fatal errors when config validation fails in coremods

This commit is contained in:
FalsePattern committed 2023-08-12 14:39:28 +02:00
1 parent ba11e5c0a8
commit 8fdaab9214
7 files changed
+73 -44

No files matched your search

@@ -21,9 +21,9 @@
package com.falsepattern.lib.config.event;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.EventUtil;
import lombok.val;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -44,13 +44,12 @@ public class AllConfigSyncEvent extends Event {
@StableAPI.Internal
public static boolean postStart() {
val event = new Start();
FMLCommonHandler.instance().bus().post(event);
return !event.isCanceled();
return EventUtil.postOnCommonBus(event);
}
@StableAPI.Internal
public static void postEnd() {
FMLCommonHandler.instance().bus().post(new End());
EventUtil.postOnCommonBus(new End());
}
@SideOnly(Side.CLIENT)
@@ -21,9 +21,9 @@
package com.falsepattern.lib.config.event;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.EventUtil;
import lombok.val;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -47,18 +47,17 @@ public class ConfigSyncEvent extends Event {
@StableAPI.Internal
public static boolean postStart(Class<?> configClass) {
val event = new Start(configClass);
FMLCommonHandler.instance().bus().post(event);
return !event.isCanceled();
return EventUtil.postOnCommonBus(event);
}
@StableAPI.Internal
public static void postEndSuccess(Class<?> configClass) {
FMLCommonHandler.instance().bus().post(new End(configClass, true, null));
EventUtil.postOnCommonBus(new End(configClass, true, null));
}
@StableAPI.Internal
public static void postEndFailure(Class<?> configClass, Throwable error) {
FMLCommonHandler.instance().bus().post(new End(configClass, false, error));
EventUtil.postOnCommonBus(new End(configClass, false, error));
}
@SideOnly(Side.CLIENT)
@@ -21,9 +21,9 @@
package com.falsepattern.lib.config.event;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.internal.EventUtil;
import net.minecraft.entity.player.EntityPlayerMP;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
import java.util.ArrayList;
@@ -43,12 +43,12 @@ public class ConfigSyncRequestEvent extends Event {
@StableAPI.Expose
public static void postClient() {
FMLCommonHandler.instance().bus().post(new Client());
EventUtil.postOnCommonBus(new Client());
}
@StableAPI.Expose
public static void postServer(List<EntityPlayerMP> players) {
FMLCommonHandler.instance().bus().post(new Server(new ArrayList<>(players)));
EventUtil.postOnCommonBus(new Server(new ArrayList<>(players)));
}
@StableAPI(since = "0.10.0")
@@ -22,6 +22,7 @@ package com.falsepattern.lib.config.event;
import com.falsepattern.lib.StableAPI;
import com.falsepattern.lib.config.Config;
import com.falsepattern.lib.internal.EventUtil;
import com.falsepattern.lib.internal.Share;
import com.falsepattern.lib.text.FormattedText;
import com.falsepattern.lib.toasts.GuiToast;
@@ -30,7 +31,6 @@ import com.falsepattern.lib.toasts.icon.ToastBG;
import lombok.val;
import net.minecraft.util.EnumChatFormatting;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@@ -61,53 +61,45 @@ public class ConfigValidationFailureEvent extends Event {
@StableAPI.Internal
public static void postNumericRangeOutOfBounds(Field field, int listIndex, String value, String min, String max) {
FMLCommonHandler.instance()
.bus()
.post(new NumericRangeOutOfBounds(field.getDeclaringClass(),
field.getName(),
listIndex,
value,
min,
max));
EventUtil.postOnCommonBus(new NumericRangeOutOfBounds(field.getDeclaringClass(),
field.getName(),
listIndex,
value,
min,
max));
}
@StableAPI.Internal
public static void postSize(Field field, int requestedSize, boolean fixedSize, int maxSize, int defaultSize) {
FMLCommonHandler.instance()
.bus()
.post(new ListSizeOutOfBounds(field.getDeclaringClass(),
field.getName(),
requestedSize,
fixedSize,
maxSize,
defaultSize));
EventUtil.postOnCommonBus(new ListSizeOutOfBounds(field.getDeclaringClass(),
field.getName(),
requestedSize,
fixedSize,
maxSize,
defaultSize));
}
@StableAPI.Internal
public static void postStringSizeOutOfBounds(Field field, int listIndex, String text, int maxSize) {
FMLCommonHandler.instance()
.bus()
.post(new StringSizeOutOfBounds(field.getDeclaringClass(),
field.getName(),
listIndex,
text,
maxSize));
EventUtil.postOnCommonBus(new StringSizeOutOfBounds(field.getDeclaringClass(),
field.getName(),
listIndex,
text,
maxSize));
}
@StableAPI.Internal
public static void fieldIsNull(Field field, int listIndex) {
FMLCommonHandler.instance().bus().post(new FieldIsNull(field.getDeclaringClass(), field.getName(), listIndex));
EventUtil.postOnCommonBus(new FieldIsNull(field.getDeclaringClass(), field.getName(), listIndex));
}
@StableAPI.Internal
public static void postStringPatternMismatch(Field field, int listIndex, String text, String pattern) {
FMLCommonHandler.instance()
.bus()
.post(new StringPatternMismatch(field.getDeclaringClass(),
field.getName(),
listIndex,
text,
pattern));
EventUtil.postOnCommonBus(new StringPatternMismatch(field.getDeclaringClass(),
field.getName(),
listIndex,
text,
pattern));
}
@SideOnly(Side.CLIENT)
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2022-2023 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice
* shall be included in all copies or substantial portions of the Software.
*
* This program 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.lib.internal;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.Event;
public class EventUtil {
public static boolean postOnCommonBus(Event event) {
if (!Share.EARLY_INIT_DONE) {
return false;
}
return FMLCommonHandler.instance()
.bus()
.post(event);
}
}
@@ -57,6 +57,7 @@ public class FalsePatternLib {
@Mod.EventHandler
public void construct(FMLConstructionEvent e) {
proxy.construct(e);
Share.EARLY_INIT_DONE = true;
}
@Mod.EventHandler
@@ -46,6 +46,8 @@ public final class Share {
}
}
public static boolean EARLY_INIT_DONE = false;
public static void deprecatedWarning(Throwable stacktrace) {
LOG.warn("DEPRECATED API CALLED!", stacktrace);
}