Moar Gamecraft commands!
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

52 рядки
1.5KB

  1. using System;
  2. using IllusionPlugin;
  3. //using UnityEngine;
  4. using System.Reflection;
  5. using GamecraftModdingAPI.Commands;
  6. using GamecraftModdingAPI.Utility;
  7. namespace ExtraCommands
  8. {
  9. public class Plugin : IllusionPlugin.IEnhancedPlugin
  10. {
  11. public override string Name { get; } = "ExtraCommands";
  12. public override string Version { get; } = Assembly.GetExecutingAssembly().GetName().Version.ToString();
  13. public string HarmonyID { get; } = "org.git.exmods.extracommands.extracommands";
  14. public override void OnApplicationQuit()
  15. {
  16. GamecraftModdingAPI.Main.Shutdown();
  17. }
  18. public override void OnApplicationStart()
  19. {
  20. GamecraftModdingAPI.Main.Init();
  21. object[] empty = new object[] { };
  22. int engineCount = 0;
  23. foreach (Type t in Assembly.GetExecutingAssembly().GetTypes())
  24. {
  25. CustomCommandAttribute[] attributes = (CustomCommandAttribute[])t.GetCustomAttributes(typeof(CustomCommandAttribute), false);
  26. ICustomCommandEngine inst = null;
  27. foreach (CustomCommandAttribute attr in attributes)
  28. {
  29. if (attr != null && CustomCommandAttribute.IsCompatible(t))
  30. {
  31. if (inst == null)
  32. {
  33. // create instance by getting the constructor through reflection
  34. inst = (ICustomCommandEngine)t.GetConstructor(new Type[] { }).Invoke(empty);
  35. CommandManager.AddCommand(inst);
  36. engineCount++;
  37. }
  38. }
  39. }
  40. }
  41. Logging.MetaLog($"Added {engineCount} custom command engines");
  42. }
  43. }
  44. }