Skip to content

Commit

Permalink
Add rich text support and MessageColor & MessageIconUrl options to co…
Browse files Browse the repository at this point in the history
…nfiguration
  • Loading branch information
RestoreMonarchy committed Nov 10, 2024
1 parent e93313e commit 173ec59
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 81 deletions.
37 changes: 23 additions & 14 deletions ZaupShop/Commands/CommandBuy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ public void Execute(IRocketPlayer caller, string[] command)

if (command.Length == 0 || command.Length > 2)
{
UnturnedChat.Say(caller, pluginInstance.Translate("buy_command_usage"));
pluginInstance.SendMessageToPlayer(player, "buy_command_usage");
return;
}

byte amountToBuy = 1;
if (command.Length == 2 && !byte.TryParse(command[1], out amountToBuy))
{
UnturnedChat.Say(caller, pluginInstance.Translate("invalid_amt"));
pluginInstance.SendMessageToPlayer(player, "invalid_amt");
return;
}

Expand All @@ -57,18 +57,18 @@ public void Execute(IRocketPlayer caller, string[] command)

if (string.IsNullOrWhiteSpace(itemName))
{
UnturnedChat.Say(caller, pluginInstance.Translate("buy_command_usage"));
pluginInstance.SendMessageToPlayer(player, "buy_command_usage");
return;
}

if (isVehicle && !pluginInstance.Configuration.Instance.CanBuyVehicles)
{
UnturnedChat.Say(caller, pluginInstance.Translate("buy_vehicles_off"));
pluginInstance.SendMessageToPlayer(player, "buy_vehicles_off");
return;
}
else if (!isVehicle && !pluginInstance.Configuration.Instance.CanBuyItems)
{
UnturnedChat.Say(caller, pluginInstance.Translate("buy_items_off"));
pluginInstance.SendMessageToPlayer(player, "buy_items_off");
return;
}

