Skip to content

Commit

Permalink
Fix errors
Browse files Browse the repository at this point in the history
  • Loading branch information
PintTheDragon committed Dec 31, 2022
1 parent 07bfefc commit 0a8902f
Show file tree
Hide file tree
Showing 17 changed files with 336 additions and 211 deletions.
32 changes: 24 additions & 8 deletions SCPStats/API/API.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
using System.Threading.Tasks;
using Exiled.API.Features;
using Exiled.API.Features.Items;
using InventorySystem;
using InventorySystem.Items;
using InventorySystem.Items.Pickups;
using JetBrains.Annotations;
using Mirror;
using SCPStats.Hats;
Expand Down Expand Up @@ -83,9 +86,22 @@ public static void SpawnHat(Player player, HatInfo hat, bool showHat = false)
if(!hat.Rotation.IsZero()) rot = hat.Rotation;
if(hat.Scale != Vector3.one || hat.Position != Vector3.zero || !hat.Rotation.IsZero()) item = hat.Item;

var itemObj = new Item(Server.Host.Inventory.CreateItemInstance(item, false)) {Scale = scale};
var itemModel = InventoryItemLoader.AvailableItems[item];

var pickup = itemObj.Spawn(Vector3.zero, Quaternion.identity);
var psi = new PickupSyncInfo()
{
ItemId = item,
Serial = ItemSerialGenerator.GenerateNext(),
Weight = itemModel.Weight
};

var pickup = Object.Instantiate(itemModel.PickupDropModel, Vector3.zero, Quaternion.identity);
pickup.transform.localScale = scale;
pickup.NetworkInfo = psi;

NetworkServer.Spawn(pickup.gameObject);
pickup.InfoReceived(new PickupSyncInfo(), psi);
pickup.RefreshPositionAndRotation();

