Commit refactoring
This commit is contained in:
parent
f735bce4e1
commit
d33d11123d
51 changed files with 348 additions and 18 deletions
52
ForgeCoreAPI/PluginSystem.cs
Normal file
52
ForgeCoreAPI/PluginSystem.cs
Normal file
|
@ -0,0 +1,52 @@
|
|||
using System.Reflection;
|
||||
using LibAC.NBT;
|
||||
using LibAC.NBT.API;
|
||||
|
||||
namespace ForgeCoreAPI;
|
||||
|
||||
public class PluginSystem
|
||||
{
|
||||
public static List<IPlugin> Plugins = new List<IPlugin>();
|
||||
|
||||
public static void InitializeSystem()
|
||||
{
|
||||
CompoundTag pluginsData = NbtIo.Read("PluginStorage.dat");
|
||||
// Search the Plugins directory for DLL files
|
||||
string[] files = Directory.GetFiles("Plugins", "*.dll");
|
||||
|
||||
// Begin loading assemblies
|
||||
foreach (var file in files)
|
||||
{
|
||||
Assembly asm = Assembly.LoadFile(file);
|
||||
// Scan types for ForgeCorePlugin attribute
|
||||
|
||||
foreach (var types in asm.GetTypes())
|
||||
{
|
||||
if (types.GetCustomAttribute<ForgeCorePluginAttribute>() != null)
|
||||
{
|
||||
IPlugin plugin = Activator.CreateInstance(types) as IPlugin;
|
||||
plugin.Initialize();
|
||||
|
||||
ForgeCorePluginAttribute attrib = types.GetCustomAttribute<ForgeCorePluginAttribute>();
|
||||
|
||||
Tag? pluginStore = pluginsData.Get(attrib.pluginName);
|
||||
if (pluginStore == null)
|
||||
{
|
||||
plugin.ResetMemory();
|
||||
}
|
||||
else
|
||||
{
|
||||
CompoundTag tag = (CompoundTag) pluginStore;
|
||||
CompoundTag dataTag = tag["data"] as CompoundTag;
|
||||
|
||||
plugin.LoadConfig(dataTag);
|
||||
if(tag.Get("enabled").AsByte() == 1) plugin.Enable();
|
||||
else plugin.Disable();
|
||||
}
|
||||
|
||||
Plugins.Add(plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue