Skip to content

Commit

Permalink
Add teleport list, fixed tpa protections and added e/q gestures
Browse files Browse the repository at this point in the history
  • Loading branch information
negrifelipe committed Dec 2, 2021
1 parent 8efdd0e commit 3c321ef
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Feli.RocketMod.Teleporting/Commands/TpaCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 => "<accept|send|cancel>";
public string Syntax => "<accept|send|cancel|list>";
public List<string> Aliases => new List<string>();
public List<string> Permissions => new List<string>();
}
Expand Down
2 changes: 2 additions & 0 deletions Feli.RocketMod.Teleporting/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -28,6 +29,7 @@ public void LoadDefaults()
TeleportProtectionTime = 5;
TeleportCombatAllowed = false;
TeleportCombatTime = 30;
AllowAcceptingWithKeys = true;
TeleportCost = new TeleportCost()
{
Enabled = false,
Expand Down
5 changes: 4 additions & 1 deletion Feli.RocketMod.Teleporting/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ protected override void Unload()

public override TranslationList DefaultTranslations => new TranslationList()
{
{"TpaCommand:WrongUsage", "Correct command usage: /tpa <accept|send|cancel>"},
{"TpaCommand:WrongUsage", "Correct command usage: /tpa <accept|send|cancel|list>"},
{"TpaCommand:WrongUsage:Send", "Correct command usage: /tpa send <playerName>"},
{"TpaCommand:WrongUsage:NotFound", "Player with name {0} was not found"},
{"TpaCommand:Send:Yourself", "There is no point on sending a tpa request to yourself"},
Expand All @@ -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}"},
Expand Down
47 changes: 46 additions & 1 deletion Feli.RocketMod.Teleporting/TeleportsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -316,6 +360,7 @@ public void Dispose()
_playersLastCombat = null;
_plugin = null;
_configuration = null;
PlayerAnimator.OnLeanChanged_Global -= OnLeanChanged;
DamageTool.onPlayerAllowedToDamagePlayer -= OnPlayerAllowedToDamagePlayer;
U.Events.OnPlayerDisconnected -= OnLeave;
}
Expand Down

0 comments on commit 3c321ef

Please sign in to comment.