diff --git a/Feli.RocketMod.Teleporting/Commands/TpaCommand.cs b/Feli.RocketMod.Teleporting/Commands/TpaCommand.cs index 4e299f7..970eb60 100644 --- a/Feli.RocketMod.Teleporting/Commands/TpaCommand.cs +++ b/Feli.RocketMod.Teleporting/Commands/TpaCommand.cs @@ -48,6 +48,8 @@ public void Execute(IRocketPlayer caller, string[] command) teleportsManager.Accept(player); else if (type == "c" | type == "cancel") teleportsManager.Cancel(player); + else if(type == "l" | type == "list") + teleportsManager.List(player); else { Say(caller, plugin.Translate("TpaCommand:WrongUsage"), messageColor, messageIcon); @@ -64,7 +66,7 @@ private void Say(IRocketPlayer rocketPlayer, string message, Color messageColor, public AllowedCaller AllowedCaller => AllowedCaller.Player; public string Name => "tpa"; public string Help => "Send, accept, deny and cancel teleport requests"; - public string Syntax => ""; + public string Syntax => ""; public List Aliases => new List(); public List Permissions => new List(); } diff --git a/Feli.RocketMod.Teleporting/Configuration.cs b/Feli.RocketMod.Teleporting/Configuration.cs index 45e0316..6e88dd0 100644 --- a/Feli.RocketMod.Teleporting/Configuration.cs +++ b/Feli.RocketMod.Teleporting/Configuration.cs @@ -15,6 +15,7 @@ public class Configuration : IRocketPluginConfiguration public double TeleportProtectionTime { get; set; } public bool TeleportCombatAllowed { get; set; } public double TeleportCombatTime { get; set; } + public bool AllowAcceptingWithKeys { get; set; } public TeleportCost TeleportCost { get; set; } public void LoadDefaults() @@ -28,6 +29,7 @@ public void LoadDefaults() TeleportProtectionTime = 5; TeleportCombatAllowed = false; TeleportCombatTime = 30; + AllowAcceptingWithKeys = true; TeleportCost = new TeleportCost() { Enabled = false, diff --git a/Feli.RocketMod.Teleporting/Plugin.cs b/Feli.RocketMod.Teleporting/Plugin.cs index 3fbfbce..60e30a7 100644 --- a/Feli.RocketMod.Teleporting/Plugin.cs +++ b/Feli.RocketMod.Teleporting/Plugin.cs @@ -38,7 +38,7 @@ protected override void Unload() public override TranslationList DefaultTranslations => new TranslationList() { - {"TpaCommand:WrongUsage", "Correct command usage: /tpa "}, + {"TpaCommand:WrongUsage", "Correct command usage: /tpa "}, {"TpaCommand:WrongUsage:Send", "Correct command usage: /tpa send "}, {"TpaCommand:WrongUsage:NotFound", "Player with name {0} was not found"}, {"TpaCommand:Send:Yourself", "There is no point on sending a tpa request to yourself"}, @@ -50,6 +50,9 @@ protected override void Unload() {"TpaCommand:Accept:Delay", "You will be teleported to {0} in {1} seconds"}, {"TpaCommand:Accept:Success", "Successfully accepted {0}'s tpa"}, {"TpaCommand:Accept:Teleported", "Successfully teleported to {0}"}, + {"TpaCommand:List:NotFound", "There are no tpa requests to list"}, + {"TpaCommand:List:Display", "You have {0} tpa requests"}, + {"TpaCommand:List:Section", "- {0}"}, {"TpaCommand:Cancel:NotRequests", "There are no tpa requests to cancel"}, {"TpaCommand:Cancel:Other", "{0} has just cancelled the tpa request"}, {"TpaCommand:Cancel:Success", "Successfully canceled the tpa with {0}"}, diff --git a/Feli.RocketMod.Teleporting/TeleportsManager.cs b/Feli.RocketMod.Teleporting/TeleportsManager.cs index 85b512d..950c194 100644 --- a/Feli.RocketMod.Teleporting/TeleportsManager.cs +++ b/Feli.RocketMod.Teleporting/TeleportsManager.cs @@ -33,6 +33,7 @@ public TeleportsManager(Plugin plugin) _messageColor = plugin.MessageColor; U.Events.OnPlayerDisconnected += OnLeave; DamageTool.onPlayerAllowedToDamagePlayer += OnPlayerAllowedToDamagePlayer; + PlayerAnimator.OnLeanChanged_Global += OnLeanChanged; } public void Send(UnturnedPlayer sender, UnturnedPlayer target) @@ -132,6 +133,26 @@ public void Accept(UnturnedPlayer target) }, _configuration.TeleportDelay); } + public void List(UnturnedPlayer player) + { + var requests = _teleportRequests.Where(x => x.Item2.Equals(player)); + + if (requests.Count() == 0) + { + Say(player, _plugin.Translate("TpaCommand:List:NotFound"), _messageColor, _messageIcon); + return; + } + + var playerNames = _teleportRequests.Select(x => x.Item2.DisplayName); + + Say(player, _plugin.Translate("TpaCommand:List:Display", requests.Count()), _messageColor, _messageIcon); + + foreach (var playerName in playerNames) + { + Say(player, _plugin.Translate("TpaCommand:List:Section", playerName), _messageColor, _messageIcon); + } + } + public void Cancel(UnturnedPlayer player) { var request = _teleportRequests.FirstOrDefault(x => x.Item1.Equals(player) || x.Item2.Equals(player)); @@ -252,6 +273,29 @@ private void OnPlayerAllowedToDamagePlayer(Player nativeInstigator, Player nativ } } } + + private void OnLeanChanged(PlayerAnimator obj) + { + if (!_configuration.AllowAcceptingWithKeys) + return; + + var player = UnturnedPlayer.FromPlayer(obj.player); + + if (obj.lean == 1) + { + var request = _teleportRequests.Any(x => x.Item2.Equals(player) || x.Item1.Equals(player)); + + if(request) + Cancel(player); + } + else if (obj.lean == -1) + { + var request = _teleportRequests.Any(x => x.Item2.Equals(player)); + + if(request) + Accept(player); + } + } private void UpdateCooldown(UnturnedPlayer player) { @@ -282,7 +326,7 @@ private void UpdateTeleportProtection(UnturnedPlayer player) if (_teleportProtections.ContainsKey(player)) _teleportProtections[player] = DateTime.Now; else - _cooldowns.Add(player, DateTime.Now); + _teleportProtections.Add(player, DateTime.Now); } private DateTime GetTeleportProtection(UnturnedPlayer player) @@ -316,6 +360,7 @@ public void Dispose() _playersLastCombat = null; _plugin = null; _configuration = null; + PlayerAnimator.OnLeanChanged_Global -= OnLeanChanged; DamageTool.onPlayerAllowedToDamagePlayer -= OnPlayerAllowedToDamagePlayer; U.Events.OnPlayerDisconnected -= OnLeave; }