-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport 1.20's 'pause-when-empty-seconds' server property
- Loading branch information
Showing
5 changed files
with
76 additions
and
2 deletions.
There are no files selected for viewing
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
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
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
64 changes: 64 additions & 0 deletions
64
...chej123/hodgepodge/mixins/early/minecraft/server/MixinMinecraftServer_PauseWhenEmpty.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,64 @@ | ||
package com.mitchej123.hodgepodge.mixins.early.minecraft.server; | ||
|
||
import com.mitchej123.hodgepodge.Common; | ||
import com.mitchej123.hodgepodge.Hodgepodge; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.dedicated.DedicatedServer; | ||
import net.minecraft.server.dedicated.PropertyManager; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.spongepowered.asm.logging.ILogger; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.io.File; | ||
import java.net.Proxy; | ||
|
||
@Mixin(DedicatedServer.class) | ||
public abstract class MixinMinecraftServer_PauseWhenEmpty extends MinecraftServer { | ||
@Shadow private PropertyManager settings; | ||
|
||
@Unique | ||
private int hodgepodge$pauseWhenEmptySeconds = 0; | ||
@Unique | ||
private int hodgepodge$emptyTicks = 0; | ||
|
||
public MixinMinecraftServer_PauseWhenEmpty(File workDir, Proxy proxy) { | ||
super(workDir, proxy); | ||
} | ||
|
||
@Inject(method = "startServer", at = @At(value = "INVOKE", target = "Lcpw/mods/fml/common/FMLCommonHandler;onServerStarted()V", shift = At.Shift.AFTER)) | ||
public void hodgepodge$setupServer(CallbackInfoReturnable<Boolean> cir){ | ||
hodgepodge$pauseWhenEmptySeconds = settings.getIntProperty("pause-when-empty-seconds", 0); | ||
} | ||
|
||
@Override | ||
public void tick(){ | ||
int pauseTicks = hodgepodge$pauseWhenEmptySeconds * 20; | ||
if (pauseTicks > 0){ | ||
if (getCurrentPlayerCount() == 0){ | ||
this.hodgepodge$emptyTicks++; | ||
} else { | ||
this.hodgepodge$emptyTicks = 0; | ||
} | ||
|
||
if (hodgepodge$emptyTicks >= pauseTicks){ | ||
if (hodgepodge$emptyTicks == pauseTicks){ | ||
Common.log.info("Server empty for {} seconds, saving and pausing", hodgepodge$pauseWhenEmptySeconds); | ||
this.serverConfigManager.saveAllPlayerData(); | ||
this.saveAllWorlds(true); | ||
} | ||
|
||
// to process new connections | ||
this.func_147137_ag().networkTick(); | ||
return; | ||
} | ||
} | ||
|
||
super.tick(); | ||
} | ||
} |
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