enhance purge_unknowns command a bit

This commit is contained in:
FaceDeer 2020-01-01 16:49:50 -07:00
parent 9545098b7b
commit a7e12f96ce
2 changed files with 7 additions and 3 deletions

View File

@ -36,6 +36,8 @@ local get_icon = function(item)
return returnstring return returnstring
end end
-- Exposed so that the purge_unknowns command can use it.
commoditymarket.get_icon = get_icon
local get_item_description = function(item) local get_item_description = function(item)
local def = minetest.registered_items[item] local def = minetest.registered_items[item]

View File

@ -383,7 +383,7 @@ end
minetest.register_chatcommand("market.removeitem", { minetest.register_chatcommand("market.removeitem", {
params = "marketname item", params = "marketname item",
privs = {server=true}, privs = {server=true},
decription = "remove item from market. All existing buys and sells will be cancelled.", decription = "remove item from market. All existing buys and sells will be canceled.",
func = function(name, param) func = function(name, param)
local params = param:split(" ") local params = param:split(" ")
if #params ~= 2 then if #params ~= 2 then
@ -400,17 +400,19 @@ minetest.register_chatcommand("market.removeitem", {
minetest.register_chatcommand("market.purge_unknowns", { minetest.register_chatcommand("market.purge_unknowns", {
params = "", params = "",
privs = {server=true}, privs = {server=true},
decription = "removes all unknown items from all markets. All existing buys and sells for those items will be cancelled.", decription = "removes all unknown items from all markets. All existing buys and sells for those items will be canceled.",
func = function(name, param) func = function(name, param)
for market_name, market in pairs(commoditymarket.registered_markets) do for market_name, market in pairs(commoditymarket.registered_markets) do
local items_to_remove = {} local items_to_remove = {}
local items_to_move = {} local items_to_move = {}
for item, orders in pairs(market.orders_for_items) do for item, orders in pairs(market.orders_for_items) do
if minetest.registered_items[item] == nil then local icon = commoditymarket.get_icon(item)
if icon == "unknown_item.png" then
table.insert(items_to_remove, item) table.insert(items_to_remove, item)
end end
end end
for _, item in ipairs(items_to_remove) do for _, item in ipairs(items_to_remove) do
minetest.chat_send_player(name, "Purging item: " .. tostring(item) .. " from market: " .. market_name)
remove_market_item(market, item) remove_market_item(market, item)
end end
end end