Fixed Funciton with Validate

master
= 2017-07-14 21:32:27 +02:00
parent 340ee4e5cf
commit a51a669956
3 changed files with 43 additions and 9 deletions

View File

@ -4,7 +4,7 @@
************************** **************************
--]] --]]
categories = { poi_categories = {
"General", "General",
"Buildings", "Buildings",
"Markets", "Markets",

View File

@ -7,8 +7,9 @@ dofile(minetest.get_modpath("minetest_poi") .. "/categories.lua")
local storage = minetest.get_mod_storage() -- initalize storage file of this mod. This can only happen here and should be always local local storage = minetest.get_mod_storage() -- initalize storage file of this mod. This can only happen here and should be always local
local poi = { local poi = {
points = {} points = {},
filter = {},
categories = {}
} }
@ -52,7 +53,7 @@ function poi.list_filter(name)
local list = "" local list = ""
local index = 0 local index = 0
for key, value in pairs(namefilter) do for key, value in pairs(poi_namefilter) do
list = list .. key .. ": " .. value .. "\n" list = list .. key .. ": " .. value .. "\n"
index = index + 1 index = index + 1
@ -67,7 +68,7 @@ function poi.list_categories(name)
local list = "" local list = ""
local index = 0 local index = 0
for key, value in pairs(categories) do for key, value in pairs(poi_categories) do
list = list .. key .. ": " .. value .. "\n" list = list .. key .. ": " .. value .. "\n"
index = index + 1 index = index + 1
@ -360,6 +361,39 @@ function poi.exist(poi_name)
end -- poi.exist end -- poi.exist
-- Checks the List and deletes invalid Poi's
function poi.validate(name)
local count = 0 -- Value of invalid Entrys
local key, value
for key, value in pairs(poi.points) do
if not poi.check_name(key) then -- is the Name valid?
count = count + 1
poi.points[key] = nil
else
if value == nil then -- is the Position of the PoI valid?
count = count + 1
poi.points[key] = nil
end -- if value
end -- if check_name
end -- for key,value
if count > 0 then
minetest.log("action","[POI] ".. name .. " has deleted with validate " .. count .. " PoI's.\n")
minetest.chat_send_player(name, core.colorize('#ff0000', count .. " invalid PoI's found and deleted.\n"))
poi.save()
else
minetest.chat_send_player(name, core.colorize('#00ff00', "No invalid PoI found.\n"))
end
end -- poi.validate
function poi.count() function poi.count()
local count = 0 local count = 0
for _,key in pairs(poi.points) do for _,key in pairs(poi.points) do
@ -384,7 +418,7 @@ function poi.check_name(name)
local valid = true local valid = true
for key, value in ipairs(poi.filter) do for key, value in ipairs(poi_namefilter) do
if string.find(string.lower(name), string.lower(value)) ~= nil then if string.find(string.lower(name), string.lower(value)) ~= nil then
valid = false valid = false
end -- if string.find end -- if string.find
@ -402,8 +436,8 @@ end -- poi.check_name()
--]] --]]
poi.openlist() -- Initalize the List on Start poi.openlist() -- Initalize the List on Start
poi.filter = namelist poi.filter = poi_namelist
poi.categories = cat poi.categories = poi_categories
minetest.register_chatcommand("poi_set", { minetest.register_chatcommand("poi_set", {
params = "<poi_name>", params = "<poi_name>",

View File

@ -7,7 +7,7 @@ All Filters will be convertet to lowercase
--]] --]]
namefilter = { poi_namefilter = {
"/", -- Filter to not start Commands "/", -- Filter to not start Commands
"{", -- Filter for Categorie "{", -- Filter for Categorie
"}", -- Filter for Categorie "}", -- Filter for Categorie