Files
MinecraftForge/src/main/java/cpw/mods/fml/server/FMLServerHandler.java
T

199 lines
5.3 KiB
Java
Raw Normal View History

/*
* The FML Forge Mod Loader suite. Copyright (C) 2012 cpw
2012-04-05 10:07:52 -04:00
*
* This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or any later version.
2012-04-05 10:07:52 -04:00
*
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
2012-04-05 10:07:52 -04:00
*
* You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
package cpw.mods.fml.server;
import java.util.List;
import java.util.Set;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.NetworkManager;
import net.minecraft.server.MinecraftServer;
import com.google.common.collect.ImmutableList;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.IFMLSidedHandler;
2012-04-03 17:04:26 -04:00
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.ModContainer;
import cpw.mods.fml.common.WorldAccessContainer;
import cpw.mods.fml.common.event.FMLMissingMappingsEvent;
import cpw.mods.fml.common.eventhandler.EventBus;
import cpw.mods.fml.common.network.FMLNetworkEvent;
2012-08-13 20:28:53 -04:00
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
2012-04-05 16:22:47 -04:00
/**
* Handles primary communication from hooked code into the system
*
* The FML entry point is {@link #beginServerLoading(MinecraftServer)} called from
2013-01-21 21:37:29 -05:00
* {@link net.minecraft.server.dedicated.DedicatedServer}
*
* Obfuscated code should focus on this class and other members of the "server"
* (or "client") code
*
2012-04-05 16:22:47 -04:00
* The actual mod loading is handled at arms length by {@link Loader}
*
* It is expected that a similar class will exist for each target environment:
* Bukkit and Client side.
*
2012-04-05 16:22:47 -04:00
* It should not be directly modified.
*
2012-04-05 16:22:47 -04:00
* @author cpw
*
2012-04-05 16:22:47 -04:00
*/
public class FMLServerHandler implements IFMLSidedHandler
2012-04-05 10:07:52 -04:00
{
2012-04-05 16:22:47 -04:00
/**
* The singleton
*/
private static final FMLServerHandler INSTANCE = new FMLServerHandler();
2012-04-05 10:07:52 -04:00
2012-04-05 16:22:47 -04:00
/**
* A reference to the server itself
*/
2012-04-05 10:07:52 -04:00
private MinecraftServer server;
private FMLServerHandler()
{
FMLCommonHandler.instance().beginLoading(this);
}
2012-04-05 16:22:47 -04:00
/**
* Called to start the whole game off from
* {@link MinecraftServer#startServer}
*
2012-04-05 16:22:47 -04:00
* @param minecraftServer
*/
2014-01-17 23:19:22 -05:00
@Override
public void beginServerLoading(MinecraftServer minecraftServer)
2012-04-05 10:07:52 -04:00
{
server = minecraftServer;
Loader.instance().loadMods();
}
2012-04-05 16:22:47 -04:00
/**
* Called a bit later on during server initialization to finish loading mods
*/
2014-01-17 23:19:22 -05:00
@Override
public void finishServerLoading()
2012-04-05 10:07:52 -04:00
{
Loader.instance().initializeMods();
}
@Override
public void haltGame(String message, Throwable exception)
{
throw new RuntimeException(message, exception);
}
2012-04-05 16:22:47 -04:00
/**
* Get the server instance
*/
2014-01-17 23:19:22 -05:00
@Override
2012-04-05 10:07:52 -04:00
public MinecraftServer getServer()
{
return server;
}
/**
* @return the instance
*/
public static FMLServerHandler instance()
2012-04-05 10:07:52 -04:00
{
return INSTANCE;
}
/* (non-Javadoc)
* @see cpw.mods.fml.common.IFMLSidedHandler#getAdditionalBrandingInformation()
*/
@Override
public List<String> getAdditionalBrandingInformation()
{
return ImmutableList.<String>of();
}
2012-06-02 15:13:55 -04:00
/* (non-Javadoc)
* @see cpw.mods.fml.common.IFMLSidedHandler#getSide()
*/
@Override
public Side getSide()
{
return Side.SERVER;
}
2012-08-08 00:31:24 -04:00
@Override
public void showGuiScreen(Object clientGuiElement)
{
2012-08-08 00:31:24 -04:00
}
@Override
public boolean shouldServerShouldBeKilledQuietly()
{
return false;
}
@Override
public void addModAsResource(ModContainer container)
{
LanguageRegistry.instance().loadLanguagesFor(container, Side.SERVER);
}
@Override
public void updateResourcePackList()
{
}
2013-09-13 19:04:25 -05:00
@Override
public String getCurrentLanguage()
{
return "en_US";
}
@Override
public void serverStopped()
{
// NOOP
}
@Override
public NetworkManager getClientToServerNetworkManager()
{
throw new RuntimeException("Missing");
}
@Override
public INetHandler getClientPlayHandler()
{
return null;
}
2014-01-16 14:58:28 -05:00
@Override
public void waitForPlayClient()
{
// NOOP
}
@Override
public void fireNetRegistrationEvent(EventBus bus, NetworkManager manager, Set<String> channelSet, String channel, Side side)
{
bus.post(new FMLNetworkEvent.CustomPacketRegistrationEvent<NetHandlerPlayServer>(manager, channelSet, channel, side, NetHandlerPlayServer.class));
}
@Override
public FMLMissingMappingsEvent.Action getDefaultMissingAction()
{
return FMLMissingMappingsEvent.Action.valueOf(System.getProperty("fml.missingBlockAction", "FAIL"));
}
@Override
public void serverLoadedSuccessfully()
{
}
@Override
public void failedServerLoading(RuntimeException ex, WorldAccessContainer wac)
{
}
}