Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
xxfogs committed Nov 20, 2022
0 parents commit 9e2924a
Show file tree
Hide file tree
Showing 26 changed files with 859 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
.vs
bin
packages
70 changes: 70 additions & 0 deletions ChatSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection;
using System.Net;
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using SDG.Unturned;
using Steamworks;
using UnityEngine;

namespace StrikesPlugin
{
public static class ChatSystem
{
public static CSteamID GetCSteamID(this ulong id)
{
return new CSteamID(id);
}

public static CSteamID GetCSteamID(this string id)
{
return new CSteamID(ulong.Parse(id));
}

public static void sendMessage(this IRocketPlayer caller, String message)
{
Regex filter = new Regex(@"<[^>]*>");
String formatlessMessage = filter.Replace(message, string.Empty);

if (caller.DisplayName == "Console")
{
UnturnedChat.Say(caller, formatlessMessage);
}
else
{
ChatManager.serverSendMessage(message, UnityEngine.Color.white, null, UnturnedPlayer.FromCSteamID(caller.Id.GetCSteamID()).SteamPlayer(), EChatMode.SAY, null, true);
}
}

public static void sendMessage(this IRocketPlayer caller, String message, String icon)
{
Regex filter = new Regex(@"<[^>]*>");
String formatlessMessage = filter.Replace(message, string.Empty);

if (caller.DisplayName == "Console")
{
UnturnedChat.Say(caller, formatlessMessage);
}
else
{
ChatManager.serverSendMessage(message, UnityEngine.Color.white, null, UnturnedPlayer.FromCSteamID(caller.Id.GetCSteamID()).SteamPlayer(), EChatMode.SAY, icon, true);
}
}

public static void sendGlobalMessage(String message)
{
ChatManager.serverSendMessage(message, UnityEngine.Color.white, null, null, EChatMode.GLOBAL, null, true);
}

public static void sendGlobalMessage(String message, String icon)
{
ChatManager.serverSendMessage(message, UnityEngine.Color.white, null, null, EChatMode.GLOBAL, icon, true);
}
}
}
68 changes: 68 additions & 0 deletions Commands/ClearStrikesCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Text;
using System.Threading.Tasks;
using Rocket.API;
using Rocket.Core;
using Rocket.Unturned;
using Rocket.Core.Logging;
using Rocket.Unturned.Player;
using SDG.Unturned;
using Rocket.Core.Plugins;
using UP = Rocket.Unturned.Player.UnturnedPlayer;
using Rocket.API.Serialisation;
using Rocket.Unturned.Chat;
using SDG.Provider;
using Steamworks;
using UnityEngine;
using System.Globalization;
using System.Net;

namespace StrikesPlugin.Commands
{
class ClearStrikesCommand : IRocketCommand
{
public AllowedCaller AllowedCaller => AllowedCaller.Both;

public string Name => "clearstrikes";

public string Help => "";

public string Syntax => "";

public List<string> Aliases => new List<string>();

public List<string> Permissions
{
get { return new List<string>() { "strikesplugin.clearstrikes" }; }
}

public void Execute(IRocketPlayer caller, string[] command)
{
UP player = UP.FromName(command[0]);
var reason = string.Join(" ", command.Where(s => !string.IsNullOrEmpty(s) && s != command[0]));

if (player != null)
{
String warnFolder = Rocket.Core.Environment.PluginsDirectory + "/StrikesPlugin/Databases/Warnings/";
XDocument warnPass = XDocument.Load(warnFolder + "Warnings.xml");

var Strikes = warnPass.Descendants("Warning").FirstOrDefault(el => (string)el.Attribute("player") == player.CSteamID.ToString()).Element("Strikes");

Strikes.Value = "0";
warnPass.Save(warnFolder + "Warnings.xml");

caller.sendMessage($"[<color=red> Strike </color>] Successfully wiped {player.DisplayName} strikes");
}
else
{
caller.sendMessage($"[<color=red> Strike </color>] No player found");
}
}
}
}
112 changes: 112 additions & 0 deletions Commands/StrikeCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Text;
using System.Threading.Tasks;
using Rocket.API;
using Rocket.Core;
using Rocket.Unturned;
using Rocket.Core.Logging;
using Rocket.Unturned.Player;
using SDG.Unturned;
using Rocket.Core.Plugins;
using UP = Rocket.Unturned.Player.UnturnedPlayer;
using Rocket.API.Serialisation;
using Rocket.Unturned.Chat;
using SDG.Provider;
using Steamworks;
using UnityEngine;
using System.Globalization;
using System.Net;

