Skip to content
This repository has been archived by the owner on Aug 31, 2021. It is now read-only.

Commit

Permalink
2 new commands + PERMISSIONS!
Browse files Browse the repository at this point in the history
  • Loading branch information
joker-119 committed Feb 8, 2020
1 parent ca35b92 commit 3e55bc3
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 20 deletions.
3 changes: 3 additions & 0 deletions AdminTools/AdminTools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
<Reference Include="EXILED_Events, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\References\EXILED_Events.dll</HintPath>
</Reference>
<Reference Include="EXILED_Permissions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\References\EXILED_Permissions.dll</HintPath>
</Reference>
<Reference Include="Mirror, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\References\Mirror.dll</HintPath>
</Reference>
Expand Down
178 changes: 165 additions & 13 deletions AdminTools/EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.IO;
using System.Linq;
using EXILED;
using EXILED.Extensions;
using GameCore;
using MEC;
using Mirror;
Expand Down Expand Up @@ -37,13 +38,18 @@ public void OnCommand(ref RACommandEvent ev)
File.AppendAllText(fileName, data);

string[] args = ev.Command.Split(' ');
ReferenceHub sender = Plugin.GetPlayer(ev.Sender.SenderId);
ReferenceHub sender = ev.Sender.SenderId == "SERVER CONSOLE" ? Plugin.GetPlayer(PlayerManager.localPlayer) : Plugin.GetPlayer(ev.Sender.SenderId);