Expand All @@ -79,15 +79,15 @@ public void Execute(IRocketPlayer caller, string[] command)
{
if (!UnturnedHelper.TryGetVehicleByIdOrName(itemName, out id, out name))
{
UnturnedChat.Say(caller, pluginInstance.Translate("could_not_find", itemName));
pluginInstance.SendMessageToPlayer(player, "could_not_find", itemName);
return;
}
}
else
{
if (!UnturnedHelper.TryGetItemByIdOrName(itemName, out id, out name))
{
UnturnedChat.Say(caller, pluginInstance.Translate("could_not_find", itemName));
pluginInstance.SendMessageToPlayer(player, "could_not_find", itemName);
return;
}
}
Expand All @@ -104,23 +104,33 @@ public void Execute(IRocketPlayer caller, string[] command)
{
if (cost <= 0m)
{
UnturnedChat.Say(caller, pluginInstance.Translate(isVehicle ? "vehicle_not_available" : "item_not_available", name));
if (isVehicle)
{
pluginInstance.SendMessageToPlayer(player, "vehicle_not_available", name);
}
else
{
pluginInstance.SendMessageToPlayer(player, "item_not_available", name);
}

return;
}

if (balance < cost)
{
string amountString = isVehicle ? "1" : amountToBuy.ToString();
UnturnedChat.Say(caller, pluginInstance.Translate("not_enough_currency_msg",
cost.ToString("N"), Uconomy.Instance.Configuration.Instance.MoneyName, amountString, name));
string costString = cost.ToString("N");
string moneyName = Uconomy.Instance.Configuration.Instance.MoneyName;

pluginInstance.SendMessageToPlayer(player, "not_enough_currency_msg", costString, moneyName, amountString, name);
return;
}

bool success = isVehicle ? player.GiveVehicle(id) : player.GiveItem(id, amountToBuy);

if (!success)
{
UnturnedChat.Say(caller, pluginInstance.Translate("error_giving_item", name));
pluginInstance.SendMessageToPlayer(player, "error_giving_item", name);
return;
}

Expand All @@ -131,9 +141,8 @@ public void Execute(IRocketPlayer caller, string[] command)
ThreadHelper.RunSynchronously(() =>
{
string messageKey = isVehicle ? "vehicle_buy_msg" : "item_buy_msg";
UnturnedChat.Say(caller, pluginInstance.Translate(messageKey,
name, cost, Uconomy.Instance.Configuration.Instance.MoneyName, newBalance,
Uconomy.Instance.Configuration.Instance.MoneyName, amountToBuy));
string moneyName = Uconomy.Instance.Configuration.Instance.MoneyName;
pluginInstance.SendMessageToPlayer(player, messageKey, name, cost, moneyName, newBalance, moneyName, amountToBuy);

string itemType = isVehicle ? "vehicle" : "item";
pluginInstance.TriggerOnShopBuy(player, cost, amountToBuy, id, itemType);
Expand Down
18 changes: 9 additions & 9 deletions ZaupShop/Commands/CommandCost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Execute(IRocketPlayer playerId, string[] command)
{
if (command.Length == 0 || command.Length > 2)
{
UnturnedChat.Say(playerId, pluginInstance.Translate("cost_command_usage"));
pluginInstance.SendMessageToPlayer(playerId, "cost_command_usage");
return;
}

Expand Down Expand Up @@ -48,14 +48,14 @@ public void Execute(IRocketPlayer playerId, string[] command)
}
else
{
UnturnedChat.Say(playerId, pluginInstance.Translate("cost_command_usage"));
pluginInstance.SendMessageToPlayer(playerId, "cost_command_usage");
return;
}
}

if (string.IsNullOrWhiteSpace(itemName))
{
UnturnedChat.Say(playerId, pluginInstance.Translate("cost_command_usage"));
pluginInstance.SendMessageToPlayer(playerId, "cost_command_usage");
return;
}

Expand All @@ -67,7 +67,7 @@ public void Execute(IRocketPlayer playerId, string[] command)
{
if (!UnturnedHelper.TryGetVehicleByIdOrName(itemName, out id, out name))
{
UnturnedChat.Say(playerId, pluginInstance.Translate("could_not_find", itemName));
pluginInstance.SendMessageToPlayer(playerId, "could_not_find", itemName);
return;
}
ThreadHelper.RunAsynchronously(() =>
Expand All @@ -77,10 +77,10 @@ public void Execute(IRocketPlayer playerId, string[] command)
{
if (cost <= 0m)
{
UnturnedChat.Say(playerId, pluginInstance.Translate("error_getting_cost", name));
pluginInstance.SendMessageToPlayer(playerId, "error_getting_cost", name);
return;
}
UnturnedChat.Say(playerId, pluginInstance.Translate("vehicle_cost_msg", name, cost.ToString("N"), moneyName));
pluginInstance.SendMessageToPlayer(playerId, "vehicle_cost_msg", name, cost.ToString("N"), moneyName);
});
});

Expand All @@ -89,7 +89,7 @@ public void Execute(IRocketPlayer playerId, string[] command)

if (!UnturnedHelper.TryGetItemByIdOrName(itemName, out id, out name))
{
UnturnedChat.Say(playerId, pluginInstance.Translate("could_not_find", itemName));
pluginInstance.SendMessageToPlayer(playerId, "could_not_find", itemName);
return;
}
ThreadHelper.RunAsynchronously(() =>
Expand All @@ -100,10 +100,10 @@ public void Execute(IRocketPlayer playerId, string[] command)
{
if (itemCost <= 0 && buybackPrice <= 0)
{
UnturnedChat.Say(playerId, pluginInstance.Translate("error_getting_cost", name));
pluginInstance.SendMessageToPlayer(playerId, "error_getting_cost", name);
return;
}
UnturnedChat.Say(playerId, pluginInstance.Translate("item_cost_msg", name, itemCost.ToString("N"), moneyName, buybackPrice.ToString("N"), moneyName));
pluginInstance.SendMessageToPlayer(playerId, "item_cost_msg", name, itemCost.ToString("N"), moneyName, buybackPrice.ToString("N"), moneyName);
});
});
}
Expand Down
17 changes: 9 additions & 8 deletions ZaupShop/Commands/CommandSell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,40 +24,40 @@ public void Execute(IRocketPlayer caller, string[] command)
UnturnedPlayer player = (UnturnedPlayer)caller;
if (command.Length == 0 || (command.Length > 0 && string.IsNullOrWhiteSpace(command[0])))
{
UnturnedChat.Say(caller, pluginInstance.Translate("sell_command_usage"));
pluginInstance.SendMessageToPlayer(player, "sell_command_usage");
return;
}

