2021-06-25 02:14:57 -04:00
|
|
|
-- The API
|
|
|
|
|
2021-06-25 16:14:47 -04:00
|
|
|
function item_replicator.add(itemstring, amount, time)
|
|
|
|
if not item_replicator.is(itemstring) then
|
|
|
|
table.insert(item_replicator_items, {itemstring, amount, time})
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Add (Insert) {'"..itemstring.."', "..amount..", "..time.."}")
|
2021-06-25 02:14:57 -04:00
|
|
|
end
|
|
|
|
else
|
2021-06-25 16:14:47 -04:00
|
|
|
local index = 1
|
|
|
|
for ind, val in pairs(item_replicator_items) do
|
|
|
|
--minetest.log("action", "[item_replicator] API Add (dump) "..ind.." {'"..val[1].."', "..val[2]..", "..val[3].."}")
|
2021-06-25 02:14:57 -04:00
|
|
|
if val[1] == itemstring then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
index = index + 1
|
|
|
|
end
|
2021-06-25 16:14:47 -04:00
|
|
|
item_replicator_items[index] = {itemstring, amount, time}
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Add (Update) {'"..itemstring.."', "..amount..", "..time.."}")
|
2021-06-25 02:14:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-25 16:14:47 -04:00
|
|
|
function item_replicator.is(itemstring)
|
2021-06-25 02:14:57 -04:00
|
|
|
local result = false
|
2021-06-25 16:14:47 -04:00
|
|
|
for ind, val in pairs(item_replicator_items) do
|
2021-06-25 02:14:57 -04:00
|
|
|
if val[1] == itemstring then
|
|
|
|
result = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if result then
|
2021-06-25 16:14:47 -04:00
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Is '"..itemstring.."' == true")
|
2021-06-25 02:14:57 -04:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
2021-06-25 16:14:47 -04:00
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Is '"..itemstring.."' == false")
|
2021-06-25 02:14:57 -04:00
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2021-06-25 16:14:47 -04:00
|
|
|
function item_replicator.get_amount(itemstring)
|
|
|
|
if item_replicator.is(itemstring) then
|
|
|
|
for ind, val in pairs(item_replicator_items) do
|
2021-06-25 02:14:57 -04:00
|
|
|
if val[1] == itemstring then
|
2021-06-25 16:14:47 -04:00
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Get Amount '"..itemstring.."' x "..val[2])
|
2021-06-25 02:14:57 -04:00
|
|
|
end
|
|
|
|
return val[2]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-06-25 16:14:47 -04:00
|
|
|
if not item_replicator_settings.allow_unknown then
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Get Amount '"..itemstring.."' was not found, return -1")
|
|
|
|
end
|
|
|
|
return -1
|
|
|
|
else
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Get Amount '"..itemstring.."' was not found, return "..item_replicator_settings.unknown_item_amount)
|
|
|
|
end
|
|
|
|
return item_replicator_settings.unknown_item_amount
|
2021-06-25 02:14:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-25 16:14:47 -04:00
|
|
|
function item_replicator.get_time(itemstring)
|
|
|
|
if item_replicator.is(itemstring) then
|
|
|
|
for ind, val in pairs(item_replicator_items) do
|
2021-06-25 02:14:57 -04:00
|
|
|
if val[1] == itemstring then
|
2021-06-25 16:14:47 -04:00
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Get Time '"..itemstring.."' @ "..val[3].." second(s)")
|
2021-06-25 02:14:57 -04:00
|
|
|
end
|
|
|
|
return val[3]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-06-25 16:14:47 -04:00
|
|
|
if not item_replicator_settings.allow_unknown then
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Get Time '"..itemstring.."' was not found, returning -1 second(s)")
|
|
|
|
end
|
|
|
|
return -1
|
|
|
|
else
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Get Time '"..itemstring.."' was not found, return "..item_replicator_settings.unknown_item_time)
|
|
|
|
end
|
|
|
|
return item_replicator_settings.unknown_item_time
|
2021-06-25 02:14:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-25 16:14:47 -04:00
|
|
|
function item_replicator.remove(itemstring)
|
|
|
|
if item_replicator.is(itemstring) then
|
|
|
|
local index = 1
|
|
|
|
for ind, val in pairs(item_replicator_items) do
|
|
|
|
--minetest.log("action", "[item_replicator] API Remove (dump) "..ind.." {'"..val[1].."', "..val[2]..", "..val[3].."}")
|
2021-06-25 02:14:57 -04:00
|
|
|
if val[1] == itemstring then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
index = index + 1
|
|
|
|
end
|
2021-06-25 16:14:47 -04:00
|
|
|
table.remove(item_replicator_items, index)
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Remove '"..itemstring.."' was removed")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Remove '"..itemstring.."' was not found, ignoring")
|
2021-06-25 02:14:57 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-09-07 17:20:13 -04:00
|
|
|
|
|
|
|
-- API for blacklist
|
|
|
|
function item_replicator.bl_is(itemstring)
|
|
|
|
local result = false
|
|
|
|
for ind, val in pairs(item_replicator_blacklist) do
|
|
|
|
if val[1] == itemstring then
|
|
|
|
result = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if result then
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Black Is '"..itemstring.."' == true")
|
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Black Is '"..itemstring.."' == false")
|
|
|
|
end
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
function item_replicator.bl_add(itemstring)
|
|
|
|
if not item_replicator.bl_is(itemstring) then
|
|
|
|
table.insert(item_replicator_blacklist, {itemstring})
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Blacklist Add '"..itemstring.."' was added")
|
|
|
|
end
|
|
|
|
if item_replicator_settings.blacklist_removes_allowed and item_replicator.is(itemstring) then
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Blacklist Add '"..itemstring.."' was removed from the known/allowed list")
|
|
|
|
end
|
|
|
|
item_replicator.remove(itemstring)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Blacklist Add '"..itemstring.."' was already found, ignoring")
|
|
|
|
end
|
|
|
|
-- If this gets called again do another check just in case (Not really a big deal though)
|
|
|
|
if item_replicator_settings.blacklist_removes_allowed and item_replicator.is(itemstring) then
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Blacklist Add '"..itemstring.."' was removed from the known/allowed list")
|
|
|
|
end
|
|
|
|
item_replicator.remove(itemstring)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function item_replicator.bl_remove(itemstring)
|
|
|
|
if item_replicator.bl_is(itemstring) then
|
|
|
|
local index = 1
|
|
|
|
for ind, val in pairs(item_replicator_items) do
|
|
|
|
--minetest.log("action", "[item_replicator] API Remove (dump) "..ind.." {'"..val[1].."', "..val[2]..", "..val[3].."}")
|
|
|
|
if val[1] == itemstring then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
index = index + 1
|
|
|
|
end
|
|
|
|
table.remove(item_replicator_blacklist, index)
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Blacklist Remove '"..itemstring.."' was removed")
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if item_replicator_settings.log_api then
|
|
|
|
minetest.log("action", "[item_replicator] API Blacklist Remove '"..itemstring.."' was not found, ignoring")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|