From c5fa8344084ca53488c6b6e0d33f65ab89b889e0 Mon Sep 17 00:00:00 2001 From: MiniDigger | Martin Date: Mon, 1 Jan 2024 17:26:32 +0100 Subject: [PATCH] 1.0.8: ignore missing random source class --- .../suggestion/numbers/RandomSourceSuggester.java | 13 ++++++++----- gradle.properties | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/numbers/RandomSourceSuggester.java b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/numbers/RandomSourceSuggester.java index 7da54ec..cb8f33e 100644 --- a/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/numbers/RandomSourceSuggester.java +++ b/codebook-lvt/src/main/java/io/papermc/codebook/lvt/suggestion/numbers/RandomSourceSuggester.java @@ -41,20 +41,23 @@ public class RandomSourceSuggester implements LvtSuggester { static final JvmType RANDOM_SOURCE_TYPE = new ClassType("net/minecraft/util/RandomSource"); - private final ClassData randomSourceClass; + private final @Nullable ClassData randomSourceClass; @Inject RandomSourceSuggester(final HypoContext hypoContext) throws IOException { - final @Nullable ClassData random = hypoContext.getContextProvider().findClass(RANDOM_SOURCE_TYPE); - if (random == null) { - throw new IllegalStateException("Cannot find " + RANDOM_SOURCE_TYPE + " on the classpath."); + this.randomSourceClass = hypoContext.getContextProvider().findClass(RANDOM_SOURCE_TYPE); + if (this.randomSourceClass == null) { + System.err.println("Failed to find RandomSource class, disabling RandomSourceSuggester"); } - this.randomSourceClass = random; } @Override public @Nullable String suggestFromMethod( final MethodCallContext call, final MethodInsnContext insn, final ContainerContext container) { + if (this.randomSourceClass == null) { + return null; + } + final String methodName = call.data().name(); ClassData ownerClass = insn.owner(); if (ownerClass.doesExtendOrImplement(this.randomSourceClass)) { diff --git a/gradle.properties b/gradle.properties index c140d1c..5fbaeea 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group = io.papermc.codebook -version = 1.0.7 +version = 1.0.8