001 /* 002 * The FML Forge Mod Loader suite. Copyright (C) 2012 cpw 003 * 004 * 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 005 * Software Foundation; either version 2.1 of the License, or any later version. 006 * 007 * 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 008 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 009 * 010 * 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 011 * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 012 */ 013 package cpw.mods.fml.server; 014 015 import java.util.List; 016 017 import net.minecraft.server.MinecraftServer; 018 import net.minecraft.src.Entity; 019 import net.minecraft.src.Packet; 020 import net.minecraft.src.World; 021 import cpw.mods.fml.common.FMLCommonHandler; 022 import cpw.mods.fml.common.IFMLSidedHandler; 023 import cpw.mods.fml.common.Loader; 024 import cpw.mods.fml.common.ObfuscationReflectionHelper; 025 import cpw.mods.fml.common.Side; 026 import cpw.mods.fml.common.network.EntitySpawnAdjustmentPacket; 027 import cpw.mods.fml.common.network.EntitySpawnPacket; 028 import cpw.mods.fml.common.network.ModMissingPacket; 029 import cpw.mods.fml.common.registry.EntityRegistry.EntityRegistration; 030 import cpw.mods.fml.common.registry.LanguageRegistry; 031 032 /** 033 * Handles primary communication from hooked code into the system 034 * 035 * The FML entry point is {@link #onPreLoad(MinecraftServer)} called from 036 * {@link MinecraftServer} 037 * 038 * Obfuscated code should focus on this class and other members of the "server" 039 * (or "client") code 040 * 041 * The actual mod loading is handled at arms length by {@link Loader} 042 * 043 * It is expected that a similar class will exist for each target environment: 044 * Bukkit and Client side. 045 * 046 * It should not be directly modified. 047 * 048 * @author cpw 049 * 050 */ 051 public class FMLServerHandler implements IFMLSidedHandler 052 { 053 /** 054 * The singleton 055 */ 056 private static final FMLServerHandler INSTANCE = new FMLServerHandler(); 057 058 /** 059 * A reference to the server itself 060 */ 061 private MinecraftServer server; 062 063 private FMLServerHandler() 064 { 065 FMLCommonHandler.instance().beginLoading(this); 066 } 067 /** 068 * Called to start the whole game off from 069 * {@link MinecraftServer#startServer} 070 * 071 * @param minecraftServer 072 */ 073 public void beginServerLoading(MinecraftServer minecraftServer) 074 { 075 server = minecraftServer; 076 ObfuscationReflectionHelper.detectObfuscation(World.class); 077 Loader.instance().loadMods(); 078 } 079 080 /** 081 * Called a bit later on during server initialization to finish loading mods 082 */ 083 public void finishServerLoading() 084 { 085 Loader.instance().initializeMods(); 086 LanguageRegistry.reloadLanguageTable(); 087 } 088 089 @Override 090 public void haltGame(String message, Throwable exception) 091 { 092 throw new RuntimeException(message, exception); 093 } 094 095 /** 096 * Get the server instance 097 * 098 * @return 099 */ 100 public MinecraftServer getServer() 101 { 102 return server; 103 } 104 105 /** 106 * @return the instance 107 */ 108 public static FMLServerHandler instance() 109 { 110 return INSTANCE; 111 } 112 113 /* (non-Javadoc) 114 * @see cpw.mods.fml.common.IFMLSidedHandler#getAdditionalBrandingInformation() 115 */ 116 @Override 117 public List<String> getAdditionalBrandingInformation() 118 { 119 return null; 120 } 121 122 /* (non-Javadoc) 123 * @see cpw.mods.fml.common.IFMLSidedHandler#getSide() 124 */ 125 @Override 126 public Side getSide() 127 { 128 return Side.SERVER; 129 } 130 131 @Override 132 public void showGuiScreen(Object clientGuiElement) 133 { 134 135 } 136 137 @Override 138 public Entity spawnEntityIntoClientWorld(EntityRegistration er, EntitySpawnPacket packet) 139 { 140 // NOOP 141 return null; 142 } 143 144 @Override 145 public void adjustEntityLocationOnClient(EntitySpawnAdjustmentPacket entitySpawnAdjustmentPacket) 146 { 147 // NOOP 148 } 149 @Override 150 public void sendPacket(Packet packet) 151 { 152 throw new RuntimeException("You cannot send a bare packet without a target on the server!"); 153 } 154 @Override 155 public void displayMissingMods(ModMissingPacket modMissingPacket) 156 { 157 // NOOP on server 158 } 159 }