Skip to content

Commit

Permalink
fix: quartz library will throw NPE if client-side re-entry the single…
Browse files Browse the repository at this point in the history
…-player world
  • Loading branch information
sakurawald committed Jul 12, 2024
1 parent 30bf79f commit 48fa9eb
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
2 changes: 1 addition & 1 deletion fuji-fabric.wiki
10 changes: 2 additions & 8 deletions src/main/java/io/github/sakurawald/Fuji.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,14 @@
// TODO: /tppos module
// TODO: playtime(every/for) rewards module
// TODO: rank module

// TODO: a light-weight way to implement chat module

// TODO: remove fabric-api dep

// TODO: a program to generate module reference DAG

// TODO: luckperms context calculator

// TODO: invsee module

// TODO: condense module

// TODO: use aop style
// TODO: a program to generate module reference DAG


public class Fuji implements ModInitializer {
public static final String MOD_ID = "fuji";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ private static int magic(CommandContext<ServerCommandSource> ctx) {
var source = ctx.getSource();
ServerPlayerEntity player = source.getPlayer();


log.warn("flyspeed = {}", Options.get(player, "fuji.flyspeed", Double::valueOf));

TriState test = Permissions.getPermissionValue(ctx.getSource(), "fuji.seed");
Expand Down
29 changes: 22 additions & 7 deletions src/main/java/io/github/sakurawald/util/ScheduleUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import io.github.sakurawald.config.Configs;
import lombok.Getter;
import lombok.experimental.UtilityClass;
import net.fabricmc.api.EnvType;
import net.fabricmc.loader.api.FabricLoader;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.core.config.Configurator;
import org.quartz.*;
Expand All @@ -22,19 +24,15 @@ public class ScheduleUtil {

public static final String CRON_EVERY_MINUTE = "0 * * ? * * *";
@Getter
private static final Scheduler scheduler;
private static Scheduler scheduler;

static {
/* set logger level for quartz */
Level level = Level.getLevel(Configs.configHandler.model().common.quartz.logger_level);
Configurator.setAllLevels("org.quartz", level);

/* new scheduler */
try {
scheduler = new StdSchedulerFactory().getScheduler();
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
// note: for some early initialize, here will cause NPE
resetScheduler();
}

public static void addJob(Class<? extends Job> jobClass, String jobName, String jobGroup, String cron, JobDataMap jobDataMap) {
Expand Down Expand Up @@ -113,7 +111,18 @@ public static void triggerJobs(String jobGroup) {
});
}

private static void resetScheduler() {
/* new scheduler */
try {
scheduler = new StdSchedulerFactory().getScheduler();
} catch (SchedulerException e) {
throw new RuntimeException(e);
}
}

public static void startScheduler() {
resetScheduler();

try {
scheduler.start();
} catch (SchedulerException e) {
Expand All @@ -124,6 +133,12 @@ public static void startScheduler() {
public static void shutdownScheduler() {
try {
scheduler.shutdown();

// note: reset scheduler right now to fix client-side NPE
if (FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT) {
resetScheduler();
}

} catch (SchedulerException e) {
LOGGER.error("Exception in ScheduleUtil.shutdownScheduler", e);
}
Expand Down

0 comments on commit 48fa9eb

Please sign in to comment.