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

Commit

Permalink
Bump version, allow configuration of command in translation file
Browse files Browse the repository at this point in the history
  • Loading branch information
Build committed Jul 15, 2022
1 parent eb2aade commit 02fe7fc
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 35 deletions.
1 change: 1 addition & 0 deletions LeftHandedPlayers.ruleset
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="New Rule Set" Description=" " ToolsVersion="15.0">
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1000" Action="None" />
<Rule Id="SA1101" Action="None" />
<Rule Id="SA1503" Action="None" />
</Rules>
Expand Down
37 changes: 21 additions & 16 deletions LeftHandedPlayers/Commands/LeftHanded.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,39 @@
namespace LeftHandedPlayers.Commands
{
using System;
using System.ComponentModel;
using CommandSystem;
using Exiled.API.Features;
using UnityEngine;

/// <inheritdoc />
public class LeftHanded : ICommand
{
private readonly Plugin plugin;

/// <summary>
/// Initializes a new instance of the <see cref="LeftHanded"/> class.
/// </summary>
/// <param name="plugin">An instance of the <see cref="Plugin"/> class.</param>
public LeftHanded(Plugin plugin) => this.plugin = plugin;

/// <inheritdoc />
public string Command => "lefthanded";
public string Command { get; set; } = "lefthanded";

/// <inheritdoc />
public string[] Aliases { get; } = { "left", "lefthand" };
public string[] Aliases { get; set; } = { "left", "lefthand" };

/// <inheritdoc />
public string Description => "Makes you left handed";
public string Description { get; set; } = "Makes you left handed";

/// <summary>
/// Gets or sets the response to provide when the player becomes left handed.
/// </summary>
[Description("The response to provide when the player becomes left handed.")]
public string LeftHandedResponse { get; set; } = "You are now left handed";

/// <summary>
/// Gets or sets the response to provide when the player becomes right handed.
/// </summary>
[Description("The response to provide when the player becomes right handed.")]
public string RightHandedResponse { get; set; } = "You are now right handed";

/// <inheritdoc />
public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out string response)
{
if (!(Player.Get(sender) is Player player))
if (Player.Get(sender) is not Player player)
{
response = "This command can only be used in game.";
return false;
Expand All @@ -44,14 +49,14 @@ public bool Execute(ArraySegment<string> arguments, ICommandSender sender, out s
if (player.Scale.x > 0f)
{
player.Scale = Vector3.Scale(player.Scale, LeftHandedCollection.ScaleVector);
plugin.LeftHandedCollection.Add(player);
response = "You are now left handed";
Plugin.Instance.LeftHandedCollection.Add(player);
response = LeftHandedResponse;
return true;
}

player.Scale = Vector3.Scale(player.Scale, LeftHandedCollection.ScaleVector);
plugin.LeftHandedCollection.Remove(player);
response = "You are no longer left handed";
Plugin.Instance.LeftHandedCollection.Remove(player);
response = RightHandedResponse;
return true;
}
}
Expand Down
3 changes: 3 additions & 0 deletions LeftHandedPlayers/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace LeftHandedPlayers
{
using System.ComponentModel;
using System.IO;
using Exiled.API.Features;
using Exiled.API.Interfaces;
Expand All @@ -20,11 +21,13 @@ public class Config : IConfig
/// <summary>
/// Gets or sets the folder the file should be stored in.
/// </summary>
[Description("The folder the file should be stored in.")]
public string FolderPath { get; set; } = Path.Combine(Paths.Configs, "LeftHandedPlayers");

/// <summary>
/// Gets or sets the name of the file to read and write from.
/// </summary>
[Description("The name of the file to read and write from.")]
public string FileName { get; set; } = "LeftHandedData.yml";
}
}
10 changes: 2 additions & 8 deletions LeftHandedPlayers/EventHandlers/ServerEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,9 @@ public class ServerEvents
public ServerEvents(Plugin plugin) => this.plugin = plugin;

/// <inheritdoc cref="Exiled.Events.Handlers.Server.OnRoundEnded(RoundEndedEventArgs)"/>
public void OnRoundEnded(RoundEndedEventArgs ev)
{
plugin.LeftHandedCollection.Save();
}
public void OnRoundEnded(RoundEndedEventArgs ev) => plugin.LeftHandedCollection.Save();

/// <inheritdoc cref="Exiled.Events.Handlers.Server.OnWaitingForPlayers()"/>
public void OnWaitingForPlayers()
{
plugin.LeftHandedCollection.Load();
}
public void OnWaitingForPlayers() => plugin.LeftHandedCollection.Load();
}
}
2 changes: 1 addition & 1 deletion LeftHandedPlayers/LeftHandedCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class LeftHandedCollection
/// <summary>
/// Gets the vector that objects should be scaled by to be flipped.
/// </summary>
public static Vector3 ScaleVector { get; } = new Vector3(-1, 1, 1);
public static Vector3 ScaleVector { get; } = new(-1, 1, 1);

