-
Notifications
You must be signed in to change notification settings - Fork 0
/
Plugin.cs
104 lines (90 loc) · 3.35 KB
/
Plugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Timers;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.IO;
using System.Net;
using System.Xml;
using System.Xml.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Reflection;
using System.Globalization;
using Rocket.API;
using Rocket.Core;
using Rocket.Unturned;
using Rocket.Unturned.Events;
using Rocket.Unturned.Items;
using Rocket.Unturned.Player;
using Rocket.Unturned.Enumerations;
using Rocket.Unturned.Plugins;
using Rocket.Core.Logging;
using Rocket.API.Collections;
using Rocket.Core.Plugins;
using SDG.Unturned;
using Steamworks;
using SDG;
using UnityEngine;
using UnityEngine.Events;
using UP = Rocket.Unturned.Player.UnturnedPlayer;
using Rocket.API.Serialisation;
using Rocket.Unturned.Chat;
using SDG.Provider;
using Logger = Rocket.Core.Logging.Logger;
namespace StrikesPlugin
{
public class StrikesPlugin : RocketPlugin<Configuration>
{
public static StrikesPlugin Instance;
public string Creator = "XXFOGS";
public string PluginName = "StrikesPlugin";
public string Version = "1.0.0";
protected override void Load()
{
Instance = this;
String warnFolder = Rocket.Core.Environment.PluginsDirectory + "/StrikesPlugin/Databases/Warnings/";
if (!System.IO.Directory.Exists(warnFolder))
{
System.IO.Directory.CreateDirectory(warnFolder);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = (" ");
settings.CloseOutput = true;
settings.OmitXmlDeclaration = true;
using (XmlWriter writer = XmlWriter.Create(warnFolder + "Warnings.xml", settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("Warnings");
writer.WriteEndElement();
writer.WriteEndDocument();
writer.Flush();
}
}
U.Events.OnPlayerConnected += PlayerConnected;
Logger.Log($"{PluginName} by {Creator} has been loaded! Version: {Version}");
}
protected override void Unload()
{
Instance = null;
U.Events.OnPlayerConnected -= PlayerConnected;
Logger.Log($"{PluginName} has been unloaded");
}
private void PlayerConnected(UnturnedPlayer player)
{
String warnFolder = Rocket.Core.Environment.PluginsDirectory + "/StrikesPlugin/Databases/Warnings/";
XDocument warnPass = XDocument.Load(warnFolder + "Warnings.xml");
var warnDocument = warnPass.Element("Warnings").Elements("Warning").Where(x => x.Element("Player")?.Value == player.CSteamID.ToString()).FirstOrDefault();
if (warnDocument == null)
{
XDocument doc = XDocument.Load(warnFolder + "Warnings.xml");
XElement root = new XElement("Warning", new XAttribute("player", player.CSteamID));
root.Add(new XElement("Player", $"{player.CSteamID}"));
root.Add(new XElement("Strikes", "0"));
doc.Element("Warnings").Add(root);
doc.Save(warnFolder + "Warnings.xml");
}
}
}
}