Skip to content

Commit

Permalink
Add 'listores' chat command
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed Aug 3, 2017
1 parent 6228eea commit a25011e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 20 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -7,10 +7,11 @@
#### Chat Commands:
- ***listitems:*** Lists registered craft items available in the game.
- ***listentities:*** Lists registered entities available in the game.
- ***listores:*** Lists registered ores available in the game.
- Invocation: ```/<command> [options] [string1] [string2] ...```
- ***command:*** Name of the command (e.g. *listitems*, *listentities*)
- ***command:*** Name of the command (e.g. *listitems*, *listentities*, etc.)
- ***options:*** Switches to control output behavior.
- ***-v:*** Display description after object name
- ***-v:*** Display description (if available) after object name
- ***string[1,2] ...:*** String parameter(s) to filter output.
- Without any string parameters, all objects registered in game are listed.
- With string parameters, only objects matching any of the strings will be listed.
Expand Down
46 changes: 37 additions & 9 deletions api.lua
Expand Up @@ -71,23 +71,30 @@ end
-- @function getRegistered
-- @local
-- @tparam string r_type Must be either "items" or "entities".
-- @treturn table Either a list of registered item or entity names & descriptions.
-- @treturn table Either a list of registered item or entity names & descriptions.
-- @note Ore names are located in the "ore" field of the registered tables
local function getRegistered(r_type)
if r_type == nil then
r_type = 'items'
end
-- Default is "items"
r_type = r_type or 'items'
local o_names = {}
local objects = {}
local o_temp = {}
if r_type == 'items' then
o_temp = core.registered_items
else
if r_type == 'entities' then
o_temp = core.registered_entities
elseif r_type == 'ores' then
o_temp = core.registered_ores
else
o_temp = core.registered_items
end
for name, def in pairs(o_temp) do
-- Ore names are located in the 'ore' field of the table
if r_type == 'ores' then
name = def.ore
end
table.insert(objects, {name=name, descr=def.description,})
table.insert(o_names, name)
end
Expand Down Expand Up @@ -294,15 +301,15 @@ end
-- @tparam string player Name of player to receive message output.
-- @tparam string params String list of parameters.
-- @tparam string switches String list of switch options for manipulating output.
-- @tparam string l_type Objects to list (either "items" or "entities").
-- @tparam string l_type Objects to list (either "items", "entities", or "ores").
-- @tparam boolean lower Case-insensitive matching if ***true***.
-- @treturn boolean
function listitems.list(player, params, switches, l_type, lower)
-- Default list type is "items"
l_type = l_type or 'items'
lower = lower == nil or lower == true
local types = {'items', 'entities',}
local types = {'items', 'entities', 'ores',}
if not listContains(types, l_type) then
listitems.logWarn('listitems.listitems called with unknown list type: ' .. tostring(l_type))
return false
Expand Down Expand Up @@ -383,3 +390,24 @@ registerChatCommand('listentities', {
return listitems.list(player, params, switches, 'entities')
end,
})
--- Lists registered ores.
--
-- @chatcmd listores
-- @chatparam [-v]
-- @chatparam [string1]
-- @chatparam [string2]
-- @chatparam ...
-- @treturn boolean
registerChatCommand('listores', {
params = '[-v] [' .. S('string1') .. '] [' .. S('string2') .. '] ...',
description = S('List registered ores'),
func = function(player, params)
local switches = extractSwitches(string.split(params, ' '))
params = removeListDuplicates(switches[2])
switches = switches[1]
return listitems.list(player, params, switches, 'ores')
end,
})
18 changes: 9 additions & 9 deletions docs/config.ld
Expand Up @@ -5,19 +5,19 @@ not_luadoc = true
--wrap = true
boilerplate = true

local function tagoutput(value)
local function italic(value)
return '<i>' .. value .. '</i>'
end

new_type('setting', 'Settings')
new_type('chatcmd', 'Chat Commands', false, 'chatparam')
custom_tags = {
{'default',
format = tagoutput,
format = italic,
},
{'type2',
title = 'Type',
format = tagoutput,
format = italic,
},
{'dfield',
title = 'Definition Fields',
Expand All @@ -38,14 +38,14 @@ custom_tags = {
},
{'settype',
title = 'Type',
format = function(item)
return '<i>' .. item .. '</i>'
end,
}
format = italic,
},
{'note',
title = 'Notes',
format = italic,
},
}

alias('tchatparam', 'chatparam')

local function chatcmd_handler(item)
local output = item.name
for i, p in ipairs(item.tags.chatparam) do
Expand Down
1 change: 1 addition & 0 deletions locale/template.txt
Expand Up @@ -4,6 +4,7 @@
## Help output description
List registered items =
List registered entities =
List registered ores =

## Help output parameters
options =
Expand Down

0 comments on commit a25011e

Please sign in to comment.