From dfba5690480abe20c52ea7a0350f771b3655220d Mon Sep 17 00:00:00 2001 From: FalsePattern <30945458+FalsePattern@users.noreply.github.com> Date: Sun, 16 Jul 2023 13:09:05 +0200 Subject: [PATCH] cleanup code --- .../falsepattern/lib/DeprecationDetails.java | 1 + .../java/com/falsepattern/lib/StableAPI.java | 3 +- .../com/falsepattern/lib/asm/ASMUtil.java | 20 +- .../com/falsepattern/lib/compat/BlockPos.java | 27 +- .../com/falsepattern/lib/compat/Vec3i.java | 3 +- .../com/falsepattern/lib/config/Config.java | 18 +- .../lib/config/SimpleGuiConfig.java | 9 +- .../event/ConfigValidationFailureEvent.java | 34 ++- .../lib/dependencies/Library.java | 31 ++- .../lib/dependencies/SemanticVersion.java | 16 +- .../falsepattern/lib/internal/Internet.java | 24 +- .../lib/internal/ReflectionUtil.java | 9 +- .../lib/internal/asm/CoreLoadingPlugin.java | 17 +- .../transformers/ConfigOrderTransformer.java | 11 +- .../transformers/IMixinPluginTransformer.java | 15 +- .../ITypeDiscovererTransformer.java | 2 +- .../lib/internal/config/LibraryConfig.java | 5 +- .../lib/internal/config/ToastConfig.java | 1 + .../impl/config/ConfigurationManagerImpl.java | 11 +- .../impl/config/ParsedConfiguration.java | 34 ++- .../config/event/ClientEventHandlerPre.java | 12 +- .../impl/config/fields/AConfigField.java | 4 +- .../impl/config/fields/AListConfigField.java | 16 +- .../config/fields/BooleanConfigField.java | 9 +- .../config/fields/BooleanListConfigField.java | 9 +- .../impl/config/fields/DoubleConfigField.java | 16 +- .../config/fields/DoubleListConfigField.java | 16 +- .../impl/config/fields/EnumConfigField.java | 48 ++-- .../impl/config/fields/IntConfigField.java | 16 +- .../config/fields/IntListConfigField.java | 16 +- .../impl/config/fields/StringConfigField.java | 26 +- .../config/fields/StringListConfigField.java | 23 +- .../dependencies/DependencyLoaderImpl.java | 253 +++++++++++------- .../impl/dependencies/RawVersion.java | 2 + .../lib/internal/impl/toast/GuiToastImpl.java | 5 +- .../impl/updates/UpdateCheckerImpl.java | 57 ++-- .../lib/mapping/MappingManager.java | 53 ++-- .../lib/mapping/types/UniversalMethod.java | 11 +- .../com/falsepattern/lib/mixin/IMixin.java | 5 +- .../falsepattern/lib/mixin/IMixinPlugin.java | 8 +- .../com/falsepattern/lib/mixin/MixinInfo.java | 18 +- .../lib/mixin/MixinInfoCompatCompanion.java | 9 +- .../falsepattern/lib/toasts/SimpleToast.java | 3 +- .../falsepattern/lib/toasts/icon/ToastBG.java | 4 +- .../lib/updates/ModUpdateInfo.java | 7 +- .../lib/updates/UpdateChecker.java | 5 +- .../com/falsepattern/lib/util/MathUtil.java | 9 +- .../com/falsepattern/lib/util/RenderUtil.java | 1 + .../falsepattern/lib/util/ResourceUtil.java | 6 +- src/main/resources/DEPENDENCIES.md | 22 +- src/main/resources/mcmod.info | 30 ++- 51 files changed, 637 insertions(+), 373 deletions(-) diff --git a/src/main/java/com/falsepattern/lib/DeprecationDetails.java b/src/main/java/com/falsepattern/lib/DeprecationDetails.java index 33179dc..9f9a193 100644 --- a/src/main/java/com/falsepattern/lib/DeprecationDetails.java +++ b/src/main/java/com/falsepattern/lib/DeprecationDetails.java @@ -34,6 +34,7 @@ import java.lang.annotation.RetentionPolicy; @StableAPI(since = "0.10.0") public @interface DeprecationDetails { @StableAPI.Expose String deprecatedSince(); + @StableAPI.Expose(since = "0.11.0") String replacement() default ""; /** diff --git a/src/main/java/com/falsepattern/lib/StableAPI.java b/src/main/java/com/falsepattern/lib/StableAPI.java index 52f9ad1..06af534 100644 --- a/src/main/java/com/falsepattern/lib/StableAPI.java +++ b/src/main/java/com/falsepattern/lib/StableAPI.java @@ -85,6 +85,5 @@ public @interface StableAPI { @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR}) @StableAPI(since = "0.10.0") - @interface Internal { - } + @interface Internal {} } diff --git a/src/main/java/com/falsepattern/lib/asm/ASMUtil.java b/src/main/java/com/falsepattern/lib/asm/ASMUtil.java index d8cf2d0..52d56ab 100644 --- a/src/main/java/com/falsepattern/lib/asm/ASMUtil.java +++ b/src/main/java/com/falsepattern/lib/asm/ASMUtil.java @@ -63,12 +63,16 @@ public class ASMUtil { public static FieldNode findFieldFromMCP(ClassNode cn, String fieldName, boolean optional) { val classMapping = discoverClassMappingType(cn); if (classMapping == null) { - throw new AsmClassNotFoundException("The class " + cn + " is not from Minecraft, or the mapping manager" + - "doesn't have it, cannot use findFieldFromMCP! Use findFieldStandard instead!"); + throw new AsmClassNotFoundException("The class " + + cn + + " is not from Minecraft, or the mapping manager" + + "doesn't have it, cannot use findFieldFromMCP! Use findFieldStandard instead!"); } - return findFieldStandard(cn, MappingManager.classForName(NameType.Internal, classMapping, cn.name) - .getField(MappingType.MCP, fieldName) - .getName(classMapping), optional); + return findFieldStandard(cn, + MappingManager.classForName(NameType.Internal, classMapping, cn.name) + .getField(MappingType.MCP, fieldName) + .getName(classMapping), + optional); } @StableAPI.Expose @@ -106,8 +110,10 @@ public class ASMUtil { public static MethodNode findMethodFromMCP(ClassNode cn, String mcpName, String mcpDescriptor, boolean optional) { val classMapping = discoverClassMappingType(cn); if (classMapping == null) { - throw new AsmClassNotFoundException("The class " + cn + " is not from Minecraft, or the mapping manager" + - "doesn't have it, cannot use findMethodFromMCP! Use findFieldStandard instead!"); + throw new AsmClassNotFoundException("The class " + + cn + + " is not from Minecraft, or the mapping manager" + + "doesn't have it, cannot use findMethodFromMCP! Use findFieldStandard instead!"); } val method = MappingManager.classForName(NameType.Internal, classMapping, cn.name) .getMethod(MappingType.MCP, mcpName, mcpDescriptor); diff --git a/src/main/java/com/falsepattern/lib/compat/BlockPos.java b/src/main/java/com/falsepattern/lib/compat/BlockPos.java index 93909ab..6f138eb 100644 --- a/src/main/java/com/falsepattern/lib/compat/BlockPos.java +++ b/src/main/java/com/falsepattern/lib/compat/BlockPos.java @@ -115,9 +115,12 @@ public class BlockPos extends Vec3i { */ @StableAPI.Expose public static Iterable getAllInBox(@NonNull BlockPos from, @NonNull BlockPos to) { - return getAllInBox(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), - Math.min(from.getZ(), to.getZ()), Math.max(from.getX(), to.getX()), - Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ())); + return getAllInBox(Math.min(from.getX(), to.getX()), + Math.min(from.getY(), to.getY()), + Math.min(from.getZ(), to.getZ()), + Math.max(from.getX(), to.getX()), + Math.max(from.getY(), to.getY()), + Math.max(from.getZ(), to.getZ())); } /** @@ -192,9 +195,12 @@ public class BlockPos extends Vec3i { */ @StableAPI.Expose public static Iterable getAllInBoxMutable(@NonNull BlockPos from, @NonNull BlockPos to) { - return getAllInBoxMutable(Math.min(from.getX(), to.getX()), Math.min(from.getY(), to.getY()), - Math.min(from.getZ(), to.getZ()), Math.max(from.getX(), to.getX()), - Math.max(from.getY(), to.getY()), Math.max(from.getZ(), to.getZ())); + return getAllInBoxMutable(Math.min(from.getX(), to.getX()), + Math.min(from.getY(), to.getY()), + Math.min(from.getZ(), to.getZ()), + Math.max(from.getX(), to.getX()), + Math.max(from.getY(), to.getY()), + Math.max(from.getZ(), to.getZ())); } /** @@ -304,7 +310,8 @@ public class BlockPos extends Vec3i { if (blocks == 0) { return this; } - return new BlockPos(x + facing.getFrontOffsetX() * blocks, y + facing.getFrontOffsetY() * blocks, + return new BlockPos(x + facing.getFrontOffsetX() * blocks, + y + facing.getFrontOffsetY() * blocks, z + facing.getFrontOffsetZ() * blocks); } @@ -380,7 +387,8 @@ public class BlockPos extends Vec3i { @Override public BlockPos crossProduct(@NonNull Vec3i vec) { - return new BlockPos(y * vec.getZ() - z * vec.getY(), z * vec.getX() - x * vec.getZ(), + return new BlockPos(y * vec.getZ() - z * vec.getY(), + z * vec.getX() - x * vec.getZ(), x * vec.getY() - y * vec.getX()); } @@ -479,7 +487,8 @@ public class BlockPos extends Vec3i { @StableAPI.Expose public BlockPos.MutableBlockPos move(@NonNull EnumFacing facing, int blocks) { - return this.setPos(x + facing.getFrontOffsetX() * blocks, y + facing.getFrontOffsetY() * blocks, + return this.setPos(x + facing.getFrontOffsetX() * blocks, + y + facing.getFrontOffsetY() * blocks, z + facing.getFrontOffsetZ() * blocks); } } diff --git a/src/main/java/com/falsepattern/lib/compat/Vec3i.java b/src/main/java/com/falsepattern/lib/compat/Vec3i.java index d24b359..c37e335 100644 --- a/src/main/java/com/falsepattern/lib/compat/Vec3i.java +++ b/src/main/java/com/falsepattern/lib/compat/Vec3i.java @@ -78,7 +78,8 @@ public class Vec3i implements Comparable { */ @StableAPI.Expose public Vec3i crossProduct(@NonNull Vec3i vec) { - return new Vec3i(y * vec.getZ() - z * vec.getY(), z * vec.getX() - x * vec.getZ(), + return new Vec3i(y * vec.getZ() - z * vec.getY(), + z * vec.getX() - x * vec.getZ(), x * vec.getY() - y * vec.getX()); } diff --git a/src/main/java/com/falsepattern/lib/config/Config.java b/src/main/java/com/falsepattern/lib/config/Config.java index 6193914..1a8ac20 100644 --- a/src/main/java/com/falsepattern/lib/config/Config.java +++ b/src/main/java/com/falsepattern/lib/config/Config.java @@ -80,8 +80,7 @@ public @interface Config { @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) - @interface Ignore { - } + @interface Ignore {} /** * The default value for a boolean field. Not having a default is deprecated since 0.10, and will be strongly @@ -253,8 +252,7 @@ public @interface Config { @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) - @interface ListFixedLength { - } + @interface ListFixedLength {} /** * This annotation limits the maximum number of elements present in an array configuration. Only effective if @@ -290,8 +288,7 @@ public @interface Config { @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.TYPE}) - @interface RequiresMcRestart { - } + @interface RequiresMcRestart {} /** * Whether the specific configuration needs a world/server rejoin to be applied. @@ -300,8 +297,7 @@ public @interface Config { @Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD, ElementType.TYPE}) - @interface RequiresWorldRestart { - } + @interface RequiresWorldRestart {} /** * Signals that this configuration class should be synchronized between the client and the server when @@ -314,8 +310,7 @@ public @interface Config { @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) - @interface Synchronize { - } + @interface Synchronize {} /** * Use this to mark config fields you don't want to synchronize in a class marked with {@link Synchronize}. @@ -324,6 +319,5 @@ public @interface Config { @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.FIELD) - @interface NoSync { - } + @interface NoSync {} } \ No newline at end of file diff --git a/src/main/java/com/falsepattern/lib/config/SimpleGuiConfig.java b/src/main/java/com/falsepattern/lib/config/SimpleGuiConfig.java index 0e14bb3..9479edf 100644 --- a/src/main/java/com/falsepattern/lib/config/SimpleGuiConfig.java +++ b/src/main/java/com/falsepattern/lib/config/SimpleGuiConfig.java @@ -40,7 +40,12 @@ public class SimpleGuiConfig extends GuiConfig { @StableAPI.Expose(since = "0.10.0") public SimpleGuiConfig(GuiScreen parent, String modID, String modName, Class... configClasses) throws ConfigException { - super(parent, ConfigurationManager.getConfigElementsMulti(configClasses), modID, false, false, - modName + " Configuration", I18n.format("falsepatternlib.gui.config.description")); + super(parent, + ConfigurationManager.getConfigElementsMulti(configClasses), + modID, + false, + false, + modName + " Configuration", + I18n.format("falsepatternlib.gui.config.description")); } } diff --git a/src/main/java/com/falsepattern/lib/config/event/ConfigValidationFailureEvent.java b/src/main/java/com/falsepattern/lib/config/event/ConfigValidationFailureEvent.java index dbe0201..ea6855d 100644 --- a/src/main/java/com/falsepattern/lib/config/event/ConfigValidationFailureEvent.java +++ b/src/main/java/com/falsepattern/lib/config/event/ConfigValidationFailureEvent.java @@ -63,23 +63,34 @@ public class ConfigValidationFailureEvent extends Event { 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)); + .post(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)); + .post(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, + .post(new StringSizeOutOfBounds(field.getDeclaringClass(), + field.getName(), + listIndex, + text, maxSize)); } @@ -92,7 +103,10 @@ public 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, + .post(new StringPatternMismatch(field.getDeclaringClass(), + field.getName(), + listIndex, + text, pattern)); } @@ -100,11 +114,13 @@ public class ConfigValidationFailureEvent extends Event { @StableAPI.Internal public void toast() { val ann = configClass.getAnnotation(Config.class); - val toast = new SimpleToast(ToastBG.TOAST_DARK, null, + 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, + FormattedText.parse(ann.modid() + ":" + ann.category()).toChatText().get(0), + false, 2000); GuiToast.add(toast); } @@ -122,7 +138,7 @@ public class ConfigValidationFailureEvent extends Event { errorString.append("\nArray index: ").append(listIndex); } customText(errorString); - for (val line: errorString.toString().split("\n")) { + for (val line : errorString.toString().split("\n")) { Share.LOG.error(line); } } diff --git a/src/main/java/com/falsepattern/lib/dependencies/Library.java b/src/main/java/com/falsepattern/lib/dependencies/Library.java index 947dd96..9b07743 100644 --- a/src/main/java/com/falsepattern/lib/dependencies/Library.java +++ b/src/main/java/com/falsepattern/lib/dependencies/Library.java @@ -130,16 +130,35 @@ public class Library { @StableAPI.Expose public Library build() { - return new Library(loadingModId, groupId, artifactId, minVersion, maxVersion, preferredVersion, - regularSuffix, devSuffix); + return new Library(loadingModId, + groupId, + artifactId, + minVersion, + maxVersion, + preferredVersion, + regularSuffix, + devSuffix); } @Override public String toString() { - return "Library.LibraryBuilder(loadingModId=" + this.loadingModId + ", groupId=" + this.groupId + - ", artifactId=" + this.artifactId + ", minVersion=" + this.minVersion + ", maxVersion=" + - this.maxVersion + ", preferredVersion=" + this.preferredVersion + ", regularSuffix=" + - this.regularSuffix + ", devSuffix=" + this.devSuffix + ")"; + return "Library.LibraryBuilder(loadingModId=" + + this.loadingModId + + ", groupId=" + + this.groupId + + ", artifactId=" + + this.artifactId + + ", minVersion=" + + this.minVersion + + ", maxVersion=" + + this.maxVersion + + ", preferredVersion=" + + this.preferredVersion + + ", regularSuffix=" + + this.regularSuffix + + ", devSuffix=" + + this.devSuffix + + ")"; } } } diff --git a/src/main/java/com/falsepattern/lib/dependencies/SemanticVersion.java b/src/main/java/com/falsepattern/lib/dependencies/SemanticVersion.java index b9fbea9..b1245be 100644 --- a/src/main/java/com/falsepattern/lib/dependencies/SemanticVersion.java +++ b/src/main/java/com/falsepattern/lib/dependencies/SemanticVersion.java @@ -111,9 +111,11 @@ public class SemanticVersion extends Version { @Override public String toString() { + // @formatter:off return majorVersion + (minorVersion < 0 ? "" : "." + minorVersion) + (patchVersion < 0 ? "" : "." + patchVersion) + (preRelease == null ? "" : "-" + preRelease) + (build == null ? "" : "+" + build); + // @formatter:on } @StableAPI(since = "0.10.0") @@ -165,9 +167,17 @@ public class SemanticVersion extends Version { @Override public String toString() { - return "SemanticVersion.SemanticVersionBuilder(majorVersion=" + this.majorVersion + ", minorVersion=" + - this.minorVersion + ", patchVersion=" + this.patchVersion + ", preRelease=" + this.preRelease + - ", build=" + this.build + ")"; + return "SemanticVersion.SemanticVersionBuilder(majorVersion=" + + this.majorVersion + + ", minorVersion=" + + this.minorVersion + + ", patchVersion=" + + this.patchVersion + + ", preRelease=" + + this.preRelease + + ", build=" + + this.build + + ")"; } } } diff --git a/src/main/java/com/falsepattern/lib/internal/Internet.java b/src/main/java/com/falsepattern/lib/internal/Internet.java index 1ad1037..e10fc8f 100644 --- a/src/main/java/com/falsepattern/lib/internal/Internet.java +++ b/src/main/java/com/falsepattern/lib/internal/Internet.java @@ -44,6 +44,7 @@ import java.util.function.Consumer; public class Internet { private static final Map NO_HEADERS = Collections.emptyMap(); + public static void connect(URL URL, Consumer onError, Consumer onSuccess) { connect(URL, NO_HEADERS, onError, onSuccess); } @@ -64,9 +65,13 @@ public class Internet { val connection = (HttpURLConnection) URL.openConnection(); connection.setConnectTimeout(3500); connection.setReadTimeout(5000); - connection.setRequestProperty("User-Agent", Tags.MODNAME + " " + Tags.VERSION + " Internet Connector" + - " (https://github.com/FalsePattern/FalsePatternLib)"); - for (val header: headers.entrySet()) { + connection.setRequestProperty("User-Agent", + Tags.MODNAME + + " " + + Tags.VERSION + + " Internet Connector" + + " (https://github.com/FalsePattern/FalsePatternLib)"); + for (val header : headers.entrySet()) { val key = header.getKey(); val value = header.getValue(); if (key == null || value == null) { @@ -87,8 +92,9 @@ public class Internet { //Check if NonUpdate is present try { if (Launch.classLoader.getClassBytes("moe.mickey.forge.nonupdate.NonUpdate") != null) { - e.addSuppressed(new Exception("NonUpdate is present, it's possible that it's blocking a library download." + - " Please disable it for a single run to allow mod dependencies to download.")); + e.addSuppressed(new Exception( + "NonUpdate is present, it's possible that it's blocking a library download." + + " Please disable it for a single run to allow mod dependencies to download.")); } } catch (IOException ex) { e.addSuppressed(ex); @@ -111,7 +117,9 @@ public class Internet { throw new CompletionException(e); } }); - if (success.get()) return result.toByteArray(); + if (success.get()) { + return result.toByteArray(); + } } throw new CompletionException(caught.get()); }); @@ -131,7 +139,9 @@ public class Internet { throw new CompletionException(e); } }); - if (success.get()) return; + if (success.get()) { + return; + } } throw new CompletionException(caught.get()); }); diff --git a/src/main/java/com/falsepattern/lib/internal/ReflectionUtil.java b/src/main/java/com/falsepattern/lib/internal/ReflectionUtil.java index fd28e6c..e4f7dd4 100644 --- a/src/main/java/com/falsepattern/lib/internal/ReflectionUtil.java +++ b/src/main/java/com/falsepattern/lib/internal/ReflectionUtil.java @@ -39,12 +39,10 @@ public class ReflectionUtil { } // ref: https://github.com/prestodb/presto/pull/15240/files#diff-8bf996e5c1d4fb088b84ae0528bc42686b0724bcf5a2692a1e7b5eff32c90cce - private static Field getModifiersField() throws NoSuchFieldException - { + private static Field getModifiersField() throws NoSuchFieldException { try { return Field.class.getDeclaredField("modifiers"); - } - catch (NoSuchFieldException e) { + } catch (NoSuchFieldException e) { try { Method getDeclaredFields0 = Class.class.getDeclaredMethod("getDeclaredFields0", boolean.class); getDeclaredFields0.setAccessible(true); @@ -54,8 +52,7 @@ public class ReflectionUtil { return field; } } - } - catch (ReflectiveOperationException ex) { + } catch (ReflectiveOperationException ex) { e.addSuppressed(ex); } throw e; diff --git a/src/main/java/com/falsepattern/lib/internal/asm/CoreLoadingPlugin.java b/src/main/java/com/falsepattern/lib/internal/asm/CoreLoadingPlugin.java index 330d0b9..6c25d6f 100644 --- a/src/main/java/com/falsepattern/lib/internal/asm/CoreLoadingPlugin.java +++ b/src/main/java/com/falsepattern/lib/internal/asm/CoreLoadingPlugin.java @@ -116,15 +116,20 @@ public class CoreLoadingPlugin implements IFMLLoadingPlugin { public static void validateGasStation() { Share.LOG.info("Got any gas?"); //Make sure everything is loaded correctly, crash if gasstation is bugged - if (!isClassPresentSafe("com.falsepattern.gasstation.core.GasStationCore") || //Validate core class - !isClassPresentSafe("makamys.mixingasm.api.TransformerInclusions") || //Validate the mixingasm compat - !isClassPresentSafe("ru.timeconqueror.spongemixins.core.SpongeMixinsCore") || //Validate the spongemixins compat - !isClassPresentSafe("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin") || //Validate the MBL compat - (!isClassPresentSafe("org.spongepowered.asm.lib.Opcodes") || isClassPresentSafe("org.spongepowered.libraries.org.objectweb.asm.Opcodes")) //Validate correct mixins class + // @formatter:off + if (!isClassPresentSafe("com.falsepattern.gasstation.core.GasStationCore") //Validate core class + || !isClassPresentSafe("makamys.mixingasm.api.TransformerInclusions") //Validate the mixingasm compat + || !isClassPresentSafe("ru.timeconqueror.spongemixins.core.SpongeMixinsCore") //Validate the spongemixins compat + || !isClassPresentSafe("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin") //Validate the MBL compat + || !isClassPresentSafe("org.spongepowered.asm.lib.Opcodes") //Validate correct mixins class + || isClassPresentSafe("org.spongepowered.libraries.org.objectweb.asm.Opcodes") ) { Share.LOG.fatal("Somebody put diesel in my gas tank!"); - throw new Error("Failed to validate your GasStation mixin plugin installation. Please make sure you have the latest GasStation installed from the official source: https://github.com/FalsePattern/GasStation"); + throw new Error("Failed to validate your GasStation mixin plugin installation. " + + "Please make sure you have the latest GasStation installed from the official source: " + + "https://github.com/FalsePattern/GasStation"); } + // @formatter:on } @Override diff --git a/src/main/java/com/falsepattern/lib/internal/asm/transformers/ConfigOrderTransformer.java b/src/main/java/com/falsepattern/lib/internal/asm/transformers/ConfigOrderTransformer.java index 097bfe9..5545f2e 100644 --- a/src/main/java/com/falsepattern/lib/internal/asm/transformers/ConfigOrderTransformer.java +++ b/src/main/java/com/falsepattern/lib/internal/asm/transformers/ConfigOrderTransformer.java @@ -33,6 +33,7 @@ public class ConfigOrderTransformer implements IClassNodeTransformer { private static final String DESC_CONFIG = Type.getDescriptor(Config.class); private static final String DESC_CONFIG_IGNORE = Type.getDescriptor(Config.Ignore.class); private static final String DESC_ORDER = Type.getDescriptor(DeclOrderInternal.class); + @Override public String getName() { return "ConfigOrderTransformer"; @@ -54,11 +55,11 @@ public class ConfigOrderTransformer implements IClassNodeTransformer { public void transform(ClassNode cn, String transformedName, boolean obfuscated) { int order = 0; outer: - for (val field: cn.fields) { - if ((field.access & Opcodes.ACC_PUBLIC) == 0 || - (field.access & Opcodes.ACC_STATIC) == 0 || - (field.access & Opcodes.ACC_FINAL) != 0) { - continue; + for (val field : cn.fields) { + if ((field.access & Opcodes.ACC_PUBLIC) == 0 + || (field.access & Opcodes.ACC_STATIC) == 0 + || (field.access & Opcodes.ACC_FINAL) != 0) { + continue; } else if (field.visibleAnnotations != null) { for (val ann : field.visibleAnnotations) { if (DESC_CONFIG_IGNORE.equals(ann.desc)) { diff --git a/src/main/java/com/falsepattern/lib/internal/asm/transformers/IMixinPluginTransformer.java b/src/main/java/com/falsepattern/lib/internal/asm/transformers/IMixinPluginTransformer.java index 9190e1c..d839de1 100644 --- a/src/main/java/com/falsepattern/lib/internal/asm/transformers/IMixinPluginTransformer.java +++ b/src/main/java/com/falsepattern/lib/internal/asm/transformers/IMixinPluginTransformer.java @@ -61,10 +61,11 @@ public class IMixinPluginTransformer implements IClassNodeTransformer { @Override public boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated) { - return IMIXINPLUGIN.equals(transformedName) || - IMIXINCONFIGPLUGIN.equals(transformedName) || - cn.interfaces.stream().anyMatch((i) -> IMIXINPLUGIN_INTERNAL.equals(i) || - IMIXINCONFIGPLUGIN_INTERNAL.equals(i)); + return IMIXINPLUGIN.equals(transformedName) + || IMIXINCONFIGPLUGIN.equals(transformedName) + || cn.interfaces.stream() + .anyMatch((i) -> IMIXINPLUGIN_INTERNAL.equals(i) + || IMIXINCONFIGPLUGIN_INTERNAL.equals(i)); } @Override @@ -89,7 +90,7 @@ public class IMixinPluginTransformer implements IClassNodeTransformer { continue; } if (CLASSNODE_REAL != null) { - for (val local: method.localVariables) { + for (val local : method.localVariables) { if (local.desc.contains("ClassNode;")) { local.desc = local.desc.replaceAll("L[a-zA-Z/$]+[a-zA-Z$]+/ClassNode;", CLASSNODE_REAL); } @@ -119,10 +120,10 @@ public class IMixinPluginTransformer implements IClassNodeTransformer { } private static String extractMethodWithReflection(String m) { - for (val method: IMixinConfigPlugin.class.getDeclaredMethods()) { + for (val method : IMixinConfigPlugin.class.getDeclaredMethods()) { if (method.getName().equals(m)) { StringBuilder b = new StringBuilder("("); - for (val param: method.getParameterTypes()) { + for (val param : method.getParameterTypes()) { if (param.getName().contains("ClassNode")) { CLASSNODE_REAL = "L" + param.getName().replace('.', '/') + ";"; } diff --git a/src/main/java/com/falsepattern/lib/internal/asm/transformers/ITypeDiscovererTransformer.java b/src/main/java/com/falsepattern/lib/internal/asm/transformers/ITypeDiscovererTransformer.java index b616be9..543e7e9 100644 --- a/src/main/java/com/falsepattern/lib/internal/asm/transformers/ITypeDiscovererTransformer.java +++ b/src/main/java/com/falsepattern/lib/internal/asm/transformers/ITypeDiscovererTransformer.java @@ -39,7 +39,7 @@ public class ITypeDiscovererTransformer implements IClassNodeTransformer { @Override public void transform(ClassNode cn, String transformedName, boolean obfuscated) { - for (val method: cn.methods) { + for (val method : cn.methods) { if (!method.name.equals("")) { continue; } diff --git a/src/main/java/com/falsepattern/lib/internal/config/LibraryConfig.java b/src/main/java/com/falsepattern/lib/internal/config/LibraryConfig.java index c1294e7..5c3c8ac 100644 --- a/src/main/java/com/falsepattern/lib/internal/config/LibraryConfig.java +++ b/src/main/java/com/falsepattern/lib/internal/config/LibraryConfig.java @@ -30,9 +30,10 @@ public class LibraryConfig { static { ConfigurationManager.selfInit(); } + @Config.Comment({"Used to control whether FalsePatternLib should check for outdated mods.", - "If you're building a public modpack, you should turn this off so that your users don't " + - "get nagged about outdated mods."}) + "If you're building a public modpack, you should turn this off so that your users don't " + + "get nagged about outdated mods."}) @Config.LangKey("config.falsepatternlib.updatecheck") @Config.DefaultBoolean(true) public static boolean ENABLE_UPDATE_CHECKER; diff --git a/src/main/java/com/falsepattern/lib/internal/config/ToastConfig.java b/src/main/java/com/falsepattern/lib/internal/config/ToastConfig.java index f598413..9689410 100644 --- a/src/main/java/com/falsepattern/lib/internal/config/ToastConfig.java +++ b/src/main/java/com/falsepattern/lib/internal/config/ToastConfig.java @@ -35,6 +35,7 @@ public class ToastConfig { static { ConfigurationManager.selfInit(); } + @Config.Comment("The maximum amount of toasts to show on the screen") @Config.LangKey("config.falsepatternlib.maxtoasts") @Config.DefaultInt(5) diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/ConfigurationManagerImpl.java b/src/main/java/com/falsepattern/lib/internal/impl/config/ConfigurationManagerImpl.java index 6bad141..83c6b20 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/ConfigurationManagerImpl.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/ConfigurationManagerImpl.java @@ -171,23 +171,20 @@ public final class ConfigurationManagerImpl { val opt = serializedNames.keySet().stream().filter((key) -> key.equals(serializedName)).findFirst(); if (!opt.isPresent()) { input.skipBytes(dataSize); - Share.LOG - .warn("Server tried to sync config not registered on our side: " + serializedName); + Share.LOG.warn("Server tried to sync config not registered on our side: " + serializedName); continue; } val clazz = serializedNames.get(opt.get()); val config = parsedConfigMap.get(clazz); if (!config.sync) { input.skipBytes(dataSize); - Share.LOG - .warn("Server tried to sync config without @Synchronize annotation on our side: " + - serializedName); + Share.LOG.warn("Server tried to sync config without @Synchronize annotation on our side: " + + serializedName); continue; } if (!ConfigSyncEvent.postStart(clazz)) { input.skipBytes(dataSize); - Share.LOG.warn( - "Config synchronization was cancelled by event for: " + serializedName); + Share.LOG.warn("Config synchronization was cancelled by event for: " + serializedName); continue; } val bytes = new byte[dataSize]; diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/ParsedConfiguration.java b/src/main/java/com/falsepattern/lib/internal/impl/config/ParsedConfiguration.java index f1182a9..7c73ef2 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/ParsedConfiguration.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/ParsedConfiguration.java @@ -82,14 +82,19 @@ public class ParsedConfiguration { public static ParsedConfiguration parseConfig(Class configClass) throws ConfigException { val cfg = Optional.ofNullable(configClass.getAnnotation(Config.class)) - .orElseThrow(() -> new ConfigException( - "Class " + configClass.getName() + " does not have a @Config annotation!")); + .orElseThrow(() -> new ConfigException("Class " + + configClass.getName() + + " does not have a @Config annotation!")); val category = Optional.of(cfg.category().trim()) .map((cat) -> cat.length() == 0 ? null : cat) - .orElseThrow(() -> new ConfigException( - "Config class " + configClass.getName() + " has an empty category!")); + .orElseThrow(() -> new ConfigException("Config class " + + configClass.getName() + + " has an empty category!")); val rawConfig = ConfigurationManagerImpl.getForgeConfig(cfg.modid()); - val parsedConfig = new ParsedConfiguration(configClass, cfg.modid(), category, rawConfig, + val parsedConfig = new ParsedConfiguration(configClass, + cfg.modid(), + category, + rawConfig, configClass.isAnnotationPresent(Config.Synchronize.class)); try { parsedConfig.reloadFields(); @@ -133,8 +138,10 @@ public class ParsedConfiguration { val fieldName = StringConfigField.receiveString(input, maxFieldNameLength, "field name", configClass.getName()); if (!syncFields.containsKey(fieldName)) { - throw new IOException("Invalid sync field name received: " + fieldName + " for config class " + - configClass.getName()); + throw new IOException("Invalid sync field name received: " + + fieldName + + " for config class " + + configClass.getName()); } syncFields.remove(fieldName).receive(input); } @@ -180,9 +187,13 @@ public class ParsedConfiguration { } else if (fieldClass.isEnum()) { fields.put(name, configField = new EnumConfigField<>(field, rawConfig, category)); } else { - throw new ConfigException("Illegal config field: " + field.getName() + " in " + configClass.getName() + - ": Unsupported type " + fieldClass.getName() + - "! Did you forget an @Ignore annotation?"); + throw new ConfigException("Illegal config field: " + + field.getName() + + " in " + + configClass.getName() + + ": Unsupported type " + + fieldClass.getName() + + "! Did you forget an @Ignore annotation?"); } if (field.isAnnotationPresent(Config.RequiresMcRestart.class)) { cat.setRequiresMcRestart(true); @@ -196,7 +207,8 @@ public class ParsedConfiguration { save(); })); } - rawConfig.setCategoryPropertyOrder(category, fieldsSorted().map((prop) -> prop.name).collect(Collectors.toList())); + rawConfig.setCategoryPropertyOrder(category, + fieldsSorted().map((prop) -> prop.name).collect(Collectors.toList())); } private Stream> fieldsSorted() { diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/event/ClientEventHandlerPre.java b/src/main/java/com/falsepattern/lib/internal/impl/config/event/ClientEventHandlerPre.java index f1a77ba..85fccfc 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/event/ClientEventHandlerPre.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/event/ClientEventHandlerPre.java @@ -61,19 +61,23 @@ public class ClientEventHandlerPre { public void onConfigSyncFinished(ConfigSyncEvent.End e) { val cfg = e.configClass.getAnnotation(Config.class); if (e.successful) { - GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK, null, + GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK, + null, FormattedText.parse(EnumChatFormatting.GREEN + "Synced config") .toChatText() .get(0), FormattedText.parse(cfg.modid() + ":" + cfg.category()).toChatText().get(0), - false, 5000)); + false, + 5000)); } else { - GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK, null, + GuiToast.add(new SimpleToast(ToastBG.TOAST_DARK, + null, FormattedText.parse(EnumChatFormatting.RED + "Failed to sync config") .toChatText() .get(0), FormattedText.parse(cfg.modid() + ":" + cfg.category()).toChatText().get(0), - false, 5000)); + false, + 5000)); } } } diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/AConfigField.java b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/AConfigField.java index 7008f4f..c4ae02d 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/AConfigField.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/AConfigField.java @@ -73,7 +73,9 @@ public abstract class AConfigField { } property.setLanguageKey(langKey); noSync = field.isAnnotationPresent(Config.NoSync.class); - order = Optional.ofNullable(field.getAnnotation(DeclOrderInternal.class)).map(DeclOrderInternal::value).orElse(-1); + order = Optional.ofNullable(field.getAnnotation(DeclOrderInternal.class)) + .map(DeclOrderInternal::value) + .orElse(-1); } protected abstract T getField(); diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/AListConfigField.java b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/AListConfigField.java index e461beb..f62d54f 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/AListConfigField.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/AListConfigField.java @@ -47,9 +47,11 @@ public abstract class AListConfigField extends AConfigField { .map(Config.ListMaxLength::value) .orElse(256); if (maxLength < 0) { - throw new ConfigException( - "Negative length list configurations are not supported!\n" + "Field name: " + field.getName() + - ", class: " + field.getDeclaringClass().getName()); + throw new ConfigException("Negative length list configurations are not supported!\n" + + "Field name: " + + field.getName() + + ", class: " + + field.getDeclaringClass().getName()); } property.setIsListLengthFixed(fixedLength); property.setMaxListLength(maxLength); @@ -105,8 +107,12 @@ public abstract class AListConfigField extends AConfigField { public void receive(DataInput input) throws IOException { int length = input.readInt(); if (length > maxLength || fixedLength && length(getDefault()) != length) { - throw new IOException("Error while retrieving config value for field " + field.getName() + " in class " + - field.getDeclaringClass().getName() + ":\n" + "Illegal array length received!"); + throw new IOException("Error while retrieving config value for field " + + field.getName() + + " in class " + + field.getDeclaringClass().getName() + + ":\n" + + "Illegal array length received!"); } val arr = createArray(length); receiveElements(input, arr); diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/BooleanConfigField.java b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/BooleanConfigField.java index cc94676..8b60e4c 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/BooleanConfigField.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/BooleanConfigField.java @@ -44,10 +44,11 @@ public class BooleanConfigField extends AConfigField { defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultBoolean.class)) .map(Config.DefaultBoolean::value) .orElseGet(() -> { - Share.LOG - .warn("The field " + field.getName() + " in class " + - field.getDeclaringClass().getName() + - " has no DefaultBoolean annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); + Share.LOG.warn("The field " + + field.getName() + + " in class " + + field.getDeclaringClass().getName() + + " has no DefaultBoolean annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); try { return field.getType().isPrimitive() ? field.getBoolean(null) : (Boolean) field.get(null); diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/BooleanListConfigField.java b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/BooleanListConfigField.java index 313a6df..87cc173 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/BooleanListConfigField.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/BooleanListConfigField.java @@ -43,10 +43,11 @@ public class BooleanListConfigField extends AListConfigField { defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultBooleanList.class)) .map(Config.DefaultBooleanList::value) .orElseGet(() -> { - Share.LOG - .warn("The field " + field.getName() + " in class " + - field.getDeclaringClass().getName() + - " has no DefaultBooleanList annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); + Share.LOG.warn("The field " + + field.getName() + + " in class " + + field.getDeclaringClass().getName() + + " has no DefaultBooleanList annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); try { return (boolean[]) field.get(null); } catch (IllegalAccessException e) { diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/DoubleConfigField.java b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/DoubleConfigField.java index c345d77..e03028a 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/DoubleConfigField.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/DoubleConfigField.java @@ -50,10 +50,11 @@ public class DoubleConfigField extends AConfigField { defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultDouble.class)) .map(Config.DefaultDouble::value) .orElseGet(() -> { - Share.LOG - .warn("The field " + field.getName() + " in class " + - field.getDeclaringClass().getName() + - " has no DefaultDouble annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); + Share.LOG.warn("The field " + + field.getName() + + " in class " + + field.getDeclaringClass().getName() + + " has no DefaultDouble annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); try { return field.getType().isPrimitive() ? field.getInt(null) : (Double) field.get(null); @@ -112,8 +113,11 @@ public class DoubleConfigField extends AConfigField { if (value >= min && value <= max) { return true; } - ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, -1, Double.toString(value), - Double.toString(min), Double.toString(max)); + ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, + -1, + Double.toString(value), + Double.toString(min), + Double.toString(max)); return false; } diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/DoubleListConfigField.java b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/DoubleListConfigField.java index 1fb9d38..2c460a0 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/DoubleListConfigField.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/DoubleListConfigField.java @@ -49,10 +49,11 @@ public class DoubleListConfigField extends AListConfigField { defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultDoubleList.class)) .map(Config.DefaultDoubleList::value) .orElseGet(() -> { - Share.LOG - .warn("The field " + field.getName() + " in class " + - field.getDeclaringClass().getName() + - " has no DefaultDoubleList annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); + Share.LOG.warn("The field " + + field.getName() + + " in class " + + field.getDeclaringClass().getName() + + " has no DefaultDoubleList annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); try { return (double[]) field.get(null); } catch (IllegalAccessException e) { @@ -107,8 +108,11 @@ public class DoubleListConfigField extends AListConfigField { for (int j = 0; j < doubles.length; j++) { double d = doubles[j]; if (d < min || d > max) { - ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, j, Double.toString(d), - Double.toString(min), Double.toString(max)); + ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, + j, + Double.toString(d), + Double.toString(min), + Double.toString(max)); valid = false; } } diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/EnumConfigField.java b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/EnumConfigField.java index 3928711..29b41ce 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/EnumConfigField.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/EnumConfigField.java @@ -58,13 +58,16 @@ public class EnumConfigField> extends AConfigField { .filter((e) -> e.name().equals(defName)) .findAny() .orElseThrow(() -> new IllegalArgumentException( - "Default value \"" + defName + - "\" was not found in enum " + enumClass.getName()))) + "Default value \"" + + defName + + "\" was not found in enum " + + enumClass.getName()))) .orElseGet(() -> { - Share.LOG - .warn("The field " + field.getName() + " in class " + - field.getDeclaringClass().getName() + - " has no DefaultEnum annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); + Share.LOG.warn("The field " + + field.getName() + + " in class " + + field.getDeclaringClass().getName() + + " has no DefaultEnum annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); try { return enumClass.cast(field.get(null)); } catch (IllegalAccessException e) { @@ -77,8 +80,12 @@ public class EnumConfigField> extends AConfigField { if (!enumNameMap.containsValue(getConfig())) { setToDefault(); } - property.comment += "\n[default: " + defaultValue + ", possible values: " + - Arrays.toString(enumNameMap.keySet().toArray(new String[0])) + "]"; + property.comment += "\n[default: " + + defaultValue + + ", possible values: " + + Arrays.toString(enumNameMap.keySet() + .toArray(new String[0])) + + "]"; } public static void transmitString(DataOutput output, String value) throws IOException { @@ -90,9 +97,12 @@ public class EnumConfigField> extends AConfigField { throws IOException { val length = input.readInt(); if (length > maxLength || length < 0) { - throw new IOException( - "Error while retrieving config value for field " + fieldName + " in class " + className + ":\n" + - "Illegal string length received!"); + throw new IOException("Error while retrieving config value for field " + + fieldName + + " in class " + + className + + ":\n" + + "Illegal string length received!"); } val arr = new char[length]; for (int i = 0; i < arr.length; i++) { @@ -103,11 +113,17 @@ public class EnumConfigField> extends AConfigField { private T getEnumByName(String name) { if (!enumNameMap.containsKey(name)) { - Share.LOG - .warn("Invalid value " + name + " for enum configuration field " + field.getName() + - " of type " + enumClass.getName() + " in config class " + - field.getDeclaringClass().getName() + "! Using default value of " + - defaultValue.name() + "!"); + Share.LOG.warn("Invalid value " + + name + + " for enum configuration field " + + field.getName() + + " of type " + + enumClass.getName() + + " in config class " + + field.getDeclaringClass().getName() + + "! Using default value of " + + defaultValue.name() + + "!"); return defaultValue; } return enumNameMap.get(name); diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/IntConfigField.java b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/IntConfigField.java index 3e50aa7..48f625f 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/IntConfigField.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/IntConfigField.java @@ -50,10 +50,11 @@ public class IntConfigField extends AConfigField { defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultInt.class)) .map(Config.DefaultInt::value) .orElseGet(() -> { - Share.LOG - .warn("The field " + field.getName() + " in class " + - field.getDeclaringClass().getName() + - " has no DefaultInt annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); + Share.LOG.warn("The field " + + field.getName() + + " in class " + + field.getDeclaringClass().getName() + + " has no DefaultInt annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); try { return field.getType().isPrimitive() ? field.getInt(null) : (Integer) field.get(null); @@ -112,8 +113,11 @@ public class IntConfigField extends AConfigField { if (value >= min && value <= max) { return true; } - ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, -1, Integer.toString(value), - Integer.toString(min), Integer.toString(max)); + ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, + -1, + Integer.toString(value), + Integer.toString(min), + Integer.toString(max)); return false; } diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/IntListConfigField.java b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/IntListConfigField.java index 23bc8ee..112628a 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/IntListConfigField.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/IntListConfigField.java @@ -49,10 +49,11 @@ public class IntListConfigField extends AListConfigField { defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultIntList.class)) .map(Config.DefaultIntList::value) .orElseGet(() -> { - Share.LOG - .warn("The field " + field.getName() + " in class " + - field.getDeclaringClass().getName() + - " has no DefaultIntList annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); + Share.LOG.warn("The field " + + field.getName() + + " in class " + + field.getDeclaringClass().getName() + + " has no DefaultIntList annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); try { return (int[]) field.get(null); } catch (IllegalAccessException e) { @@ -107,8 +108,11 @@ public class IntListConfigField extends AListConfigField { for (int j = 0; j < ints.length; j++) { int i = ints[j]; if (i < min || i > max) { - ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, j, Integer.toString(i), - Integer.toString(min), Integer.toString(max)); + ConfigValidationFailureEvent.postNumericRangeOutOfBounds(field, + j, + Integer.toString(i), + Integer.toString(min), + Integer.toString(max)); valid = false; } } diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/StringConfigField.java b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/StringConfigField.java index 60d2a23..d5fb021 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/StringConfigField.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/StringConfigField.java @@ -49,10 +49,11 @@ public class StringConfigField extends AConfigField { defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultString.class)) .map(Config.DefaultString::value) .orElseGet(() -> { - Share.LOG - .warn("The field " + field.getName() + " in class " + - field.getDeclaringClass().getName() + - " has no DefaultString annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); + Share.LOG.warn("The field " + + field.getName() + + " in class " + + field.getDeclaringClass().getName() + + " has no DefaultString annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); try { return (String) field.get(null); } catch (IllegalAccessException e) { @@ -63,9 +64,12 @@ public class StringConfigField extends AConfigField { .map(Config.StringMaxLength::value) .orElse(256); property.setDefaultValue(defaultValue); - property.comment += - "\n[max length: " + maxLength + (pattern != null ? ", pattern: \"" + pattern.pattern() + "\"" : "") + - ", default: \"" + defaultValue + "\"]"; + property.comment += "\n[max length: " + + maxLength + + (pattern != null ? ", pattern: \"" + pattern.pattern() + "\"" : "") + + ", default: \"" + + defaultValue + + "\"]"; } public static boolean validateString(String value, int maxLength, Pattern pattern, Field field, int listIndex) { @@ -93,8 +97,12 @@ public class StringConfigField extends AConfigField { throws IOException { val length = input.readInt(); if (length > maxLength || length < 0) { - throw new IOException("Error while retrieving value for " + valueName + " in class " + className + ":\n" + - "Illegal string length received!"); + throw new IOException("Error while retrieving value for " + + valueName + + " in class " + + className + + ":\n" + + "Illegal string length received!"); } val arr = new char[length]; for (int i = 0; i < arr.length; i++) { diff --git a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/StringListConfigField.java b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/StringListConfigField.java index c7077d7..c2ada52 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/config/fields/StringListConfigField.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/config/fields/StringListConfigField.java @@ -49,10 +49,11 @@ public class StringListConfigField extends AListConfigField { defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultStringList.class)) .map(Config.DefaultStringList::value) .orElseGet(() -> { - Share.LOG - .warn("The field " + field.getName() + " in class " + - field.getDeclaringClass().getName() + - " has no DefaultStringList annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); + Share.LOG.warn("The field " + + field.getName() + + " in class " + + field.getDeclaringClass().getName() + + " has no DefaultStringList annotation!\nThis will be a crash in FalsePatternLib 0.11, update your code!"); try { return (String[]) field.get(null); } catch (IllegalAccessException e) { @@ -66,9 +67,13 @@ public class StringListConfigField extends AListConfigField { if (!property.isList()) { setToDefault(); } - property.comment += "\n[max string length: " + maxLength + - (pattern != null ? ", pattern: \"" + pattern.pattern() + "\"" : "") + ", default: \"" + - stringify(defaultValue) + "\"]"; + property.comment += + "\n[max string length: " + + maxLength + + (pattern != null ? ", pattern: \"" + pattern.pattern() + "\"" : "") + + ", default: \"" + + stringify(defaultValue) + + "\"]"; } private static String stringify(String[] arr) { @@ -102,7 +107,9 @@ public class StringListConfigField extends AListConfigField { @Override protected void receiveElements(DataInput input, String[] arr) throws IOException { for (int i = 0; i < arr.length; i++) { - arr[i] = StringConfigField.receiveString(input, maxStringLength, field.getName(), + arr[i] = StringConfigField.receiveString(input, + maxStringLength, + field.getName(), field.getDeclaringClass().getName()); } } diff --git a/src/main/java/com/falsepattern/lib/internal/impl/dependencies/DependencyLoaderImpl.java b/src/main/java/com/falsepattern/lib/internal/impl/dependencies/DependencyLoaderImpl.java index e9425ed..ebb6563 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/dependencies/DependencyLoaderImpl.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/dependencies/DependencyLoaderImpl.java @@ -115,12 +115,17 @@ public class DependencyLoaderImpl { } } if (oldLibDir.exists()) { - LOG.info("Migrating old library folder. From: " + oldLibDir.getAbsolutePath() + ", To: " + libDir.getAbsolutePath()); + LOG.info("Migrating old library folder. From: " + + oldLibDir.getAbsolutePath() + + ", To: " + + libDir.getAbsolutePath()); val oldFiles = oldLibDir.listFiles(); if (oldFiles != null) { - for (val file: oldFiles) { + for (val file : oldFiles) { try { - Files.move(file.toPath(), libDir.toPath().resolve(oldLibDir.toPath().relativize(file.toPath())), StandardCopyOption.REPLACE_EXISTING); + Files.move(file.toPath(), + libDir.toPath().resolve(oldLibDir.toPath().relativize(file.toPath())), + StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { LOG.warn("Failed to move file " + file.getName() + " to new dir! Deleting instead."); try { @@ -214,9 +219,14 @@ public class DependencyLoaderImpl { public static CompletableFuture loadLibrariesAsync(Library... libraries) { val futures = new ArrayList>(); for (val library : libraries) { - val task = new DependencyLoadTask(library.loadingModId, library.groupId, library.artifactId, - library.minVersion, library.maxVersion, library.preferredVersion, - library.regularSuffix, library.devSuffix); + val task = new DependencyLoadTask(library.loadingModId, + library.groupId, + library.artifactId, + library.minVersion, + library.maxVersion, + library.preferredVersion, + library.regularSuffix, + library.devSuffix); futures.add(CompletableFuture.runAsync(task::load, executor)); } return CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])); @@ -230,7 +240,8 @@ public class DependencyLoaderImpl { boolean found = false; if (fileName.endsWith(".jar")) { //Scan jar file for json in META-INF, add them to the list - try (val inputStream = new BufferedInputStream(source.openStream(), 65536); val jarFile = new JarInputStream(inputStream)) { + try (val inputStream = new BufferedInputStream(source.openStream(), 65536); + val jarFile = new JarInputStream(inputStream)) { ZipEntry entry; while ((entry = jarFile.getNextEntry()) != null) { if (!entry.getName().startsWith("META-INF") || !entry.getName().endsWith(".json")) { @@ -301,11 +312,12 @@ public class DependencyLoaderImpl { return mapper.apply(pair.b).map(b -> new Pair<>(a, b)); } - private static final Pattern VERSION_PATTERN = Pattern.compile("" - + "(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:\\.(0|[1-9]\\d*))?" - + "(?:-((?:(?:[0-9]+[a-zA-Z-][\\w-]*)|(?:[a-zA-Z][\\w-]*)|(?:[1-9]\\d*)|0)" - + "(?:\\.(?:(?:[0-9]+[a-zA-Z-][\\w-]*)|(?:[a-zA-Z][\\w-]*)|(?:[1-9]\\d*)|0))*))?" - + "(?:\\+([\\w-]+(\\.[\\w-]+)*))?"); + private static final Pattern VERSION_PATTERN = + Pattern.compile("(0|[1-9]\\d*)(?:\\.(0|[1-9]\\d*))?(?:\\.(0|[1-9]\\d*))?" + + "(?:-((?:(?:[0-9]+[a-zA-Z-][\\w-]*)|(?:[a-zA-Z][\\w-]*)|(?:[1-9]\\d*)|0)" + + "(?:\\.(?:(?:[0-9]+[a-zA-Z-][\\w-]*)|(?:[a-zA-Z][\\w-]*)|(?:[1-9]\\d*)|0))*))?" + + "(?:\\+([\\w-]+(\\.[\\w-]+)*))?"); + public static void scanDeps() { LOG.debug("Discovering dependency source candidates..."); val modsDir = new File(FileUtil.getMinecraftHome(), "mods"); @@ -327,48 +339,43 @@ public class DependencyLoaderImpl { .filter((url) -> !urlsWithoutDeps.contains(url.toString())) .collect(Collectors.toList()); val urls = new ArrayList(); - for (val candidate: candidates) { + for (val candidate : candidates) { if (!scanForDepSpecs(candidate, urls)) { urlsWithoutDeps.add(candidate.toString()); } } try (val out = Files.newBufferedWriter(depCache.toPath())) { - for (val noDep: urlsWithoutDeps) { + for (val noDep : urlsWithoutDeps) { out.append(noDep).append(System.lineSeparator()); } } catch (IOException e) { LOG.error("Could not write dependency scanner cache", e); } - val dependencySpecs = urls.stream() - .map((source) -> { - //Convert source to GSON json - try (val is = new BufferedInputStream(source.openStream())) { - val jsonRaw = new JsonParser().parse(new InputStreamReader(is)); - if (!jsonRaw.isJsonObject()) { - return null; - } - val json = jsonRaw.getAsJsonObject(); - if (!(json.has("identifier") && - json.get("identifier") + val dependencySpecs = urls.stream().map((source) -> { + //Convert source to GSON json + try (val is = new BufferedInputStream(source.openStream())) { + val jsonRaw = new JsonParser().parse(new InputStreamReader(is)); + if (!jsonRaw.isJsonObject()) { + return null; + } + val json = jsonRaw.getAsJsonObject(); + if (!(json.has("identifier") && json.get("identifier") .getAsString() - .equals("falsepatternlib_dependencies") - )) { - return null; - } - val builder = new GsonBuilder(); - builder.excludeFieldsWithoutExposeAnnotation(); - val gson = builder.create(); - json.remove("identifier"); - val root = gson.fromJson(json, DepRoot.class); - root.source(source.toString()); - return root; - } catch (Exception e) { - LOG.error("Failed to read json from source {}: {}", source, e); - return null; - } - }) - .filter(Objects::nonNull) - .collect(Collectors.toSet()); + .equals("falsepatternlib_dependencies"))) { + return null; + } + val builder = new GsonBuilder(); + builder.excludeFieldsWithoutExposeAnnotation(); + val gson = builder.create(); + json.remove("identifier"); + val root = gson.fromJson(json, DepRoot.class); + root.source(source.toString()); + return root; + } catch (Exception e) { + LOG.error("Failed to read json from source {}: {}", source, e); + return null; + } + }).filter(Objects::nonNull).collect(Collectors.toSet()); long end = System.currentTimeMillis(); LOG.debug("Discovered {} dependency source candidates in {}ms", dependencySpecs.size(), end - start); mavenRepositories.addAll(dependencySpecs.stream() @@ -376,11 +383,16 @@ public class DependencyLoaderImpl { .collect(Collectors.toSet())); val artifacts = dependencySpecs.stream() .map((root) -> new Pair<>(root.source(), root.dependencies())) - .flatMap(pair -> flatMap(pair, (dep) -> Stream.of(dep.always(), Share.DEV_ENV ? dep.dev() : dep.obf()))) - .flatMap(pair -> flatMap(pair, (dep) -> Stream.concat(dep.common().stream(), - FMLLaunchHandler.side().isClient() ? - dep.client().stream() : - dep.server().stream()))) + .flatMap(pair -> flatMap(pair, + (dep) -> Stream.of(dep.always(), + Share.DEV_ENV ? dep.dev() + : dep.obf()))) + .flatMap(pair -> flatMap(pair, + (dep) -> Stream.concat(dep.common().stream(), + FMLLaunchHandler.side() + .isClient() + ? dep.client().stream() + : dep.server().stream()))) .map((pair) -> { val source = pair.a; val dep = pair.b; @@ -398,38 +410,57 @@ public class DependencyLoaderImpl { throw new IllegalArgumentException("Invalid version: " + parts[2]); } val major = Integer.parseInt(matcher.group(1)); - val minor = matcher.group(2) == null ? -1 : Integer.parseInt(matcher.group(2)); - val patch = matcher.group(3) == null ? -1 : Integer.parseInt(matcher.group(3)); + val minor = matcher.group(2) == null ? -1 + : Integer.parseInt(matcher.group(2)); + val patch = matcher.group(3) == null ? -1 + : Integer.parseInt(matcher.group(3)); val preRelease = matcher.group(4); val build = matcher.group(5); version = new SemanticVersion(major, minor, patch, preRelease, build); } catch (IllegalArgumentException e) { - LOG.warn("Unparseable dependency version {}:{}:{} from {}", groupId, artifactId, parts[2], source); + LOG.warn("Unparseable dependency version {}:{}:{} from {}", + groupId, + artifactId, + parts[2], + source); version = new RawVersion(parts[2]); } final String classifier = parts.length > 3 ? parts[3] : null; if (classifier != null) { - LOG.info("Found dependency: {}:{}:{}:{} from {}", groupId, artifactId, - version, classifier, source); + LOG.info("Found dependency: {}:{}:{}:{} from {}", + groupId, + artifactId, + version, + classifier, + source); } else { - LOG.info("Found dependency: {}:{}:{} from {}", groupId, artifactId, - version, source); + LOG.info("Found dependency: {}:{}:{} from {}", + groupId, + artifactId, + version, + source); } - return new DependencyLoadTask(source, groupId, artifactId, - version, null, version, - classifier, classifier); + return new DependencyLoadTask(source, + groupId, + artifactId, + version, + null, + version, + classifier, + classifier); }) .filter(Objects::nonNull) .collect(Collectors.toSet()); val artifactMap = new HashMap(); - for (val artifact: artifacts) { + for (val artifact : artifacts) { val id = artifact.getGroupArtifact(); if (artifactMap.containsKey(id)) { val otherArtifact = artifactMap.get(id); //TODO: Check for conflicts if (artifact.preferredVersion.compareTo(otherArtifact.preferredVersion) > 0) { LOG.info("Replacing dependency {}:{} from {} with version {} from {}", - otherArtifact.getGroupArtifact(), otherArtifact.preferredVersion, + otherArtifact.getGroupArtifact(), + otherArtifact.preferredVersion, otherArtifact.loadingModId, artifact.preferredVersion, artifact.loadingModId); @@ -495,16 +526,18 @@ public class DependencyLoaderImpl { } private void crashCouldNotDownload() { - val errorMessage = "Failed to download library " + groupId + ":" + artifactId + ":" + preferredVersion + - ((suffix != null) ? ":" + suffix : "") + " from any repository! Requested by mod: " + - loadingModId; + val errorMessage = "Failed to download library " + groupId + ":" + artifactId + ":" + preferredVersion + ( + (suffix != null) ? ":" + suffix : "") + " from any repository! Requested by mod: " + loadingModId; LOG.fatal(errorMessage); throw new IllegalStateException(errorMessage); } private void setupLibraryNames() { suffix = Share.DEV_ENV ? devSuffix : regularSuffix; - artifactLogName = String.format("%s:%s:%s%s", groupId, artifactId, preferredVersion, + artifactLogName = String.format("%s:%s:%s%s", + groupId, + artifactId, + preferredVersion, suffix != null ? "-" + suffix : ""); LOG.info("Adding library {}, requested by mod {}", artifactLogName, loadingModId); artifact = groupId + ":" + artifactId + ":" + suffix; @@ -520,19 +553,31 @@ public class DependencyLoaderImpl { for (int i = 0; i < 16; i++) { LOG.fatal("ALERT VVVVVVVVVVVV ALERT"); } - LOG.fatal("Library {}:{}{} already loaded with version {}, " + - "but a version in the range {} was requested! Thing may go horribly wrong! " + - "Requested by mod: {}, previously loaded by mod: {}", groupId, artifactId, - suffix != null ? ":" + suffix : "", currentVer, rangeString, loadingModId, + LOG.fatal("Library {}:{}{} already loaded with version {}, " + + "but a version in the range {} was requested! Thing may go horribly wrong! " + + "Requested by mod: {}, previously loaded by mod: {}", + groupId, + artifactId, + suffix != null ? ":" + suffix : "", + currentVer, + rangeString, + loadingModId, loadedLibraryMods.get(artifact)); for (int i = 0; i < 16; i++) { LOG.fatal("ALERT ^^^^^^^^^^^^ ALERT"); } } else { - LOG.info("Attempted loading of library {}:{}{} with preferred version {}, " + - "but version {} was already loaded, which matched the range {}. This is not an " + "error. " + - "Requested by mod: {}, previously loaded by mod: {}", groupId, artifactId, - suffix != null ? ":" + suffix : "", preferredVersion, currentVer, rangeString, loadingModId, + LOG.info("Attempted loading of library {}:{}{} with preferred version {}, " + + "but version {} was already loaded, which matched the range {}. This is not an " + + "error. " + + "Requested by mod: {}, previously loaded by mod: {}", + groupId, + artifactId, + suffix != null ? ":" + suffix : "", + preferredVersion, + currentVer, + rangeString, + loadingModId, loadedLibraryMods.get(artifact)); } } @@ -553,8 +598,8 @@ public class DependencyLoaderImpl { if (status == ChecksumStatus.FAILED) { return false; } else if (status == ChecksumStatus.MISSING) { - LOG.debug("Library {} is missing checksum data! Either it was manually deleted, " + - "or the source repo didn't have it in the first place", artifactLogName); + LOG.debug("Library {} is missing checksum data! Either it was manually deleted, " + + "or the source repo didn't have it in the first place", artifactLogName); } } catch (IOException e) { LOG.error("Failed to execute validation check for " + artifactLogName, e); @@ -575,10 +620,18 @@ public class DependencyLoaderImpl { private void validateDownloadsAllowed() { if (!LibraryConfig.ENABLE_LIBRARY_DOWNLOADS) { - val errorMessage = "Failed to load library " + groupId + ":" + artifactId + ":" + preferredVersion + - ((suffix != null) ? ":" + suffix : "") + ": " + Tags.MODNAME + - " library downloading has been disabled in the config, and the library is not present " + - "on disk! Requested by mod: " + loadingModId; + val errorMessage = "Failed to load library " + + groupId + + ":" + + artifactId + + ":" + + preferredVersion + + ((suffix != null) ? ":" + suffix : "") + + ": " + + Tags.MODNAME + + " library downloading has been disabled in the config, and the library is not present " + + "on disk! Requested by mod: " + + loadingModId; LOG.fatal(errorMessage); throw new IllegalStateException(errorMessage); } @@ -589,7 +642,11 @@ public class DependencyLoaderImpl { if (!repo.endsWith("/")) { repo = repo + "/"; } - val url = String.format("%s%s/%s/%s/%s", repo, groupId.replace('.', '/'), artifactId, preferredVersion, + val url = String.format("%s%s/%s/%s/%s", + repo, + groupId.replace('.', '/'), + artifactId, + preferredVersion, mavenJarName); String finalRepo = repo; int retryCount = 0; @@ -601,12 +658,15 @@ public class DependencyLoaderImpl { val success = new AtomicBoolean(false); Internet.connect(new URL(url), (ex) -> LOG.debug("Artifact {} could not be downloaded from repo {}: {}", - artifactLogName, finalRepo, ex.getMessage()), (input) -> { - LOG.debug("Downloading {} from {}", artifactLogName, finalRepo); - download(input, file); - LOG.debug("Downloaded {} from {}", artifactLogName, finalRepo); - success.set(true); - }); + artifactLogName, + finalRepo, + ex.getMessage()), + (input) -> { + LOG.debug("Downloading {} from {}", artifactLogName, finalRepo); + download(input, file); + LOG.debug("Downloaded {} from {}", artifactLogName, finalRepo); + success.set(true); + }); if (success.get()) { LOG.debug("Validating checksum for {}", artifactLogName); val hadChecksum = validateChecksum(url); @@ -616,9 +676,9 @@ public class DependencyLoaderImpl { case OK: break; case MISSING: - LOG.warn("The library {} had no checksum available on the repository.\n" + - "There's a chance it might have gotten corrupted during download,\n" + - "but we're loading it anyways.", artifactLogName); + LOG.warn("The library {} had no checksum available on the repository.\n" + + "There's a chance it might have gotten corrupted during download,\n" + + "but we're loading it anyways.", artifactLogName); } loadedLibraries.put(artifact, preferredVersion); loadedLibraryMods.put(artifact, loadingModId); @@ -638,13 +698,16 @@ public class DependencyLoaderImpl { LOG.debug("Attempting to get {} checksum...", checksumType); val success = new AtomicBoolean(false); Internet.connect(new URL(checksumURL), - (ex) -> LOG.debug("Could not get {} checksum for {}: {}", checksumType, - artifactLogName, ex.getMessage()), (input) -> { - LOG.debug("Downloading {} checksum for {}", checksumType, artifactLogName); - download(input, checksumFile); - LOG.debug("Downloaded {} checksum for {}", checksumType, artifactLogName); - success.set(true); - }); + (ex) -> LOG.debug("Could not get {} checksum for {}: {}", + checksumType, + artifactLogName, + ex.getMessage()), + (input) -> { + LOG.debug("Downloading {} checksum for {}", checksumType, artifactLogName); + download(input, checksumFile); + LOG.debug("Downloaded {} checksum for {}", checksumType, artifactLogName); + success.set(true); + }); if (success.get()) { return getChecksumStatus(file, checksumType, checksumFile); } diff --git a/src/main/java/com/falsepattern/lib/internal/impl/dependencies/RawVersion.java b/src/main/java/com/falsepattern/lib/internal/impl/dependencies/RawVersion.java index 05712fc..2a69eb6 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/dependencies/RawVersion.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/dependencies/RawVersion.java @@ -28,9 +28,11 @@ import org.jetbrains.annotations.NotNull; public class RawVersion extends Version { public final String versionString; + public RawVersion(String versionString) { this.versionString = versionString; } + @Override public int compareTo(@NotNull Version o) { if (o instanceof RawVersion) { diff --git a/src/main/java/com/falsepattern/lib/internal/impl/toast/GuiToastImpl.java b/src/main/java/com/falsepattern/lib/internal/impl/toast/GuiToastImpl.java index b133d70..4012be1 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/toast/GuiToastImpl.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/toast/GuiToastImpl.java @@ -99,8 +99,9 @@ public class GuiToastImpl extends Gui { @Nullable public T getToast(Class toastClass, Object type) { for (val toast : this.visible) { - if (toast != null && toastClass.isAssignableFrom(toast.getToast().getClass()) && - toast.getToast().getType().equals(type)) { + if (toast != null && toastClass.isAssignableFrom(toast.getToast().getClass()) && toast.getToast() + .getType() + .equals(type)) { return toastClass.cast(toast); } } diff --git a/src/main/java/com/falsepattern/lib/internal/impl/updates/UpdateCheckerImpl.java b/src/main/java/com/falsepattern/lib/internal/impl/updates/UpdateCheckerImpl.java index 80332a1..58b08de 100644 --- a/src/main/java/com/falsepattern/lib/internal/impl/updates/UpdateCheckerImpl.java +++ b/src/main/java/com/falsepattern/lib/internal/impl/updates/UpdateCheckerImpl.java @@ -100,30 +100,33 @@ public final class UpdateCheckerImpl { continue; } val latest = parsedVersions.get(0).getAsJsonObject(); - result.add(new ModUpdateInfo(modid, currentVersion, latest.get("version").getAsString(), latest.get("url").getAsString())); + result.add(new ModUpdateInfo(modid, + currentVersion, + latest.get("version").getAsString(), + latest.get("url").getAsString())); } return result; } catch (Exception e) { throw new UpdateCheckException("Failed to check for updates!", e); } } + public static List updateListToChatMessages(String initiator, List updates) { if (updates == null || updates.size() == 0) { return null; } - val updateText = new ArrayList( - FormattedText.parse(I18n.format("falsepatternlib.chat.updatesavailable", initiator)).toChatText()); + val updateText = new ArrayList(FormattedText.parse(I18n.format( + "falsepatternlib.chat.updatesavailable", + initiator)).toChatText()); val mods = Loader.instance().getIndexedModList(); for (val update : updates) { val mod = mods.get(update.modID); - updateText.addAll( - FormattedText.parse(I18n.format("falsepatternlib.chat.modname", mod.getName())).toChatText()); - updateText.addAll( - FormattedText.parse(I18n.format("falsepatternlib.chat.currentversion", update.currentVersion)) - .toChatText()); - updateText.addAll( - FormattedText.parse(I18n.format("falsepatternlib.chat.latestversion", update.latestVersion)) - .toChatText()); + updateText.addAll(FormattedText.parse(I18n.format("falsepatternlib.chat.modname", mod.getName())) + .toChatText()); + updateText.addAll(FormattedText.parse(I18n.format("falsepatternlib.chat.currentversion", + update.currentVersion)).toChatText()); + updateText.addAll(FormattedText.parse(I18n.format("falsepatternlib.chat.latestversion", + update.latestVersion)).toChatText()); if (!update.updateURL.isEmpty()) { val pre = FormattedText.parse(I18n.format("falsepatternlib.chat.updateurlpre")).toChatText(); val link = FormattedText.parse(I18n.format("falsepatternlib.chat.updateurl")).toChatText(); @@ -184,7 +187,7 @@ public final class UpdateCheckerImpl { private static CompletableFuture parseVersionSpecs(JsonArray versions) { return CompletableFuture.supplyAsync(() -> { val result = new JsonArray(); - for (val entry: versions) { + for (val entry : versions) { if (!entry.isJsonObject()) { continue; } @@ -238,17 +241,20 @@ public final class UpdateCheckerImpl { val response = new AtomicReference(); val result = new JsonObject(); Internet.connect(new URL("https://api.github.com/repos/" + owner + "/" + name + "/releases/latest"), - Internet.constructHeaders("Accept", "application/vnd.github+json", - "X-GitHub-Api-Version", "2022-11-28"), - (e) -> {throw new CompletionException(e); + Internet.constructHeaders("Accept", + "application/vnd.github+json", + "X-GitHub-Api-Version", + "2022-11-28"), + (e) -> { + throw new CompletionException(e); }, (stream) -> { - val parser = new JsonParser(); - val json = parser.parse(new InputStreamReader(stream)); - if (!json.isJsonObject()) { - return; - } - response.set(json.getAsJsonObject()); + val parser = new JsonParser(); + val json = parser.parse(new InputStreamReader(stream)); + if (!json.isJsonObject()) { + return; + } + response.set(json.getAsJsonObject()); }); if (response.get() == null) { return null; @@ -306,11 +312,10 @@ public final class UpdateCheckerImpl { if (latestVersions.contains(currentVersion)) { continue; } - val updateURL = obj.has("updateURL") && - obj.get("updateURL").isJsonPrimitive() && - obj.get("updateURL").getAsJsonPrimitive().isString() - ? obj.get("updateURL").getAsString() - : ""; + val updateURL = obj.has("updateURL") && obj.get("updateURL").isJsonPrimitive() && obj.get("updateURL") + .getAsJsonPrimitive() + .isString() + ? obj.get("updateURL").getAsString() : ""; result.add(new ModUpdateInfo(modid, currentVersion, latestVersions.get(0), updateURL)); } return result; diff --git a/src/main/java/com/falsepattern/lib/mapping/MappingManager.java b/src/main/java/com/falsepattern/lib/mapping/MappingManager.java index d95a48c..b85a6a1 100644 --- a/src/main/java/com/falsepattern/lib/mapping/MappingManager.java +++ b/src/main/java/com/falsepattern/lib/mapping/MappingManager.java @@ -45,6 +45,7 @@ public class MappingManager { private static final Map stringPool = new HashMap<>(); private static boolean initialized = false; private static final Object MUTEX = new Object(); + @SneakyThrows public static void initialize() { synchronized (MUTEX) { @@ -53,20 +54,23 @@ public class MappingManager { } initialized = true; } - val classMappings = new String(ResourceUtil.getResourceBytesFromJar("/classes.csv", CoreLoadingPlugin.class)).split("\n"); + val classMappings = + new String(ResourceUtil.getResourceBytesFromJar("/classes.csv", CoreLoadingPlugin.class)).split("\n"); for (int i = 1; i < classMappings.length; i++) { val line = classMappings[i].split(","); val clazz = new UniversalClass(line, stringPool); internalLookup.unwrap(clazz.internalName, clazz); regularLookup.unwrap(clazz.regularName, clazz); } - var fieldMappings = new String(ResourceUtil.getResourceBytesFromJar("/fields.csv", CoreLoadingPlugin.class)).split("\n"); + var fieldMappings = + new String(ResourceUtil.getResourceBytesFromJar("/fields.csv", CoreLoadingPlugin.class)).split("\n"); for (int i = 1; i < fieldMappings.length; i++) { val line = fieldMappings[i].split(","); val clazz = internalLookup.get(MappingType.Notch, line[0].substring(0, line[0].lastIndexOf('/'))); UniversalField.createAndAddToParent(clazz, line, stringPool); } - val methodMappings = new String(ResourceUtil.getResourceBytesFromJar("/methods.csv", CoreLoadingPlugin.class)).split("\n"); + val methodMappings = + new String(ResourceUtil.getResourceBytesFromJar("/methods.csv", CoreLoadingPlugin.class)).split("\n"); for (int i = 1; i < methodMappings.length; i++) { val line = methodMappings[i].split(","); val clazz = internalLookup.get(MappingType.Notch, line[0].substring(0, line[0].lastIndexOf('/'))); @@ -88,9 +92,14 @@ public class MappingManager { throw new IllegalArgumentException("Invalid enum value " + nameType); } } catch (Lookup.LookupException e) { - throw new ClassNotFoundException( - "Could not find class \"" + className + "\" with " + nameType.name().toLowerCase() + - " name in the " + mappingType.name() + " mapping."); + throw new ClassNotFoundException("Could not find class \"" + + className + + "\" with " + + nameType.name() + .toLowerCase() + + " name in the " + + mappingType.name() + + " mapping."); } } @@ -116,8 +125,9 @@ public class MappingManager { return classForName(NameType.Internal, MappingType.MCP, instruction.owner).getField(MappingType.MCP, instruction.name); } catch (ClassNotFoundException e) { - throw new ClassNotFoundException("Could not find the class " + instruction.owner + - " in the MCP mappings. Are you sure it's a Minecraft class? (we're in dev, cannot use SRG or Notch here)."); + throw new ClassNotFoundException("Could not find the class " + + instruction.owner + + " in the MCP mappings. Are you sure it's a Minecraft class? (we're in dev, cannot use SRG or Notch here)."); } } else { try { @@ -125,11 +135,13 @@ public class MappingManager { instruction.name); } catch (ClassNotFoundException e) { try { - return classForName(NameType.Internal, MappingType.Notch, instruction.owner).getField( - MappingType.Notch, instruction.name); + return classForName(NameType.Internal, + MappingType.Notch, + instruction.owner).getField(MappingType.Notch, instruction.name); } catch (ClassNotFoundException ex) { - throw new ClassNotFoundException("Could not find the class " + instruction.owner + - " neither in the SRG nor in the Notch mappings. Are you sure it's a Minecraft class? (we're in obf, cannot use MCP here)"); + throw new ClassNotFoundException("Could not find the class " + + instruction.owner + + " neither in the SRG nor in the Notch mappings. Are you sure it's a Minecraft class? (we're in obf, cannot use MCP here)"); } } } @@ -145,8 +157,9 @@ public class MappingManager { instruction.name, instruction.desc); } catch (ClassNotFoundException e) { - throw new ClassNotFoundException("Could not find the class " + instruction.owner + - " in the MCP mappings. Are you sure it's a Minecraft class? (we're in dev, cannot use SRG or Notch here)."); + throw new ClassNotFoundException("Could not find the class " + + instruction.owner + + " in the MCP mappings. Are you sure it's a Minecraft class? (we're in dev, cannot use SRG or Notch here)."); } } else { try { @@ -155,11 +168,15 @@ public class MappingManager { instruction.desc); } catch (ClassNotFoundException e) { try { - return classForName(NameType.Internal, MappingType.Notch, instruction.owner).getMethod( - MappingType.Notch, instruction.name, instruction.desc); + return classForName(NameType.Internal, + MappingType.Notch, + instruction.owner).getMethod(MappingType.Notch, + instruction.name, + instruction.desc); } catch (ClassNotFoundException ex) { - throw new ClassNotFoundException("Could not find the class " + instruction.owner + - " neither in the SRG nor in the Notch mappings. Are you sure it's a Minecraft class? (we're in obf, cannot use MCP here)"); + throw new ClassNotFoundException("Could not find the class " + + instruction.owner + + " neither in the SRG nor in the Notch mappings. Are you sure it's a Minecraft class? (we're in obf, cannot use MCP here)"); } } } diff --git a/src/main/java/com/falsepattern/lib/mapping/types/UniversalMethod.java b/src/main/java/com/falsepattern/lib/mapping/types/UniversalMethod.java index 57ea7fb..40e3923 100644 --- a/src/main/java/com/falsepattern/lib/mapping/types/UniversalMethod.java +++ b/src/main/java/com/falsepattern/lib/mapping/types/UniversalMethod.java @@ -150,8 +150,8 @@ public class UniversalMethod { return javaMethodCache; } val parentClass = parent.asJavaClass(); - javaMethodCache = parentClass.getDeclaredMethod(getName(parent.realClassMapping()), decodeMethodDescriptor( - getDescriptor(parent.realClassMapping()))); + javaMethodCache = parentClass.getDeclaredMethod(getName(parent.realClassMapping()), + decodeMethodDescriptor(getDescriptor(parent.realClassMapping()))); ReflectionUtil.jailBreak(javaMethodCache); return javaMethodCache; } @@ -175,7 +175,10 @@ public class UniversalMethod { @StableAPI.Expose public MethodInsnNode asInstruction(int opcode, MappingType mapping, boolean itf) { - return new MethodInsnNode(opcode, parent.getName(NameType.Internal, mapping), getName(mapping), - getDescriptor(mapping), itf); + return new MethodInsnNode(opcode, + parent.getName(NameType.Internal, mapping), + getName(mapping), + getDescriptor(mapping), + itf); } } diff --git a/src/main/java/com/falsepattern/lib/mixin/IMixin.java b/src/main/java/com/falsepattern/lib/mixin/IMixin.java index 8670e9f..065b576 100644 --- a/src/main/java/com/falsepattern/lib/mixin/IMixin.java +++ b/src/main/java/com/falsepattern/lib/mixin/IMixin.java @@ -43,8 +43,9 @@ public interface IMixin { default boolean shouldLoad(List loadedMods) { val side = getSide(); - return (side == Side.COMMON || side == Side.SERVER && FMLLaunchHandler.side().isServer() || - side == Side.CLIENT && FMLLaunchHandler.side().isClient()) && getFilter().test(loadedMods); + return (side == Side.COMMON + || side == Side.SERVER && FMLLaunchHandler.side().isServer() + || side == Side.CLIENT && FMLLaunchHandler.side().isClient()) && getFilter().test(loadedMods); } @StableAPI(since = "0.10.0") diff --git a/src/main/java/com/falsepattern/lib/mixin/IMixinPlugin.java b/src/main/java/com/falsepattern/lib/mixin/IMixinPlugin.java index f6904d4..04d8e7f 100644 --- a/src/main/java/com/falsepattern/lib/mixin/IMixinPlugin.java +++ b/src/main/java/com/falsepattern/lib/mixin/IMixinPlugin.java @@ -58,10 +58,7 @@ public interface IMixinPlugin extends IMixinConfigPlugin { static File findJarOf(final ITargetedMod mod) { File result = null; try (val stream = walk(MODS_DIRECTORY_PATH)) { - result = stream.filter(mod::isMatchingJar) - .map(Path::toFile) - .findFirst() - .orElse(null); + result = stream.filter(mod::isMatchingJar).map(Path::toFile).findFirst().orElse(null); } catch (Exception e) { e.printStackTrace(); } @@ -75,7 +72,8 @@ public interface IMixinPlugin extends IMixinConfigPlugin { found = path.toFile(); break; } - } catch (Exception ignored) {} + } catch (Exception ignored) { + } } result = found; } diff --git a/src/main/java/com/falsepattern/lib/mixin/MixinInfo.java b/src/main/java/com/falsepattern/lib/mixin/MixinInfo.java index 3548f14..e24d0f8 100644 --- a/src/main/java/com/falsepattern/lib/mixin/MixinInfo.java +++ b/src/main/java/com/falsepattern/lib/mixin/MixinInfo.java @@ -105,21 +105,27 @@ public final class MixinInfo { } private static MixinBootstrapperType detect() { - if (!isClassPresentSafe("org.spongepowered.asm.launch.MixinBootstrap")) + if (!isClassPresentSafe("org.spongepowered.asm.launch.MixinBootstrap")) { return MixinBootstrapperType.None; - for (val candidate: MixinInfoCompatCompanion.UNIMIXIN_CANDIDATES) { + } + for (val candidate : MixinInfoCompatCompanion.UNIMIXIN_CANDIDATES) { if (isClassPresentSafe(candidate)) { return MixinBootstrapperType.UniMixin; } } - if (isClassPresentSafe("com.falsepattern.gasstation.GasStation")) + if (isClassPresentSafe("com.falsepattern.gasstation.GasStation")) { return MixinBootstrapperType.GasStation; - if (isClassPresentSafe("ru.timeconqueror.spongemixins.core.SpongeMixinsCore")) + } + if (isClassPresentSafe("ru.timeconqueror.spongemixins.core.SpongeMixinsCore")) { return MixinBootstrapperType.SpongeMixins; - if (isClassPresentSafe("io.github.crucible.grimoire.Grimoire") || isClassPresentSafe("io.github.crucible.grimoire.common.GrimoireCore")) + } + if (isClassPresentSafe("io.github.crucible.grimoire.Grimoire") || isClassPresentSafe( + "io.github.crucible.grimoire.common.GrimoireCore")) { return MixinBootstrapperType.Grimoire; - if (isClassPresentSafe("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin")) + } + if (isClassPresentSafe("io.github.tox1cozz.mixinbooterlegacy.MixinBooterLegacyPlugin")) { return MixinBootstrapperType.MixinBooterLegacy; + } return MixinBootstrapperType.Other; } diff --git a/src/main/java/com/falsepattern/lib/mixin/MixinInfoCompatCompanion.java b/src/main/java/com/falsepattern/lib/mixin/MixinInfoCompatCompanion.java index 7a58ba4..2465be4 100644 --- a/src/main/java/com/falsepattern/lib/mixin/MixinInfoCompatCompanion.java +++ b/src/main/java/com/falsepattern/lib/mixin/MixinInfoCompatCompanion.java @@ -39,10 +39,11 @@ public class MixinInfoCompatCompanion { * This is used to determine if a mixin plugin is unimixins. Once MixinInfo is classloaded, this list has no effect. */ @StableAPI.Expose - public static final List UNIMIXIN_CANDIDATES = new ArrayList<>(Arrays.asList("io.github.legacymoddingmc.unimixins.compat.CompatCore", - "io.github.legacymoddingmc.unimixins.devcompat.DevCompatCore", - "io.github.legacymoddingmc.unimixins.all.AllCore", - "io.github.legacymoddingmc.unimixins.mixin.MixinModule")); + public static final List UNIMIXIN_CANDIDATES = new ArrayList<>(Arrays.asList( + "io.github.legacymoddingmc.unimixins.compat.CompatCore", + "io.github.legacymoddingmc.unimixins.devcompat.DevCompatCore", + "io.github.legacymoddingmc.unimixins.all.AllCore", + "io.github.legacymoddingmc.unimixins.mixin.MixinModule")); @Getter(onMethod_ = @StableAPI.Expose) static boolean mixinInfoClassLoaded = false; diff --git a/src/main/java/com/falsepattern/lib/toasts/SimpleToast.java b/src/main/java/com/falsepattern/lib/toasts/SimpleToast.java index a022114..9d139d7 100644 --- a/src/main/java/com/falsepattern/lib/toasts/SimpleToast.java +++ b/src/main/java/com/falsepattern/lib/toasts/SimpleToast.java @@ -83,7 +83,8 @@ public class SimpleToast implements IToast { if (hasProgressBar) { val bgWidth = background.getIcon().getIconWidth(); Gui.drawRect(3, bgHeight - 4, bgWidth - 3, bgHeight - 3, 0xFFFFFFFF); - float f = (float) MathUtil.clampedLerp(displayedProgress, currentProgress, + float f = (float) MathUtil.clampedLerp(displayedProgress, + currentProgress, (float) (delta - lastDelta) / 100.0F); int i; diff --git a/src/main/java/com/falsepattern/lib/toasts/icon/ToastBG.java b/src/main/java/com/falsepattern/lib/toasts/icon/ToastBG.java index 48c8f32..3faa173 100644 --- a/src/main/java/com/falsepattern/lib/toasts/icon/ToastBG.java +++ b/src/main/java/com/falsepattern/lib/toasts/icon/ToastBG.java @@ -46,7 +46,9 @@ public class ToastBG extends ToastTexture { new ToastBG(new ResourceLocation(Tags.MODID, "textures/gui/toast_narrator.png"), 160, 32, 0xFFAAAA00); @StableAPI.Expose public static final ToastBG TOAST_NARRATOR_ROUNDED = - new ToastBG(new ResourceLocation(Tags.MODID, "textures/gui/toast_narrator_rounded.png"), 160, 32, + new ToastBG(new ResourceLocation(Tags.MODID, "textures/gui/toast_narrator_rounded.png"), + 160, + 32, 0xFFAAAA00); @StableAPI.Expose public static final ToastBG TOAST_WHITE = diff --git a/src/main/java/com/falsepattern/lib/updates/ModUpdateInfo.java b/src/main/java/com/falsepattern/lib/updates/ModUpdateInfo.java index 1053afd..df0d7dc 100644 --- a/src/main/java/com/falsepattern/lib/updates/ModUpdateInfo.java +++ b/src/main/java/com/falsepattern/lib/updates/ModUpdateInfo.java @@ -46,8 +46,11 @@ public class ModUpdateInfo { @StableAPI.Expose public void log(Logger logger) { - logger.info("Updates are available for mod {}: Currently installed version is {}, " + - "latest available version is {}. Update URL: {}", modID, currentVersion, latestVersion, + logger.info("Updates are available for mod {}: Currently installed version is {}, " + + "latest available version is {}. Update URL: {}", + modID, + currentVersion, + latestVersion, updateURL.isEmpty() ? "unavailable" : updateURL); } } diff --git a/src/main/java/com/falsepattern/lib/updates/UpdateChecker.java b/src/main/java/com/falsepattern/lib/updates/UpdateChecker.java index 5329321..9cfdc37 100644 --- a/src/main/java/com/falsepattern/lib/updates/UpdateChecker.java +++ b/src/main/java/com/falsepattern/lib/updates/UpdateChecker.java @@ -68,7 +68,7 @@ public final class UpdateChecker { * "updateURL": "https://example.com/mods/mymod" * } * } - * + *

* GitHub version entry: *

{@code
      * {
@@ -76,7 +76,7 @@ public final class UpdateChecker {
      *    "repo": "Example/ExampleMod"
      * }
      * }
- * + *

* The GitHub version entry will automatically fetch the latest release from the specified repository using the GitHub API. * * @param url The URL to check @@ -116,6 +116,7 @@ public final class UpdateChecker { } //region deprecated + /** * DEPRECATED: Use the V2 API instead. This is kept for backwards compatibility. */ diff --git a/src/main/java/com/falsepattern/lib/util/MathUtil.java b/src/main/java/com/falsepattern/lib/util/MathUtil.java index 967d09e..038243c 100644 --- a/src/main/java/com/falsepattern/lib/util/MathUtil.java +++ b/src/main/java/com/falsepattern/lib/util/MathUtil.java @@ -603,9 +603,12 @@ public final class MathUtil { f6 = f2; break; default: - throw new RuntimeException( - "Something went wrong when converting from HSV to RGB. Input was " + hue + ", " + saturation + - ", " + value); + throw new RuntimeException("Something went wrong when converting from HSV to RGB. Input was " + + hue + + ", " + + saturation + + ", " + + value); } int j = clamp((int) (f4 * 255.0F), 0, 255); diff --git a/src/main/java/com/falsepattern/lib/util/RenderUtil.java b/src/main/java/com/falsepattern/lib/util/RenderUtil.java index e99cdf5..0bad8ae 100644 --- a/src/main/java/com/falsepattern/lib/util/RenderUtil.java +++ b/src/main/java/com/falsepattern/lib/util/RenderUtil.java @@ -71,6 +71,7 @@ public final class RenderUtil { * @param iconName The icon name * @param width The icon width in pixels * @param height The icon height in pixels + * * @return The full resolution texture icon. */ @StableAPI.Expose(since = "0.10.0") diff --git a/src/main/java/com/falsepattern/lib/util/ResourceUtil.java b/src/main/java/com/falsepattern/lib/util/ResourceUtil.java index 176a8ad..10a763e 100644 --- a/src/main/java/com/falsepattern/lib/util/ResourceUtil.java +++ b/src/main/java/com/falsepattern/lib/util/ResourceUtil.java @@ -128,8 +128,10 @@ public final class ResourceUtil { } } //Fallback logic - System.out.println("Using fallback resource loading logic for " + resourcePath + " with reference to " + - referenceClass.getName()); + System.out.println("Using fallback resource loading logic for " + + resourcePath + + " with reference to " + + referenceClass.getName()); return referenceClass.getResourceAsStream(resourcePath); } diff --git a/src/main/resources/DEPENDENCIES.md b/src/main/resources/DEPENDENCIES.md index f42dcb6..cbde496 100644 --- a/src/main/resources/DEPENDENCIES.md +++ b/src/main/resources/DEPENDENCIES.md @@ -3,6 +3,7 @@ Version 1 An example JSON file that can be used to download dependencies using FalsePatternLib. This replaces the legacy DependencyLoader api. This file needs to reside inside the META-INF directory. + ```json { "identifier": "falsepatternlib_dependencies", @@ -32,24 +33,29 @@ DependencyLoader api. This file needs to reside inside the META-INF directory. ``` Explanation: -- `identifier`: The identifier of the json file. This must always be `falsepatternlib_dependencies` for the library downloader + +- `identifier`: The identifier of the json file. This must always be `falsepatternlib_dependencies` for the library + downloader to recognize it. - `repositories`: A list of maven repositories to use when downloading dependencies. These are used in addition to the default maven repositories. This is just a list of strings, each string being a https repository url. - `dependencies`: A categorized list of dependencies. - - The `always` category gets downloaded both inside and outside the dev environment. Usually not needed, as gradle - will automatically download dependencies. - - The `obf` category gets downloaded only in the obfuscated environment. Any third party libraries that are not - available by default from minecraft or forge, AND are also not shaded/shadowed into the jar, should be placed here. - - The `dev` category gets downloaded only in the dev environment. Usually not needed, as gradle will automatically - download dependencies. + - The `always` category gets downloaded both inside and outside the dev environment. Usually not needed, as gradle + will automatically download dependencies. + - The `obf` category gets downloaded only in the obfuscated environment. Any third party libraries that are not + available by default from minecraft or forge, AND are also not shaded/shadowed into the jar, should be placed + here. + - The `dev` category gets downloaded only in the dev environment. Usually not needed, as gradle will automatically + download dependencies. Each of these categories also have 3 more subcategories: + - `common`: Dependencies that are required on both the client and the server. - `client`: Dependencies that are required on the client only. - `server`: Dependencies that are required on the server only. Each of these subcategories is a list of strings, each string being a maven dependency string. These are the same as the ones used in the gradle dependencies block. Note that this DOES NOT support the version range syntax, so you must -specify a specific version. For example, `com.example:examplejar:1.0.0` is valid, but `com.example:examplejar:[1.0.0,2.0.0]` +specify a specific version. For example, `com.example:examplejar:1.0.0` is valid, +but `com.example:examplejar:[1.0.0,2.0.0]` is not. \ No newline at end of file diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info index f905e59..bf42781 100644 --- a/src/main/resources/mcmod.info +++ b/src/main/resources/mcmod.info @@ -1,16 +1,18 @@ [ - { - "modid": "${modId}", - "name": "${modName}", - "description": "FalsePattern's library.", - "version": "${modVersion}", - "mcversion": "${minecraftVersion}", - "url": "https://github.com/FalsePattern/FalsePatternLib", - "updateUrl": "", - "authorList": ["FalsePattern"], - "credits": "", - "logoFile": "", - "screenshots": [], - "dependencies": [] - } + { + "modid": "${modId}", + "name": "${modName}", + "description": "FalsePattern's library.", + "version": "${modVersion}", + "mcversion": "${minecraftVersion}", + "url": "https://github.com/FalsePattern/FalsePatternLib", + "updateUrl": "", + "authorList": [ + "FalsePattern" + ], + "credits": "", + "logoFile": "", + "screenshots": [], + "dependencies": [] + } ]