Skip to content

Commit

Permalink
fix: prevent async save and saveAll
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Jul 26, 2023
1 parent 1815657 commit 7e0c776
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
@@ -0,0 +1,36 @@
package com.ishland.c2me.fixes.general.threading_issues.mixin.asynccatchers;

import net.minecraft.server.MinecraftServer;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.ConcurrentModificationException;

@Mixin(MinecraftServer.class)
public class MixinMinecraftServer {

@Shadow @Final private Thread serverThread;

@Inject(method = "save", at = @At("HEAD"))
private void preventAsyncSave(CallbackInfoReturnable<Boolean> cir) {
if (Thread.currentThread() != this.serverThread) {
final ConcurrentModificationException exception = new ConcurrentModificationException("Attempted to call MinecraftServer#save async");
exception.printStackTrace();
throw exception;
}
}

@Inject(method = "saveAll", at = @At("HEAD"))
private void preventAsyncSaveAll(CallbackInfoReturnable<Boolean> cir) {
if (Thread.currentThread() != this.serverThread) {
final ConcurrentModificationException exception = new ConcurrentModificationException("Attempted to call MinecraftServer#saveAll async");
exception.printStackTrace();
throw exception;
}
}

}
Expand Up @@ -7,6 +7,7 @@
"MixinChunkHolder",
"MixinChunkTicketManager",
"MixinThreadedAnvilChunkStorage",
"asynccatchers.MixinMinecraftServer",
"asynccatchers.MixinServerChunkManager"
]
}

0 comments on commit 7e0c776

Please sign in to comment.