Skip to content

Commit

Permalink
Add message icon
Browse files Browse the repository at this point in the history
  • Loading branch information
negrifelipe committed Dec 2, 2021
1 parent 247c250 commit 8efdd0e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 31 deletions.
19 changes: 14 additions & 5 deletions Feli.RocketMod.Teleporting/Commands/TpaCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System.Collections.Generic;
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using SDG.Unturned;
using UnityEngine;

namespace Feli.RocketMod.Teleporting.Commands
{
Expand All @@ -11,10 +12,11 @@ public void Execute(IRocketPlayer caller, string[] command)
{
var plugin = Plugin.Instance;
var messageColor = plugin.MessageColor;
var messageIcon = plugin.Configuration.Instance.MessageIcon;

if (command.Length < 1)
{
UnturnedChat.Say(caller, plugin.Translate("TpaCommand:WrongUsage"), messageColor, true);
Say(caller, plugin.Translate("TpaCommand:WrongUsage"), messageColor, messageIcon);
return;
}

Expand All @@ -28,15 +30,15 @@ public void Execute(IRocketPlayer caller, string[] command)
{
if (command.Length < 2)
{
UnturnedChat.Say(caller, plugin.Translate("TpaCommand:WrongUsage:Send"), messageColor, true);
Say(caller, plugin.Translate("TpaCommand:WrongUsage:Send"), messageColor, messageIcon);
return;
}

var target = UnturnedPlayer.FromName(command[1]);

if (target == null)
{
UnturnedChat.Say(caller, plugin.Translate("TpaCommand:WrongUsage:NotFound", command[1]), messageColor, true);
Say(caller, plugin.Translate("TpaCommand:WrongUsage:NotFound", command[1]), messageColor, messageIcon);
return;
}

Expand All @@ -48,10 +50,17 @@ public void Execute(IRocketPlayer caller, string[] command)
teleportsManager.Cancel(player);
else
{
UnturnedChat.Say(caller, plugin.Translate("TpaCommand:WrongUsage"), messageColor, true);
Say(caller, plugin.Translate("TpaCommand:WrongUsage"), messageColor, messageIcon);
}
}

private void Say(IRocketPlayer rocketPlayer, string message, Color messageColor, string icon = null)
{
var player = rocketPlayer as UnturnedPlayer;

ChatManager.serverSendMessage(message, messageColor, toPlayer: player.SteamPlayer(), mode: EChatMode.SAY, iconURL: icon, useRichTextFormatting: true);
}

public AllowedCaller AllowedCaller => AllowedCaller.Player;
public string Name => "tpa";
public string Help => "Send, accept, deny and cancel teleport requests";
Expand Down
3 changes: 3 additions & 0 deletions Feli.RocketMod.Teleporting/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Feli.RocketMod.Teleporting.Economy.Configuration;
using Rocket.API;
using SDG.Unturned;

namespace Feli.RocketMod.Teleporting
{
public class Configuration : IRocketPluginConfiguration
{
public string MessageColor { get; set; }
public string MessageIcon { get; set; }
public float TeleportDelay { get; set; }
public double TeleportCooldown { get; set; }
public bool CancelWhenMove { get; set; }
Expand All @@ -18,6 +20,7 @@ public class Configuration : IRocketPluginConfiguration
public void LoadDefaults()
{
MessageColor = "magenta";
MessageIcon = Provider.configData.Browser.Icon;
TeleportDelay = 5;
TeleportCooldown = 60;
CancelWhenMove = false;
Expand Down
4 changes: 2 additions & 2 deletions Feli.RocketMod.Teleporting/Feli.RocketMod.Teleporting.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Feli.RocketMod.Teleporting</RootNamespace>
<AssemblyName>Feli.RocketMod.Teleporting</AssemblyName>
<AssemblyVersion>1.3.0</AssemblyVersion>
<Version>1.3.0</Version>
<AssemblyVersion>1.4.0</AssemblyVersion>
<Version>1.4.0</Version>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion 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.3.0 loaded !");
Logger.Log($"Teleporting plugin v1.4.0 loaded !");
Logger.Log("Do you want more cool plugins? Join now: https://discord.gg/4FF2548 !");
Logger.Log($"Economy Provider: {EconomyProvider.GetType().Name}");
}
Expand Down
55 changes: 32 additions & 23 deletions Feli.RocketMod.Teleporting/TeleportsManager.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.Eventing.Reader;
using System.Linq;
using Rocket.API;
using Rocket.Core.Utils;
using Rocket.Unturned;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using SDG.Unturned;
using UnityEngine;
Expand All @@ -15,6 +14,7 @@ public class TeleportsManager : IDisposable
{
private Plugin _plugin;
private Color _messageColor;
private string _messageIcon;
private Configuration _configuration;
private List<Tuple<UnturnedPlayer, UnturnedPlayer>> _teleportRequests;
private Dictionary<UnturnedPlayer, DateTime> _cooldowns;
Expand All @@ -29,6 +29,7 @@ public TeleportsManager(Plugin plugin)
_cooldowns = new Dictionary<UnturnedPlayer, DateTime>();
_plugin = plugin;
_configuration = plugin.Configuration.Instance;
_messageIcon = _configuration.MessageIcon;
_messageColor = plugin.MessageColor;
U.Events.OnPlayerDisconnected += OnLeave;
DamageTool.onPlayerAllowedToDamagePlayer += OnPlayerAllowedToDamagePlayer;
Expand All @@ -38,7 +39,7 @@ public void Send(UnturnedPlayer sender, UnturnedPlayer target)
{
if (sender.Equals(target))
{
UnturnedChat.Say(sender, _plugin.Translate("TpaCommand:Send:Yourself"), _messageColor, true);
Say(sender, _plugin.Translate("TpaCommand:Send:Yourself"), _messageColor, _messageIcon);
return;
}

Expand All @@ -56,7 +57,7 @@ public void Send(UnturnedPlayer sender, UnturnedPlayer target)
if (cooldownTime > DateTime.Now)
{
var waitTime = (cooldownTime - DateTime.Now).TotalSeconds;
UnturnedChat.Say(sender, _plugin.Translate("TpaCommand:Send:Cooldown", Math.Round(waitTime)), _messageColor, true);
Say(sender, _plugin.Translate("TpaCommand:Send:Cooldown", Math.Round(waitTime)), _messageColor, _messageIcon);
return;
}

Expand All @@ -69,7 +70,7 @@ public void Send(UnturnedPlayer sender, UnturnedPlayer target)
if (combatTime > DateTime.Now)
{
var waitTime = (combatTime - DateTime.Now).TotalSeconds;
UnturnedChat.Say(sender, _plugin.Translate("TpaCommand:Send:Combat", Math.Round(waitTime)), true);
Say(sender, _plugin.Translate("TpaCommand:Send:Combat", Math.Round(waitTime)), _messageColor, _messageIcon);
return;
}
}
Expand All @@ -80,8 +81,8 @@ public void Send(UnturnedPlayer sender, UnturnedPlayer target)

_teleportRequests.Add(request);

UnturnedChat.Say(sender, _plugin.Translate("TpaCommand:Send:Sender", target.DisplayName), _messageColor, true);
UnturnedChat.Say(target, _plugin.Translate("TpaCommand:Send:Target", sender.DisplayName), _messageColor, true);
Say(sender, _plugin.Translate("TpaCommand:Send:Sender", target.DisplayName), _messageColor, _messageIcon);
Say(target, _plugin.Translate("TpaCommand:Send:Target", sender.DisplayName), _messageColor, _messageIcon);
}

public void Accept(UnturnedPlayer target)
Expand All @@ -90,16 +91,16 @@ public void Accept(UnturnedPlayer target)

if (request == null)
{
UnturnedChat.Say(target, _plugin.Translate("TpaCommand:Accept:NoRequests"), _messageColor, true);
Say(target , _plugin.Translate("TpaCommand:Accept:NoRequests"), _messageColor, _messageIcon);
return;
}

var sender = request.Item1;

UnturnedChat.Say(target, _plugin.Translate("TpaCommand:Accept:Success", sender.DisplayName), _messageColor, true);
Say(target, _plugin.Translate("TpaCommand:Accept:Success", sender.DisplayName), _messageColor, _messageIcon);
if (_configuration.TeleportDelay > 0)
{
UnturnedChat.Say(sender, _plugin.Translate("TpaCommand:Accept:Delay", target.DisplayName, _configuration.TeleportDelay), _messageColor, true);
Say(sender, _plugin.Translate("TpaCommand:Accept:Delay", target.DisplayName, _configuration.TeleportDelay), _messageColor, _messageIcon);
}

var senderPosition = sender.Position;
Expand Down Expand Up @@ -127,7 +128,7 @@ public void Accept(UnturnedPlayer target)
sender.Player.teleportToLocationUnsafe(target.Position, target.Player.look.yaw);
_teleportRequests.Remove(request);

UnturnedChat.Say(sender, _plugin.Translate("TpaCommand:Accept:Teleported", target.DisplayName), _messageColor, true);
Say(sender, _plugin.Translate("TpaCommand:Accept:Teleported", target.DisplayName), _messageColor, _messageIcon);
}, _configuration.TeleportDelay);
}

Expand All @@ -137,16 +138,16 @@ public void Cancel(UnturnedPlayer player)

if (request == null)
{
UnturnedChat.Say(player, _plugin.Translate("TpaCommand:Cancel:NotRequests"), _messageColor, true);
Say(player, _plugin.Translate("TpaCommand:Cancel:NotRequests"), _messageColor, _messageIcon);
return;
}

var other = request.Item2.Equals(player) ? request.Item1 : request.Item2;

_teleportRequests.Remove(request);

UnturnedChat.Say(player, _plugin.Translate("TpaCommand:Cancel:Success", other.DisplayName), _messageColor, true);
UnturnedChat.Say(other, _plugin.Translate("TpaCommand:Cancel:Other", player.DisplayName), _messageColor, true);
Say(player, _plugin.Translate("TpaCommand:Cancel:Success", other.DisplayName), _messageColor, _messageIcon);
Say(other, _plugin.Translate("TpaCommand:Cancel:Other", player.DisplayName), _messageColor, _messageIcon);
}

