Skip to content

Commit

Permalink
Update language to C# 9.0
Browse files Browse the repository at this point in the history
Use `is null` and `is not null` pattern matching.
Use `target-typed new` keywords.
Remove redundant parameter new initializations.
  • Loading branch information
joker-119 committed Mar 29, 2022
1 parent 189d05a commit 3e5b1f6
Show file tree
Hide file tree
Showing 151 changed files with 509 additions and 508 deletions.
146 changes: 73 additions & 73 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
# Exiled 2.14.0 -> 3.0.0 changelog
### This will be a mostly all-inclusive list of all changes between EXILED 2.14.0 and the current 3.0.0 alpha build. This is meant to work as a guide for Plugin Developers to see and understand the API changes that have occured.

First of all, anything that was marked as [Obsolete] in 2.14.0 has been removed from 3.0.0.
This includes all things like outdated extensions (we still had SCP-330 STUFF!) and Stuff like Map.SpawnRagdoll. Not all obsolete removals will be noted, consider this fair warning that if you were using an obsolete something, it's gone now.
This may not be a completely all-inclusive list of every change, as there are MANY of them. But the goal is to give general direction for people to look for what they need.

## Exiled.API
### Renamed/Moved API Features
- EffectType.Scp268 -> EffectType.Invisible
- DoorExtensions -> Features.Door


### Changes to Existing API Features
- AmmoType has been expanded to include all new base-game ammo types.
- ZoneType is now a flag.
- RoleType.GetRandomSpawnPoint() -> RoleTYpe.GetRandomSpawnProperties()
- Map.IsLCZDecontaminated -> Map.IsLczDecontaminated
- Map.TurnOffAllLights(float, bool) -> Map.TurnOffAllLights(float, ZoneType)
- ZoneType is a flag, so multiple values can be set at once, if for example you want LCZ and ENT to go dark, but not HCZ. If you pass the sole flag as Unspecified, it will blackout every light in every room.
- Map.SpawnGrenade -> Player.ThrowItem() OR Throwable.Throw()
- AmmoBox Player.Ammo -> Dictionary<ItemType, ushort> Player.Ammo
- int Player.CufferId -> Player Player.Cuffer
- Player.AddItem(SyncItemInfo) -> Player.AddItem(Item)
- You can also use Item.Give(Player)



### New API Features
- Enum: DoorBeepType
- Enum: DoorLockType
- Enum: HidState
- Enum: ItemType
- Enum: KeycardPermissions
- Enum: RadioRange
- Enum: SpawnReason
- Enum: ThrowRequest
- Struct: ArmorAmmoLimit
- Struct: RadioRangeSettings
- Feature: Item
- Inherited by: Ammo, Armor, ExplosiveGrenade (also inherits Throwable), Firearm, FlashGrenade (also inherits Throwable), Keycard, MicroHID, Radio, Throwable, Usable
* You can implicitly cast between Item and any of these subtypes. Most events and Player API objects will be given as generic Items, but you can `if (ev.Item is Firearm firearm)` to access firearm-specific features, if it is a firearm.
- To spawn an item, instead of the old `ItemType.Type.Spawn(Vector3)` extension, you now use `new Item(ItemType).Spawn(Vector3)`. Note that if you want to change attributes of the item, you can do so in the initialization like so: `new Item(ItemType) { Weight = 5f }.Spawn(Vector3)`.
- If you want to spawn a specific subtype item, like a gun, and change things like how much ammo it has, it's attachments, etc. You can use ``new Firearm(ItemType) { Ammo = byte.MaxValue, Weight = 10f }.Spawn(Vector3)`` for example. This works with all of the Item subtypes.
- Feature: Pickup
- Scp914.Scp914Controller
- Feature: Door
- Includes most commonly used members, such as Door.Open, Door.Type, Door.LockType, Door.IsBreakable, etc.
- Feature: Map.Lockers
- Feature: Map.PocketDimensionTeleporters
- Feature: Map.Pickups
- Feature: Player.Radio
- Feature: Player.Get(uint)
- This is to be used to get a player based off their NetworkIdentity.netId
- Feature: Player.ReloadWeapon()
- Feature: Player.ChangeEffectIntensity(EffectType)
- Feature: Room.LightIntensity
- Feature: Room.Cameras
- Feature: Server.PlayerCount
- Feature: Server.MaxPlayerCount
- Feature: Server.RunCommand()



