Skip to content

Commit

Permalink
Merge pull request #2 from raggebatman/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ragge authored Sep 30, 2023
2 parents 052cce4 + 639b240 commit 68b8bfd
Show file tree
Hide file tree
Showing 16 changed files with 189 additions and 101 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ View the config file for details.

## Commands

Radiation is managed using the `radiation` command.

- `radiation start`
- `radiation stop`
- `radiation enable`
Expand All @@ -20,13 +18,10 @@ Radiation is managed using the `radiation` command.

## Permissions

Each command has its own permission.

- `radiation.start`
- `radiation.stop`
- `radiation.enable`
- `radiation.disable`
- `radiation.status`

## Details

Expand Down
32 changes: 32 additions & 0 deletions Radiation/API/RadiationAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using PlayerStatsSystem;
using Radiation.Enums;
using PlayerRoles;
using System;

namespace Radiation.API
{
Expand Down Expand Up @@ -123,5 +124,36 @@ public static bool DealDamage(Player player)

return true;
}

public static Tuple<RadiationStatus, string> Status()
{
RadiationStatus status;
string response;

if (!Plugin.Singleton.radiationEnabled)
{
status = RadiationStatus.Disabled;
response = "Radiation is disabled.";
}
else
if (Plugin.Singleton.radiationDelayed)
{
status = RadiationStatus.Delayed;
response = "Radiation will occur soon.";
}
else
if (Plugin.Singleton.radiationStarted)
{
status = RadiationStatus.Started;
response = "Radiation is active.";
}
else
{
status = RadiationStatus.Stopped;
response = "Radiation is inactive.";
}

return Tuple.Create(status, response);
}
}
}
14 changes: 4 additions & 10 deletions Radiation/Commands/Radiation/DisableCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
return false;
}

if (Plugin.Singleton.DisableRadiation())
{
response = "Radiation has been disabled.";
return true;
}
else
{
response = "Radiation is already disabled.";
return false;
}
var command = Plugin.Singleton.DisableRadiation();

response = command.Item2;
return command.Item1;
}
}
}
14 changes: 4 additions & 10 deletions Radiation/Commands/Radiation/EnableCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
return false;
}

if (Plugin.Singleton.EnableRadiation())
{
response = "Radiation has been enabled.";
return true;
}
else
{
response = "Radiation is already enabled.";
return false;
}
var command = Plugin.Singleton.EnableRadiation();

response = command.Item2;
return command.Item1;
}
}
}
14 changes: 4 additions & 10 deletions Radiation/Commands/Radiation/StartCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
return false;
}

if (Plugin.Singleton.StartRadiation())
{
response = "Radiation has been started.";
return true;
}
else
{
response = "Radiation has already started.";
return false;
}
var command = Plugin.Singleton.StartRadiation();

response = command.Item2;
return command.Item1;
}
}
}
28 changes: 3 additions & 25 deletions Radiation/Commands/Radiation/StatusCommand.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using CommandSystem;
using NWAPIPermissionSystem;
using Radiation.API;

namespace Radiation.Commands
{
Expand All @@ -12,31 +12,9 @@ public class StatusCommand : ICommand

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (!sender.CheckPermission("radiation.status"))
{
response = "You do not have the required permission (radiation.status) to execute this command";
return false;
}

if (!Plugin.Singleton.radiationEnabled)
{
response = "Radiation is disabled.";
}
else
if (Plugin.Singleton.radiationDelayed)
{
response = "Radiation will occur soon.";
}
else
if (Plugin.Singleton.radiationStarted)
{
response = "Radiation is active.";
}
else
{
response = "Radiation is inactive.";
}
var status = RadiationAPI.Status();

response = status.Item2;
return true;
}
}
Expand Down
16 changes: 5 additions & 11 deletions Radiation/Commands/Radiation/StopCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,10 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
return false;
}

if (Plugin.Singleton.StopRadiation())
{
response = "Radiation has been stopped.";
return true;
}
else
{
response = "Radiation has already stopped.";
return false;
}
var command = Plugin.Singleton.StopRadiation();

response = command.Item2;
return command.Item1;
}
}
}
}
18 changes: 18 additions & 0 deletions Radiation/Commands/Radiation/VersionCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using CommandSystem;

namespace Radiation.Commands
{
public class VersionCommand : ICommand
{
public string Command { get; } = "version";
public string Description { get; } = "Show plugin version";
public string[] Aliases { get; }

public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
response = "This server is using Radiation v1.1.1";
return true;
}
}
}
2 changes: 2 additions & 0 deletions Radiation/Commands/RadiationCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public override void LoadGeneratedCommands()
RegisterCommand(new EnableCommand());
RegisterCommand(new DisableCommand());
RegisterCommand(new StatusCommand());
RegisterCommand(new VersionCommand());
}
catch (Exception e)
{
Expand All @@ -49,6 +50,7 @@ protected override bool ExecuteParent(ArraySegment<string> arguments, ICommandSe
stringBuilder.AppendLine("- radiation enable - Enable tick damage, will start tick damage if warhead is detonated");
stringBuilder.AppendLine("- radiation disable - Disable tick damage, will not start tick damage if warhead detonates");
stringBuilder.AppendLine("- radiation status - Show radiation status");
stringBuilder.AppendLine("- radiation version - Show plugin version");

response = StringBuilderPool.Shared.ToStringReturn(stringBuilder);

Expand Down
10 changes: 10 additions & 0 deletions Radiation/Enums/RadiationStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Radiation.Enums
{
public enum RadiationStatus
{
Disabled,
Delayed,
Started,
Stopped
}
}
3 changes: 3 additions & 0 deletions Radiation/Events/ServerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public ServerEvents()
[PluginEvent(ServerEventType.RoundStart)]
private void OnRoundStart(RoundStartEvent @event)
{
Plugin.Singleton.StopDelay();
Plugin.Singleton.StopRadiation();

if (_config.EnableRadiationOnRoundStart)
Expand All @@ -28,12 +29,14 @@ private void OnRoundStart(RoundStartEvent @event)
[PluginEvent(ServerEventType.RoundEnd)]
private void OnRoundEnd(RoundEndEvent @event)
{
Plugin.Singleton.StopDelay();
Plugin.Singleton.StopRadiation();
}

[PluginEvent(ServerEventType.RoundRestart)]
private void OnRoundRestart(RoundRestartEvent @event)
{
Plugin.Singleton.StopDelay();
Plugin.Singleton.StopRadiation();
}

Expand Down
Loading

0 comments on commit 68b8bfd

Please sign in to comment.