/// <summary>
/// Adds a player to the collection.
Expand Down
5 changes: 3 additions & 2 deletions LeftHandedPlayers/LeftHandedPlayers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
<PropertyGroup>
<AssemblyName>LeftHandedPlayers</AssemblyName>
<TargetFramework>net472</TargetFramework>
<LangVersion>9</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Authors>Build</Authors>
<Version>1.0.0</Version>
<Version>2.0.0</Version>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EXILED" Version="5.0.0-beta.5" />
<PackageReference Include="EXILED" Version="5.2.2" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" />
<PackageReference Include="YamlDotNet" Version="9.1.4" />
</ItemGroup>
Expand Down
27 changes: 19 additions & 8 deletions LeftHandedPlayers/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace LeftHandedPlayers
{
using System;
using Exiled.API.Features;
using LeftHandedPlayers.Commands;
using LeftHandedPlayers.EventHandlers;
using RemoteAdmin;
using PlayerHandlers = Exiled.Events.Handlers.Player;
Expand All @@ -18,18 +17,30 @@ namespace LeftHandedPlayers
/// <summary>
/// The main plugin class.
/// </summary>
public class Plugin : Plugin<Config>
public class Plugin : Plugin<Config, Translation>
{
private ServerEvents serverEvents;
private PlayerEvents playerEvents;

private LeftHanded leftHandedCommand;
/// <summary>
/// Gets an instance of the <see cref="Plugin"/> class.
/// </summary>
public static Plugin Instance { get; private set; }

/// <inheritdoc />
public override string Author => "Build";

/// <inheritdoc />
public override Version RequiredExiledVersion { get; } = new Version(5, 0, 0);
public override string Name => "LeftHandedPlayers";

/// <inheritdoc />
public override string Prefix => "LeftHandedPlayers";

/// <inheritdoc />
public override Version RequiredExiledVersion { get; } = new(5, 2, 2);

/// <inheritdoc />
public override Version Version { get; } = new(2, 0, 0);

/// <summary>
/// Gets the collection of left handed players.
Expand All @@ -39,6 +50,7 @@ public class Plugin : Plugin<Config>
/// <inheritdoc />
public override void OnEnabled()
{
Instance = this;
LeftHandedCollection = new LeftHandedCollection(this);
serverEvents = new ServerEvents(this);
playerEvents = new PlayerEvents(this);
Expand All @@ -57,21 +69,20 @@ public override void OnDisabled()
serverEvents = null;
playerEvents = null;
LeftHandedCollection = null;
Instance = null;
base.OnDisabled();
}

/// <inheritdoc />
public override void OnRegisteringCommands()
{
leftHandedCommand = new LeftHanded(this);
QueryProcessor.DotCommandHandler.RegisterCommand(leftHandedCommand);
QueryProcessor.DotCommandHandler.RegisterCommand(Translation.Command);
}

/// <inheritdoc />
public override void OnUnregisteringCommands()
{
QueryProcessor.DotCommandHandler.UnregisterCommand(leftHandedCommand);
leftHandedCommand = null;
QueryProcessor.DotCommandHandler.UnregisterCommand(Translation.Command);
}
}
}
21 changes: 21 additions & 0 deletions LeftHandedPlayers/Translation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// -----------------------------------------------------------------------
// <copyright file="Translation.cs" company="Build">
// Copyright (c) Build. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace LeftHandedPlayers
{
using Exiled.API.Interfaces;
using LeftHandedPlayers.Commands;

/// <inheritdoc />
public class Translation : ITranslation
{
/// <summary>
/// Gets or sets an instance of the <see cref="LeftHanded"/> command.
/// </summary>
public LeftHanded Command { get; set; } = new();
}
}

0 comments on commit 02fe7fc

Please sign in to comment.