## Exiled.Events
### Renamed Events/EventArgs
- ThrowingGrenade event has been renamed to ThrowingItem
- UsingMedicalItem event has been renamed to UsingItem

### Removed Events
- DequippedMedicalItem event has been removed.
- DroppedItem event has been removed.
- ChangedRole event has been removed.
# Exiled 2.14.0 -> 3.0.0 changelog
### This will be a mostly all-inclusive list of all changes between EXILED 2.14.0 and the current 3.0.0 alpha build. This is meant to work as a guide for Plugin Developers to see and understand the API changes that have occured.

First of all, anything that was marked as [Obsolete] in 2.14.0 has been removed from 3.0.0.
This includes all things like outdated extensions (we still had SCP-330 STUFF!) and Stuff like Map.SpawnRagdoll. Not all obsolete removals will be noted, consider this fair warning that if you were using an obsolete something, it's gone now.
This may not be a completely all-inclusive list of every change, as there are MANY of them. But the goal is to give general direction for people to look for what they need.

## Exiled.API
### Renamed/Moved API Features
- EffectType.Scp268 -> EffectType.Invisible
- DoorExtensions -> Features.Door


### Changes to Existing API Features
- AmmoType has been expanded to include all new base-game ammo types.
- ZoneType is now a flag.
- RoleType.GetRandomSpawnPoint() -> RoleTYpe.GetRandomSpawnProperties()
- Map.IsLCZDecontaminated -> Map.IsLczDecontaminated
- Map.TurnOffAllLights(float, bool) -> Map.TurnOffAllLights(float, ZoneType)
- ZoneType is a flag, so multiple values can be set at once, if for example you want LCZ and ENT to go dark, but not HCZ. If you pass the sole flag as Unspecified, it will blackout every light in every room.
- Map.SpawnGrenade -> Player.ThrowItem() OR Throwable.Throw()
- AmmoBox Player.Ammo -> Dictionary<ItemType, ushort> Player.Ammo
- int Player.CufferId -> Player Player.Cuffer
- Player.AddItem(SyncItemInfo) -> Player.AddItem(Item)
- You can also use Item.Give(Player)



### New API Features
- Enum: DoorBeepType
- Enum: DoorLockType
- Enum: HidState
- Enum: ItemType
- Enum: KeycardPermissions
- Enum: RadioRange
- Enum: SpawnReason
- Enum: ThrowRequest
- Struct: ArmorAmmoLimit
- Struct: RadioRangeSettings
- Feature: Item
- Inherited by: Ammo, Armor, ExplosiveGrenade (also inherits Throwable), Firearm, FlashGrenade (also inherits Throwable), Keycard, MicroHID, Radio, Throwable, Usable
* You can implicitly cast between Item and any of these subtypes. Most events and Player API objects will be given as generic Items, but you can `if (ev.Item is Firearm firearm)` to access firearm-specific features, if it is a firearm.
- To spawn an item, instead of the old `ItemType.Type.Spawn(Vector3)` extension, you now use `new Item(ItemType).Spawn(Vector3)`. Note that if you want to change attributes of the item, you can do so in the initialization like so: `new Item(ItemType) { Weight = 5f }.Spawn(Vector3)`.
- If you want to spawn a specific subtype item, like a gun, and change things like how much ammo it has, it's attachments, etc. You can use ``new Firearm(ItemType) { Ammo = byte.MaxValue, Weight = 10f }.Spawn(Vector3)`` for example. This works with all of the Item subtypes.
- Feature: Pickup
- Scp914.Scp914Controller
- Feature: Door
- Includes most commonly used members, such as Door.Open, Door.Type, Door.LockType, Door.IsBreakable, etc.
- Feature: Map.Lockers
- Feature: Map.PocketDimensionTeleporters
- Feature: Map.Pickups
- Feature: Player.Radio
- Feature: Player.Get(uint)
- This is to be used to get a player based off their NetworkIdentity.netId
- Feature: Player.ReloadWeapon()
- Feature: Player.ChangeEffectIntensity(EffectType)
- Feature: Room.LightIntensity
- Feature: Room.Cameras
- Feature: Server.PlayerCount
- Feature: Server.MaxPlayerCount
- Feature: Server.RunCommand()



