mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-13 00:37:52 +00:00
Fix problem with nulls in getModList
Work on the meta information file
This commit is contained in:
1 parent
7ec180ee7c
commit
4c2c7cb2f3
10 files changed
+200
-1
No files matched your search
@@ -7,3 +7,4 @@
|
||||
/.metadata/
|
||||
/eclipse/.metadata/
|
||||
/target
|
||||
fmlbranding.properties
|
||||
@@ -16,6 +16,7 @@ import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -52,15 +53,19 @@ import net.minecraft.src.RenderPlayer;
|
||||
import net.minecraft.src.StringTranslate;
|
||||
import net.minecraft.src.World;
|
||||
import net.minecraft.src.WorldType;
|
||||
import argo.jdom.JdomParser;
|
||||
import argo.jdom.JsonNode;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.IFMLSidedHandler;
|
||||
import cpw.mods.fml.common.IKeyHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.ModContainer.TickType;
|
||||
import cpw.mods.fml.common.ModMetadata;
|
||||
import cpw.mods.fml.common.modloader.ModLoaderHelper;
|
||||
import cpw.mods.fml.common.modloader.ModLoaderModContainer;
|
||||
|
||||
|
||||
/**
|
||||
* Handles primary communication from hooked code into the system
|
||||
*
|
||||
@@ -685,4 +690,17 @@ public class FMLClientHandler implements IFMLSidedHandler
|
||||
objectName+=".name";
|
||||
return objectName;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.IFMLSidedHandler#readMetadataFrom(java.io.InputStream, cpw.mods.fml.common.ModContainer)
|
||||
*/
|
||||
@Override
|
||||
public ModMetadata readMetadataFrom(InputStream input, ModContainer mod) throws Exception
|
||||
{
|
||||
JsonNode root=new JdomParser().func_27366_a(new InputStreamReader(input));
|
||||
ModMetadata meta=new ModMetadata(mod);
|
||||
meta.name=root.func_27213_a("name");
|
||||
meta.description=root.func_27213_a("description");
|
||||
return meta;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,8 @@
|
||||
package cpw.mods.fml.common;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -25,7 +27,14 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipException;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import cpw.mods.fml.common.ModContainer.SourceType;
|
||||
import cpw.mods.fml.common.ModContainer.TickType;
|
||||
|
||||
import net.minecraft.src.StringTranslate;
|
||||
@@ -49,6 +58,7 @@ public class FMLCommonHandler
|
||||
* The singleton
|
||||
*/
|
||||
private static final FMLCommonHandler INSTANCE = new FMLCommonHandler();
|
||||
private static final Pattern metadataFile = Pattern.compile("$/modinfo.json$");;
|
||||
/**
|
||||
* A map of mods to their network channels
|
||||
*/
|
||||
@@ -431,4 +441,29 @@ public class FMLCommonHandler
|
||||
return brandings.toArray(new String[brandings.size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mod
|
||||
*/
|
||||
public void loadMetadataFor(ModContainer mod)
|
||||
{
|
||||
if (mod.getSourceType()==SourceType.JAR) {
|
||||
try
|
||||
{
|
||||
ZipFile jar = new ZipFile(mod.getSource());
|
||||
ZipEntry infoFile=jar.getEntry("/modinfo.json");
|
||||
if (infoFile!=null) {
|
||||
InputStream input=jar.getInputStream(infoFile);
|
||||
ModMetadata data=sidedDelegate.readMetadataFrom(input, mod);
|
||||
mod.setMetadata(data);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// Something wrong but we don't care
|
||||
}
|
||||
} else {
|
||||
getFMLLogger().fine(String.format("Unable to load metadata for mod %s as it is not a jar/zip packaged file",mod.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -337,4 +337,40 @@ public class FMLModContainer implements ModContainer
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getSourceType()
|
||||
*/
|
||||
@Override
|
||||
public SourceType getSourceType()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#setSourceType(cpw.mods.fml.common.ModContainer.SourceType)
|
||||
*/
|
||||
@Override
|
||||
public void setSourceType(SourceType type)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getMetadata()
|
||||
*/
|
||||
@Override
|
||||
public ModMetadata getMetadata()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#setMetadata(cpw.mods.fml.common.ModMetadata)
|
||||
*/
|
||||
@Override
|
||||
public void setMetadata(ModMetadata meta)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package cpw.mods.fml.common;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -16,4 +17,5 @@ public interface IFMLSidedHandler
|
||||
String getCurrentLanguage();
|
||||
Properties getCurrentLanguageTable();
|
||||
String getObjectName(Object minecraftObject);
|
||||
ModMetadata readMetadataFrom(InputStream input, ModContainer mod) throws Exception;
|
||||
}
|
||||
@@ -492,6 +492,7 @@ public class Loader
|
||||
// Unrecognized
|
||||
}
|
||||
if (mod!=null) {
|
||||
FMLCommonHandler.instance().loadMetadataFor(mod);
|
||||
mods.add(mod);
|
||||
mod.nextState();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ package cpw.mods.fml.common;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.ModContainer.SourceType;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.IBlockAccess;
|
||||
|
||||
@@ -42,6 +44,10 @@ public interface ModContainer
|
||||
return this.label;
|
||||
}
|
||||
}
|
||||
|
||||
public enum SourceType {
|
||||
JAR, CLASSPATH, DIR;
|
||||
}
|
||||
/**
|
||||
* The enclosed mod wants to be called during pre-initialization.
|
||||
* @return
|
||||
@@ -203,4 +209,11 @@ public interface ModContainer
|
||||
}
|
||||
|
||||
List<IKeyHandler> getKeys();
|
||||
|
||||
SourceType getSourceType();
|
||||
|
||||
void setSourceType(SourceType type);
|
||||
|
||||
ModMetadata getMetadata();
|
||||
void setMetadata(ModMetadata meta);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* The FML Forge Mod Loader suite.
|
||||
* Copyright (C) 2012 cpw
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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.common;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import cpw.mods.fml.common.modloader.ModLoaderModContainer;
|
||||
/**
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
public class ModMetadata
|
||||
{
|
||||
public enum ModType { MODLOADER, FML };
|
||||
public ModContainer mod;
|
||||
public ModType type;
|
||||
|
||||
public String name;
|
||||
public String description;
|
||||
|
||||
public String url;
|
||||
public String updateUrl;
|
||||
|
||||
public String logoFile;
|
||||
|
||||
/**
|
||||
* @param mod2
|
||||
* @param type2
|
||||
*/
|
||||
public ModMetadata(ModContainer mod)
|
||||
{
|
||||
this.mod=mod;
|
||||
this.type=(mod instanceof FMLModContainer ? ModType.FML : ModType.MODLOADER);
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,9 @@ import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.LoaderException;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.ModContainer.ModState;
|
||||
import cpw.mods.fml.common.ModContainer.SourceType;
|
||||
import cpw.mods.fml.common.ModContainer.TickType;
|
||||
import cpw.mods.fml.common.ModMetadata;
|
||||
|
||||
public class ModLoaderModContainer implements ModContainer
|
||||
{
|
||||
@@ -60,6 +62,8 @@ public class ModLoaderModContainer implements ModContainer
|
||||
private ArrayList<String> postDependencies;
|
||||
private ArrayList<IKeyHandler> keyHandlers;
|
||||
private ModState state;
|
||||
private SourceType sourceType;
|
||||
private ModMetadata metadata;
|
||||
|
||||
public ModLoaderModContainer(Class <? extends BaseMod > modClazz, File modSource)
|
||||
{
|
||||
@@ -386,7 +390,7 @@ public class ModLoaderModContainer implements ModContainer
|
||||
|
||||
for (ModContainer mc : Loader.getModList())
|
||||
{
|
||||
if (mc instanceof ModLoaderModContainer)
|
||||
if (mc instanceof ModLoaderModContainer && mc.getModState().ordinal()>ModState.LOADED.ordinal())
|
||||
{
|
||||
modList.add(((ModLoaderModContainer)mc).mod);
|
||||
}
|
||||
@@ -610,4 +614,32 @@ public class ModLoaderModContainer implements ModContainer
|
||||
}
|
||||
return keyHandlers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSourceType(SourceType type) {
|
||||
this.sourceType=type;
|
||||
}
|
||||
@Override
|
||||
public SourceType getSourceType()
|
||||
{
|
||||
return sourceType;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#getMetadata()
|
||||
*/
|
||||
@Override
|
||||
public ModMetadata getMetadata()
|
||||
{
|
||||
return metadata;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.ModContainer#setMetadata(cpw.mods.fml.common.ModMetadata)
|
||||
*/
|
||||
@Override
|
||||
public void setMetadata(ModMetadata meta)
|
||||
{
|
||||
this.metadata=meta;
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ package cpw.mods.fml.server;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Properties;
|
||||
@@ -45,6 +46,7 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.IFMLSidedHandler;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.ModMetadata;
|
||||
import cpw.mods.fml.common.modloader.ModLoaderModContainer;
|
||||
|
||||
/**
|
||||
@@ -586,4 +588,13 @@ public class FMLServerHandler implements IFMLSidedHandler
|
||||
objectName+=".name";
|
||||
return objectName;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see cpw.mods.fml.common.IFMLSidedHandler#readMetadataFrom(java.io.InputStream, cpw.mods.fml.common.ModContainer)
|
||||
*/
|
||||
@Override
|
||||
public ModMetadata readMetadataFrom(InputStream input, ModContainer mod) throws Exception
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user