Skip to content

Commit

Permalink
Dont teleport if the player is dead
Browse files Browse the repository at this point in the history
Closes: #3
  • Loading branch information
negrifelipe committed Jan 30, 2022
1 parent 994cc2e commit a9ca787
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
11 changes: 11 additions & 0 deletions Feli.OpenMod.Teleporting/Services/TeleportsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ private async Task<bool> ValidateRequest(Tuple<UnturnedUser, UnturnedUser> reque
return false;
}

if (!sender.Player.IsAlive || !target.Player.IsAlive)
{
var dead = !sender.Player.IsAlive ? sender : target;
var alive = sender.Player.IsAlive ? sender : target;

await Say(dead, _stringLocalizer["tpaValidation:dead:dead"]);
await Say(alive, _stringLocalizer["tpaValidation:dead:alive", dead.DisplayName]);

return false;
}

if (_configuration.GetSection("teleportCost:enabled").Get<bool>())
{
var balance = await _economyProvider.GetBalanceAsync(sender.Id, KnownActorTypes.Player);
Expand Down
6 changes: 5 additions & 1 deletion Feli.OpenMod.Teleporting/translations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,8 @@ tpaValidation:

balance:
sender: "You dont have enough balance to teleport. Teleport cost: {0}"
target: "The teleport was cancelled because {0} does not have enough balance"
target: "The teleport was cancelled because {0} does not have enough balance"

dead:
alive: "The teleport was cancelled because {0} is dead"
dead: "The teleport was cancelled because you died"
6 changes: 4 additions & 2 deletions Feli.RocketMod.Teleporting/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected override void Load()
? new ExperienceEconomyProvider() as IEconomyProvider
: new UconomyEconomyProvider();

Logger.Log($"Teleporting plugin v1.6.1 loaded !");
Logger.Log($"Teleporting plugin v1.6.2 loaded !");
Logger.Log("Do you want more cool plugins? Join now: https://discord.gg/4FF2548 !");
Logger.Log($"Economy Provider: {EconomyProvider.GetType().Name}");
}
Expand Down Expand Up @@ -65,7 +65,9 @@ protected override void Unload()
{"TpaValidation:Combat:Sender", "The teleport was cancelled because you are in combat. The combat mode expires in {0} seconds"},
{"TpaValidation:Combat:Target", "The teleport was cancelled because {0} is in combat"},
{"TpaValidation:Balance:Sender", "You dont have enough balance to teleport. Teleport cost: {0}"},
{"TpaValidation:Balance:Target", "The teleport was cancelled because {0} does not have enough balance"}
{"TpaValidation:Balance:Target", "The teleport was cancelled because {0} does not have enough balance"},
{"TpaValidation:Dead:Alive", "The teleport was cancelled because {0} is dead" },
{"TpaValidation:Dead:Dead", "The teleport was cancelled because you died" }
};
}
}
5 changes: 3 additions & 2 deletions Feli.RocketMod.Teleporting/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("795C0322-F7CE-4896-B0E7-09B37D0F8440")]
[assembly: AssemblyVersion("1.5.*")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: AssemblyInformationalVersion("1.6.2")]
[assembly: AssemblyVersion("1.6.2")]
[assembly: AssemblyFileVersion("1.6.2")]
11 changes: 11 additions & 0 deletions Feli.RocketMod.Teleporting/TeleportsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,17 @@ private bool ValidateRequest(Tuple<UnturnedPlayer, UnturnedPlayer> request)
return false;
}

if(sender.Dead || target.Dead)
{
var dead = sender.Dead ? sender : target;
var alive = !sender.Dead ? sender : target;

Say(dead, _plugin.Translate("TpaValidation:Dead:Dead"), _messageColor, _messageIcon);
Say(alive, _plugin.Translate("TpaValidation:Dead:Alive", dead.DisplayName), _messageColor, _messageIcon);

return false;
}

if (_configuration.TeleportCost.Enabled && _plugin.EconomyProvider.GetBalance(sender.Id) < _configuration.TeleportCost.TpaCost)
{
Say(sender, _plugin.Translate("TpaValidation:Balance:Sender", _configuration.TeleportCost.TpaCost), _messageColor, _messageIcon);
Expand Down

0 comments on commit a9ca787

Please sign in to comment.