switch (args[0].ToLower())
{
case "kick":
{
ev.Allow = false;
if (!sender.CheckPermission("at.kick"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
IEnumerable<string> reasons = args.Where(s => s != args[0] && s != args[1]);
string reason = "";
foreach (string st in reasons)
Expand All @@ -61,6 +67,12 @@ public void OnCommand(ref RACommandEvent ev)
}
case "reconnectrs":
{
ev.Allow = false;
if (!sender.CheckPermission("at.reconnectrs"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
foreach (ReferenceHub hub in Plugin.GetHubs())
hub.playerStats.RpcRoundrestart(0);
Application.Quit();
Expand All @@ -70,6 +82,11 @@ public void OnCommand(ref RACommandEvent ev)
case "muteall":
{
ev.Allow = false;
if (!sender.CheckPermission("at.mute"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
foreach (ReferenceHub hub in Plugin.GetHubs())
if (!hub.serverRoles.RemoteAdmin)
hub.characterClassManager.SetMuted(true);
Expand All @@ -79,6 +96,11 @@ public void OnCommand(ref RACommandEvent ev)
case "unmuteall":
{
ev.Allow = false;
if (!sender.CheckPermission("at.mute"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
foreach (ReferenceHub hub in Plugin.GetHubs())
if (!hub.serverRoles.RemoteAdmin)
hub.characterClassManager.SetMuted(false);
Expand All @@ -88,6 +110,11 @@ public void OnCommand(ref RACommandEvent ev)
case "rocket":
{
ev.Allow = false;
if (!sender.CheckPermission("at.rocket"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
ReferenceHub hub = Plugin.GetPlayer(args[1]);
if (hub == null && args[1] != "*" && args[1] != "all")
{
Expand All @@ -112,6 +139,11 @@ public void OnCommand(ref RACommandEvent ev)
case "bc":
{
ev.Allow = false;
if (!sender.CheckPermission("at.bc"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
IEnumerable<string> thing = args.Skip(2);
string msg = "";
foreach (string s in thing)
Expand All @@ -137,6 +169,11 @@ public void OnCommand(ref RACommandEvent ev)
case "pbc":
{
ev.Allow = false;
if (!sender.CheckPermission("at.bc"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
if (args.Length < 4)
{
ev.Sender.RAMessage(
Expand All @@ -162,6 +199,11 @@ public void OnCommand(ref RACommandEvent ev)
case "tut":
{
ev.Allow = false;
if (!sender.CheckPermission("at.tut"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}

if (args.Length < 2)
{
Expand Down Expand Up @@ -191,6 +233,11 @@ public void OnCommand(ref RACommandEvent ev)
}
case "hidetags":
ev.Allow = false;
if (!sender.CheckPermission("at.tags"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
foreach (ReferenceHub hub in Plugin.GetHubs())
if (hub.serverRoles.RemoteAdmin)
{
Expand All @@ -207,6 +254,11 @@ public void OnCommand(ref RACommandEvent ev)
break;
case "showtags":
ev.Allow = false;
if (!sender.CheckPermission("at.tags"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
foreach (ReferenceHub hub in Plugin.GetHubs())
if (hub.serverRoles.RemoteAdmin && !hub.serverRoles.RaEverywhere)
{
Expand All @@ -221,6 +273,11 @@ public void OnCommand(ref RACommandEvent ev)
case "jail":
{
ev.Allow = false;
if (!sender.CheckPermission("at.jail"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
if (args.Length < 2)
{
ev.Sender.RaReply("Joker's Plugin#You must supply a player name or ID", false, true,
Expand Down Expand Up @@ -251,6 +308,11 @@ public void OnCommand(ref RACommandEvent ev)
case "abc":
{
ev.Allow = false;
if (!sender.CheckPermission("at.bc"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
if (args.Length < 3)
{
ev.Sender.RAMessage("You must include a duration and a message.", false);
Expand Down Expand Up @@ -281,6 +343,11 @@ public void OnCommand(ref RACommandEvent ev)
case "drop":
{
ev.Allow = false;
if (!sender.CheckPermission("at.items"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
int result;
if (args.Length != 4)
{
Expand Down Expand Up @@ -317,6 +384,11 @@ public void OnCommand(ref RACommandEvent ev)
case "pos":
{
ev.Allow = false;
if (!sender.CheckPermission("at.tp"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}

if (args.Length < 3)
{
Expand Down Expand Up @@ -414,6 +486,11 @@ public void OnCommand(ref RACommandEvent ev)
case "tpx":
{
ev.Allow = false;
if (!sender.CheckPermission("at.tp"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}

if (args.Length < 3)
{
Expand Down Expand Up @@ -443,6 +520,11 @@ public void OnCommand(ref RACommandEvent ev)
case "ghost":
{
ev.Allow = false;
if (!sender.CheckPermission("at.ghost"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
if (args.Length < 2)
{
ev.Sender.RAMessage("You must supply a playername to ghost.", false);
Expand All @@ -467,24 +549,14 @@ public void OnCommand(ref RACommandEvent ev)
ev.Sender.RAMessage($"{rh.nicknameSync.MyNick} ghosted.");
return;
}
case "restart":
case "scale":
{
ev.Allow = false;
if (ev.Sender.Nickname != "BLART" || ev.Sender.SenderId != "BLART")
if (!sender.CheckPermission("at.size"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}

ev.Sender.RAMessage("Restarting server forcefully...");
foreach (PlayerStats stats in UnityEngine.Object.FindObjectsOfType<PlayerStats>())
stats.CallRpcRoundrestart(0f);
Application.Quit();
return;
}
case "scale":
{
ev.Allow = false;
if (args.Length < 3)
{
ev.Sender.RAMessage("You must provide a target and scale size.");
Expand All @@ -511,6 +583,11 @@ public void OnCommand(ref RACommandEvent ev)
case "size":
{
ev.Allow = false;
if (!sender.CheckPermission("at.size"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
if (args.Length < 5)
{
ev.Sender.RAMessage("You must provide a target, x size, y size and z size.", false);
Expand Down Expand Up @@ -549,6 +626,12 @@ public void OnCommand(ref RACommandEvent ev)
}
case "spawnworkbench":
{
ev.Allow = false;
if (!sender.CheckPermission("at.benches"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
if (args.Length < 5)
{
ev.Sender.RAMessage("Invalid number of arguments.", false);
Expand Down Expand Up @@ -588,6 +671,11 @@ public void OnCommand(ref RACommandEvent ev)
case "drops":
{
ev.Allow = false;
if (!sender.CheckPermission("at.items"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
if (args.Length < 4)
{
ev.Sender.RAMessage("haha no, try again with correct arguments 4head");
Expand Down Expand Up @@ -622,6 +710,11 @@ public void OnCommand(ref RACommandEvent ev)
case "ragdoll":
{
ev.Allow = false;
if (!sender.CheckPermission("at.dolls"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
if (args.Length < 4)
{
ev.Sender.RAMessage("Try again");
Expand Down Expand Up @@ -662,6 +755,65 @@ public void OnCommand(ref RACommandEvent ev)

return;
}
case "hp":
{
ev.Allow = false;
if (!sender.CheckPermission("at.hp"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
if (args.Length < 3)
{
ev.Sender.RAMessage("You must supply a player name/ID and an amount.", false);
return;
}

if (!int.TryParse(args[2], out int result))
{
ev.Sender.RAMessage($"Invalid health amount: {args[2]}");
return;
}

ReferenceHub player = Plugin.GetPlayer(args[1]);
if (player == null)
{
ev.Sender.RAMessage($"Player not found: {args[1]}.", false);
return;
}

if (result > player.playerStats.maxHP)
{
player.playerStats.maxHP = result;
}

player.playerStats.health = result;
ev.Sender.RAMessage($"{player.nicknameSync.MyNick} ({player.characterClassManager.UserId}'s health has been set to {result}");
return;
}
case "cleanup":
{
ev.Allow = false;
if (!sender.CheckPermission("at.cleanup"))
{
ev.Sender.RAMessage("Permission denied.");
return;
}
if (args.Length < 2)
{
ev.Sender.RAMessage("You must supply a type of cleanup: items or ragdolls.", false);
return;
}

if (args[1].ToLower() == "items")
foreach (Pickup item in Object.FindObjectsOfType<Pickup>())
item.Delete();
else if (args[1].ToLower() == "ragdolls")
foreach (Ragdoll doll in Object.FindObjectsOfType<Ragdoll>())
NetworkServer.Destroy(doll.gameObject);
ev.Sender.RAMessage("Cleanup complete.");
return;
}
}
}
catch (Exception e)
Expand Down
7 changes: 0 additions & 7 deletions AdminTools/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,12 @@ namespace AdminTools
{
public static class Extensions
{
public static void RAMessage(this CommandSender sender, string message, bool success = true) =>
sender.RaReply("AdminTools#" + message, success, true, string.Empty);

public static void InvokeStaticMethod(this Type type, string methodName, object[] param)
{
BindingFlags flags = BindingFlags.Instance | BindingFlags.InvokeMethod | BindingFlags.NonPublic |
BindingFlags.Static | BindingFlags.Public;
MethodInfo info = type.GetMethod(methodName, flags);
info?.Invoke(null, param);
}

public static void Broadcast(this ReferenceHub rh, uint time, string message) =>
rh.GetComponent<Broadcast>()
.TargetAddElement(rh.scp079PlayerScript.connectionToClient, message, time, false);
}
}

0 comments on commit 3e55bc3

Please sign in to comment.