Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
Caedis committed Jan 9, 2025
1 parent bddbe2d commit bbd8490
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,8 +418,8 @@ public enum Mixins {
.addMixinClasses("minecraft.server.MixinMinecraftServer_AutoSaveInterval")
.setApplyIf(() -> TweaksConfig.autoSaveInterval != 900)),

PAUSE_WHEN_EMPTY(new Builder("Pauses the server when noone is online after X seconds; Servers Only").setPhase(Phase.EARLY).setSide(Side.SERVER)
.addTargetedMod(TargetedMod.VANILLA)
PAUSE_WHEN_EMPTY(new Builder("Pauses the server when noone is online after X seconds; Servers Only")
.setPhase(Phase.EARLY).setSide(Side.SERVER).addTargetedMod(TargetedMod.VANILLA)
.addMixinClasses("minecraft.server.MixinMinecraftServer_PauseWhenEmpty")
.setApplyIf(() -> TweaksConfig.pauseWhenEmpty)),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
package com.mitchej123.hodgepodge.mixins.early.minecraft.server;

import com.mitchej123.hodgepodge.Common;
import com.mitchej123.hodgepodge.Hodgepodge;
import java.io.File;
import java.net.Proxy;

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;
import com.mitchej123.hodgepodge.Common;

@Mixin(DedicatedServer.class)
public abstract class MixinMinecraftServer_PauseWhenEmpty extends MinecraftServer {
@Shadow private PropertyManager settings;

@Shadow
private PropertyManager settings;

@Unique
private int hodgepodge$pauseWhenEmptySeconds = 0;
Expand All @@ -31,24 +31,30 @@ 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){
@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(){
public void tick() {
int pauseTicks = hodgepodge$pauseWhenEmptySeconds * 20;
if (pauseTicks > 0){
if (getCurrentPlayerCount() == 0){
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);
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);
}
Expand Down

0 comments on commit bbd8490

Please sign in to comment.