Add a simple property annotation system for mods.
This commit is contained in:
parent
b2e9557b87
commit
611c3b9591
7 changed files with 84 additions and 1 deletions
|
@ -16,6 +16,7 @@ import java.io.File;
|
|||
import java.security.cert.Certificate;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
@ -168,4 +169,10 @@ public class DummyModContainer implements ModContainer
|
|||
{
|
||||
return md != null ? getModId() : "Dummy Container ("+label+") @" + System.identityHashCode(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getCustomModProperties()
|
||||
{
|
||||
return EMPTY_PROPERTIES;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import com.google.common.collect.BiMap;
|
|||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableList.Builder;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.ListMultimap;
|
||||
|
@ -48,6 +49,7 @@ import com.google.common.collect.Sets;
|
|||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import cpw.mods.fml.common.Mod.CustomProperty;
|
||||
import cpw.mods.fml.common.Mod.Instance;
|
||||
import cpw.mods.fml.common.Mod.Metadata;
|
||||
import cpw.mods.fml.common.discovery.ASMDataTable;
|
||||
|
@ -108,6 +110,7 @@ public class FMLModContainer implements ModContainer
|
|||
private String modLanguage;
|
||||
private ILanguageAdapter languageAdapter;
|
||||
private ListMultimap<Class<? extends FMLEvent>,Method> eventMethods;
|
||||
private Map<String, String> customModProperties;
|
||||
|
||||
public FMLModContainer(String className, File modSource, Map<String,Object> modDescriptor)
|
||||
{
|
||||
|
@ -489,6 +492,22 @@ public class FMLModContainer implements ModContainer
|
|||
}
|
||||
}
|
||||
|
||||
CustomProperty[] props = (CustomProperty[]) descriptor.get("customProperties");
|
||||
if (props!=null && props.length > 0)
|
||||
{
|
||||
com.google.common.collect.ImmutableMap.Builder<String, String> builder = ImmutableMap.<String,String>builder();
|
||||
for (CustomProperty p : props)
|
||||
{
|
||||
builder.put(p.k(),p.v());
|
||||
}
|
||||
customModProperties = builder.build();
|
||||
}
|
||||
else
|
||||
{
|
||||
customModProperties = EMPTY_PROPERTIES;
|
||||
}
|
||||
|
||||
|
||||
Method factoryMethod = gatherAnnotations(clazz);
|
||||
isNetworkMod = FMLNetworkHandler.instance().registerNetworkMod(this, clazz, event.getASMHarvestedData());
|
||||
modInstance = getLanguageAdapter().getNewInstance(this,clazz, modClassLoader, factoryMethod);
|
||||
|
@ -570,4 +589,10 @@ public class FMLModContainer implements ModContainer
|
|||
{
|
||||
return "FMLMod:"+getModId()+"{"+getVersion()+"}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getCustomModProperties()
|
||||
{
|
||||
return customModProperties;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ package cpw.mods.fml.common;
|
|||
import java.io.File;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
@ -154,4 +155,10 @@ public class InjectedModContainer implements ModContainer
|
|||
{
|
||||
return "Wrapped{"+wrappedContainer.toString()+"}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getCustomModProperties()
|
||||
{
|
||||
return wrappedContainer.getCustomModProperties();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -832,4 +832,10 @@ public class Loader
|
|||
}
|
||||
return fmlBrandingProperties;
|
||||
}
|
||||
|
||||
|
||||
public Map<String,String> getCustomModProperties(String modId)
|
||||
{
|
||||
return getIndexedModList().get(modId).getCustomModProperties();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,6 +178,33 @@ public @interface Mod
|
|||
@Deprecated
|
||||
String asmHookClass() default "";
|
||||
|
||||
/**
|
||||
* A list of custom properties for this mod. Completely up to the mod author if/when they
|
||||
* want to put anything in here.
|
||||
* @return an optional list of custom properties
|
||||
*/
|
||||
CustomProperty[] customProperties() default {};
|
||||
|
||||
/**
|
||||
* A custom key => value property pair for use with {@link Mod#customProperties()}
|
||||
* @author cpw
|
||||
*
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({})
|
||||
public @interface CustomProperty
|
||||
{
|
||||
/**
|
||||
* A key. Should be unique.
|
||||
* @return A key
|
||||
*/
|
||||
String k();
|
||||
/**
|
||||
* A value. Can be anything.
|
||||
* @return A value
|
||||
*/
|
||||
String v();
|
||||
}
|
||||
/**
|
||||
* Marks the associated method as handling an FML lifecycle event.
|
||||
* The method must have a single parameter, one of the following types. This annotation
|
||||
|
|
|
@ -15,8 +15,10 @@ package cpw.mods.fml.common;
|
|||
import java.io.File;
|
||||
import java.security.cert.Certificate;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.eventbus.EventBus;
|
||||
|
||||
import cpw.mods.fml.common.versioning.ArtifactVersion;
|
||||
|
@ -131,4 +133,7 @@ public interface ModContainer
|
|||
VersionRange acceptableMinecraftVersionRange();
|
||||
|
||||
Certificate getSigningCertificate();
|
||||
|
||||
public static final Map<String,String> EMPTY_PROPERTIES = ImmutableMap.of();
|
||||
Map<String,String> getCustomModProperties();
|
||||
}
|
||||
|
|
|
@ -615,4 +615,10 @@ public class ModLoaderModContainer implements ModContainer
|
|||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getCustomModProperties()
|
||||
{
|
||||
return EMPTY_PROPERTIES;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue