Skip to content

Commit

Permalink
Offline playerlist
Browse files Browse the repository at this point in the history
  • Loading branch information
justmangoou committed Jan 28, 2023
1 parent ac56f85 commit cb16163
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package xyz.mangostudio.smp.bridge;

import java.util.List;

public interface MinecraftServerBridge {
List<String> getWhitelistNames();

void setWhitelistNames(List<String> whitelistNames);
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
package xyz.mangostudio.smp.mixin.server;

import java.util.List;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import xyz.mangostudio.smp.bridge.MinecraftServerBridge;

import net.minecraft.server.MinecraftServer;
import net.minecraft.server.world.ServerChunkManager;

@Mixin(MinecraftServer.class)
public class MinecraftServerMixin {
public class MinecraftServerMixin implements MinecraftServerBridge {
private List<String> whitelistNames;

@Redirect(method = "prepareStartRegion", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerChunkManager;getTotalChunksLoadedCount()I"))
public int onPrepareStartReg_redirectChunksLoaded(ServerChunkManager scm) {
return 441;
}

@Override
public List<String> getWhitelistNames() {
return this.whitelistNames;
}

@Override
public void setWhitelistNames(List<String> whitelistNames) {
this.whitelistNames = whitelistNames;
}
}
17 changes: 17 additions & 0 deletions src/main/java/xyz/mangostudio/smp/mod/SMPMod.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
package xyz.mangostudio.smp.mod;

import java.io.FileInputStream;
import java.util.List;
import java.util.Properties;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import xyz.mangostudio.smp.bridge.MinecraftServerBridge;

import net.fabricmc.api.DedicatedServerModInitializer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;

public class SMPMod implements DedicatedServerModInitializer {
private static final Logger LOGGER = LogManager.getLogger("MangoplexSMP");

@Override
public void onInitializeServer() {
Properties properties = new Properties();

try {
properties.load(new FileInputStream("smp.properties"));
} catch (Exception e) {
LOGGER.error("Failed to load smp.properties", e);
}

ServerLifecycleEvents.SERVER_STARTING.register(server -> {
((MinecraftServerBridge) server).setWhitelistNames(List.of(properties.getProperty("offline_users").split(",")));
});
}
}

0 comments on commit cb16163

Please sign in to comment.