Skip to content

Commit

Permalink
Make the v. in buy and cost commands case insensitive and priotirize …
Browse files Browse the repository at this point in the history
…id over asset name
  • Loading branch information
RestoreMonarchy committed Dec 3, 2024
1 parent 97a4f85 commit 72fb2cd
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 16 deletions.
7 changes: 4 additions & 3 deletions ZaupShop/Commands/CommandBuy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Rocket.API;
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using System;
using System.Collections.Generic;
using UnityEngine;
using ZaupShop.Helpers;
Expand Down Expand Up @@ -39,12 +40,12 @@ public void Execute(IRocketPlayer caller, string[] command)
bool isVehicle = false;
string itemName;

if (command[0].StartsWith("v."))
if (command[0].StartsWith("v.", StringComparison.OrdinalIgnoreCase))
{
isVehicle = true;
itemName = command[0].Substring(2);
}
else if (command[0] == "v" && command.Length == 2)
else if (command[0].Equals("v", StringComparison.OrdinalIgnoreCase) && command.Length == 2)
{
isVehicle = true;
itemName = command[1];
Expand Down Expand Up @@ -142,7 +143,7 @@ public void Execute(IRocketPlayer caller, string[] command)
{
string messageKey = isVehicle ? "vehicle_buy_msg" : "item_buy_msg";
string moneyName = Uconomy.Instance.Configuration.Instance.MoneyName;
pluginInstance.SendMessageToPlayer(player, messageKey, name, cost, moneyName, newBalance, moneyName, amountToBuy);
pluginInstance.SendMessageToPlayer(player, messageKey, name, cost, moneyName, newBalance.ToString("N"), moneyName, amountToBuy);

string itemType = isVehicle ? "vehicle" : "item";
pluginInstance.TriggerOnShopBuy(player, cost, amountToBuy, id, itemType);
Expand Down
8 changes: 4 additions & 4 deletions ZaupShop/Commands/CommandCost.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using fr34kyn01535.Uconomy;
using Rocket.API;
using Rocket.Unturned.Chat;
using System;
using System.Collections.Generic;
using ZaupShop.Helpers;

Expand Down Expand Up @@ -29,7 +29,7 @@ public void Execute(IRocketPlayer playerId, string[] command)

if (command.Length == 1)
{
if (command[0].StartsWith("v."))
if (command[0].StartsWith("v.", StringComparison.OrdinalIgnoreCase))
{
isVehicle = true;
itemName = command[0].Substring(2);
Expand All @@ -39,9 +39,9 @@ public void Execute(IRocketPlayer playerId, string[] command)
itemName = command[0];
}
}
else // command.Length == 2
else
{
if (command[0] == "v")
if (command[0].Equals("v", StringComparison.OrdinalIgnoreCase))
{
isVehicle = true;
itemName = command[1];
Expand Down
2 changes: 1 addition & 1 deletion ZaupShop/Commands/CommandSell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void Execute(IRocketPlayer caller, string[] command)
ThreadHelper.RunSynchronously(() =>
{
string moneyName = Uconomy.Instance.Configuration.Instance.MoneyName;
pluginInstance.SendMessageToPlayer(player, "sold_items", amount, asset.itemName, addMoney, moneyName, balance, moneyName);
pluginInstance.SendMessageToPlayer(player, "sold_items", amount, asset.itemName, addMoney, moneyName, balance.ToString("N"), moneyName);
pluginInstance.TriggerOnShopSell(player, addMoney, amount, asset.id);
player.Player.gameObject.SendMessage("ZaupShopOnSell", new object[] { player, addMoney, amount, asset.id }, SendMessageOptions.DontRequireReceiver);
});
Expand Down
5 changes: 3 additions & 2 deletions ZaupShop/Commands/CommandShop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Rocket.Unturned.Chat;
using Rocket.Unturned.Player;
using SDG.Unturned;
using System;
using System.Collections.Generic;
using System.Linq;
using ZaupShop.Helpers;
Expand Down Expand Up @@ -34,7 +35,7 @@ public void Execute(IRocketPlayer caller, string[] msg)
}

string[] type = Parser.getComponentsFromSerial(msg[1], '.');
if (type.Length > 1 && type[0] != "v")
if (type.Length > 1 && !type[0].Equals("v", StringComparison.OrdinalIgnoreCase))
{
pluginInstance.SendMessageToPlayer(caller, "v_not_provided");
return;
Expand Down Expand Up @@ -67,7 +68,7 @@ private void HandleAddOrChange(IRocketPlayer caller, string[] msg, string[] type

// add basically adds or change, this is kept for backward compatibility
bool isChange = true;
bool isVehicle = type[0] == "v";
bool isVehicle = type[0].Equals("v", StringComparison.OrdinalIgnoreCase);

if (!decimal.TryParse(msg[2], out decimal cost))
{
Expand Down
21 changes: 18 additions & 3 deletions ZaupShop/Helpers/UnturnedHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,16 @@ internal static Asset GetVehicleByIdOrName(string idOrName)
if (!ushort.TryParse(idOrName, out ushort id))
{
idOrName = idOrName.ToLower();
}
} else
{
Asset asset = assets.FirstOrDefault(a => a.id == id);
if (asset != null)
{
return asset;
}
}

return assets.FirstOrDefault(a => (id != 0 && a.id == id) || (a?.FriendlyName != null && a.FriendlyName.ToLower().Contains(idOrName)));
return assets.FirstOrDefault(a => a?.FriendlyName != null && a.FriendlyName.ToLower().Contains(idOrName));
}

internal static ItemAsset GetItemByIdOrName(string idOrName)
Expand All @@ -58,8 +65,16 @@ internal static ItemAsset GetItemByIdOrName(string idOrName)
{
idOrName = idOrName.ToLower();
}
else
{
ItemAsset itemAsset = itemAssets.FirstOrDefault(a => a.id == id);
if (itemAsset != null)
{
return itemAsset;
}
}

return itemAssets.FirstOrDefault(a => (id != 0 && a.id == id) || (a?.FriendlyName != null && a.FriendlyName.ToLower().Contains(idOrName)));
return itemAssets.FirstOrDefault(a => a?.FriendlyName != null && a.FriendlyName.ToLower().Contains(idOrName));
}

internal static IEnumerable<Asset> GetAllVehicles()
Expand Down
4 changes: 2 additions & 2 deletions ZaupShop/ZaupShop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ protected override void Unload()
{ "error_getting_cost", "Error: [[b]]{0}[[/b]] is not for sale" },
{ "item_cost_msg", "Item: [[b]]{0}[[/b]] | Buy: [[b]]{1} {2}[[/b]] | Sell: [[b]]{3} {4}[[/b]]" },
{ "vehicle_cost_msg", "Vehicle: [[b]]{0}[[/b]] | Buy: [[b]]{1} {2}[[/b]]" },
{ "item_buy_msg", "Purchase successful: [[b]]{5} {0}[[/b]] for [[b]]{1} {2}[[/b]]. Your balance: [[b]]{3} {4}[[/b]]" },
{ "vehicle_buy_msg", "Purchase successful: [[b]]1 {0}[[/b]] for [[b]]{1} {2}[[/b]]. Your balance: [[b]]{3} {4}[[/b]]" },
{ "item_buy_msg", "Purchase successful: [[b]]{5}x {0}[[/b]] for [[b]]{1} {2}[[/b]]. Your balance: [[b]]{3} {4}[[/b]]" },
{ "vehicle_buy_msg", "Purchase successful: [[b]]1x {0}[[/b]] for [[b]]{1} {2}[[/b]]. Your balance: [[b]]{3} {4}[[/b]]" },
{ "not_enough_currency_msg", "Insufficient funds: You need [[b]]{0} {1}[[/b]] to buy [[b]]x{2} {3}[[/b]]" },
{ "buy_items_off", "Error: Item purchasing is currently disabled" },
{ "buy_vehicles_off", "Error: Vehicle purchasing is currently disabled" },
Expand Down
2 changes: 1 addition & 1 deletion ZaupShop/ZaupShop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<LangVersion>latest</LangVersion>
<RootNamespace>ZaupShop</RootNamespace>
<AssemblyName>ZaupShop</AssemblyName>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 72fb2cd

Please sign in to comment.