From 8efdd0e6a8143e9dcf6559b8b17c38e05ae5ac0d Mon Sep 17 00:00:00 2001 From: Feli Date: Thu, 2 Dec 2021 12:25:57 -0300 Subject: [PATCH] Add message icon --- .../Commands/TpaCommand.cs | 19 +++++-- Feli.RocketMod.Teleporting/Configuration.cs | 3 + .../Feli.RocketMod.Teleporting.csproj | 4 +- Feli.RocketMod.Teleporting/Plugin.cs | 2 +- .../TeleportsManager.cs | 55 +++++++++++-------- 5 files changed, 52 insertions(+), 31 deletions(-) diff --git a/Feli.RocketMod.Teleporting/Commands/TpaCommand.cs b/Feli.RocketMod.Teleporting/Commands/TpaCommand.cs index 08425de..4e299f7 100644 --- a/Feli.RocketMod.Teleporting/Commands/TpaCommand.cs +++ b/Feli.RocketMod.Teleporting/Commands/TpaCommand.cs @@ -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 { @@ -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; } @@ -28,7 +30,7 @@ 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; } @@ -36,7 +38,7 @@ public void Execute(IRocketPlayer caller, string[] command) 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; } @@ -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"; diff --git a/Feli.RocketMod.Teleporting/Configuration.cs b/Feli.RocketMod.Teleporting/Configuration.cs index 1dfadab..45e0316 100644 --- a/Feli.RocketMod.Teleporting/Configuration.cs +++ b/Feli.RocketMod.Teleporting/Configuration.cs @@ -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; } @@ -18,6 +20,7 @@ public class Configuration : IRocketPluginConfiguration public void LoadDefaults() { MessageColor = "magenta"; + MessageIcon = Provider.configData.Browser.Icon; TeleportDelay = 5; TeleportCooldown = 60; CancelWhenMove = false; diff --git a/Feli.RocketMod.Teleporting/Feli.RocketMod.Teleporting.csproj b/Feli.RocketMod.Teleporting/Feli.RocketMod.Teleporting.csproj index 8877f50..79c0a7c 100644 --- a/Feli.RocketMod.Teleporting/Feli.RocketMod.Teleporting.csproj +++ b/Feli.RocketMod.Teleporting/Feli.RocketMod.Teleporting.csproj @@ -9,8 +9,8 @@ Properties Feli.RocketMod.Teleporting Feli.RocketMod.Teleporting - 1.3.0 - 1.3.0 + 1.4.0 + 1.4.0 v4.6.1 512 diff --git a/Feli.RocketMod.Teleporting/Plugin.cs b/Feli.RocketMod.Teleporting/Plugin.cs index af42baa..3fbfbce 100644 --- a/Feli.RocketMod.Teleporting/Plugin.cs +++ b/Feli.RocketMod.Teleporting/Plugin.cs @@ -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}"); } diff --git a/Feli.RocketMod.Teleporting/TeleportsManager.cs b/Feli.RocketMod.Teleporting/TeleportsManager.cs index fe13b78..85b512d 100644 --- a/Feli.RocketMod.Teleporting/TeleportsManager.cs +++ b/Feli.RocketMod.Teleporting/TeleportsManager.cs @@ -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; @@ -15,6 +14,7 @@ public class TeleportsManager : IDisposable { private Plugin _plugin; private Color _messageColor; + private string _messageIcon; private Configuration _configuration; private List> _teleportRequests; private Dictionary _cooldowns; @@ -29,6 +29,7 @@ public TeleportsManager(Plugin plugin) _cooldowns = new Dictionary(); _plugin = plugin; _configuration = plugin.Configuration.Instance; + _messageIcon = _configuration.MessageIcon; _messageColor = plugin.MessageColor; U.Events.OnPlayerDisconnected += OnLeave; DamageTool.onPlayerAllowedToDamagePlayer += OnPlayerAllowedToDamagePlayer; @@ -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; } @@ -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; } @@ -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; } } @@ -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) @@ -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; @@ -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); } @@ -137,7 +138,7 @@ 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; } @@ -145,8 +146,8 @@ public void Cancel(UnturnedPlayer player) _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 request) @@ -158,17 +159,18 @@ private bool ValidateRequest(Tuple 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; } @@ -182,8 +184,8 @@ private bool ValidateRequest(Tuple 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; } @@ -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); } @@ -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 { @@ -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;