Skip to content
This repository has been archived by the owner. It is now read-only.
Browse files

Added the ability to close server (with /closed) so only OP's and man…

…ual whitelist entries can get on.
  • Loading branch information...
dries007 committed Mar 17, 2016
1 parent b091889 commit ed3d24e18bb66cda6b04b185d9f98b1e956db020
Showing with 46 additions and 2 deletions.
  1. +46 −2 src/main/java/net/doubledoordev/fsw/
@@ -28,14 +28,19 @@
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLServerStartingEvent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.relauncher.Side;
import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.ChatComponentText;
import net.minecraftforge.common.config.Configuration;
import org.apache.logging.log4j.Logger;
@@ -63,13 +68,15 @@

private static Configuration configuration;

private static String[] kickMsg = new String[]{"You must be subscribed to join this server.", "Make sure your accounts are linked:"};
private static String[] kickMsg = new String[] {"You must be subscribed to join this server.", "Make sure your accounts are linked:"};
private static String apiToken;
private static boolean twitch = true;
private static boolean beam = true;
private static int gamewisp = -1;
private static Logger logger;
private static String url;
private static boolean closed = false;
private static String closed_msg = "Sorry, the server isn't open yet.";

public void init(FMLPreInitializationEvent event) throws IOException
@@ -94,14 +101,45 @@ public void joinEvent(final FMLNetworkEvent.ServerConnectionFromClientEvent even
new Thread(new ForgeSubWhitelist.Checker(((NetHandlerPlayServer) event.handler).playerEntity.getGameProfile())).start();

public void serverStart(FMLServerStartingEvent event) throws IOException
event.registerServerCommand(new CommandBase()
public String getCommandName()
return "closed";

public String getCommandUsage(ICommandSender sender)
return "/closed [true|false]";

public void processCommand(ICommandSender sender, String[] args)
if (args.length == 1)
closed = parseBoolean(sender, args[0]);
configuration.get(MODID, "closed", closed).set(closed);
if (configuration.hasChanged());
sender.addChatMessage(new ChatComponentText("The server is currently " + (closed ? "closed" : "open" + ".")));

public void tickEvent(TickEvent.ServerTickEvent event)
String kick = TO_KICK.poll();
while (kick != null)
EntityPlayerMP player = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().func_152612_a(kick);
player.playerNetServerHandler.kickPlayerFromServer(closed ? closed_msg : Joiner.on('\n').join(kickMsg));

kick = TO_KICK.poll();
@@ -117,6 +155,9 @@ public void syncConfig()
beam = configuration.getBoolean("beam", MODID, beam, "If true anyone who is subbed on beam will be able to join this server.");
gamewisp = configuration.getInt("gamewisp", MODID, gamewisp, -1, Integer.MAX_VALUE, "If -1, use ignore. Put in the tier at which subs get access to this server. (Includes all above). Your first tier is 1, second is 2, ...");

closed = configuration.getBoolean("closed", MODID, closed, "Used for not-yet-public state. Enable ingame with /closed <true|false>.");
closed_msg = configuration.getString("closed_msg", MODID, closed_msg, "The message when the server is closed.");

if (configuration.hasChanged());"Trying out the API token. This could take a couple of seconds.");
@@ -159,6 +200,9 @@ public void run()"Letting {} join, manual or op.", uuid);

if (closed) TO_KICK.add(gameProfile.getName());

if (CACHE_MAP.containsKey(uuid) && CACHE_MAP.get(uuid) - System.currentTimeMillis() < 0)

0 comments on commit ed3d24e

Please sign in to comment.
You can’t perform that action at this time.