private bool ValidateRequest(Tuple<UnturnedPlayer, UnturnedPlayer> request)
Expand All @@ -158,17 +159,18 @@ private bool ValidateRequest(Tuple<UnturnedPlayer, UnturnedPlayer> request)
{
var problem = sender.CurrentVehicle != null ? sender : target;

UnturnedChat.Say(problem, _plugin.Translate("TpaValidation:Car:Self"), _messageColor, true);
UnturnedChat.Say(sender, _plugin.Translate("TpaValidation:Car:Other", problem.DisplayName),
_messageColor, true);
Say(problem, _plugin.Translate("TpaValidation:Car:Self"), _messageColor, _messageIcon);
Say(sender, _plugin.Translate("TpaValidation:Car:Other", problem.DisplayName),
_messageColor, _messageIcon);

return false;
}

if (_configuration.TeleportCost.Enabled && _plugin.EconomyProvider.GetBalance(sender.Id) < _configuration.TeleportCost.TpaCost)
{
UnturnedChat.Say(sender, _plugin.Translate("TpaValidation:Balance:Sender", _configuration.TeleportCost.TpaCost), _messageColor, true);
UnturnedChat.Say(target, _plugin.Translate("TpaValidation:Balance:Target", sender.DisplayName), _messageColor, true);
Say(sender, _plugin.Translate("TpaValidation:Balance:Sender", _configuration.TeleportCost.TpaCost), _messageColor, _messageIcon);
Say(target, _plugin.Translate("TpaValidation:Balance:Target", sender.DisplayName), _messageColor, _messageIcon);

return false;
}

Expand All @@ -182,8 +184,8 @@ private bool ValidateRequest(Tuple<UnturnedPlayer, UnturnedPlayer> request)
{
var waitTime = (combatTime - DateTime.Now).TotalSeconds;

UnturnedChat.Say(sender, _plugin.Translate("TpaValidation:Combat:Sender", Math.Round(waitTime)), true);
UnturnedChat.Say(target, _plugin.Translate("TpaValidation:Combat:Target", sender.DisplayName), true);
Say(sender, _plugin.Translate("TpaValidation:Combat:Sender", Math.Round(waitTime)), _messageColor, _messageIcon);
Say(target, _plugin.Translate("TpaValidation:Combat:Target", sender.DisplayName), _messageColor, _messageIcon);

return false;
}
Expand All @@ -200,7 +202,7 @@ private void OnLeave(UnturnedPlayer player)
{
var other = request.Item1.Equals(player) ? request.Item2 : request.Item1;

UnturnedChat.Say(other, _plugin.Translate("TpaValidation:Leave", player.DisplayName), _messageColor, true);
Say(other, _plugin.Translate("TpaValidation:Leave", player.DisplayName), _messageColor, _messageIcon);
_teleportRequests.Remove(request);
}

Expand Down Expand Up @@ -242,7 +244,7 @@ private void OnPlayerAllowedToDamagePlayer(Player nativeInstigator, Player nativ
isAllowed = false;
var waitTime = (teleportProtectionTime - DateTime.Now).TotalSeconds;

UnturnedChat.Say(instigator, _plugin.Translate("TpaProtection", Math.Round(waitTime), victim.DisplayName), true);
Say(instigator, _plugin.Translate("TpaProtection", Math.Round(waitTime), victim.DisplayName), _messageColor, _messageIcon);
}
else
{
Expand Down Expand Up @@ -299,6 +301,13 @@ private DateTime GetCooldown(UnturnedPlayer player)
return DateTime.MinValue;
}

private void Say(IRocketPlayer rocketPlayer, string message, Color messageColor, string icon = null)
{
var player = rocketPlayer as UnturnedPlayer;

ChatManager.serverSendMessage(message, messageColor, toPlayer: player.SteamPlayer(), mode: EChatMode.SAY, iconURL: icon, useRichTextFormatting: true);
}

public void Dispose()
{
_teleportRequests = null;
Expand Down

0 comments on commit 8efdd0e

Please sign in to comment.