Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
louis1706 committed Sep 6, 2022
2 parents 1e97f68 + 545618e commit 2b39bed
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 54 deletions.
4 changes: 2 additions & 2 deletions Commands/DisableTesla.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public class DisableTesla : ICommand, IUsageProvider

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if(sender.CheckPermission(PlayerPermissions.FacilityManagement, out response))
if(!sender.CheckPermission(PlayerPermissions.FacilityManagement, out response))
{
return false;
}
if (float.TryParse(arguments.ElementAtOrDefault(0), out float time))
if (!float.TryParse(arguments.ElementAtOrDefault(0), out float time))
{
response = $"Invalid duration time {arguments.ElementAtOrDefault(0)}";
return false;
Expand Down
14 changes: 7 additions & 7 deletions EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class EventHandlers
public FacilityManagement plugin;
public int LuresCount;

public void HandleRoundStart()
public void OnRoundStarted()
{
LuresCount = 0;
if (plugin.Config.CustomTesla is not null)
Expand Down Expand Up @@ -85,7 +85,7 @@ public void HandleRoundStart()
if (plugin.Config.Scp106LureAmount < 1)
Object.FindObjectOfType<LureSubjectContainer>().SetState(false, true);
}
public void HandleWeaponShoot(ShootingEventArgs ev)
public void OnShooting(ShootingEventArgs ev)
{
if (ev.Shooter.CurrentItem is null)
return;
Expand All @@ -94,11 +94,11 @@ public void HandleWeaponShoot(ShootingEventArgs ev)
firearm.Ammo++;
}
}
public void HandleEnergyMicroHid(UsingMicroHIDEnergyEventArgs ev)
public void OnUsingMicroHIDEnergy(UsingMicroHIDEnergyEventArgs ev)
{
ev.Drain *= plugin.Config.EnergyMicroHid;
}
public void HandleEnergyRadio(UsingRadioBatteryEventArgs ev)
public void OnUsingRadioBattery(UsingRadioBatteryEventArgs ev)
{
ev.Drain *= plugin.Config.EnergyRadio;
}
Expand All @@ -118,7 +118,7 @@ public void OnHurting(HurtingEventArgs ev)
ev.Target.ActiveArtificialHealthProcesses.First().SustainTime = ahpProccessBuild.Sustain;
}

public void HandleFemurEnter(EnteringFemurBreakerEventArgs ev)
public void OnEnteringFemurBreaker(EnteringFemurBreakerEventArgs ev)
{
// That means the femur breaker is always open
if (plugin.Config.Scp106LureAmount < 1)
Expand All @@ -141,15 +141,15 @@ public void HandleFemurEnter(EnteringFemurBreakerEventArgs ev)
}
}

public void HandleContain106(ContainingEventArgs ev)
public void OnContaining(ContainingEventArgs ev)
{
if (plugin.Config.Scp106LureAmount < 1)
return;
ev.IsAllowed = LuresCount > plugin.Config.Scp106LureAmount;
}


