Skip to content

Commit

Permalink
fix config hung up the thread
Browse files Browse the repository at this point in the history
  • Loading branch information
GlodBlock committed Jan 5, 2024
1 parent a4e5ea1 commit 6719a33
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.github.glodblock.extendedae.mixins.config;

import com.github.glodblock.extendedae.util.mixinutil.IConfigStop;
import dev.toma.configuration.Configuration;
import dev.toma.configuration.config.io.ConfigIO;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.minecraft.server.dedicated.DedicatedServer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Configuration.class)
public abstract class MixinConfiguration {

@Inject(
method = "<init>",
at = @At("TAIL"),
remap = false
)
private void stopServer(CallbackInfo ci) {
ServerLifecycleEvents.SERVER_STOPPING.register(server -> {
if (server instanceof DedicatedServer) {
((IConfigStop) (Object) ConfigIO.FILE_WATCH_MANAGER).extendedae_$stop();
}
});
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.github.glodblock.extendedae.mixins.config;

import com.github.glodblock.extendedae.util.mixinutil.IConfigStop;
import dev.toma.configuration.config.io.FileWatchManager;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;

import java.io.IOException;
import java.nio.file.WatchService;
import java.util.concurrent.ScheduledExecutorService;

@Mixin(FileWatchManager.class)
public abstract class MixinFileWatchManager implements IConfigStop {

@Final
@Shadow(remap = false)
private WatchService service;

@Final
@Shadow(remap = false)
private ScheduledExecutorService executorService;

@Unique
@Override
public void extendedae_$stop() {
try {
executorService.shutdown();
service.close();
} catch (IOException e) {
throw new IllegalStateException("Error while stopping FileWatch service", e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.glodblock.extendedae.util.mixinutil;

public interface IConfigStop {

void extendedae_$stop();

}
4 changes: 3 additions & 1 deletion src/main/resources/extendedae.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
"compatibilityLevel": "JAVA_17",
"mixins": [
"MixinInitUpgrades",
"MixinPatternAccessTermMenu"
"MixinPatternAccessTermMenu",
"config.MixinConfiguration",
"config.MixinFileWatchManager"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 6719a33

Please sign in to comment.