1
0
Fork 0

Add error handling for invalid /weather syntax

This commit is contained in:
Wuzzy 2017-05-14 22:04:38 +02:00
parent e4938ae8d1
commit 7a64990ffa
1 changed files with 10 additions and 1 deletions

View File

@ -137,12 +137,18 @@ minetest.register_chatcommand("weather", {
description = "Changes the weather to the specified parameter.", description = "Changes the weather to the specified parameter.",
privs = {weather_manager = true}, privs = {weather_manager = true},
func = function(name, param) func = function(name, param)
if (param == "") then
minetest.chat_send_player(name, "Error: No weather specified.")
return
end
local success = false
if (param == "clear") then if (param == "clear") then
if (weather.state ~= nil and weather.reg_weathers[weather.state] ~= nil) then if (weather.state ~= nil and weather.reg_weathers[weather.state] ~= nil) then
weather.reg_weathers[weather.state].clear() weather.reg_weathers[weather.state].clear()
weather.state = param
end end
weather.state = "none" weather.state = "none"
success = true
return
end end
if (weather.reg_weathers ~= nil and weather.reg_weathers[param] ~= nil) then if (weather.reg_weathers ~= nil and weather.reg_weathers[param] ~= nil) then
@ -150,6 +156,9 @@ minetest.register_chatcommand("weather", {
weather.reg_weathers[weather.state].clear() weather.reg_weathers[weather.state].clear()
end end
weather.state = param weather.state = param
return
else
minetest.chat_send_player(name, "Error: Invalid weather specified. Use “clear”, “rain”, “snow” or “thunder”.")
end end
end end
}) })