code cleanup

This commit is contained in:
FalsePattern committed 2022-07-31 20:41:56 +02:00
1 parent eaec528f5d
commit 316908baae
76 files changed
+691 -622

No files matched your search

@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -32,7 +32,7 @@ import cpw.mods.fml.relauncher.SideOnly;
/**
* This event is pushed on the FMLCommonHandler event bus once all the config synchronizations have finished.
*
* <p>
* This is a client-only event, and is never triggered serverside!
*/
@SideOnly(Side.CLIENT)
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -32,7 +32,7 @@ import cpw.mods.fml.relauncher.SideOnly;
/**
* This event is pushed on the FMLCommonHandler event bus once each time a single config synchronization has finished.
*
* <p>
* This is a client-only event, and is never triggered serverside!
*/
@SideOnly(Side.CLIENT)
@@ -1,4 +1,4 @@
/**
/*
* Copyright (C) 2022 FalsePattern
* All Rights Reserved
*
@@ -36,11 +36,20 @@ import java.util.List;
* You can use this event to manually trigger a synchronization request. The two different flavors are used on the two
* different game sides. If you want to trigger this on the server, use {@link #postServer}, and if on the client, use
* {@link #postClient}
*
*/
@StableAPI(since = "0.10.0")
@RequiredArgsConstructor(access = AccessLevel.PROTECTED)
public class ConfigSyncRequestEvent extends Event {
@StableAPI(since = "0.10.0")
public static void postClient() {
FMLCommonHandler.instance().bus().post(new Client());
}
@StableAPI(since = "0.10.0")
public static void postServer(List<EntityPlayerMP> players) {
FMLCommonHandler.instance().bus().post(new Server(new ArrayList<>(players)));
}
@StableAPI(since = "0.10.0")
public static class Client extends ConfigSyncRequestEvent {
@@ -55,14 +64,4 @@ public class ConfigSyncRequestEvent extends Event {
return Collections.unmodifiableList(players);
}
}
@StableAPI(since = "0.10.0")
public static void postClient() {
FMLCommonHandler.instance().bus().post(new Client());
}
@StableAPI(since = "0.10.0")
public static void postServer(List<EntityPlayerMP> players) {
FMLCommonHandler.instance().bus().post(new Server(new ArrayList<>(players)));
}
}
@@ -54,15 +54,24 @@ public abstract class ConfigValidationFailureEvent extends Event {
public final int listIndex;
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));
FMLCommonHandler.instance()
.bus()
.post(new NumericRangeOutOfBounds(field.getDeclaringClass(), field.getName(), listIndex, value,
min, max));
}
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));
FMLCommonHandler.instance()
.bus()
.post(new ListSizeOutOfBounds(field.getDeclaringClass(), field.getName(), requestedSize,
fixedSize, maxSize, defaultSize));
}
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));
FMLCommonHandler.instance()
.bus()
.post(new StringSizeOutOfBounds(field.getDeclaringClass(), field.getName(), listIndex, text,
maxSize));
}
public static void fieldIsNull(Field field, int listIndex) {
@@ -70,7 +79,35 @@ public abstract class ConfigValidationFailureEvent extends Event {
}
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));
FMLCommonHandler.instance()
.bus()
.post(new StringPatternMismatch(field.getDeclaringClass(), field.getName(), listIndex, text,
pattern));
}
@SideOnly(Side.CLIENT)
public void toast() {
val ann = configClass.getAnnotation(Config.class);
val toast = new SimpleToast(ToastBG.TOAST_DARK, null,
FormattedText.parse(EnumChatFormatting.RED + "Config validation failed")
.toChatText()
.get(0),
FormattedText.parse(ann.modid() + ":" + ann.category()).toChatText().get(0), false,
2000);
GuiToast.add(toast);
}
protected abstract void customText(StringBuilder b);
public void logWarn() {
val errorString = new StringBuilder("Error validating configuration field!");
errorString.append("\nReason: ").append(reason);
errorString.append("\nClass: ").append(configClass.getName()).append("\nField: ").append(fieldName);
if (listElement) {
errorString.append("\nArray index: ").append(listIndex);
}
customText(errorString);
FalsePatternLib.getLog().error(errorString.toString());
}
@StableAPI(since = "0.10.0")
@@ -91,9 +128,7 @@ public abstract class ConfigValidationFailureEvent extends Event {
@Override
protected void customText(StringBuilder b) {
b.append("\nValue: ").append(value)
.append("\nMin: ").append(min)
.append("\nMax: ").append(max);
b.append("\nValue: ").append(value).append("\nMin: ").append(min).append("\nMax: ").append(max);
}
}
@@ -132,6 +167,7 @@ public abstract class ConfigValidationFailureEvent extends Event {
public final String text;
@StableAPI(since = "0.10.0")
public final int maxSize;
private StringSizeOutOfBounds(Class<?> configClass, String fieldName, int listIndex, String text, int maxSize) {
super("String size out of bounds", configClass, fieldName, listIndex >= 0, listIndex);
this.text = text;
@@ -140,9 +176,12 @@ public abstract class ConfigValidationFailureEvent extends Event {
@Override
protected void customText(StringBuilder b) {
b.append("\nText: ").append(text)
.append("\nSize: ").append(text.length())
.append("\nMax size:").append(maxSize);
b.append("\nText: ")
.append(text)
.append("\nSize: ")
.append(text.length())
.append("\nMax size:")
.append(maxSize);
}
}
@@ -173,32 +212,7 @@ public abstract class ConfigValidationFailureEvent extends Event {
@Override
protected void customText(StringBuilder b) {
b.append("\nText: ").append(text)
.append("\nPattern: ").append(pattern);
b.append("\nText: ").append(text).append("\nPattern: ").append(pattern);
}
}
@SideOnly(Side.CLIENT)
public void toast() {
val ann = configClass.getAnnotation(Config.class);
val toast = new SimpleToast(ToastBG.TOAST_DARK, null,
FormattedText.parse(EnumChatFormatting.RED + "Config validation failed").toChatText().get(0),
FormattedText.parse(ann.modid() + ":" + ann.category()).toChatText().get(0),
false, 2000);
GuiToast.add(toast);
}
protected abstract void customText(StringBuilder b);
public void logWarn() {
val errorString = new StringBuilder("Error validating configuration field!");
errorString.append("\nReason: ").append(reason);
errorString.append("\nClass: ").append(configClass.getName())
.append("\nField: ").append(fieldName);
if (listElement) {
errorString.append("\nArray index: ").append(listIndex);
}
customText(errorString);
FalsePatternLib.getLog().error(errorString.toString());
}
}