Skip to content

Commit

Permalink
Add rich text support and remove "x player homes data has been saved!…
Browse files Browse the repository at this point in the history
…" log
  • Loading branch information
RestoreMonarchy committed Oct 18, 2024
1 parent 7b00124 commit 314045b
Show file tree
Hide file tree
Showing 21 changed files with 119 additions and 116 deletions.
13 changes: 6 additions & 7 deletions MoreHomes/Commands/DestroyHomeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,37 @@
using Rocket.Unturned.Player;
using System.Collections.Generic;
using System.Linq;
using Rocket.Unturned.Chat;
using RestoreMonarchy.MoreHomes.Models;
using RestoreMonarchy.MoreHomes.Helpers;

namespace RestoreMonarchy.MoreHomes.Commands
{
public class DestroyHomeCommand : IRocketCommand
{
private MoreHomesPlugin pluginInstance => MoreHomesPlugin.Instance;
private MoreHomesPlugin pluginInstance => MoreHomesPlugin.Instance;

public void Execute(IRocketPlayer caller, string[] command)
{
UnturnedPlayer player = (UnturnedPlayer)caller;
string homeName = command.ElementAtOrDefault(0);

if (string.IsNullOrEmpty(homeName))
{
UnturnedChat.Say(caller, pluginInstance.Translate("DestroyHomeFormat"), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(caller, "DestroyHomeFormat");
return;
}

PlayerHome home = HomesHelper.GetPlayerHome(player.CSteamID, homeName);
if (home == null)
{
UnturnedChat.Say(caller, pluginInstance.Translate("HomeNotFound", home.Name), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(caller, "HomeNotFound", homeName);
return;
}

HomesHelper.RemoveHome(player.CSteamID, home);
home.Destroy();

UnturnedChat.Say(caller, pluginInstance.Translate("DestroyHomeSuccess", home.Name), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(caller, "DestroyHomeSuccess", home.Name);
}

public AllowedCaller AllowedCaller => AllowedCaller.Player;
Expand All @@ -48,4 +47,4 @@ public void Execute(IRocketPlayer caller, string[] command)

public List<string> Permissions => new List<string>();
}
}
}
31 changes: 15 additions & 16 deletions MoreHomes/Commands/HomeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Rocket.API;
using System.Collections.Generic;
using System.Linq;
using Rocket.Unturned.Chat;
using Rocket.Core.Utils;
using Rocket.Unturned.Player;
using SDG.Unturned;
Expand All @@ -11,7 +10,6 @@
using System;
using RestoreMonarchy.MoreHomes.Helpers;
using UnityEngine;
using System.Threading;

namespace RestoreMonarchy.MoreHomes.Commands
{
Expand All @@ -26,17 +24,18 @@ public void Execute(IRocketPlayer caller, string[] command)

if (home == null)
{
UnturnedChat.Say(caller, pluginInstance.Translate("NoHome"), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(caller, "NoHome");
return;
}

if (!ValidateTeleportation(player, home))
{
return;
}

if (pluginInstance.PlayerCooldowns.TryGetValue(caller.Id, out DateTime cooldownExpire) && cooldownExpire > DateTime.Now)
{
UnturnedChat.Say(caller, pluginInstance.Translate("HomeCooldown", System.Math.Round((cooldownExpire - DateTime.Now).TotalSeconds)),
pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(caller, "HomeCooldown", Math.Round((cooldownExpire - DateTime.Now).TotalSeconds));
return;
}

Expand All @@ -46,7 +45,7 @@ public void Execute(IRocketPlayer caller, string[] command)

if (delay > 0)
{
UnturnedChat.Say(caller, pluginInstance.Translate("HomeDelayWarn", delay), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(caller, "HomeDelayWarn", delay);
}

bool shouldCancel = false;
Expand All @@ -56,9 +55,9 @@ public void Execute(IRocketPlayer caller, string[] command)
pluginInstance.MovementDetector.AddPlayer(player.Player, () =>
{
shouldCancel = true;
UnturnedChat.Say(player, pluginInstance.Translate("HomeCanceledYouMoved"), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(player, "HomeCanceledYouMoved");
});
}
}

TaskDispatcher.QueueOnMainThread(() =>
{
Expand All @@ -80,11 +79,11 @@ public void Execute(IRocketPlayer caller, string[] command)
if (!player.Player.teleportToLocation(home.LivePosition + new Vector3(0f, pluginInstance.Configuration.Instance.TeleportHeight, 0f), player.Rotation))
{
UnturnedChat.Say(caller, pluginInstance.Translate("HomeTeleportationFailed", home.Name), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(caller, "HomeTeleportationFailed", home.Name);
pluginInstance.PlayerCooldowns.Remove(caller.Id);
return;
}
UnturnedChat.Say(caller, pluginInstance.Translate("HomeSuccess", home.Name), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(caller, "HomeSuccess", home.Name);
}, delay);
}

Expand All @@ -93,13 +92,13 @@ private bool ValidateTeleportation(UnturnedPlayer player, PlayerHome home)
if (home.InteractableBed == null || !home.InteractableBed.isActiveAndEnabled || home.InteractableBed.owner != player.CSteamID)
{
HomesHelper.RemoveHome(player.CSteamID, home);
UnturnedChat.Say(player, pluginInstance.Translate("BedDestroyed"), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(player, "BedDestroyed");
return false;
}

if (player.Stance == EPlayerStance.DRIVING)
{
UnturnedChat.Say(player, pluginInstance.Translate("WhileDriving"), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(player, "WhileDriving");
return false;
}

Expand All @@ -116,18 +115,18 @@ private bool ValitedateRaidAndCombat(UnturnedPlayer player)
TeleportationPlugin teleportation = pluginInstance.TeleportationPlugin as TeleportationPlugin;
if (teleportation.IsPlayerInCombat(player.CSteamID))
{
UnturnedChat.Say(player, pluginInstance.Translate("WhileCombat"), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(player, "WhileCombat");
return false;
}

if (teleportation.IsPlayerInRaid(player.CSteamID))
{
UnturnedChat.Say(player, pluginInstance.Translate("WhileRaid"), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(player, "WhileRaid");
return false;
}
return true;
}

public AllowedCaller AllowedCaller => AllowedCaller.Player;

public string Name => "home";
Expand All @@ -140,4 +139,4 @@ private bool ValitedateRaidAndCombat(UnturnedPlayer player)

public List<string> Permissions => new List<string>();
}
}
}
13 changes: 6 additions & 7 deletions MoreHomes/Commands/HomesCommand.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using RestoreMonarchy.MoreHomes.Helpers;
using RestoreMonarchy.MoreHomes.Models;
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using System.Collections.Generic;
using System.Text;
Expand All @@ -14,24 +13,24 @@ public class HomesCommand : IRocketCommand
public void Execute(IRocketPlayer caller, string[] command)
{
UnturnedPlayer player = (UnturnedPlayer)caller;

PlayerData playerData = HomesHelper.GetOrCreatePlayer(player.CSteamID);

if (playerData.Homes.Count == 0)
{
UnturnedChat.Say(caller, pluginInstance.Translate("NoHomes"), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(caller, "NoHomes");
return;
}

StringBuilder sb = new StringBuilder(pluginInstance.Translate("HomeList", playerData.Homes.Count, VipHelper.GetPlayerMaxHomes(player.Id)));

foreach (PlayerHome home in playerData.Homes)
{
sb.Append($"{home.Name}, ");
}
string msg = sb.ToString().TrimEnd(',', ' ');

UnturnedChat.Say(caller, msg, pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(caller, msg);
}

public AllowedCaller AllowedCaller => AllowedCaller.Player;
Expand All @@ -44,6 +43,6 @@ public void Execute(IRocketPlayer caller, string[] command)

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

public List<string> Permissions => new List<string>();
public List<string> Permissions => new List<string>();
}
}
}
11 changes: 5 additions & 6 deletions MoreHomes/Commands/RenameHomeCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using System.Collections.Generic;
using RestoreMonarchy.MoreHomes.Helpers;
Expand All @@ -15,25 +14,25 @@ public void Execute(IRocketPlayer caller, string[] command)
UnturnedPlayer player = (UnturnedPlayer)caller;
if (command.Length < 2)
{
UnturnedChat.Say(caller, pluginInstance.Translate("RenameHomeFormat"));
pluginInstance.SendMessageToPlayer(caller, "RenameHomeFormat");
return;
}

var home = HomesHelper.GetPlayerHome(player.CSteamID, command[0]);
if (home == null)
{
UnturnedChat.Say(player, pluginInstance.Translate("HomeNotFound", command[0]), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(player, "HomeNotFound", command[0]);
return;
}

if (HomesHelper.GetPlayerHome(player.CSteamID, command[1]) != null)
{
UnturnedChat.Say(player, pluginInstance.Translate("RenameHomeFail", command[1]), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(player, "RenameHomeFail", command[1]);
return;
}

home.Name = command[1];
UnturnedChat.Say(player, pluginInstance.Translate("RenameHomeSuccess", command[0], command[1]), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(player, "RenameHomeSuccess", command[0], command[1]);
}

public AllowedCaller AllowedCaller => AllowedCaller.Player;
Expand All @@ -48,4 +47,4 @@ public void Execute(IRocketPlayer caller, string[] command)

public List<string> Permissions => new List<string>();
}
}
}
6 changes: 3 additions & 3 deletions MoreHomes/Commands/RestoreHomesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ public void Execute(IRocketPlayer caller, string[] command)
InteractableBed interactableBed = drop.interactable as InteractableBed;
if (interactableBed != null && interactableBed.isClaimed)
{
var player = HomesHelper.GetOrCreatePlayer(interactableBed.owner);
var playerHome = new PlayerHome(player.GetUniqueHomeName(), interactableBed);
PlayerData player = HomesHelper.GetOrCreatePlayer(interactableBed.owner);
PlayerHome playerHome = new PlayerHome(player.GetUniqueHomeName(), interactableBed);
player.Homes.Add(playerHome);
num++;
}
}
}
pluginInstance.DataService.SaveData();
UnturnedChat.Say(caller, pluginInstance.Translate("RestoreHomesSuccess", num), pluginInstance.MessageColor);
pluginInstance.SendMessageToPlayer(caller, "RestoreHomesSuccess", num.ToString("N0"));
}

public AllowedCaller AllowedCaller => AllowedCaller.Console;
Expand Down
39 changes: 2 additions & 37 deletions MoreHomes/MoreHomes.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,19 @@
<TargetFramework>net48</TargetFramework>
<LangVersion>latest</LangVersion>
<RootNamespace>RestoreMonarchy.MoreHomes</RootNamespace>
<Version>1.9.0</Version>
<Version>1.10.0</Version>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Lib.Harmony" Version="2.2.2" />
<PackageReference Include="RestoreMonarchy.RocketRedist" Version="3.24.6" ExcludeAssets="runtime" />
</ItemGroup>

<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\lib\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="com.rlabrecque.steamworks.net">
<HintPath>..\lib\com.rlabrecque.steamworks.net.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\lib\Newtonsoft.Json.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Rocket.API">
<HintPath>..\lib\Rocket.API.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Rocket.Core">
<HintPath>..\lib\Rocket.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Rocket.Unturned">
<HintPath>..\lib\Rocket.Unturned.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="SDG.NetTransport">
<HintPath>..\lib\SDG.NetTransport.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Teleportation">
<HintPath>..\lib\Teleportation.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine">
<HintPath>..\lib\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="UnityEngine.CoreModule">
<HintPath>..\lib\UnityEngine.CoreModule.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>

</Project>
4 changes: 3 additions & 1 deletion MoreHomes/MoreHomesConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ namespace RestoreMonarchy.MoreHomes
{
public class MoreHomesConfiguration : IRocketPluginConfiguration
{
public string MessageColor { get; set; }
public string MessageColor { get; set; }
public string MessageIconUrl { get; set; } = "https://i.imgur.com/9TF5aB1.png";
public int DefaultHomeCooldown { get; set; }
public int DefaultHomeDelay { get; set; }
public int DefaultMaxHomes { get; set; }
Expand All @@ -20,6 +21,7 @@ public class MoreHomesConfiguration : IRocketPluginConfiguration
public void LoadDefaults()
{
MessageColor = "yellow";
MessageIconUrl = "https://i.imgur.com/9TF5aB1.png";
DefaultHomeCooldown = 20;
DefaultHomeDelay = 10;
DefaultMaxHomes = 2;
Expand Down
Loading

0 comments on commit 314045b

Please sign in to comment.