SpawnHat(player, pickup, itemOffset, rot, showHat);
}
Expand All @@ -94,11 +110,11 @@ public static void SpawnHat(Player player, HatInfo hat, bool showHat = false)
/// Turn a pickup into a <see cref="Player"/>'s hat. It is recommended to use <see cref="SpawnHat(Exiled.API.Features.Player,ItemType)"/> over this method.
/// </summary>
/// <param name="player">The <see cref="Player"/> who should wear the hat.</param>
/// <param name="pickup">The <see cref="Pickup"/> that should be worn.</param>
/// <param name="pickup">The <see cref="ItemPickupBase"/> that should be worn.</param>
/// <param name="posOffset">A <see cref="Vector3"/> that will be added to the hat's position each time it is updated.</param>
/// <param name="rotOffset">A <see cref="Quaternion"/> that will be added to the hat's rotation each time it is updated.</param>
/// <param name="showHat">A <see cref="bool"/> indicating if the hat should be displayed on its owner's screen.</param>
public static void SpawnHat(Player player, Pickup pickup, Vector3 posOffset, Quaternion rotOffset, bool showHat = false)
public static void SpawnHat(Player player, ItemPickupBase pickup, Vector3 posOffset, Quaternion rotOffset, bool showHat = false)
{
HatPlayerComponent playerComponent;

Expand All @@ -113,12 +129,12 @@ public static void SpawnHat(Player player, Pickup pickup, Vector3 posOffset, Qua
playerComponent.item = null;
}

var rigidbody = pickup.Base.gameObject.GetComponent<Rigidbody>();
var rigidbody = pickup.gameObject.GetComponent<Rigidbody>();
rigidbody.useGravity = false;
rigidbody.isKinematic = true;

playerComponent.item = pickup.Base.gameObject.AddComponent<HatItemComponent>();
playerComponent.item.item = pickup.Base;
playerComponent.item = pickup.gameObject.AddComponent<HatItemComponent>();
playerComponent.item.item = pickup;
playerComponent.item.player = playerComponent;
playerComponent.item.pos = Hats.Hats.GetHatPosForRole(player.Role);
playerComponent.item.itemOffset = posOffset;
Expand All @@ -133,7 +149,7 @@ public static void SpawnHat(Player player, Pickup pickup, Vector3 posOffset, Qua
/// <returns>A list of all the warnings that the specified player has.</returns>
public static async Task<List<Warning>> GetWarnings(Player player)
{
return await GetWarnings(player.RawUserId);
return await GetWarnings(Helper.HandleId(player));
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion SCPStats/API/EventArgs/GeneratingWarningMessageEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
// -----------------------------------------------------------------------

using System.Collections.Generic;
using Exiled.Events.EventArgs.Interfaces;
using SCPStats.Websocket.Data;

namespace SCPStats.API.EventArgs
{
/// <summary>
/// Includes all of the information before a warning message is generated.
/// </summary>
public class GeneratingWarningMessageEventArgs : System.EventArgs
public class GeneratingWarningMessageEventArgs : IExiledEvent
{
internal GeneratingWarningMessageEventArgs(List<Warning> warnings, string initialMessage)
{
Expand Down
3 changes: 2 additions & 1 deletion SCPStats/API/EventArgs/SendingWarningMessageEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
// -----------------------------------------------------------------------

using System.Collections.Generic;
using Exiled.Events.EventArgs.Interfaces;
using SCPStats.Websocket.Data;

namespace SCPStats.API.EventArgs
{
/// <summary>
/// Includes all of the information before a warning message is sent.
/// </summary>
public class SendingWarningMessageEventArgs : System.EventArgs
public class SendingWarningMessageEventArgs : IExiledEvent
{
internal SendingWarningMessageEventArgs(List<Warning> warnings, string message)
{
Expand Down
3 changes: 2 additions & 1 deletion SCPStats/API/EventArgs/UserInfoEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
// -----------------------------------------------------------------------

using Exiled.API.Features;
using Exiled.Events.EventArgs.Interfaces;
using SCPStats.Websocket.Data;

namespace SCPStats.API.EventArgs
{
/// <summary>
/// Includes all of the information for user info events.
/// </summary>
public class UserInfoEventArgs : System.EventArgs
public class UserInfoEventArgs : IExiledEvent
{
internal UserInfoEventArgs(Player player, UserInfoData userInfo, CentralAuthPreauthFlags? flags)
{
Expand Down
8 changes: 4 additions & 4 deletions SCPStats/API/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public static class Events
/// </summary>
public static Exiled.Events.Events.CustomEventHandler<SendingWarningMessageEventArgs> SendingWarningMessage;

internal static void OnUserInfoReceived(UserInfoEventArgs ev) => UserInfoReceived.InvokeSafely(ev);
internal static void OnUserInfoReceived(UserInfoEventArgs ev) => UserInfoReceived?.InvokeSafely(ev);

internal static void OnUserInfoHandled(UserInfoEventArgs ev) => UserInfoHandled.InvokeSafely(ev);
internal static void OnUserInfoHandled(UserInfoEventArgs ev) => UserInfoHandled?.InvokeSafely(ev);

internal static void OnGeneratingWarningMessage(GeneratingWarningMessageEventArgs ev) => GeneratingWarningMessage.InvokeSafely(ev);
internal static void OnGeneratingWarningMessage(GeneratingWarningMessageEventArgs ev) => GeneratingWarningMessage?.InvokeSafely(ev);

internal static void OnSendingWarningMessage(SendingWarningMessageEventArgs ev) => SendingWarningMessage.InvokeSafely(ev);
internal static void OnSendingWarningMessage(SendingWarningMessageEventArgs ev) => SendingWarningMessage?.InvokeSafely(ev);
}
}
9 changes: 5 additions & 4 deletions SCPStats/Commands/HatCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using CommandSystem;
using Exiled.API.Features;
using Exiled.Permissions.Extensions;
using PlayerRoles;
using RemoteAdmin;
using SCPStats.Hats;
using UnityEngine;
Expand Down Expand Up @@ -139,7 +140,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
case "on":
if (playerComponent.item == null)
{
if(p.Role != RoleType.None && p.Role != RoleType.Spectator) p.SpawnHat(HatPlayers[p.UserId].Item1, hasInfo && info.Item2.ShowHat);
if(p.Role != RoleTypeId.None && p.Role != RoleTypeId.Spectator) p.SpawnHat(HatPlayers[p.UserId].Item1, hasInfo && info.Item2.ShowHat);
response = SCPStats.Singleton?.Translation?.HatEnabled ?? "You put on your hat.";
return true;
}
Expand All @@ -158,7 +159,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
case "toggle":
if (playerComponent.item == null)
{
if(p.Role != RoleType.None && p.Role != RoleType.Spectator) p.SpawnHat(HatPlayers[p.UserId].Item1, hasInfo && info.Item2.ShowHat);
if(p.Role != RoleTypeId.None && p.Role != RoleTypeId.Spectator) p.SpawnHat(HatPlayers[p.UserId].Item1, hasInfo && info.Item2.ShowHat);
response = SCPStats.Singleton?.Translation?.HatEnabled ?? "You put on your hat.";
return true;
}
Expand All @@ -170,7 +171,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
}
case "default":
HatPlayers[p.UserId] = new Tuple<HatInfo, HatInfo, bool, bool>(HatPlayers[p.UserId].Item2, HatPlayers[p.UserId].Item2, HatPlayers[p.UserId].Item3, HatPlayers[p.UserId].Item4);
if(p.Role != RoleType.None && p.Role != RoleType.Spectator) p.SpawnHat(HatPlayers[p.UserId].Item1, hasInfo && info.Item2.ShowHat);
if(p.Role != RoleTypeId.None && p.Role != RoleTypeId.Spectator) p.SpawnHat(HatPlayers[p.UserId].Item1, hasInfo && info.Item2.ShowHat);

response = SCPStats.Singleton?.Translation?.HatDefault ?? "Your hat has been changed back to your default hat.";
return true;
Expand Down Expand Up @@ -221,7 +222,7 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
}

HatPlayers[p.UserId] = new Tuple<HatInfo, HatInfo, bool, bool>(item, HatPlayers[p.UserId].Item2, HatPlayers[p.UserId].Item3, HatPlayers[p.UserId].Item4);
if(p.Role != RoleType.None && p.Role != RoleType.Spectator) p.SpawnHat(HatPlayers[p.UserId].Item1, hasInfo && info.Item2.ShowHat);
if(p.Role != RoleTypeId.None && p.Role != RoleTypeId.Spectator) p.SpawnHat(HatPlayers[p.UserId].Item1, hasInfo && info.Item2.ShowHat);

response = SCPStats.Singleton?.Translation?.HatChanged ?? "Your hat has been changed.";
return true;
Expand Down
Loading

0 comments on commit 0a8902f

Please sign in to comment.