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

Commit

Permalink
reeee
Browse files Browse the repository at this point in the history
  • Loading branch information
joker-119 committed Jan 25, 2020
1 parent 2f26baf commit b624309
Show file tree
Hide file tree
Showing 2 changed files with 160 additions and 4 deletions.
136 changes: 133 additions & 3 deletions AdminTools/EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ public void OnCommand(ref RACommandEvent ev)
ev.Sender.RAMessage("Player was kicked.");
return;
}
case "reconnectrs":
{
foreach (ReferenceHub hub in Plugin.GetHubs())
hub.playerStats.RpcRoundrestart(0);
Application.Quit();
ev.Sender.RAMessage("Restarting server...");
return;
}
case "muteall":
{
ev.Allow = false;
Expand Down Expand Up @@ -481,6 +489,45 @@ public void OnCommand(ref RACommandEvent ev)
ev.Sender.RAMessage($"{rh.nicknameSync.MyNick} size set to {scale}");
return;
}
case "size":
{
ev.Allow = false;
if (args.Length < 5)
{
ev.Sender.RAMessage("You must provide a target, x size, y size and z size.", false);
return;
}

if (!float.TryParse(args[2], out float x))
{
ev.Sender.RAMessage($"Invalid x size: {args[2]}", false);
return;
}

if (!float.TryParse(args[3], out float y))
{
ev.Sender.RAMessage($"Invalid y size: {args[3]}", false);
return;
}

if (!float.TryParse(args[4], out float z))
{
ev.Sender.RAMessage($"Invalid z size: {args[4]}", false);
return;
}

ReferenceHub rh = Plugin.GetPlayer(args[1]);

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

SetPlayerScale(rh.gameObject, x, y, z);
ev.Sender.RAMessage($"{rh.nicknameSync.MyNick}'s size has been changed.");
return;
}
}
}

Expand All @@ -491,6 +538,9 @@ public void SpawnItem(ItemType type, Vector3 pos, Vector3 rot)

private IEnumerator<float> DoTut(ReferenceHub rh)
{
if (rh.serverRoles.OverwatchEnabled)
rh.serverRoles.OverwatchEnabled = false;

rh.characterClassManager.SetPlayersClass(RoleType.Tutorial, rh.gameObject, true);
yield return Timing.WaitForSeconds(1f);
var d = UnityEngine.Object.FindObjectsOfType<Door>();
Expand Down Expand Up @@ -631,14 +681,46 @@ public ItemType GetItemFromId(string id)
}
}

public void SetPlayerScale(GameObject target, float x, float y, float z)
{
try
{
NetworkIdentity identity = target.GetComponent<NetworkIdentity>();


target.transform.localScale = new Vector3(1 * x, 1 * y, 1 * z);

ObjectDestroyMessage destroyMessage = new ObjectDestroyMessage();
destroyMessage.netId = identity.netId;


foreach (GameObject player in PlayerManager.players)
{
if (player == target)
continue;

NetworkConnection playerCon = player.GetComponent<NetworkIdentity>().connectionToClient;

playerCon.Send(destroyMessage, 0);

object[] parameters = new object[] {identity, playerCon};
typeof(NetworkServer).InvokeStaticMethod("SendSpawnMessage", parameters);
}
}
catch (Exception e)
{
Plugin.Info($"Set Scale error: {e}");
}
}

public void SetPlayerScale(GameObject target, float scale)
{
try
{
NetworkIdentity identity = target.GetComponent<NetworkIdentity>();


target.transform.localScale *= scale;
target.transform.localScale = Vector3.one * scale;

ObjectDestroyMessage destroyMessage = new ObjectDestroyMessage();
destroyMessage.netId = identity.netId;
Expand Down Expand Up @@ -697,6 +779,8 @@ public IEnumerator<float> DoJail(ReferenceHub rh, bool skipadd = false)
Role = rh.characterClassManager.CurClass,
Userid = rh.characterClassManager.UserId,
});
if (rh.serverRoles.OverwatchEnabled)
rh.serverRoles.OverwatchEnabled = false;
yield return Timing.WaitForSeconds(1f);
rh.characterClassManager.SetClassID(RoleType.Tutorial);
rh.gameObject.transform.position = new Vector3(53f, 1020f, -44f);
Expand All @@ -718,8 +802,54 @@ private IEnumerator<float> DoUnJail(ReferenceHub rh)

