From 77504e75d4a6309005399d40abeca0132df72ffd Mon Sep 17 00:00:00 2001 From: Leonardo Santos Date: Tue, 19 Jul 2016 02:37:50 -0200 Subject: [PATCH] Clean up --- src/Commands/CommandBack.cs | 5 +++-- src/Commands/CommandBoom.cs | 4 +++- src/Commands/CommandRespawnZombies.cs | 2 +- src/Commands/CommandTpAll.cs | 5 ++--- src/Commands/CommandTpa.cs | 9 +++------ src/Commands/CommandUnfreeze.cs | 17 +++++++---------- src/Commands/MiscCommands.cs | 16 ++++++---------- src/Event/Handling/EssentialsEventHandler.cs | 13 ++++++------- uEssentials.csproj | 1 + 9 files changed, 32 insertions(+), 40 deletions(-) diff --git a/src/Commands/CommandBack.cs b/src/Commands/CommandBack.cs index fff906bb..398c1b58 100644 --- a/src/Commands/CommandBack.cs +++ b/src/Commands/CommandBack.cs @@ -24,6 +24,7 @@ using UnityEngine; using Essentials.I18n; using Essentials.Api; +using Essentials.Core; using Essentials.Event.Handling; namespace Essentials.Commands { @@ -39,11 +40,11 @@ public class CommandBack : EssCommand { public override CommandResult OnExecute(ICommandSource src, ICommandArgs args) { var player = src.ToPlayer(); - if (!player.HasMetadata("back_pos")) { + if (!player.HasMetadata(Consts.BACK_METADATA_KEY)) { return CommandResult.Lang("NOT_DIED_YET"); } - var backPosition = player.GetMetadata("back_pos"); + var backPosition = player.GetMetadata(Consts.BACK_METADATA_KEY); src.ToPlayer().Teleport(backPosition); EssLang.Send(src, "RETURNED"); diff --git a/src/Commands/CommandBoom.cs b/src/Commands/CommandBoom.cs index e39fe0d8..833b85e6 100644 --- a/src/Commands/CommandBoom.cs +++ b/src/Commands/CommandBoom.cs @@ -33,7 +33,9 @@ namespace Essentials.Commands { Name = "boom", Aliases = new[] { "explode" }, Description = "Create an explosion on player's/given position", - Usage = "[player | * | x, y, z]" + Usage = "[player | * | x, y, z]", + MinArgs = 0, + MaxArgs = 3 )] public class CommandBoom : EssCommand { diff --git a/src/Commands/CommandRespawnZombies.cs b/src/Commands/CommandRespawnZombies.cs index 2e4c1aac..b631afff 100644 --- a/src/Commands/CommandRespawnZombies.cs +++ b/src/Commands/CommandRespawnZombies.cs @@ -48,7 +48,7 @@ public class CommandRespawnZombies : EssCommand { zombie.gear, zombie.transform.position, 0 - ); + ); count++; }); diff --git a/src/Commands/CommandTpAll.cs b/src/Commands/CommandTpAll.cs index 331e83cb..7578d326 100644 --- a/src/Commands/CommandTpAll.cs +++ b/src/Commands/CommandTpAll.cs @@ -38,9 +38,7 @@ namespace Essentials.Commands { public class CommandTpAll : EssCommand { private static readonly Action> TeleportAll = (pos, players) => { - players.ForEach( - player => player.UnturnedPlayer.sendTeleport(pos, 0) - ); + players.ForEach(player => player.UnturnedPlayer.sendTeleport(pos, 0)); }; public override CommandResult OnExecute(ICommandSource src, ICommandArgs args) { @@ -49,6 +47,7 @@ public class CommandTpAll : EssCommand { if (players.Count == (src.IsConsole ? 0 : 1)) { return CommandResult.Lang("NO_PLAYERS_FOR_TELEPORT"); } + switch (args.Length) { case 0: if (src.IsConsole) { diff --git a/src/Commands/CommandTpa.cs b/src/Commands/CommandTpa.cs index 025a087e..4be4e256 100644 --- a/src/Commands/CommandTpa.cs +++ b/src/Commands/CommandTpa.cs @@ -39,18 +39,15 @@ namespace Essentials.Commands { [CommandInfo( Name = "tpa", - Usage = "[player | accept | deny | cancel]", - AllowedSource = AllowedSource.PLAYER + Usage = "[player/accept/deny/cancel]", + AllowedSource = AllowedSource.PLAYER, + MinArgs = 1 )] public class CommandTpa : EssCommand { public static Dictionary Requests = new Dictionary(); public override CommandResult OnExecute(ICommandSource src, ICommandArgs args) { - if (args.Length < 1) { - return CommandResult.ShowUsage(); - } - var player = src.ToPlayer(); var senderId = player.CSteamId.m_SteamID; diff --git a/src/Commands/CommandUnfreeze.cs b/src/Commands/CommandUnfreeze.cs index 75d1d0f6..458a81e5 100644 --- a/src/Commands/CommandUnfreeze.cs +++ b/src/Commands/CommandUnfreeze.cs @@ -31,15 +31,13 @@ namespace Essentials.Commands { [CommandInfo( Name = "unfreeze", Usage = "[player/*]", - Description = "Unfreeze a player/everyone" + Description = "Unfreeze a player/everyone", + MinArgs = 1, + MaxArgs = 1 )] public class CommandUnfreeze : EssCommand { public override CommandResult OnExecute(ICommandSource src, ICommandArgs args) { - if (args.Length == 0) { - return CommandResult.ShowUsage(); - } - if (args[0].Is("*")) { foreach (var player in UServer.Players.Where(player => player.HasComponent())) { player.RemoveComponent(); @@ -57,12 +55,11 @@ public class CommandUnfreeze : EssCommand { if (!target.HasComponent()) { return CommandResult.Lang("NOT_FROZEN", target.DisplayName); - } else { - target.RemoveComponent(); - - EssLang.Send(src, "UNFROZEN_SENDER", target.DisplayName); - EssLang.Send(target, "UNFROZEN_PLAYER", src.DisplayName); } + target.RemoveComponent(); + + EssLang.Send(src, "UNFROZEN_SENDER", target.DisplayName); + EssLang.Send(target, "UNFROZEN_PLAYER", src.DisplayName); } return CommandResult.Success(); diff --git a/src/Commands/MiscCommands.cs b/src/Commands/MiscCommands.cs index 4cbda37f..80548550 100644 --- a/src/Commands/MiscCommands.cs +++ b/src/Commands/MiscCommands.cs @@ -670,16 +670,12 @@ public class MiscCommands { Description = "Show tps." )] private CommandResult TpsCommand(ICommandSource src, ICommandArgs args) { - Color color; var tps = Provider.debugTPS; - - if (tps > 40) - color = Color.green; - else if (tps < 40 && tps > 25) - color = Color.yellow; - else - color = Color.red; - + var color = + tps > 40 ? Color.green : + tps > 25 ? Color.yellow : + Color.red; + src.SendMessage($"Ticks per second: {tps}", color); return CommandResult.Success(); } @@ -776,7 +772,7 @@ public class MiscCommands { [CommandInfo( Name = "pvp", - Description = "Enable or disable pvp", + Description = "Enable or disable server pvp.", Usage = "[on|off]" )] private CommandResult PvpCommand(ICommandSource src, ICommandArgs args) { diff --git a/src/Event/Handling/EssentialsEventHandler.cs b/src/Event/Handling/EssentialsEventHandler.cs index eeee8983..d15084a3 100644 --- a/src/Event/Handling/EssentialsEventHandler.cs +++ b/src/Event/Handling/EssentialsEventHandler.cs @@ -80,19 +80,18 @@ internal class EssentialsEventHandler { [SubscribeEvent(EventType.PLAYER_DISCONNECTED)] private void GenericPlayerDisconnected(UnturnedPlayer player) { - var displayName = player.CharacterName; + var playerId = player.CSteamID.m_SteamID; - MiscCommands.Spies.Remove(player.CSteamID.m_SteamID); - CommandTell.Conversations.Remove(player.CSteamID.m_SteamID); - CachedSkills.Remove(player.CSteamID.m_SteamID); + MiscCommands.Spies.Remove(playerId); + CommandTell.Conversations.Remove(playerId); + CachedSkills.Remove(playerId); CommandHome.Cooldown.RemoveEntry(player.CSteamID); /* Kit Stuffs */ UEssentials.ModuleManager.GetModule().IfPresent(m => { if (CommandKit.Cooldowns.Count == 0) return; - if (!CommandKit.Cooldowns.ContainsKey(player.CSteamID.m_SteamID)) return; + if (!CommandKit.Cooldowns.ContainsKey(playerId)) return; - var playerId = player.CSteamID.m_SteamID; var playerCooldowns = CommandKit.Cooldowns[playerId]; var keys = new List(playerCooldowns.Keys); @@ -474,7 +473,7 @@ internal class EssentialsEventHandler { return; } - UPlayer.TryGet(player, p => p.SetMetadata("back_pos", player.Position)); + UPlayer.TryGet(player, p => p.SetMetadata(Consts.BACK_METADATA_KEY, player.Position)); } diff --git a/uEssentials.csproj b/uEssentials.csproj index c7e62584..eef017a8 100644 --- a/uEssentials.csproj +++ b/uEssentials.csproj @@ -118,6 +118,7 @@ +