From 6bc798092a5833d771d07743429750c8afeb0ebe Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 3 Mar 2022 09:32:46 +0800 Subject: Catch SearchFilterPrepareWatcher race condition --- .../rei/plugin/client/SearchFilterPrepareWatcher.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/SearchFilterPrepareWatcher.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/SearchFilterPrepareWatcher.java index e7657afdb..73d182fe2 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/SearchFilterPrepareWatcher.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/SearchFilterPrepareWatcher.java @@ -46,18 +46,22 @@ public class SearchFilterPrepareWatcher implements HintProvider { @Override public List provide() { lastProcess = null; - if (Argument.prepareStage != null && Argument.currentStages != null && Argument.prepareStacks != null && Argument.prepareStacks.size() > 100) { - if (Util.getEpochMillis() - Argument.prepareStart < 500) return Collections.emptyList(); + try { + if (Argument.prepareStage != null && Argument.currentStages != null && Argument.prepareStacks != null && Argument.prepareStacks.size() > 100 + && Argument.prepareStart != null) { + if (Util.getEpochMillis() - Argument.prepareStart < 500) return Collections.emptyList(); int prepareStageCurrent = Argument.prepareStage.getLeft(); int prepareStageTotal = Argument.prepareStage.getRight(); MutablePair currentStage = Iterables.get(Arrays.asList(Argument.currentStages), prepareStageCurrent - 1, null); int currentStageCurrent = currentStage == null ? 0 : currentStage.getLeft(); int currentStageTotal = currentStage == null ? 0 : currentStage.getRight(); - double prepareStageProgress = prepareStageTotal == 0 ? 0 : prepareStageCurrent / (double) prepareStageTotal; - double currentStageProgress = currentStageTotal == 0 ? 0 : currentStageCurrent / (double) currentStageTotal; - lastProcess = prepareStageTotal == 0 ? 0 : Math.max(0, prepareStageProgress - (1 - currentStageProgress) / prepareStageTotal); - return ImmutableList.of(new TranslatableComponent("text.rei.caching.search"), - new TranslatableComponent("text.rei.caching.search.step", prepareStageCurrent, prepareStageTotal, Math.round(lastProcess * 100))); + double prepareStageProgress = prepareStageTotal == 0 ? 0 : prepareStageCurrent / (double) prepareStageTotal; + double currentStageProgress = currentStageTotal == 0 ? 0 : currentStageCurrent / (double) currentStageTotal; + lastProcess = prepareStageTotal == 0 ? 0 : Math.max(0, prepareStageProgress - (1 - currentStageProgress) / prepareStageTotal); + return ImmutableList.of(new TranslatableComponent("text.rei.caching.search"), + new TranslatableComponent("text.rei.caching.search.step", prepareStageCurrent, prepareStageTotal, Math.round(lastProcess * 100))); + } + } catch (NullPointerException ignored) { } return Collections.emptyList(); } -- cgit