byte amount = 1;
if (command.Length > 1 && !byte.TryParse(command[1], out amount))
{
UnturnedChat.Say(caller, pluginInstance.Translate("invalid_amt"));
pluginInstance.SendMessageToPlayer(player, "invalid_amt");
return;
}

if (!pluginInstance.Configuration.Instance.CanSellItems)
{
UnturnedChat.Say(caller, pluginInstance.Translate("sell_items_off"));
pluginInstance.SendMessageToPlayer(player, "sell_items_off");
return;
}

ItemAsset asset = UnturnedHelper.GetItemByIdOrName(command[0]);
if (asset == null)
{
UnturnedChat.Say(caller, pluginInstance.Translate("could_not_find", command[0]));
pluginInstance.SendMessageToPlayer(player, "could_not_find", command[0]);
return;
}

List<InventorySearch> items = player.Inventory.search(asset.id, true, true);
if (items.Count == 0)
{
UnturnedChat.Say(caller, pluginInstance.Translate("not_have_item_sell", asset.itemName));
pluginInstance.SendMessageToPlayer(player, "not_have_item_sell", asset.itemName);
return;
}

if (items.Count < amount)
{
UnturnedChat.Say(caller, pluginInstance.Translate("not_enough_items_sell", amount.ToString(), asset.itemName));
pluginInstance.SendMessageToPlayer(player, "not_enough_items_sell", amount.ToString(), asset.itemName);
return;
}

Expand All @@ -69,7 +69,7 @@ public void Execute(IRocketPlayer caller, string[] command)
{
if (price <= 0.00m)
{
UnturnedChat.Say(caller, pluginInstance.Translate("no_sell_price_set", asset.itemName));
pluginInstance.SendMessageToPlayer(player, "no_sell_price_set", asset.itemName);
return;
}

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

ThreadHelper.RunSynchronously(() =>
{
UnturnedChat.Say(player, pluginInstance.Translate("sold_items", amount, asset.itemName, addMoney, Uconomy.Instance.Configuration.Instance.MoneyName, balance, Uconomy.Instance.Configuration.Instance.MoneyName));
string moneyName = Uconomy.Instance.Configuration.Instance.MoneyName;
pluginInstance.SendMessageToPlayer(player, "sold_items", amount, asset.itemName, addMoney, moneyName, balance, moneyName);
pluginInstance.TriggerOnShopSell(player, addMoney, amount, asset.id);
player.Player.gameObject.SendMessage("ZaupShopOnSell", new object[] { player, addMoney, amount, asset.id }, SendMessageOptions.DontRequireReceiver);
});
Expand Down
43 changes: 21 additions & 22 deletions ZaupShop/Commands/CommandShop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ public void Execute(IRocketPlayer caller, string[] msg)
|| ((subCommand == "remove" || subCommand == "rem") && msg.Length < 2)
|| (subCommand != "add" && subCommand != "remove" && subCommand != "rem"))
{
UnturnedChat.Say(caller, pluginInstance.Translate("shop_command_usage"));
pluginInstance.SendMessageToPlayer(caller, "shop_command_usage");
return;
}

string[] type = Parser.getComponentsFromSerial(msg[1], '.');
if (type.Length > 1 && type[0] != "v")
{
UnturnedChat.Say(caller, pluginInstance.Translate("v_not_provided"));
pluginInstance.SendMessageToPlayer(caller, "v_not_provided");
return;
}

if (!ushort.TryParse(type.Length > 1 ? type[1] : type[0], out ushort id))
{
UnturnedChat.Say(caller, pluginInstance.Translate("invalid_id_given"));
pluginInstance.SendMessageToPlayer(caller, "invalid_id_given");
return;
}

