Move commonly used API systems to a plugin based system
Create a class that implements IBloodMagicPlugin and annotate it with `@BloodMagicPlugin`. The `register` method will be called during init. Currently implemented systems: - Blacklisting - Teleposer - Teleposer (entity) - Transposition - Well of Suffering - Green Grove - Setting sacrificial values - Adding altar components
This commit is contained in:
parent
5fcdd978d7
commit
554c9852e6
86 changed files with 528 additions and 496 deletions
36
src/main/java/WayofTime/bloodmagic/util/PluginUtil.java
Normal file
36
src/main/java/WayofTime/bloodmagic/util/PluginUtil.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package WayofTime.bloodmagic.util;
|
||||
|
||||
import WayofTime.bloodmagic.apiv2.BloodMagicPlugin;
|
||||
import WayofTime.bloodmagic.apiv2.IBloodMagicPlugin;
|
||||
import com.google.common.collect.Lists;
|
||||
import net.minecraftforge.fml.common.discovery.ASMDataTable;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class PluginUtil {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nonnull
|
||||
public static List<Pair<IBloodMagicPlugin, BloodMagicPlugin>> getPlugins(ASMDataTable dataTable) {
|
||||
List<Pair<IBloodMagicPlugin, BloodMagicPlugin>> discoveredAnnotations = Lists.newArrayList();
|
||||
Set<ASMDataTable.ASMData> discoveredPlugins = dataTable.getAll(BloodMagicPlugin.class.getCanonicalName());
|
||||
|
||||
for (ASMDataTable.ASMData data : discoveredPlugins) {
|
||||
try {
|
||||
Class<?> asmClass = Class.forName(data.getClassName());
|
||||
Class<? extends IBloodMagicPlugin> pluginClass = asmClass.asSubclass(IBloodMagicPlugin.class);
|
||||
|
||||
IBloodMagicPlugin instance = pluginClass.newInstance();
|
||||
|
||||
discoveredAnnotations.add(Pair.of(instance, pluginClass.getAnnotation(BloodMagicPlugin.class)));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return discoveredAnnotations;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue