Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
...ishland/c2me/fixes/general/threading_issues/mixin/asynccatchers/MixinMinecraftServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters