Skip to content

Commit

Permalink
Add MessageIconUrl and rich text support
Browse files Browse the repository at this point in the history
  • Loading branch information
RestoreMonarchy committed Dec 28, 2024
1 parent f2a542a commit 52e2b7d
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 158 deletions.
58 changes: 30 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ The only permission this plugin has is `tpa` for all teleportation actions (send
<?xml version="1.0" encoding="utf-8"?>
<TeleportationConfiguration xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MessageColor>gray</MessageColor>
<MessageIconUrl>https://i.imgur.com/wr879ca.png</MessageIconUrl>
<TPACooldown>90</TPACooldown>
<TPADelay>3</TPADelay>
<TPADuration>90</TPADuration>
<AllowCave>false</AllowCave>
<AllowRaid>false</AllowRaid>
<RaidDuration>30</RaidDuration>
<AllowCombat>false</AllowCombat>
Expand All @@ -42,32 +42,34 @@ The only permission this plugin has is `tpa` for all teleportation actions (send
```xml
<?xml version="1.0" encoding="utf-8"?>
<Translations xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Translation Id="TargetNotFound" Value="Failed to find a target" />
<Translation Id="CombatStart" Value="Combat mode started" />
<Translation Id="CombatExpire" Value="Combat mode expired" />
<Translation Id="RaidStart" Value="Raid mode started" />
<Translation Id="RaidExpire" Value="Raid mode expired" />
<Translation Id="TPAHelp" Value="Use: /tpa &lt;player/accept/deny/cancel&gt;" />
<Translation Id="TPACooldown" Value="You have to wait {0} before you can send request again" />
<Translation Id="TPADuplicate" Value="You already sent a teleportation request to that player" />
<Translation Id="TPASent" Value="Successfully sent TPA request to {0}" />
<Translation Id="TPAReceive" Value="You received TPA request from {0}" />
<Translation Id="TPANoRequest" Value="There is no TPA requests to you" />
<Translation Id="TPAAccepted" Value="Successfully accepted TPA request from {0}" />
<Translation Id="TPADelay" Value="You will be teleported to {0} in {1} seconds" />
<Translation Id="TPAWhileCombat" Value="Teleportation canceled because {0} is in combat mode" />
<Translation Id="TPAWhileCombatYou" Value="Teleportation canceled because you are in combat mode" />
<Translation Id="TPAWhileRaid" Value="Teleportation canceled because {0} is in raid mode" />
<Translation Id="TPAWhileRaidYou" Value="Teleportation canceled because you are in raid mode" />
<Translation Id="TPADead" Value="Teleportation canceled because you or {0} is dead" />
<Translation Id="TPACave" Value="Teleportation canceled because {0} is in cave" />
<Translation Id="TPACaveYou" Value="Teleportation canceled because you are in cave" />
<Translation Id="TPANoSentRequest" Value="You did not send any TPA request" />
<Translation Id="TPACanceled" Value="Successfully canceled TPA request to {0}" />
<Translation Id="TPADenied" Value="Successfully denied TPA request from {0}" />
<Translation Id="TPASuccess" Value="You have been teleported to {0}" />
<Translation Id="TPAYourself" Value="You cannot send TPA request to yourself" />
<Translation Id="TPAVehicle" Value="Teleportation canceled because {0} is in vehicle" />
<Translation Id="TPAVehicleYou" Value="Teleportation canceled because you are in vehicle" />
<Translation Id="TargetNotFound" Value="Target not found" />
<Translation Id="CombatStart" Value="Combat mode activated" />
<Translation Id="CombatExpire" Value="Combat mode ended" />
<Translation Id="RaidStart" Value="Raid mode activated" />
<Translation Id="RaidExpire" Value="Raid mode ended" />
<Translation Id="TPAHelp" Value="[[b]]TPA Commands:[[/b]]&#xA;/tpa [[player]] - Send request&#xA;/tpa accept - Accept request&#xA;/tpa deny - Deny request&#xA;/tpa cancel - Cancel your request" />
<Translation Id="TPACooldown" Value="Please wait [[b]]{0}[[/b]] seconds before sending another request" />
<Translation Id="TPADuplicate" Value="You already have a pending request to this player" />
<Translation Id="TPASent" Value="TPA request sent to [[b]]{0}[[/b]]" />
<Translation Id="TPAReceive" Value="[[b]]{0}[[/b]] wants to teleport to you&#xA;Type [[b]]/tpa accept[[/b]] to allow" />
<Translation Id="TPANoRequest" Value="No pending TPA requests" />
<Translation Id="TPAAccepted" Value="Accepted [[b]]{0}'s[[/b]] TPA request" />
<Translation Id="TPADelay" Value="Teleporting to [[b]]{0}[[/b]] in [[b]]{1}[[/b]] seconds..." />
<Translation Id="TPAWhileCombat" Value="Teleport failed - [[b]]{0}[[/b]] is in combat" />
<Translation Id="TPAWhileCombatYou" Value="Teleport failed - You are in combat" />
<Translation Id="TPAWhileRaid" Value="Teleport failed - [[b]]{0}[[/b]] is in raid mode" />
<Translation Id="TPAWhileRaidYou" Value="Teleport failed - You are in raid mode" />
<Translation Id="TPADead" Value="Teleport failed - Player death detected" />
<Translation Id="TPACave" Value="Teleport failed - [[b]]{0}[[/b]] is in a cave" />
<Translation Id="TPACaveYou" Value="Teleport failed - You are in a cave" />
<Translation Id="TPAVehicle" Value="Teleport failed - [[b]]{0}[[/b]] is in a vehicle" />
<Translation Id="TPAVehicleYou" Value="Teleport failed - You are in a vehicle" />
<Translation Id="TPANoSentRequest" Value="You have no pending outgoing requests" />
<Translation Id="TPACanceled" Value="TPA request to [[b]]{0}[[/b]] canceled" />
<Translation Id="TPADenied" Value="Denied TPA request from [[b]]{0}[[/b]]" />
<Translation Id="TPACanceledSenderMoved" Value="Teleport canceled - [[b]]{0}[[/b]] moved" />
<Translation Id="TPACanceledYouMoved" Value="Teleport canceled - You moved" />
<Translation Id="TPASuccess" Value="Successfully teleported to [[b]]{0}[[/b]]" />
<Translation Id="TPAYourself" Value="You cannot send a TPA request to yourself" />
</Translations>
```
53 changes: 30 additions & 23 deletions Teleportation/Commands/TPACommand.cs
Original file line number Diff line number Diff line change
@@ -1,55 +1,62 @@
using RestoreMonarchy.Teleportation.Utils;
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using System.Collections.Generic;

namespace RestoreMonarchy.Teleportation.Commands
{
public class TPACommand : IRocketCommand
{
public AllowedCaller AllowedCaller => AllowedCaller.Player;

public string Name => "tpa";

public string Help => "Teleportation request command";

public string Syntax => "(player/accept/deny/cancel)";

public List<string> Aliases => new List<string>();

public List<string> Permissions => new List<string>();
private TeleportationPlugin pluginInstance => TeleportationPlugin.Instance;

public void Execute(IRocketPlayer caller, string[] command)
{
if (command.Length < 1)
{
UnturnedChat.Say(caller, TeleportationPlugin.Instance.Translate("TPAHelp"), TeleportationPlugin.Instance.MessageColor);
pluginInstance.SendMessageToPlayer(caller, "TPAHelp");
return;
}

UnturnedPlayer player = (UnturnedPlayer)caller;

string cmd = command[0].ToLower();

if (cmd == "accept" || cmd == "a")
{
TeleportationPlugin.Instance.AcceptTPARequest((UnturnedPlayer)caller);
} else if (cmd == "cancel" || cmd == "c")
pluginInstance.AcceptTPARequest(player);
}
else if (cmd == "cancel" || cmd == "c")
{
TeleportationPlugin.Instance.CancelTPARequest((UnturnedPlayer)caller);
} else if (cmd == "deny" || cmd == "d")
pluginInstance.CancelTPARequest(player);
}
else if (cmd == "deny" || cmd == "d")
{
TeleportationPlugin.Instance.DenyTPARequest((UnturnedPlayer)caller);
} else
pluginInstance.DenyTPARequest(player);
}
else
{
var target = UnturnedPlayer.FromName(cmd);
UnturnedPlayer target = UnturnedPlayer.FromName(cmd);
if (target != null)
{
TeleportationPlugin.Instance.SendTPARequest((UnturnedPlayer)caller, target);
} else
pluginInstance.SendTPARequest(player, target);
}
else
{
UnturnedChat.Say(caller, TeleportationPlugin.Instance.Translate("TargetNotFound"), TeleportationPlugin.Instance.MessageColor);
pluginInstance.SendMessageToPlayer(caller, "TargetNotFound");
}
}
}