public void OnPlayerJoin(PlayerJoinEvent ev)
{
if (plugin.JailedPlayers.Any(j => j.Userid == ev.Player.characterClassManager.UserId))
Timing.RunCoroutine(DoJail(ev.Player, true));
try
{
if (plugin.JailedPlayers.Any(j => j.Userid == ev.Player.characterClassManager.UserId))
Timing.RunCoroutine(DoJail(ev.Player, true));

if (File.ReadAllText(plugin.OverwatchFilePath).Contains(ev.Player.characterClassManager.UserId))
ev.Player.serverRoles.OverwatchEnabled = true;
if (File.ReadAllText(plugin.HiddenTagsFilePath).Contains(ev.Player.characterClassManager.UserId))
{
ev.Player.serverRoles._hideLocalBadge = true;
ev.Player.serverRoles.RefreshHiddenTag();
}
}
catch (Exception e)
{
Plugin.Error($"Player Join: {e}");
}
}

public void OnRoundEnd()
{
try
{
List<string> overwatchRead = File.ReadAllLines(plugin.OverwatchFilePath).ToList();
List<string> tagsRead = File.ReadAllLines(plugin.HiddenTagsFilePath).ToList();

foreach (ReferenceHub hub in Plugin.GetHubs())
{
string userId = hub.characterClassManager.UserId;

if (hub.serverRoles.OverwatchEnabled && !overwatchRead.Contains(userId))
overwatchRead.Add(userId);
else if (!hub.serverRoles.OverwatchEnabled && overwatchRead.Contains(userId))
overwatchRead.Remove(userId);

if (hub.serverRoles._hideLocalBadge && !tagsRead.Contains(userId))
tagsRead.Add(userId);
else if (!hub.serverRoles._hideLocalBadge && tagsRead.Contains(userId))
tagsRead.Remove(userId);
}

File.WriteAllLines(plugin.OverwatchFilePath, overwatchRead);
File.WriteAllLines(plugin.HiddenTagsFilePath, tagsRead);
}
catch (Exception e)
{
Plugin.Error($"Round End: {e}");
}
}
}
}
28 changes: 27 additions & 1 deletion AdminTools/Plugin.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using EXILED;

namespace AdminTools
Expand All @@ -7,17 +9,41 @@ public class Plugin : EXILED.Plugin
{
public EventHandlers EventHandlers;
public List<Jailed> JailedPlayers = new List<Jailed>();
public string OverwatchFilePath;
public string HiddenTagsFilePath;

public override void OnEnable()
{
string appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string pluginPath = Path.Combine(appData, "Plugins");
string path = Path.Combine(pluginPath, "AdminTools");
string overwatchFileName = Path.Combine(path, "AdminTools-Overwatch.txt");
string hiddenTagFileName = Path.Combine(path, "AdminTools-HiddenTags.txt");

if (!Directory.Exists(path))
Directory.CreateDirectory(path);

if (!File.Exists(overwatchFileName))
File.Create(overwatchFileName).Close();

if (!File.Exists(hiddenTagFileName))
File.Create(hiddenTagFileName).Close();

OverwatchFilePath = overwatchFileName;
HiddenTagsFilePath = hiddenTagFileName;

EventHandlers = new EventHandlers(this);
Events.RemoteAdminCommandEvent += EventHandlers.OnCommand;
Events.PlayerJoinEvent += EventHandlers.OnPlayerJoin;
Events.RoundEndEvent += EventHandlers.OnRoundEnd;
}

public override void OnDisable()
{

Events.RemoteAdminCommandEvent -= EventHandlers.OnCommand;
Events.PlayerJoinEvent -= EventHandlers.OnPlayerJoin;
Events.RoundEndEvent -= EventHandlers.OnRoundEnd;
EventHandlers = null;
}

public override void OnReload()
Expand Down

0 comments on commit b624309

Please sign in to comment.