Merge branch 'master' into bukkit

This commit is contained in:
Christian Weeks 2012-04-28 16:35:15 -04:00
commit c3b0dca9b2
4 changed files with 96 additions and 36 deletions

View file

@ -136,7 +136,7 @@
<zip destfile="${basedir}/target/${jarname}.zip">
<fileset dir="${output}" includes="**/*.class" />
<zipfileset dir="${basedir}" includes="LICENSE-fml.txt" />
<zipfileset dir="${basedir}" includes="install/CREDITS-fml.txt" prefix="/"/>
<zipfileset dir="${basedir}" includes="install/CREDITS-fml.txt" fullpath="CREDITS-fml.txt"/>
<mappedresources>
<concat>
<fileset dir="${basedir}/install" includes="README.txt" />

View file

@ -44,18 +44,21 @@ import cpw.mods.fml.common.ModContainer;
/**
* Handles primary communication from hooked code into the system
*
* The FML entry point is {@link #onPreLoad(MinecraftServer)} called from {@link MinecraftServer}
* The FML entry point is {@link #onPreLoad(MinecraftServer)} called from
* {@link MinecraftServer}
*
* Obfuscated code should focus on this class and other members of the "server" (or "client") code
* Obfuscated code should focus on this class and other members of the "server"
* (or "client") code
*
* 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.
* It is expected that a similar class will exist for each target environment:
* Bukkit and Client side.
*
* It should not be directly modified.
*
* @author cpw
*
*
*/
public class FMLServerHandler implements IFMLSidedHandler
{
@ -75,11 +78,41 @@ public class FMLServerHandler implements IFMLSidedHandler
private BiomeGenBase[] defaultOverworldBiomes;
/**
* Called to start the whole game off from {@link MinecraftServer#startServer}
* Called to start the whole game off from
* {@link MinecraftServer#startServer}
*
* @param minecraftServer
*/
public void onPreLoad(MinecraftServer minecraftServer)
{
try
{
Class.forName("BaseModMp", false, getClass().getClassLoader());
MinecraftServer.field_6038_a.severe(""
+ "Forge Mod Loader has detected that this server has an ModLoaderMP installed alongside Forge Mod Loader.\n"
+ "This will cause a serious problem with compatibility. To protect your worlds, this minecraft server will now shutdown.\n"
+ "You should follow the installation instructions of either Minecraft Forge of Forge Mod Loader and NOT install ModLoaderMP \n"
+ "into the minecraft_server.jar file "
+ "before this server will be allowed to start up.\n\nFailure to do so will simply result in more startup failures.\n\n"
+ "The authors of Minecraft Forge and Forge Mod Loader strongly suggest you talk to your mod's authors and get them to\nupdate their "
+ "requirements. ModLoaderMP is not compatible with Minecraft Forge on the server and they will need to update their mod\n"
+ "for Minecraft Forge and other server compatibility, unless they are Minecraft Forge mods, in which case they already\n"
+ "don't need ModLoaderMP and the mod author simply has failed to update his requirements and should be informed appropriately.\n\n"
+ "The authors of Forge Mod Loader would like to be compatible with ModLoaderMP but it is closed source and owned by SDK.\n"
+ "SDK, the author of ModLoaderMP, has a standing invitation to submit compatibility patches \n"
+ "to the open source community project that is Forge Mod Loader so that this incompatibility doesn't last. \n"
+ "Users who wish to enjoy mods of both types are "
+ "encouraged to request of SDK that he submit a\ncompatibility patch to the Forge Mod Loader project at \n"
+ "http://github.com/cpw/FML.\nPosting on the minecraft forums at\nhttp://www.minecraftforum.net/topic/86765- (the MLMP thread)\n"
+ "may encourage him in this effort. However, I ask that your requests be polite.\n"
+ "Now, the server has to shutdown so you can reinstall your minecraft_server.jar\nproperly, until such time as we can work together.");
throw new RuntimeException(
"This FML based server has detected an installation of ModLoaderMP alongside. This will cause serious compatibility issues, so the server will now shut down.");
}
catch (ClassNotFoundException e)
{
// We're safe. continue
}
server = minecraftServer;
FMLCommonHandler.instance().registerSidedDelegate(this);
CommonRegistry.registerRegistry(new ServerRegistry());
@ -112,6 +145,7 @@ public class FMLServerHandler implements IFMLSidedHandler
/**
* Get the server instance
*
* @return
*/
public MinecraftServer getServer()
@ -130,8 +164,8 @@ public class FMLServerHandler implements IFMLSidedHandler
/**
* Called from ChunkProviderServer when a chunk needs to be populated
*
* To avoid polluting the worldgen seed, we generate a new random from the world seed and
* generate a seed from that
* To avoid polluting the worldgen seed, we generate a new random from the
* world seed and generate a seed from that
*
* @param chunkProvider
* @param chunkX
@ -175,7 +209,8 @@ public class FMLServerHandler implements IFMLSidedHandler
}
/**
* Is the offered class and instance of BaseMod and therefore a ModLoader mod?
* Is the offered class and instance of BaseMod and therefore a ModLoader
* mod?
*/
public boolean isModLoaderMod(Class<?> clazz)
{
@ -188,12 +223,13 @@ public class FMLServerHandler implements IFMLSidedHandler
public ModContainer loadBaseModMod(Class<?> clazz, File canonicalFile)
{
@SuppressWarnings("unchecked")
Class <? extends BaseMod > bmClazz = (Class <? extends BaseMod >) clazz;
Class<? extends BaseMod> bmClazz = (Class<? extends BaseMod>) clazz;
return new ModLoaderModContainer(bmClazz, canonicalFile);
}
/**
* Called to notify that an item was picked up from the world
*
* @param entityItem
* @param entityPlayer
*/
@ -210,6 +246,7 @@ public class FMLServerHandler implements IFMLSidedHandler
/**
* Raise an exception
*
* @param exception
* @param message
* @param stopGame
@ -221,7 +258,8 @@ public class FMLServerHandler implements IFMLSidedHandler
}
/**
* Attempt to dispense the item as an entity other than just as a the item itself
* Attempt to dispense the item as an entity other than just as a the item
* itself
*
* @param world
* @param x
@ -255,6 +293,7 @@ public class FMLServerHandler implements IFMLSidedHandler
/**
* Build a list of default overworld biomes
*
* @return
*/
public BiomeGenBase[] getDefaultOverworldBiomes()
@ -282,6 +321,7 @@ public class FMLServerHandler implements IFMLSidedHandler
/**
* Called when an item is crafted
*
* @param player
* @param craftedItem
* @param craftingGrid
@ -319,7 +359,8 @@ public class FMLServerHandler implements IFMLSidedHandler
*
* @param chat
* @param player
* @return true if you want the packet to stop processing and not echo to the rest of the world
* @return true if you want the packet to stop processing and not echo to
* the rest of the world
*/
public boolean handleChatPacket(Packet3Chat chat, EntityPlayer player)
{
@ -336,6 +377,7 @@ public class FMLServerHandler implements IFMLSidedHandler
/**
* Called when a packet 250 packet is received from the player
*
* @param packet
* @param player
*/
@ -357,11 +399,13 @@ public class FMLServerHandler implements IFMLSidedHandler
/**
* Handle register requests for packet 250 channels
*
* @param packet
*/
private void handleClientRegistration(Packet250CustomPayload packet, EntityPlayer player)
{
if (packet.field_44004_c==null) {
if (packet.field_44004_c == null)
{
return;
}
try
@ -392,6 +436,7 @@ public class FMLServerHandler implements IFMLSidedHandler
/**
* Handle a login
*
* @param loginPacket
* @param networkManager
*/
@ -401,12 +446,14 @@ public class FMLServerHandler implements IFMLSidedHandler
packet.field_44005_a = "REGISTER";
packet.field_44004_c = FMLCommonHandler.instance().getPacketRegistry();
packet.field_44003_b = packet.field_44004_c.length;
if (packet.field_44003_b>0) {
if (packet.field_44003_b > 0)
{
networkManager.func_745_a(packet);
}
}
public void announceLogin(EntityPlayer player) {
public void announceLogin(EntityPlayer player)
{
for (ModContainer mod : Loader.getModList())
{
if (mod.wantsPlayerTracking())
@ -415,6 +462,7 @@ public class FMLServerHandler implements IFMLSidedHandler
}
}
}
/**
* Are we a server?
*/
@ -436,9 +484,12 @@ public class FMLServerHandler implements IFMLSidedHandler
@Override
public File getMinecraftRootDirectory()
{
try {
try
{
return server.func_6009_a(".").getCanonicalFile();
} catch (IOException ioe) {
}
catch (IOException ioe)
{
return new File(".");
}
}
@ -449,8 +500,10 @@ public class FMLServerHandler implements IFMLSidedHandler
*/
public boolean handleServerCommand(String command, String player, ICommandListener listener)
{
for (ModContainer mod : Loader.getModList()) {
if (mod.wantsConsoleCommands() && mod.getConsoleHandler().handleCommand(command, player, listener)) {
for (ModContainer mod : Loader.getModList())
{
if (mod.wantsConsoleCommands() && mod.getConsoleHandler().handleCommand(command, player, listener))
{
return true;
}
}

View file

@ -85,13 +85,15 @@ public class ModLoaderModContainer implements ModContainer
private void configureMod()
{
File configDir = Loader.instance().getConfigDir();
File modConfig = new File(configDir, String.format("%s.cfg", modClazz.getSimpleName()));
String modConfigName = modClazz.getSimpleName();
File modConfig = new File(configDir, String.format("%s.cfg", modConfigName));
Properties props = new Properties();
if (modConfig.exists())
{
try
{
Loader.log.fine(String.format("Reading existing configuration file for %s : %s", modConfigName, modConfig.getName()));
FileReader configReader = new FileReader(modConfig);
props.load(configReader);
configReader.close();
@ -130,10 +132,12 @@ public class ModLoaderModContainer implements ModContainer
{
defaultValue = f.get(null);
propertyValue = props.getProperty(propertyName, extractValue(defaultValue));
Object currentValue = parseValue(propertyValue, property, f.getType());
Object currentValue = parseValue(propertyValue, property, f.getType(), propertyName, modConfigName);
Loader.log.finest(String.format("Configuration for %s.%s found values default: %s, configured: %s, interpreted: %s", modConfigName, propertyName, defaultValue, propertyValue, currentValue));
if (currentValue != null && !currentValue.equals(defaultValue))
{
Loader.log.finest(String.format("Configuration for %s.%s value set to: %s", modConfigName, propertyName, currentValue));
f.set(null, currentValue);
}
}
@ -168,6 +172,7 @@ public class ModLoaderModContainer implements ModContainer
{
props.setProperty(propertyName, extractValue(propertyValue));
}
comments.append("\n");
}
}
}
@ -178,6 +183,7 @@ public class ModLoaderModContainer implements ModContainer
FileWriter configWriter = new FileWriter(modConfig);
props.store(configWriter, comments.toString());
configWriter.close();
Loader.log.fine(String.format("Configuration for %s written to %s", modConfigName, modConfig.getName()));
}
catch (IOException e)
{
@ -188,7 +194,7 @@ public class ModLoaderModContainer implements ModContainer
}
}
private Object parseValue(String val, MLProp property, Class<?> type)
private Object parseValue(String val, MLProp property, Class<?> type, String propertyName, String modConfigName)
{
if (type.isAssignableFrom(String.class))
{
@ -198,41 +204,42 @@ public class ModLoaderModContainer implements ModContainer
{
return Boolean.parseBoolean(val);
}
else if (Number.class.isAssignableFrom(type))
else if (Number.class.isAssignableFrom(type) || type.isPrimitive())
{
Number n = null;
if (Double.class.isAssignableFrom(type))
if (type.isAssignableFrom(Double.TYPE) || Double.class.isAssignableFrom(type))
{
n = Double.parseDouble(val);
}
if (Float.class.isAssignableFrom(type))
else if (type.isAssignableFrom(Float.TYPE) || Float.class.isAssignableFrom(type))
{
n = Float.parseFloat(val);
}
if (Long.class.isAssignableFrom(type))
else if (type.isAssignableFrom(Long.TYPE) || Long.class.isAssignableFrom(type))
{
n = Long.parseLong(val);
}
if (Integer.class.isAssignableFrom(type))
else if (type.isAssignableFrom(Integer.TYPE) || Integer.class.isAssignableFrom(type))
{
n = Integer.parseInt(val);
}
if (Short.class.isAssignableFrom(type))
else if (type.isAssignableFrom(Short.TYPE) || Short.class.isAssignableFrom(type))
{
n = Short.parseShort(val);
}
if (Byte.class.isAssignableFrom(type))
else if (type.isAssignableFrom(Byte.TYPE) || Byte.class.isAssignableFrom(type))
{
n = Byte.parseByte(val);
}
else
{
throw new IllegalArgumentException("MLProp declared on non-standard type");
throw new IllegalArgumentException(String.format("MLProp declared on %s of type %s, an unsupported type",propertyName, type.getName()));
}
if (n.doubleValue() < property.min() || n.doubleValue() > property.max())
{
Loader.log.warning(String.format("Configuration for %s.%s found value %s outside acceptable range %s,%s", modConfigName,propertyName, n, property.min(), property.max()));
return null;
}
else
@ -241,7 +248,7 @@ public class ModLoaderModContainer implements ModContainer
}
}
return null;
throw new IllegalArgumentException(String.format("MLProp declared on %s of type %s, an unsupported type",propertyName, type.getName()));
}
private String extractValue(Object value)
{

View file

@ -19,7 +19,7 @@ import static java.lang.annotation.ElementType.*;
/**
* @author cpw
*
*
*/
@Retention(value = RUNTIME)
@Target(value = FIELD)
@ -28,21 +28,21 @@ public @interface MLProp
/**
* Adds additional help to top of configuration file.
*/
String info() default "";
String info() default "";
/**
* Maximum value allowed if field is a number.
*/
double max() default 1D;
double max() default Double.MAX_VALUE;
/**
* Minimum value allowed if field is a number.
*/
double min() default -1D;
double min() default Double.MIN_VALUE;
/**
* Overrides the field name for property key.
*/
String name() default "";
String name() default "";
}