## Exiled.Events
### Renamed Events/EventArgs
- ThrowingGrenade event has been renamed to ThrowingItem
- UsingMedicalItem event has been renamed to UsingItem

### Removed Events
- DequippedMedicalItem event has been removed.
- DroppedItem event has been removed.
- ChangedRole event has been removed.
2 changes: 1 addition & 1 deletion EXILED.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<PropertyGroup Condition="$(BuildProperties) == '' OR $(BuildProperties) == 'true'">
<TargetFramework>net472</TargetFramework>
<LangVersion>7.3</LangVersion>
<LangVersion>9.0</LangVersion>
<PlatformTarget>x64</PlatformTarget>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<OutputPath>$(MSBuildThisFileDirectory)\bin\$(Configuration)\</OutputPath>
Expand Down
26 changes: 13 additions & 13 deletions Exiled.API/Extensions/MirrorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ namespace Exiled.API.Extensions
/// </summary>
public static class MirrorExtensions
{
private static readonly Dictionary<Type, MethodInfo> WriterExtensionsValue = new Dictionary<Type, MethodInfo>();
private static readonly Dictionary<string, ulong> SyncVarDirtyBitsValue = new Dictionary<string, ulong>();
private static readonly ReadOnlyDictionary<Type, MethodInfo> ReadOnlyWriterExtensionsValue = new ReadOnlyDictionary<Type, MethodInfo>(WriterExtensionsValue);
private static readonly ReadOnlyDictionary<string, ulong> ReadOnlySyncVarDirtyBitsValue = new ReadOnlyDictionary<string, ulong>(SyncVarDirtyBitsValue);
private static readonly Dictionary<Type, MethodInfo> WriterExtensionsValue = new();
private static readonly Dictionary<string, ulong> SyncVarDirtyBitsValue = new();
private static readonly ReadOnlyDictionary<Type, MethodInfo> ReadOnlyWriterExtensionsValue = new(WriterExtensionsValue);
private static readonly ReadOnlyDictionary<string, ulong> ReadOnlySyncVarDirtyBitsValue = new(SyncVarDirtyBitsValue);
private static MethodInfo setDirtyBitsMethodInfoValue = null;
private static MethodInfo sendSpawnMessageMethodInfoValue = null;

Expand Down Expand Up @@ -77,10 +77,10 @@ public static ReadOnlyDictionary<string, ulong> SyncVarDirtyBits
.Where(m => m.Name.StartsWith("Network")))
{
MethodInfo setMethod = property.GetSetMethod();
if (setMethod == null)
if (setMethod is null)
continue;
MethodBody methodBody = setMethod.GetMethodBody();
if (methodBody == null)
if (methodBody is null)
continue;
byte[] bytecodes = methodBody.GetILAsByteArray();
if (!SyncVarDirtyBitsValue.ContainsKey($"{property.Name}"))
Expand All @@ -99,7 +99,7 @@ public static MethodInfo SetDirtyBitsMethodInfo
{
get
{
if (setDirtyBitsMethodInfoValue == null)
if (setDirtyBitsMethodInfoValue is null)
{
setDirtyBitsMethodInfoValue = typeof(NetworkBehaviour).GetMethod(nameof(NetworkBehaviour.SetDirtyBit));
}
Expand All @@ -115,7 +115,7 @@ public static MethodInfo SendSpawnMessageMethodInfo
{
get
{
if (sendSpawnMessageMethodInfoValue == null)
if (sendSpawnMessageMethodInfoValue is null)
{
sendSpawnMessageMethodInfoValue = typeof(NetworkServer).GetMethod("SendSpawnMessage", BindingFlags.NonPublic | BindingFlags.Static);
}
Expand Down Expand Up @@ -154,7 +154,7 @@ public static MethodInfo SendSpawnMessageMethodInfo
/// <param name="audioClipId">GunAudioMessage's audioClipId to set (default = 0).</param>
public static void PlayGunSound(this Player player, Vector3 position, ItemType itemType, byte volume, byte audioClipId = 0)
{
GunAudioMessage message = new GunAudioMessage
GunAudioMessage message = new()
{
Weapon = itemType,
AudioClipId = audioClipId,
Expand Down Expand Up @@ -230,7 +230,7 @@ public static void ChangeAppearance(this Player player, RoleType type)
/// <param name="isSubtitles">Same on <see cref="Cassie.MessageTranslated(string, string, bool, bool, bool)"/>'s isSubtitles.</param>
public static void MessageTranslated(this Player player, string words, string translation, bool makeHold = false, bool makeNoise = true, bool isSubtitles = true)
{
StringBuilder annoucement = new StringBuilder();
StringBuilder annoucement = new();
string[] cassies = words.Split('\n');
string[] translations = translation.Split('\n');
for (int i = 0; i < cassies.Count(); i++)
Expand Down Expand Up @@ -314,7 +314,7 @@ public static void SendFakeTargetRpc(Player target, NetworkIdentity behaviorOwne
foreach (object value in values)
WriterExtensions[value.GetType()].Invoke(null, new object[] { writer, value });

RpcMessage msg = new RpcMessage
RpcMessage msg = new()
{
netId = behaviorOwner.netId,
componentIndex = GetComponentIndex(behaviorOwner, targetType),
Expand Down Expand Up @@ -363,7 +363,7 @@ public static void EditNetworkObject(NetworkIdentity identity, Action<NetworkIde
{
customAction.Invoke(identity);

ObjectDestroyMessage objectDestroyMessage = new ObjectDestroyMessage
ObjectDestroyMessage objectDestroyMessage = new()
{
netId = identity.netId,
};
Expand Down Expand Up @@ -406,7 +406,7 @@ private static void MakeCustomSyncWriter(NetworkIdentity behaviorOwner, Type tar
int position2 = owner.Position;

// Write custom sync data
if (customSyncObject != null)
if (customSyncObject is not null)
customSyncObject.Invoke(owner);
else
behaviour.SerializeObjectsDelta(owner);
Expand Down
2 changes: 1 addition & 1 deletion Exiled.API/Extensions/RoleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public static Tuple<Vector3, float> GetRandomSpawnProperties(this RoleType roleT
{
GameObject randomPosition = SpawnpointManager.GetRandomPosition(roleType);

return randomPosition == null ? new Tuple<Vector3, float>(Vector3.zero, 0f) : new Tuple<Vector3, float>(randomPosition.transform.position, randomPosition.transform.rotation.eulerAngles.y);
return randomPosition is null ? new Tuple<Vector3, float>(Vector3.zero, 0f) : new Tuple<Vector3, float>(randomPosition.transform.position, randomPosition.transform.rotation.eulerAngles.y);
}
}
}
2 changes: 1 addition & 1 deletion Exiled.API/Extensions/SpawnExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static Vector3 GetPosition(this SpawnLocation location)
{
Transform transform = location.GetDoor();

if (transform == null)
if (transform is null)
return default;

// Returns a value that is offset from the door's location.
Expand Down
8 changes: 4 additions & 4 deletions Exiled.API/Features/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public class Camera
/// <summary>
/// A <see cref="List{T}"/> of <see cref="Camera"/>s on the map.
/// </summary>
internal static readonly List<Camera> CamerasValue = new List<Camera>(250);
internal static readonly List<Camera> CamerasValue = new(250);

private static readonly Dictionary<string, CameraType> NameToCameraType = new Dictionary<string, CameraType>
private static readonly Dictionary<string, CameraType> NameToCameraType = new()
{
// Light Containment
["173 chamber"] = CameraType.Lcz173Chamber,
Expand Down Expand Up @@ -169,7 +169,7 @@ public CameraType Type
{
string cameraName = Name.ToLower();

if (Room == null)
if (Room is null)
return NameToCameraType.ContainsKey(cameraName) ? NameToCameraType[cameraName] : CameraType.Unknown;

switch (cameraName)
Expand Down Expand Up @@ -379,7 +379,7 @@ public bool IsBeingUsed
{
while (enumerator.MoveNext())
{
if (enumerator.Current.currentCamera == null || enumerator.Current.currentCamera != Base)
if (enumerator.Current.currentCamera is null || enumerator.Current.currentCamera != Base)
continue;

return true;
Expand Down
2 changes: 1 addition & 1 deletion Exiled.API/Features/Cassie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static void Message(string message, bool isHeld = false, bool isNoisy = t
/// <param name="isSubtitles">Indicates whether C.A.S.S.I.E has to make subtitles.</param>
public static void MessageTranslated(string message, string translation, bool isHeld = false, bool isNoisy = true, bool isSubtitles = true)
{
StringBuilder annoucement = new StringBuilder();
StringBuilder annoucement = new();
string[] cassies = message.Split('\n');
string[] translations = translation.Split('\n');
for (int i = 0; i < cassies.Count(); i++)
Expand Down
8 changes: 4 additions & 4 deletions Exiled.API/Features/Components/CollisionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ private void OnCollisionEnter(Collision collision)
{
if (!initialized)
return;
if (Owner == null)
if (Owner is null)
Log.Error($"Owner is null!");
if (Grenade == null)
if (Grenade is null)
Log.Error("Grenade is null!");
if (collision == null)
if (collision is null)
Log.Error("wat");
if (collision.gameObject == null)
if (collision.gameObject is null)
Log.Error("pepehm");
if (collision.gameObject == Owner || collision.gameObject.TryGetComponent<EffectGrenade>(out _))
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public override void ProcessDamage(Player player)

if ((player.IsSpawnProtected && player != Attacker) ||
(!PlayerStatsSystem.AttackerDamageHandler._allowSpawnProtectedDamage &&
Attacker != null && Attacker.IsSpawnProtected))
Attacker is not null && Attacker.IsSpawnProtected))
{
Damage = 0f;
return;
Expand Down
8 changes: 4 additions & 4 deletions Exiled.API/Features/DamageHandlers/CustomDamageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public sealed class CustomDamageHandler : AttackerDamageHandler
public CustomDamageHandler(Player target, BaseHandler baseHandler)
: base(target, baseHandler)
{
if (Attacker != null)
if (Attacker is not null)
{
if (Attacker.IsScp)
CustomBase = new ScpDamageHandler(target, baseHandler);
else if (Attacker.CurrentItem != null && Attacker.CurrentItem.IsWeapon &&
else if (Attacker.CurrentItem is not null && Attacker.CurrentItem.IsWeapon &&
baseHandler is BaseFirearmHandler)
CustomBase = new FirearmDamageHandler(Attacker.CurrentItem, target, baseHandler);
else
Expand All @@ -63,7 +63,7 @@ public CustomDamageHandler(Player target, Player attacker, float damage, DamageT
{
Damage = damage;
Type = damageType;
Firearm firearm = new Firearm(ItemType.GunAK)
Firearm firearm = new(ItemType.GunAK)
{
Base =
{
Expand Down Expand Up @@ -132,7 +132,7 @@ private static Action KillPlayer(Player player, DamageHandlerBase damageHandlerB
{
Ragdoll.Spawn(player, damageHandlerBase.Base);

if (damageHandlerBase.Is(out BaseAttackerHandler handler) && damageHandlerBase.BaseAs<FirearmDamageHandler>().Attacker != null)
if (damageHandlerBase.Is(out BaseAttackerHandler handler) && damageHandlerBase.BaseAs<FirearmDamageHandler>().Attacker is not null)
player.ReferenceHub.playerStats.TargetReceiveAttackerDeathReason(damageHandlerBase.BaseAs<FirearmDamageHandler>().Attacker.Nickname, damageHandlerBase.BaseAs<FirearmDamageHandler>().Attacker.Role);
else
player.ReferenceHub.playerStats.TargetReceiveSpecificDeathReason(handler);
Expand Down
2 changes: 1 addition & 1 deletion Exiled.API/Features/DamageHandlers/DamageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,6 @@ public override Action ApplyDamage(Player player)
}

/// <inheritdoc/>
public override string ToString() => $"{Target} {Damage} ({Type}) {(Attacker != null ? Attacker.Nickname : "No one")}";
public override string ToString() => $"{Target} {Damage} ({Type}) {(Attacker is not null ? Attacker.Nickname : "No one")}";
}
}
Loading

0 comments on commit 3e5b1f6

Please sign in to comment.