Skip to content
This repository has been archived by the owner on Oct 9, 2022. It is now read-only.

Commit

Permalink
Yes
Browse files Browse the repository at this point in the history
  • Loading branch information
Build committed Mar 28, 2022
1 parent ffab337 commit eb2aade
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 40 deletions.
7 changes: 4 additions & 3 deletions LeftHandedPlayers/Commands/LeftHanded.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ namespace LeftHandedPlayers.Commands
using System;
using CommandSystem;
using Exiled.API.Features;
using UnityEngine;

/// <inheritdoc />
public class LeftHanded : ICommand
Expand Down Expand Up @@ -40,15 +41,15 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
return false;
}

if (player.Scale.x > 0)
if (player.Scale.x > 0f)
{
player.Scale.Scale(new UnityEngine.Vector3(-1, 1, 1));
player.Scale = Vector3.Scale(player.Scale, LeftHandedCollection.ScaleVector);
plugin.LeftHandedCollection.Add(player);
response = "You are now left handed";
return true;
}

player.Scale.Scale(new UnityEngine.Vector3(-1, 1, 1));
player.Scale = Vector3.Scale(player.Scale, LeftHandedCollection.ScaleVector);
plugin.LeftHandedCollection.Remove(player);
response = "You are no longer left handed";
return true;
Expand Down
36 changes: 1 addition & 35 deletions LeftHandedPlayers/EventHandlers/PlayerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@

namespace LeftHandedPlayers.EventHandlers
{
using Exiled.API.Features.Items;
using Exiled.Events.EventArgs;
using InventorySystem.Items.Firearms.Attachments;
using UnityEngine;

/// <summary>
/// Handles events derived from <see cref="Exiled.Events.Handlers.Player"/>.
Expand All @@ -25,42 +22,11 @@ public class PlayerEvents
/// <param name="plugin">An instance of the <see cref="Plugin"/> class.</param>
public PlayerEvents(Plugin plugin) => this.plugin = plugin;

/// <inheritdoc cref="Exiled.Events.Handlers.Player.OnChangingItem(ChangingItemEventArgs)"/>
public void OnChangingItem(ChangingItemEventArgs ev)
{
if (ev.NewItem.Type != ItemType.GunE11SR)
return;

if (ev.NewItem.Scale[0] < 0)
{
if (plugin.LeftHandedCollection.Contains(ev.Player))
{
ev.NewItem.Scale.Scale(new Vector3(-1, 1, 1));
}

return;
}

if (!plugin.LeftHandedCollection.Contains(ev.Player))
return;

Firearm firearm = (Firearm)ev.NewItem;

foreach (FirearmAttachment st in firearm.Attachments)
{
if ((st.Name == AttachmentNameTranslation.NightVisionSight || st.Name == AttachmentNameTranslation.ScopeSight) && st.IsEnabled)
{
firearm.Scale.Scale(new Vector3(-1, 1, 1));
return;
}
}
}

/// <inheritdoc cref="Exiled.Events.Handlers.Player.OnVerified(VerifiedEventArgs)"/>
public void OnVerified(VerifiedEventArgs ev)
{
if (plugin.LeftHandedCollection.Contains(ev.Player))
ev.Player.Scale = new Vector3(-1, 1, 1);
ev.Player.Scale = LeftHandedCollection.ScaleVector;
}
}
}
6 changes: 6 additions & 0 deletions LeftHandedPlayers/LeftHandedCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace LeftHandedPlayers
using System.IO;
using Exiled.API.Features;
using Exiled.Loader;
using UnityEngine;

/// <summary>
/// Handles an underlying <see cref="HashSet{T}"/> of user ids that should be considered to be left handed.
Expand All @@ -26,6 +27,11 @@ public class LeftHandedCollection
/// <param name="plugin">An instance of the <see cref="Plugin"/> class.</param>
public LeftHandedCollection(Plugin plugin) => this.plugin = plugin;

/// <summary>
/// Gets the vector that objects should be scaled by to be flipped.
/// </summary>
public static Vector3 ScaleVector { get; } = new Vector3(-1, 1, 1);

/// <summary>
/// Adds a player to the collection.
/// </summary>
Expand Down
2 changes: 0 additions & 2 deletions LeftHandedPlayers/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public override void OnEnabled()
ServerHandlers.RoundEnded += serverEvents.OnRoundEnded;
ServerHandlers.WaitingForPlayers += serverEvents.OnWaitingForPlayers;
PlayerHandlers.Verified += playerEvents.OnVerified;
PlayerHandlers.ChangingItem += playerEvents.OnChangingItem;
base.OnEnabled();
}

Expand All @@ -55,7 +54,6 @@ public override void OnDisabled()
ServerHandlers.RoundEnded -= serverEvents.OnRoundEnded;
ServerHandlers.WaitingForPlayers -= serverEvents.OnWaitingForPlayers;
PlayerHandlers.Verified -= playerEvents.OnVerified;
PlayerHandlers.ChangingItem -= playerEvents.OnChangingItem;
serverEvents = null;
playerEvents = null;
LeftHandedCollection = null;
Expand Down

0 comments on commit eb2aade

Please sign in to comment.