Expand All @@ -56,7 +56,7 @@ public void Execute(IRocketPlayer caller, string[] msg)
HandleRemove(caller, type, id, isConsole);
break;
default:
UnturnedChat.Say(caller, pluginInstance.Translate("invalid_shop_command"));
pluginInstance.SendMessageToPlayer(caller, "invalid_shop_command");
break;
}
}
Expand All @@ -71,7 +71,7 @@ private void HandleAddOrChange(IRocketPlayer caller, string[] msg, string[] type

if (!decimal.TryParse(msg[2], out decimal cost))
{
UnturnedChat.Say(caller, pluginInstance.Translate("invalid_cost"));
pluginInstance.SendMessageToPlayer(caller, "invalid_cost");
return;
}

Expand All @@ -80,7 +80,7 @@ private void HandleAddOrChange(IRocketPlayer caller, string[] msg, string[] type
{
if (!decimal.TryParse(msg[3], out decimal buyBackDecimal))
{
UnturnedChat.Say(caller, pluginInstance.Translate("invalid_buyback"));
pluginInstance.SendMessageToPlayer(caller, "invalid_buyback");
return;
}
else
Expand All @@ -94,15 +94,15 @@ private void HandleAddOrChange(IRocketPlayer caller, string[] msg, string[] type
{
if (!UnturnedHelper.TryGetVehicleByIdOrName(id.ToString(), out _, out name))
{
UnturnedChat.Say(caller, pluginInstance.Translate("invalid_id_given"));
pluginInstance.SendMessageToPlayer(caller, "invalid_id_given");
return;
}
}
else
{
if (!UnturnedHelper.TryGetItemByIdOrName(id.ToString(), out _, out name))
{
UnturnedChat.Say(caller, pluginInstance.Translate("invalid_id_given"));
pluginInstance.SendMessageToPlayer(caller, "invalid_id_given");
return;
}
}
Expand All @@ -115,24 +115,21 @@ private void HandleAddOrChange(IRocketPlayer caller, string[] msg, string[] type

ThreadHelper.RunSynchronously(() =>
{
string message;
if (success)
{
if (buyback.HasValue)
{
message = pluginInstance.Translate("changed_or_added_to_shop_with_buyback", name, cost.ToString("N"), buyback.Value.ToString("N"));
pluginInstance.SendMessageToPlayer(caller, "changed_or_added_to_shop_with_buyback", name, cost.ToString("N"), buyback.Value.ToString("N"));
}
else
{
message = pluginInstance.Translate("changed_or_added_to_shop", name, cost.ToString("N"));
pluginInstance.SendMessageToPlayer(caller, "changed_or_added_to_shop", name, cost.ToString("N"));
}
}
else
{
message = pluginInstance.Translate("error_adding_or_changing", name);
pluginInstance.SendMessageToPlayer(caller, "error_adding_or_changing", name);
}

UnturnedChat.Say(caller, message);
});
});
}
Expand All @@ -148,15 +145,15 @@ private void HandleRemove(IRocketPlayer caller, string[] type, ushort id, bool i
{
if (!UnturnedHelper.TryGetVehicleByIdOrName(id.ToString(), out _, out name))
{
UnturnedChat.Say(caller, pluginInstance.Translate("invalid_id_given"));
pluginInstance.SendMessageToPlayer(caller, "invalid_id_given");
return;
}
}
else
{
if (!UnturnedHelper.TryGetItemByIdOrName(id.ToString(), out _, out name))
{
UnturnedChat.Say(caller, pluginInstance.Translate("invalid_id_given"));
pluginInstance.SendMessageToPlayer(caller, "invalid_id_given");
return;
}
}
Expand All @@ -169,11 +166,13 @@ private void HandleRemove(IRocketPlayer caller, string[] type, ushort id, bool i

ThreadHelper.RunSynchronously(() =>
{
string message = success
? pluginInstance.Translate("removed_from_shop", name)
: pluginInstance.Translate("not_in_shop_to_remove", name);

UnturnedChat.Say(caller, message);
if (success)
{
pluginInstance.SendMessageToPlayer(caller, "removed_from_shop", name);
} else
{
pluginInstance.SendMessageToPlayer(caller, "not_in_shop_to_remove", name);
}
});
});
}
Expand All @@ -184,7 +183,7 @@ private bool HasRequiredPermission(IRocketPlayer caller, string action, bool isC
string permission = $"shop.{action}";
if (!caller.HasPermission(permission))
{
UnturnedChat.Say(caller, pluginInstance.Translate($"no_permission_shop_{action}"));
pluginInstance.SendMessageToPlayer(caller, $"no_permission_shop_{action}");
return false;
}
return true;
Expand Down
Loading

0 comments on commit 173ec59

Please sign in to comment.