public AllowedCaller AllowedCaller => AllowedCaller.Player;

public string Name => "tpa";

public string Help => "Teleportation request command";

public string Syntax => "(player/accept/deny/cancel)";

public List<string> Aliases => new List<string>();

public List<string> Permissions => new List<string>();
}
}
81 changes: 50 additions & 31 deletions Teleportation/Models/TPARequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using RestoreMonarchy.Teleportation.Utils;
using Rocket.Core.Utils;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using Steamworks;
using System;
Expand All @@ -9,19 +8,22 @@ namespace RestoreMonarchy.Teleportation.Models
{
public class TPARequest
{
private TeleportationPlugin plugin => TeleportationPlugin.Instance;
private TeleportationPlugin pluginInstance => TeleportationPlugin.Instance;

public TPARequest(CSteamID sender, CSteamID target)
{
Sender = sender;
Target = target;

double duration = plugin.Configuration.Instance.TPADuration;
double duration = pluginInstance.Configuration.Instance.TPADuration;
if (duration == 0)
{
duration = 30;
}
ExpireDate = DateTime.Now.AddSeconds(duration);

SenderPlayer = UnturnedPlayer.FromCSteamID(sender);
TargetPlayer = UnturnedPlayer.FromCSteamID(target);
}

public TPARequest() { }
Expand All @@ -31,22 +33,22 @@ public TPARequest() { }
public DateTime ExpireDate { get; set; }
public bool IsCanceled { get; private set; }

public UnturnedPlayer SenderPlayer => UnturnedPlayer.FromCSteamID(Sender);
public UnturnedPlayer TargetPlayer => UnturnedPlayer.FromCSteamID(Target);
public UnturnedPlayer SenderPlayer { get; set; }
public UnturnedPlayer TargetPlayer { get; set; }

public bool IsExpired => ExpireDate < DateTime.Now;

public void Execute(double delay)
{
{
if (delay > 0)
{
UnturnedChat.Say(Sender, plugin.Translate("TPADelay", TargetPlayer.DisplayName, delay), plugin.MessageColor);
if (plugin.Configuration.Instance.CancelOnMove)
pluginInstance.SendMessageToPlayer(SenderPlayer, "TPADelay", TargetPlayer.DisplayName, delay);
if (pluginInstance.Configuration.Instance.CancelOnMove)
{
plugin.MovementDetector.AddPlayer(SenderPlayer.Player, () =>
pluginInstance.MovementDetector.AddPlayer(SenderPlayer.Player, () =>
{
UnturnedChat.Say(Sender, plugin.Translate("TPACanceledYouMoved"), plugin.MessageColor);
UnturnedChat.Say(Target, plugin.Translate("TPACanceledSenderMoved", SenderPlayer.DisplayName), plugin.MessageColor);
pluginInstance.SendMessageToPlayer(SenderPlayer, "TPACanceledYouMoved");
pluginInstance.SendMessageToPlayer(TargetPlayer, "TPACanceledSenderMoved", SenderPlayer.DisplayName);
Cancel();
});
}
Expand All @@ -55,66 +57,83 @@ public void Execute(double delay)
TaskDispatcher.QueueOnMainThread(() =>
{
if (IsCanceled)
{
return;
}

plugin.MovementDetector.RemovePlayer(SenderPlayer.Player);
pluginInstance.MovementDetector.RemovePlayer(SenderPlayer.Player);

if (!Validate(true))
{
plugin.Cooldowns.Remove(Sender);
pluginInstance.Cooldowns.Remove(Sender);
return;
}

if (plugin.Configuration.Instance.UseUnsafeTeleport)
if (pluginInstance.Configuration.Instance.UseUnsafeTeleport)
{
SenderPlayer.Player.teleportToLocationUnsafe(TargetPlayer.Position, TargetPlayer.Rotation);
} else
{
SenderPlayer.Teleport(TargetPlayer);
}
UnturnedChat.Say(Sender, plugin.Translate("TPASuccess", TargetPlayer.DisplayName), plugin.MessageColor);
}

pluginInstance.SendMessageToPlayer(SenderPlayer, "TPASuccess", TargetPlayer.DisplayName);

}, (float)delay);
}

public bool Validate(bool isFinal = false)
{
var plugin = TeleportationPlugin.Instance;
var pluginInstance = TeleportationPlugin.Instance;

if (plugin.IsPlayerInCombat(SenderPlayer.CSteamID))
if (pluginInstance.IsPlayerInCombat(SenderPlayer.CSteamID))
{
UnturnedChat.Say(SenderPlayer, plugin.Translate("TPAWhileCombatYou"), plugin.MessageColor);
pluginInstance.SendMessageToPlayer(SenderPlayer, "TPAWhileCombatYou");
if (isFinal)
UnturnedChat.Say(TargetPlayer, plugin.Translate("TPAWhileCombat", SenderPlayer.DisplayName), plugin.MessageColor);
{
pluginInstance.SendMessageToPlayer(TargetPlayer, "TPAWhileCombat", SenderPlayer.DisplayName);
}

return false;
}
else if (plugin.IsPlayerInRaid(SenderPlayer.CSteamID))
else if (pluginInstance.IsPlayerInRaid(SenderPlayer.CSteamID))
{
UnturnedChat.Say(SenderPlayer, plugin.Translate("TPAWhileRaidYou"), plugin.MessageColor);
pluginInstance.SendMessageToPlayer(SenderPlayer, "TPAWhileRaidYou");
if (isFinal)
UnturnedChat.Say(TargetPlayer, plugin.Translate("TPAWhileRaid", SenderPlayer.DisplayName), plugin.MessageColor);
{
pluginInstance.SendMessageToPlayer(TargetPlayer, "TPAWhileRaid", SenderPlayer.DisplayName);
}

return false;
}
else if (SenderPlayer.Dead || (TargetPlayer.Dead && isFinal))
{
UnturnedChat.Say(SenderPlayer, plugin.Translate("TPADead", TargetPlayer.DisplayName), plugin.MessageColor);
pluginInstance.SendMessageToPlayer(SenderPlayer, "TPADead", TargetPlayer.DisplayName);
if (isFinal)
UnturnedChat.Say(TargetPlayer, plugin.Translate("TPADead", SenderPlayer.DisplayName), plugin.MessageColor);
{
pluginInstance.SendMessageToPlayer(TargetPlayer, "TPADead", SenderPlayer.DisplayName);
}

return false;
}
else if (plugin.IsPlayerInCave(TargetPlayer))
else if (pluginInstance.IsPlayerInCave(TargetPlayer))
{
UnturnedChat.Say(SenderPlayer, plugin.Translate("TPACave", TargetPlayer.DisplayName), plugin.MessageColor);
pluginInstance.SendMessageToPlayer(SenderPlayer, "TPACave", TargetPlayer.DisplayName);
if (isFinal)
UnturnedChat.Say(TargetPlayer, plugin.Translate("TPACaveYou", SenderPlayer.DisplayName), plugin.MessageColor);
{
pluginInstance.SendMessageToPlayer(TargetPlayer, "TPACaveYou", SenderPlayer.DisplayName);
}

return false;
}
else if (SenderPlayer.IsInVehicle)
{
UnturnedChat.Say(SenderPlayer, plugin.Translate("TPAVehicleYou"), plugin.MessageColor);
pluginInstance.SendMessageToPlayer(SenderPlayer, "TPAVehicleYou");
if (isFinal)
UnturnedChat.Say(TargetPlayer, plugin.Translate("TPAVehicle", SenderPlayer.DisplayName), plugin.MessageColor);
{
pluginInstance.SendMessageToPlayer(TargetPlayer, "TPAVehicle", SenderPlayer.DisplayName);
}

return false;
}

Expand Down
2 changes: 1 addition & 1 deletion Teleportation/Teleportation.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net48</TargetFramework>
<LangVersion>latest</LangVersion>
<RootNamespace>RestoreMonarchy.Teleportation</RootNamespace>
<Version>1.8.1</Version>
<Version>1.8.2</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions Teleportation/TeleportationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace RestoreMonarchy.Teleportation
public class TeleportationConfiguration : IRocketPluginConfiguration
{
public string MessageColor { get; set; }
public string MessageIconUrl { get; set; } = "https://i.imgur.com/wr879ca.png";
public double TPACooldown { get; set; }
public double TPADelay { get; set; }
public double TPADuration { get; set; }
Expand All @@ -21,6 +22,7 @@ public class TeleportationConfiguration : IRocketPluginConfiguration
public void LoadDefaults()
{
MessageColor = "gray";
MessageIconUrl = "https://i.imgur.com/wr879ca.png";
TPACooldown = 90;
TPADelay = 3;
TPADuration = 90;
Expand Down
Loading

0 comments on commit 52e2b7d

Please sign in to comment.