PageRenderTime 30ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/MJS/Event.cs

https://bitbucket.org/realquaisaq/mcrevive
C# | 68 lines | 65 code | 3 blank | 0 comment | 12 complexity | 31d8051b13d4fc2de8016cc0c8da95c2 MD5 | raw file
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using System.Text;
  5. namespace MJS
  6. {
  7. public static class Event
  8. {
  9. public static bool Trigger(string Event, string Parameters)
  10. {
  11. Events.Log("Event " + Event + " was triggered with parameters: " + Parameters);
  12. if (!Exists(Event)) return false;
  13. Script.Execute("mjs/events/" + Event + ".mjs", Parameters);
  14. return true;
  15. }
  16. public static bool Exists(string Event)
  17. {
  18. return File.Exists("mjs/events/" + Event + ".mjs");
  19. }
  20. public static void LoadShit()
  21. {
  22. }
  23. public static void SaveShit()
  24. {
  25. int errLoc = 0;
  26. try
  27. {
  28. if (!File.Exists("memory/MJSvars.txt")) File.Create("memory/MJSvars.txt").Close();
  29. errLoc++;
  30. string[] lines = new string[Player.variableNames.Count + Map.variableNames.Count + 2];
  31. int i = 0;
  32. lines[i] = "Player variables: name[=]type[=]default";
  33. i++;
  34. errLoc++;
  35. int j = 0;
  36. foreach (string varName in Player.variableNames)
  37. {
  38. string thetype = Player.variableTypes[j];
  39. object thedefault = Player.variableDefaultValues[j];
  40. lines[i] = varName + "[=]" + thetype + "[=]" + thetype == "string" || thetype == "double" ? (string)thedefault : thetype == "Level" ? ((Map)thedefault).name : thetype == "Player" ? ((Player)thedefault).name : "";
  41. i++;
  42. j++;
  43. }
  44. errLoc++;
  45. lines[i] = "Map variables: name[=]type[=]default";
  46. i++;
  47. j = 0;
  48. foreach (string varName in Map.variableNames)
  49. {
  50. string thetype = Map.variableTypes[j];
  51. object thedefault = Map.variableDefaultValues[j];
  52. lines[i] = varName + "[=]" + thetype + "[=]" + thetype == "string" || thetype == "double" ? (string)thedefault : thetype == "Level" ? ((Map)thedefault).name : thetype == "Player" ? ((Player)thedefault).name : "";
  53. i++;
  54. j++;
  55. }
  56. errLoc++;
  57. File.WriteAllLines("memory/MJSvars.txt", lines);
  58. }
  59. catch (Exception e)
  60. {
  61. Events.Log("Error while saving shit on location " + errLoc + ": " + e.Message);
  62. }
  63. }
  64. }
  65. }