public void HandleWarheadDetonation()
public void OnDetonated()
{
if (!plugin.Config.WarheadCleanup)
return;
Expand Down
4 changes: 2 additions & 2 deletions FacilityManagement.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@
<Compile Include="EventHandlers.cs" />
<Compile Include="Patches\CommandIntercomTextFix.cs" />
<Compile Include="Patches\IntercomDisplayTextFix.cs" />
<Compile Include="Patches\IntercomPatche.cs" />
<Compile Include="Patches\IntercomPatch.cs" />
<Compile Include="Main.cs" />
<Compile Include="Patches\NameFormaterPatche.cs" />
<Compile Include="Patches\NameFormaterPatch.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
72 changes: 32 additions & 40 deletions Main.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
namespace FacilityManagement
{
using Exiled.API.Enums;
using Exiled.Events.Handlers;
using HarmonyLib;
using MEC;
using System;
using System.Collections.Generic;
using System.Diagnostics;

public class FacilityManagement : Exiled.API.Features.Plugin<Config>
{
public static FacilityManagement Singleton;
public static FacilityManagement Singleton;

public override string Name => "FacilityManagement";
public override string Prefix => "FacilityManagement";
public override string Author => "Yamato#8987";
public override Version Version => new(1,0,0);
public override Version RequiredExiledVersion => new(5,2,2);
public override string Name => "FacilityManagement";
public override string Prefix => "FacilityManagement";
public override string Author => "Yamato#8987";
public override Version Version { get; } = new(1,0,0);
public override Version RequiredExiledVersion { get; } = new(5,2,2);

public EventHandlers EventHandlers { get; private set; }

Expand All @@ -28,21 +26,17 @@ public class FacilityManagement : Exiled.API.Features.Plugin<Config>

public override void OnEnabled()
{
if (!Config.IsEnabled) return;
Singleton = this;
base.OnEnabled();

RegistEvents();
RegisterEvents();

RegistPatch();

Exiled.API.Features.Log.Info($"[OnEnabled] FacilityManagement({Version}) Enabled Complete.");
RegisterPatch();
}
public override void OnReloaded()
{
if (!Config.IsEnabled) return;
RegistEvents();
RegistPatch();
RegisterEvents();
RegisterPatch();

base.OnReloaded();
}
Expand All @@ -54,47 +48,45 @@ public override void OnDisabled()
Timing.KillCoroutines(cor);
RoundCoroutines.Clear();

UnRegistEvents();

UnRegistPatch();
UnRegisterEvents();

Exiled.API.Features.Log.Info($"[OnDisable] SanyaRemastered({Version}) Disabled Complete.");
UnRegisterPatch();
}
private void RegistEvents()
private void RegisterEvents()
{
EventHandlers = new(this);
Server.RoundStarted += EventHandlers.HandleRoundStart;
Server.RoundStarted += EventHandlers.OnRoundStarted;

Player.Shooting += EventHandlers.HandleWeaponShoot;
Player.UsingMicroHIDEnergy += EventHandlers.HandleEnergyMicroHid;
Player.UsingRadioBattery += EventHandlers.HandleEnergyRadio;
Player.Shooting += EventHandlers.OnShooting;
Player.UsingMicroHIDEnergy += EventHandlers.OnUsingMicroHIDEnergy;
Player.UsingRadioBattery += EventHandlers.OnUsingRadioBattery;
Player.Spawning += EventHandlers.OnSpawning;
Player.Hurting += EventHandlers.OnHurting;
Player.EnteringFemurBreaker += EventHandlers.HandleFemurEnter;
Player.EnteringFemurBreaker += EventHandlers.OnEnteringFemurBreaker;

Scp106.Containing += EventHandlers.HandleContain106;
Scp106.Containing += EventHandlers.OnContaining;

Warhead.Detonated += EventHandlers.HandleWarheadDetonation;
Warhead.Detonated += EventHandlers.OnDetonated;
}
private void UnRegistEvents()
private void UnRegisterEvents()
{
Server.RoundStarted -= EventHandlers.HandleRoundStart;
Server.RoundStarted -= EventHandlers.OnRoundStarted;

Player.Shooting -= EventHandlers.HandleWeaponShoot;
Player.UsingMicroHIDEnergy -= EventHandlers.HandleEnergyMicroHid;
Player.UsingRadioBattery -= EventHandlers.HandleEnergyRadio;
Player.Shooting -= EventHandlers.OnShooting;
Player.UsingMicroHIDEnergy -= EventHandlers.OnUsingMicroHIDEnergy;
Player.UsingRadioBattery -= EventHandlers.OnUsingRadioBattery;
Player.Spawning -= EventHandlers.OnSpawning;
Player.Hurting -= EventHandlers.OnHurting;
Player.EnteringFemurBreaker -= EventHandlers.HandleFemurEnter;
Player.EnteringFemurBreaker -= EventHandlers.OnEnteringFemurBreaker;

Scp106.Containing -= EventHandlers.HandleContain106;
Scp106.Containing -= EventHandlers.OnContaining;

Warhead.Detonated -= EventHandlers.HandleWarheadDetonation;
Warhead.Detonated -= EventHandlers.OnDetonated;

EventHandlers = null;
}

private void RegistPatch()
private void RegisterPatch()
{
try
{
Expand All @@ -103,13 +95,13 @@ private void RegistPatch()
}
catch (Exception ex)
{
Exiled.API.Features.Log.Error($"[RegistPatch] Patching Failed : {ex}");
Exiled.API.Features.Log.Error($"[RegisterPatch] Patching Failed : {ex}");
}
}

private void UnRegistPatch()
private void UnRegisterPatch()
{
Harmony.UnpatchAll(Harmony.Id);
}
}
}
}
2 changes: 1 addition & 1 deletion Patches/CommandIntercomTextFix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace FacilityManagement.Patches
{
[HarmonyPatch(typeof(IntercomTextCommand), nameof(IntercomTextCommand.Execute))]
public static class IntercomTextCommandPatches
public static class IntercomTextCommandFix
{
public static bool Prefix(ref bool __result, ArraySegment<string> arguments, ICommandSender sender, out string response)
{
Expand Down
2 changes: 1 addition & 1 deletion Patches/IntercomPatche.cs → Patches/IntercomPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace FacilityManagement.Patches
{
public class IntercomUpdateTextPatche
public class IntercomUpdateTextPatch
{
[HarmonyPatch(typeof(Intercom), nameof(Intercom.IntercomState), MethodType.Setter)]
public static class CommandIntercomTextSetterFix
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace FacilityManagement.Patches
{
[HarmonyPatch(typeof(Intercom), nameof(Intercom.Start))]
public class NameFormaterPatche
public class NameFormaterPatch
{
public static void Postfix(Intercom __instance)
{
Expand Down

0 comments on commit 2b39bed

Please sign in to comment.