namespace StrikesPlugin.Commands
{
class StrikeCommand : IRocketCommand
{
public AllowedCaller AllowedCaller => AllowedCaller.Both;

public string Name => "strike";

public string Help => "";

public string Syntax => "";

public List<string> Aliases => new List<string>();

public List<string> Permissions
{
get { return new List<string>() { "strikesplugin.strike" }; }
}

public void Execute(IRocketPlayer caller, string[] command)
{
UP player = UP.FromName(command[0]);
var reason = string.Join(" ", command.Where(s => !string.IsNullOrEmpty(s) && s != command[0]));

if (player != null)
{
if (command.Length > 1)
{
String warnFolder = Rocket.Core.Environment.PluginsDirectory + "/StrikesPlugin/Databases/Warnings/";
XDocument warnPass = XDocument.Load(warnFolder + "Warnings.xml");

var Strikes = warnPass.Descendants("Warning").FirstOrDefault(el => (string)el.Attribute("player") == player.CSteamID.ToString()).Element("Strikes");
var ConfStrike = StrikesPlugin.Instance.Configuration.Instance.StrikeSequence.Find(el => el.SequenceNumber == (int.Parse(Strikes.Value) + 1));

if (ConfStrike.Action.ToUpper() == "BAN")
{
player.Ban(ConfStrike.Reason, ConfStrike.BanTime);

if (StrikesPlugin.Instance.Configuration.Instance.AnnounceKickAndBanGlobally)
{
ChatSystem.sendGlobalMessage($"[<color=red> Strike </color>] {player.DisplayName} has been banned for reaching {ConfStrike.SequenceNumber} strikes");
}
else
{
caller.sendMessage($"[<color=red> Strike </color>] {player.DisplayName} has been banned for reaching {ConfStrike.SequenceNumber} strikes");
}
}

if (ConfStrike.Action.ToUpper() == "KICK")
{
player.Kick(ConfStrike.Reason);

if (StrikesPlugin.Instance.Configuration.Instance.AnnounceKickAndBanGlobally)
{
ChatSystem.sendGlobalMessage($"[<color=red> Strike </color>] {player.DisplayName} has been kicked for reaching {ConfStrike.SequenceNumber} strikes");
} else
{
caller.sendMessage($"[<color=red> Strike </color>] {player.DisplayName} has been kicked for reaching {ConfStrike.SequenceNumber} strikes");
}
}

if (ConfStrike.ClearWarnings)
{
Strikes.Value = "0";
warnPass.Save(warnFolder + "Warnings.xml");
caller.sendMessage($"[<color=red> Strike </color>] {player.DisplayName} has been issued another strike. This has wiped all previous");
caller.sendMessage($"[<color=red> Strike </color>] You have been striked for {reason}");
if (StrikesPlugin.Instance.Configuration.Instance.AnnounceStrikesGlobally) ChatSystem.sendGlobalMessage($"[<color=red> Strike </color>] {player.DisplayName} has been issued another strike for '{reason}'");
} else
{
Strikes.Value = (int.Parse(Strikes.Value) + 1).ToString();
warnPass.Save(warnFolder + "Warnings.xml");
caller.sendMessage($"[<color=red> Strike </color>] {player.DisplayName} has been issued another strike");
caller.sendMessage($"[<color=red> Strike </color>] You have been striked for {reason}");
if (StrikesPlugin.Instance.Configuration.Instance.AnnounceStrikesGlobally) ChatSystem.sendGlobalMessage($"[<color=red> Strike </color>] {player.DisplayName} has been issued another strike for '{reason}'");
}
} else
{
caller.sendMessage($"[<color=red> Strike </color>] No reason provided");
}
} else
{
caller.sendMessage($"[<color=red> Strike </color>] No user found");
}
}
}
}
78 changes: 78 additions & 0 deletions Commands/StrikesCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Text;
using System.Threading.Tasks;
using Rocket.API;
using Rocket.Core;
using Rocket.Unturned;
using Rocket.Core.Logging;
using Rocket.Unturned.Player;
using SDG.Unturned;
using Rocket.Core.Plugins;
using UP = Rocket.Unturned.Player.UnturnedPlayer;
using Rocket.API.Serialisation;
using Rocket.Unturned.Chat;
using SDG.Provider;
using Steamworks;
using UnityEngine;
using System.Globalization;
using System.Net;

namespace StrikesPlugin.Commands
{
class StrikesCommand : IRocketCommand
{
public AllowedCaller AllowedCaller => AllowedCaller.Player;

public string Name => "strikes";

public string Help => "";

public string Syntax => "";

public List<string> Aliases => new List<string>();

public List<string> Permissions
{
get { return new List<string>() { "strikesplugin.strikes" }; }
}

public void Execute(IRocketPlayer caller, string[] command)
{
var reason = string.Join(" ", command.Where(s => !string.IsNullOrEmpty(s) && s != command[0]));

if (command.Length > 0)
{
UP player = UP.FromName(command[0]);

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)
{
caller.sendMessage($"[<color=red> Strike </color>] {player.DisplayName} has {warnDocument.Element("Strikes").Value} strike(s)");
}
} else
{
UP player = (UP)caller;

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)
{
caller.sendMessage($"[<color=red> Strike </color>] You have {warnDocument.Element("Strikes").Value} strike(s)");
}
}
}
}
}
Loading

0 comments on commit 9e2924a

Please sign in to comment.