From 02fe7fc3f4849dcbedcc1bdccd22312a973bd023 Mon Sep 17 00:00:00 2001 From: Build Date: Fri, 15 Jul 2022 12:57:23 -0400 Subject: [PATCH] Bump version, allow configuration of command in translation file --- LeftHandedPlayers.ruleset | 1 + LeftHandedPlayers/Commands/LeftHanded.cs | 37 +++++++++++-------- LeftHandedPlayers/Config.cs | 3 ++ .../EventHandlers/ServerEvents.cs | 10 +---- LeftHandedPlayers/LeftHandedCollection.cs | 2 +- LeftHandedPlayers/LeftHandedPlayers.csproj | 5 ++- LeftHandedPlayers/Plugin.cs | 27 ++++++++++---- LeftHandedPlayers/Translation.cs | 21 +++++++++++ 8 files changed, 71 insertions(+), 35 deletions(-) create mode 100644 LeftHandedPlayers/Translation.cs diff --git a/LeftHandedPlayers.ruleset b/LeftHandedPlayers.ruleset index 28130f2..ac631c4 100644 --- a/LeftHandedPlayers.ruleset +++ b/LeftHandedPlayers.ruleset @@ -1,6 +1,7 @@  + diff --git a/LeftHandedPlayers/Commands/LeftHanded.cs b/LeftHandedPlayers/Commands/LeftHanded.cs index 6e91adc..1e4f09a 100644 --- a/LeftHandedPlayers/Commands/LeftHanded.cs +++ b/LeftHandedPlayers/Commands/LeftHanded.cs @@ -8,6 +8,7 @@ namespace LeftHandedPlayers.Commands { using System; + using System.ComponentModel; using CommandSystem; using Exiled.API.Features; using UnityEngine; @@ -15,27 +16,31 @@ namespace LeftHandedPlayers.Commands /// public class LeftHanded : ICommand { - private readonly Plugin plugin; - - /// - /// Initializes a new instance of the class. - /// - /// An instance of the class. - public LeftHanded(Plugin plugin) => this.plugin = plugin; - /// - public string Command => "lefthanded"; + public string Command { get; set; } = "lefthanded"; /// - public string[] Aliases { get; } = { "left", "lefthand" }; + public string[] Aliases { get; set; } = { "left", "lefthand" }; /// - public string Description => "Makes you left handed"; + public string Description { get; set; } = "Makes you left handed"; + + /// + /// Gets or sets the response to provide when the player becomes left handed. + /// + [Description("The response to provide when the player becomes left handed.")] + public string LeftHandedResponse { get; set; } = "You are now left handed"; + + /// + /// Gets or sets the response to provide when the player becomes right handed. + /// + [Description("The response to provide when the player becomes right handed.")] + public string RightHandedResponse { get; set; } = "You are now right handed"; /// public bool Execute(ArraySegment 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; @@ -44,14 +49,14 @@ public bool Execute(ArraySegment 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; } } diff --git a/LeftHandedPlayers/Config.cs b/LeftHandedPlayers/Config.cs index bdaa283..65db56a 100644 --- a/LeftHandedPlayers/Config.cs +++ b/LeftHandedPlayers/Config.cs @@ -7,6 +7,7 @@ namespace LeftHandedPlayers { + using System.ComponentModel; using System.IO; using Exiled.API.Features; using Exiled.API.Interfaces; @@ -20,11 +21,13 @@ public class Config : IConfig /// /// Gets or sets the folder the file should be stored in. /// + [Description("The folder the file should be stored in.")] public string FolderPath { get; set; } = Path.Combine(Paths.Configs, "LeftHandedPlayers"); /// /// Gets or sets the name of the file to read and write from. /// + [Description("The name of the file to read and write from.")] public string FileName { get; set; } = "LeftHandedData.yml"; } } diff --git a/LeftHandedPlayers/EventHandlers/ServerEvents.cs b/LeftHandedPlayers/EventHandlers/ServerEvents.cs index a7fe186..57f8a6c 100644 --- a/LeftHandedPlayers/EventHandlers/ServerEvents.cs +++ b/LeftHandedPlayers/EventHandlers/ServerEvents.cs @@ -23,15 +23,9 @@ public class ServerEvents public ServerEvents(Plugin plugin) => this.plugin = plugin; /// - public void OnRoundEnded(RoundEndedEventArgs ev) - { - plugin.LeftHandedCollection.Save(); - } + public void OnRoundEnded(RoundEndedEventArgs ev) => plugin.LeftHandedCollection.Save(); /// - public void OnWaitingForPlayers() - { - plugin.LeftHandedCollection.Load(); - } + public void OnWaitingForPlayers() => plugin.LeftHandedCollection.Load(); } } diff --git a/LeftHandedPlayers/LeftHandedCollection.cs b/LeftHandedPlayers/LeftHandedCollection.cs index 43dc376..41de82b 100644 --- a/LeftHandedPlayers/LeftHandedCollection.cs +++ b/LeftHandedPlayers/LeftHandedCollection.cs @@ -30,7 +30,7 @@ public class LeftHandedCollection /// /// Gets the vector that objects should be scaled by to be flipped. /// - public static Vector3 ScaleVector { get; } = new Vector3(-1, 1, 1); + public static Vector3 ScaleVector { get; } = new(-1, 1, 1); /// /// Adds a player to the collection. diff --git a/LeftHandedPlayers/LeftHandedPlayers.csproj b/LeftHandedPlayers/LeftHandedPlayers.csproj index 0c0814e..57da3cc 100644 --- a/LeftHandedPlayers/LeftHandedPlayers.csproj +++ b/LeftHandedPlayers/LeftHandedPlayers.csproj @@ -3,16 +3,17 @@ LeftHandedPlayers net472 + 9 true Build - 1.0.0 + 2.0.0 false false true - + diff --git a/LeftHandedPlayers/Plugin.cs b/LeftHandedPlayers/Plugin.cs index cc6efdc..4bf2e22 100644 --- a/LeftHandedPlayers/Plugin.cs +++ b/LeftHandedPlayers/Plugin.cs @@ -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; @@ -18,18 +17,30 @@ namespace LeftHandedPlayers /// /// The main plugin class. /// - public class Plugin : Plugin + public class Plugin : Plugin { private ServerEvents serverEvents; private PlayerEvents playerEvents; - private LeftHanded leftHandedCommand; + /// + /// Gets an instance of the class. + /// + public static Plugin Instance { get; private set; } /// public override string Author => "Build"; /// - public override Version RequiredExiledVersion { get; } = new Version(5, 0, 0); + public override string Name => "LeftHandedPlayers"; + + /// + public override string Prefix => "LeftHandedPlayers"; + + /// + public override Version RequiredExiledVersion { get; } = new(5, 2, 2); + + /// + public override Version Version { get; } = new(2, 0, 0); /// /// Gets the collection of left handed players. @@ -39,6 +50,7 @@ public class Plugin : Plugin /// public override void OnEnabled() { + Instance = this; LeftHandedCollection = new LeftHandedCollection(this); serverEvents = new ServerEvents(this); playerEvents = new PlayerEvents(this); @@ -57,21 +69,20 @@ public override void OnDisabled() serverEvents = null; playerEvents = null; LeftHandedCollection = null; + Instance = null; base.OnDisabled(); } /// public override void OnRegisteringCommands() { - leftHandedCommand = new LeftHanded(this); - QueryProcessor.DotCommandHandler.RegisterCommand(leftHandedCommand); + QueryProcessor.DotCommandHandler.RegisterCommand(Translation.Command); } /// public override void OnUnregisteringCommands() { - QueryProcessor.DotCommandHandler.UnregisterCommand(leftHandedCommand); - leftHandedCommand = null; + QueryProcessor.DotCommandHandler.UnregisterCommand(Translation.Command); } } } diff --git a/LeftHandedPlayers/Translation.cs b/LeftHandedPlayers/Translation.cs new file mode 100644 index 0000000..cd15f10 --- /dev/null +++ b/LeftHandedPlayers/Translation.cs @@ -0,0 +1,21 @@ +// ----------------------------------------------------------------------- +// +// Copyright (c) Build. All rights reserved. +// Licensed under the CC BY-SA 3.0 license. +// +// ----------------------------------------------------------------------- + +namespace LeftHandedPlayers +{ + using Exiled.API.Interfaces; + using LeftHandedPlayers.Commands; + + /// + public class Translation : ITranslation + { + /// + /// Gets or sets an instance of the command. + /// + public LeftHanded Command { get; set; } = new(); + } +} \ No newline at end of file