Get basic ForgeCore server implemented
This commit is contained in:
parent
65f5cb722b
commit
0c694c3e78
9 changed files with 168 additions and 11 deletions
|
@ -6,13 +6,22 @@ namespace ForgeCoreAPI;
|
|||
|
||||
public class PluginSystem
|
||||
{
|
||||
public static List<IPlugin> Plugins = new List<IPlugin>();
|
||||
public static string PluginDirectory { get; set; } = "Plugins";
|
||||
|
||||
public static List<PluginContainer> Plugins = new List<PluginContainer>();
|
||||
|
||||
public static void InitializeSystem()
|
||||
public static void InitializeSystem(string pluginDirectory)
|
||||
{
|
||||
CompoundTag pluginsData = NbtIo.Read("PluginStorage.dat");
|
||||
CompoundTag pluginsData = new CompoundTag();
|
||||
if (!File.Exists("PluginStorage.dat"))
|
||||
{
|
||||
// We have no existing saved config for plugins, or this is the first run
|
||||
// Leave pluginsData empty
|
||||
} else pluginsData = NbtIo.Read("PluginStorage.dat");
|
||||
|
||||
|
||||
// Search the Plugins directory for DLL files
|
||||
string[] files = Directory.GetFiles("Plugins", "*.dll");
|
||||
string[] files = Directory.GetFiles(pluginDirectory, "*.dll");
|
||||
|
||||
// Begin loading assemblies
|
||||
foreach (var file in files)
|
||||
|
@ -24,12 +33,17 @@ public class PluginSystem
|
|||
{
|
||||
if (types.GetCustomAttribute<ForgeCorePluginAttribute>() != null)
|
||||
{
|
||||
PluginContainer nPlugin = new PluginContainer();
|
||||
IPlugin plugin = Activator.CreateInstance(types) as IPlugin;
|
||||
plugin.Initialize();
|
||||
nPlugin.plugin = plugin;
|
||||
|
||||
ForgeCorePluginAttribute attrib = types.GetCustomAttribute<ForgeCorePluginAttribute>();
|
||||
|
||||
Tag? pluginStore = pluginsData.Get(attrib.pluginName);
|
||||
nPlugin.pluginName = attrib.pluginName;
|
||||
|
||||
|
||||
if (pluginStore == null)
|
||||
{
|
||||
plugin.ResetMemory();
|
||||
|
@ -40,11 +54,19 @@ public class PluginSystem
|
|||
CompoundTag dataTag = tag["data"] as CompoundTag;
|
||||
|
||||
plugin.LoadConfig(dataTag);
|
||||
if(tag.Get("enabled").AsByte() == 1) plugin.Enable();
|
||||
else plugin.Disable();
|
||||
if (NbtUtils.ReadBoolean(tag, "enabled"))
|
||||
{
|
||||
nPlugin.enabled = true;
|
||||
plugin.Enable();
|
||||
}
|
||||
else
|
||||
{
|
||||
plugin.Disable();
|
||||
nPlugin.enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
Plugins.Add(plugin);
|
||||
Plugins.Add(nPlugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue