Compare commits
23 Commits
master
...
chat-comma
Author | SHA1 | Date |
---|---|---|
AFCMS | 2d7ee83d3e | |
AFCMS | a65acd3ab8 | |
AFCMS | 3718bb6f80 | |
AFCMS | 19745cafbc | |
AFCMS | bc2e122652 | |
AFCMS | b0ca506688 | |
AFCMS | 0a57666771 | |
AFCMS | 07513d8e52 | |
AFCMS | a6e0605b7c | |
AFCMS | cc0ed855a9 | |
AFCMS | 658028e90a | |
AFCMS | 3f1b12e327 | |
AFCMS | e436f1a6af | |
AFCMS | d19f88d226 | |
AFCMS | 6d1bc8f865 | |
AFCMS | 102f45336b | |
AFCMS | be75150725 | |
AFCMS | 0619d480dd | |
AFCMS | 0129fdafef | |
AFCMS | 5ddc3cf99a | |
AFCMS | 84900b39ad | |
AFCMS | 528f1cb81f | |
AFCMS | bb576148f4 |
|
@ -0,0 +1,55 @@
|
||||||
|
### `mcl_commands.register_command(name, def)`
|
||||||
|
|
||||||
|
#### Complex commands (WIP):
|
||||||
|
|
||||||
|
```
|
||||||
|
mcl_commands.register_command("test", {
|
||||||
|
type = "complex",
|
||||||
|
priv_level = 4,
|
||||||
|
func = function(context)
|
||||||
|
if self.match_type("int", {min=1, max=255} then
|
||||||
|
print(self.last_type)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Basic commands:
|
||||||
|
|
||||||
|
* `context.type` is the context of execution: `player` or `commandblock`
|
||||||
|
* `context.commander` is the executor/commander of the command
|
||||||
|
* `context.pos` is the position where the command is executed
|
||||||
|
|
||||||
|
This param allow the use of position target selectors
|
||||||
|
|
||||||
|
```
|
||||||
|
mcl_commands.register_command("test", {
|
||||||
|
type = "basic",
|
||||||
|
priv_level = 4,
|
||||||
|
func = function(context)
|
||||||
|
if context.commander then
|
||||||
|
print(context.pos)
|
||||||
|
print("--------") --this "concept" param allow to run command correctly
|
||||||
|
--(with target selector and logging) from mods or command blocks
|
||||||
|
return true, S("Succesfull")
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
### `mcl_commands.execute_command(name, params, context)`
|
||||||
|
|
||||||
|
#### As a player:
|
||||||
|
```
|
||||||
|
mcl_commands.execute_command("test", "foo bar true 1", {type="player", commander=player, pos=player:get_pos()})
|
||||||
|
```
|
||||||
|
#### As a command block:
|
||||||
|
```
|
||||||
|
mcl_commands.execute_command("test", "foo bar true 1", {type="commandblock", commander=commander, pos=node_pos})
|
||||||
|
```
|
||||||
|
|
||||||
|
### `mcl_commands.get_target_selector(target_selector)`
|
||||||
|
|
||||||
|
This function allow mods and commands to get the result of a given target selector in that form: `@e[gamemode=creative,limit=5]`
|
||||||
|
|
||||||
|
This function returns a code indicating the success and a table of ObjectRefs (can be empty)
|
|
@ -0,0 +1,7 @@
|
||||||
|
mcl_commands.alias_command("?", "help", false)
|
||||||
|
mcl_commands.alias_command("pardon", "unban", false)
|
||||||
|
mcl_commands.rename_command("stop", "shutdown", false)
|
||||||
|
mcl_commands.alias_command("tell", "msg", false)
|
||||||
|
mcl_commands.alias_command("w", "msg", false)
|
||||||
|
mcl_commands.alias_command("tp", "teleport", false)
|
||||||
|
mcl_commands.rename_command("clear", "clearinv", false)
|
|
@ -0,0 +1,201 @@
|
||||||
|
local S = minetest.get_translator(minetest.get_current_modname())
|
||||||
|
local C = minetest.colorize
|
||||||
|
|
||||||
|
--TODO: like mc error message
|
||||||
|
--TODO: complex command handling
|
||||||
|
--TODO: mc like help system
|
||||||
|
|
||||||
|
mcl_commands.types = {
|
||||||
|
bool = {
|
||||||
|
lengh = 1,
|
||||||
|
msg = S("Invalid boolean"),
|
||||||
|
func = function(word)
|
||||||
|
if word == "true" then
|
||||||
|
return true, true
|
||||||
|
elseif world == "false" then
|
||||||
|
return true, false
|
||||||
|
else
|
||||||
|
return false, nil
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
int = {
|
||||||
|
lengh = 1,
|
||||||
|
msg = S("Invalid integer"),
|
||||||
|
func = function(int)
|
||||||
|
if tonumber(int) and tonumber(int) == math.round(int) then
|
||||||
|
return true, tonumber(int)
|
||||||
|
else
|
||||||
|
return false, nil
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
float = {
|
||||||
|
lengh = 1,
|
||||||
|
msg = S("Invalid integer"),
|
||||||
|
func = function(float)
|
||||||
|
if tonumber(float) then
|
||||||
|
return true, tonumber(float)
|
||||||
|
else
|
||||||
|
return false, nil
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
word = {
|
||||||
|
lengh = 1,
|
||||||
|
msg = S("Invalid word"),
|
||||||
|
func = function(word)
|
||||||
|
if word then
|
||||||
|
return true, word
|
||||||
|
else
|
||||||
|
return false, nil
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
text = {},
|
||||||
|
pos = {
|
||||||
|
lengh = 3,
|
||||||
|
msg = S("Invalid position"),
|
||||||
|
func = function(x, y, z)
|
||||||
|
--FIXME
|
||||||
|
if true then
|
||||||
|
return true, nil
|
||||||
|
else
|
||||||
|
return false, nil
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
target = {
|
||||||
|
lengh = 1,
|
||||||
|
msg = S("Invalid target selector"),
|
||||||
|
func = function(target)
|
||||||
|
--mcl_commands.get_target_selector(target_selector)
|
||||||
|
if minetest.player_exists(target) then
|
||||||
|
return true, target
|
||||||
|
else
|
||||||
|
return false, nil
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
playername = {
|
||||||
|
lengh = 1,
|
||||||
|
msg = S("Invalid player name"),
|
||||||
|
func = function(name)
|
||||||
|
if minetest.player_exists(name) then
|
||||||
|
return true, name
|
||||||
|
else
|
||||||
|
return false, nil
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
function mcl_commands.match_param(table, index, type, params)
|
||||||
|
local typedef = mcl_commands.types[type]
|
||||||
|
if typedef.lengh > 1 then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
local params = {}
|
||||||
|
typedef.func()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
mcl_commands.registered_commands = {}
|
||||||
|
|
||||||
|
function mcl_commands.register_complex_command()
|
||||||
|
end
|
||||||
|
|
||||||
|
--aims to avoid complexity for basic commands while keeping proper messages and privs management
|
||||||
|
function mcl_commands.register_basic_command(name, def)
|
||||||
|
local func
|
||||||
|
if def.params then
|
||||||
|
func = function(name, param)
|
||||||
|
local funcparams = {}
|
||||||
|
local i = 0
|
||||||
|
for str in string.gmatch(params, "([^ ]+)") do
|
||||||
|
i = i + 1
|
||||||
|
funcparams[i] = str
|
||||||
|
end
|
||||||
|
for _,type in pairs(def.params) do
|
||||||
|
mcl_commands.match_param(funcparams, index, type, params)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
mcl_commands.registered_commands[name] = {type = "basic", description = def.desc, privs = def.privs}
|
||||||
|
func = function(name, param)
|
||||||
|
if param == "" then
|
||||||
|
local out, msg = def.func(name)
|
||||||
|
if out then
|
||||||
|
return true, C(mcl_colors.GRAY, msg) or C(mcl_colors.GRAY, S("succesful"))
|
||||||
|
else
|
||||||
|
return false, C(mcl_colors.RED, msg) or C(mcl_colors.RED, S("failed"))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return false, C(mcl_colors.RED, S("Invalid command usage"))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
minetest.register_chatcommand(name, {
|
||||||
|
description = def.desc,
|
||||||
|
privs = def.privs,
|
||||||
|
func = func,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[
|
||||||
|
mcl_commands.register_basic_command("test", {
|
||||||
|
description = S("testing command"),
|
||||||
|
params = nil,
|
||||||
|
func = function(name)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
]]
|
||||||
|
|
||||||
|
mcl_commands.register_basic_command("testb", {
|
||||||
|
description = S("testing command"),
|
||||||
|
params = {
|
||||||
|
{type="bool"},
|
||||||
|
{type="int", params={min=1, max=10}}
|
||||||
|
},
|
||||||
|
func = function(name, bool, int)
|
||||||
|
return true, "test: "..int
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
function mcl_commands.alias_command(alias, original_name, bypass_setting)
|
||||||
|
if minetest.settings:get_bool("mcl_builtin_commands_overide", true) or bypass_setting then
|
||||||
|
local def = minetest.registered_chatcommands[original_name]
|
||||||
|
minetest.register_chatcommand(alias, def)
|
||||||
|
minetest.log("action", string.format("[mcl_commands] Aliasing [%s] command to [%s]", original_name, alias))
|
||||||
|
else
|
||||||
|
minetest.log("action", string.format("[mcl_commands] Aliasing [%s] command to [%s] skipped according to setting", original_name, alias))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function mcl_commands.rename_command(new_name, original_name, bypass_setting)
|
||||||
|
if minetest.settings:get_bool("mcl_builtin_commands_overide", true) or bypass_setting then
|
||||||
|
local def = minetest.registered_chatcommands[original_name]
|
||||||
|
minetest.register_chatcommand(new_name, def)
|
||||||
|
minetest.unregister_chatcommand(original_name)
|
||||||
|
minetest.log("action", string.format("[mcl_commands] Renaming [%s] command to [%s]", original_name, new_name))
|
||||||
|
else
|
||||||
|
minetest.log("action", string.format("[mcl_commands] Renaming [%s] command to [%s] skipped according to setting", original_name, new_name))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
--0: succesfull, table
|
||||||
|
--1: not connected player, nil
|
||||||
|
--2: invalid target selector, nil
|
||||||
|
function mcl_commands.get_target_selector(target_selector)
|
||||||
|
if minetest.player_exists(target_selector) then
|
||||||
|
local obj = minetest.get_player_by_name(target_selector)
|
||||||
|
if obj then
|
||||||
|
return 0, {obj}
|
||||||
|
else
|
||||||
|
return 1, nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return 0, {}
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,16 @@
|
||||||
|
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
||||||
|
|
||||||
|
mcl_commands = {}
|
||||||
|
|
||||||
|
dofile(modpath.."/api.lua")
|
||||||
|
|
||||||
|
dofile(modpath.."/register/kill.lua")
|
||||||
|
dofile(modpath.."/register/setblock.lua")
|
||||||
|
dofile(modpath.."/register/seed.lua")
|
||||||
|
dofile(modpath.."/register/summon.lua")
|
||||||
|
dofile(modpath.."/register/say.lua")
|
||||||
|
dofile(modpath.."/register/list.lua")
|
||||||
|
dofile(modpath.."/register/sound.lua")
|
||||||
|
dofile(modpath.."/register/banlist.lua")
|
||||||
|
|
||||||
|
dofile(modpath.."/alias.lua")
|
|
@ -0,0 +1,16 @@
|
||||||
|
local S = minetest.get_translator(minetest.get_current_modname())
|
||||||
|
|
||||||
|
--[[minetest.register_chatcommand("banlist", {
|
||||||
|
description = S("List bans"),
|
||||||
|
privs = minetest.registered_chatcommands["ban"].privs,
|
||||||
|
func = function(name)
|
||||||
|
return true, S("Ban list: @1", minetest.get_ban_list())
|
||||||
|
end,
|
||||||
|
})]]
|
||||||
|
|
||||||
|
mcl_commands.register_basic_command("banlist", {
|
||||||
|
description = S("List bans"),
|
||||||
|
func = function(name)
|
||||||
|
return true, S("Ban list: @1", minetest.get_ban_list())
|
||||||
|
end,
|
||||||
|
})
|
|
@ -0,0 +1,52 @@
|
||||||
|
local S = minetest.get_translator(minetest.get_current_modname())
|
||||||
|
|
||||||
|
--[[
|
||||||
|
minetest.register_chatcommand("list", {
|
||||||
|
description = S("Show who is logged on"),
|
||||||
|
params = "",
|
||||||
|
privs = {},
|
||||||
|
func = function(name)
|
||||||
|
--local players = ""
|
||||||
|
--for _, player in ipairs(minetest.get_connected_players()) do
|
||||||
|
-- players = players..player:get_player_name().."\n"
|
||||||
|
--end
|
||||||
|
--minetest.chat_send_player(name, players)
|
||||||
|
local player_list = minetest.get_connected_players()
|
||||||
|
local header = S("There are @1/@2 players online:", #player_list, minetest.settings:get("max_users") or "unknown").."\n"
|
||||||
|
local players = {}
|
||||||
|
for _, player in ipairs(player_list) do
|
||||||
|
table.insert(players, player:get_player_name())
|
||||||
|
end
|
||||||
|
return true, header..table.concat(players, ", ")
|
||||||
|
end
|
||||||
|
})
|
||||||
|
]]
|
||||||
|
|
||||||
|
local max_users = minetest.settings:get("max_users") or "unknown" --TODO: check if the setting is dynamic in mc
|
||||||
|
local playersstring = ""
|
||||||
|
|
||||||
|
local function generate_player_list()
|
||||||
|
local player_list = minetest.get_connected_players()
|
||||||
|
local header = S("There are @1/@2 players online:", #player_list, max_users).."\n"
|
||||||
|
local players = {}
|
||||||
|
for _, player in ipairs(player_list) do
|
||||||
|
table.insert(players, player:get_player_name())
|
||||||
|
end
|
||||||
|
playersstring = header..table.concat(players, ", ")
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
generate_player_list()
|
||||||
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_leaveplayer(function(player)
|
||||||
|
generate_player_list()
|
||||||
|
end)
|
||||||
|
|
||||||
|
mcl_commands.register_basic_command("list", {
|
||||||
|
description = S("Show who is logged on"),
|
||||||
|
params = nil,
|
||||||
|
func = function(name)
|
||||||
|
return true, playersstring
|
||||||
|
end,
|
||||||
|
})
|
|
@ -1,10 +1,12 @@
|
||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
local S = minetest.get_translator(minetest.get_current_modname())
|
||||||
|
|
||||||
|
local seed = minetest.get_mapgen_setting("seed")
|
||||||
|
|
||||||
minetest.register_chatcommand("seed", {
|
minetest.register_chatcommand("seed", {
|
||||||
description = S("Displays the world seed"),
|
description = S("Displays the world seed"),
|
||||||
params = "",
|
params = "",
|
||||||
privs = {},
|
privs = {},
|
||||||
func = function(name)
|
func = function(name)
|
||||||
minetest.chat_send_player(name, "Seed: "..minetest.get_mapgen_setting("seed"))
|
minetest.chat_send_player(name, "Seed: "..seed)
|
||||||
end
|
end
|
||||||
})
|
})
|
|
@ -1,30 +0,0 @@
|
||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
|
||||||
|
|
||||||
local function register_chatcommand_alias(alias, cmd)
|
|
||||||
local def = minetest.chatcommands[cmd]
|
|
||||||
minetest.register_chatcommand(alias, def)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function rename_chatcommand(newname, cmd)
|
|
||||||
local def = minetest.chatcommands[cmd]
|
|
||||||
minetest.register_chatcommand(newname, def)
|
|
||||||
minetest.unregister_chatcommand(cmd)
|
|
||||||
end
|
|
||||||
|
|
||||||
if minetest.settings:get_bool("mcl_builtin_commands_overide", true) then
|
|
||||||
register_chatcommand_alias("?", "help")
|
|
||||||
register_chatcommand_alias("pardon", "unban")
|
|
||||||
rename_chatcommand("stop", "shutdown")
|
|
||||||
register_chatcommand_alias("tell", "msg")
|
|
||||||
register_chatcommand_alias("w", "msg")
|
|
||||||
register_chatcommand_alias("tp", "teleport")
|
|
||||||
rename_chatcommand("clear", "clearinv")
|
|
||||||
|
|
||||||
minetest.register_chatcommand("banlist", {
|
|
||||||
description = S("List bans"),
|
|
||||||
privs = minetest.chatcommands["ban"].privs,
|
|
||||||
func = function(name)
|
|
||||||
return true, S("Ban list: @1", minetest.get_ban_list())
|
|
||||||
end,
|
|
||||||
})
|
|
||||||
end
|
|
|
@ -1,11 +0,0 @@
|
||||||
local modpath = minetest.get_modpath(minetest.get_current_modname())
|
|
||||||
|
|
||||||
dofile(modpath.."/kill.lua")
|
|
||||||
dofile(modpath.."/setblock.lua")
|
|
||||||
dofile(modpath.."/seed.lua")
|
|
||||||
dofile(modpath.."/summon.lua")
|
|
||||||
dofile(modpath.."/say.lua")
|
|
||||||
dofile(modpath.."/list.lua")
|
|
||||||
dofile(modpath.."/sound.lua")
|
|
||||||
|
|
||||||
dofile(modpath.."/alias.lua")
|
|
|
@ -1,14 +0,0 @@
|
||||||
local S = minetest.get_translator(minetest.get_current_modname())
|
|
||||||
|
|
||||||
minetest.register_chatcommand("list", {
|
|
||||||
description = S("Show who is logged on"),
|
|
||||||
params = "",
|
|
||||||
privs = {},
|
|
||||||
func = function(name)
|
|
||||||
local players = ""
|
|
||||||
for _, player in ipairs(minetest.get_connected_players()) do
|
|
||||||
players = players..player:get_player_name().."\n"
|
|
||||||
end
|
|
||||||
minetest.chat_send_player(name, players)
|
|
||||||
end
|
|
||||||
})
|
|
|
@ -6,15 +6,8 @@ mcl_death_drop = {}
|
||||||
|
|
||||||
mcl_death_drop.registered_dropped_lists = {}
|
mcl_death_drop.registered_dropped_lists = {}
|
||||||
|
|
||||||
function mcl_death_drop.register_dropped_list(inv, listname, drop)
|
--This function can be overiden by mods
|
||||||
table.insert(mcl_death_drop.registered_dropped_lists, {inv = inv, listname = listname, drop = drop})
|
function mcl_death_drop.handler(player)
|
||||||
end
|
|
||||||
|
|
||||||
mcl_death_drop.register_dropped_list("PLAYER", "main", true)
|
|
||||||
mcl_death_drop.register_dropped_list("PLAYER", "craft", true)
|
|
||||||
mcl_death_drop.register_dropped_list("PLAYER", "armor", true)
|
|
||||||
|
|
||||||
minetest.register_on_dieplayer(function(player)
|
|
||||||
local keep = minetest.settings:get_bool("mcl_keepInventory", false)
|
local keep = minetest.settings:get_bool("mcl_keepInventory", false)
|
||||||
if keep == false then
|
if keep == false then
|
||||||
-- Drop inventory, crafting grid and armor
|
-- Drop inventory, crafting grid and armor
|
||||||
|
@ -53,4 +46,16 @@ minetest.register_on_dieplayer(function(player)
|
||||||
end
|
end
|
||||||
mcl_armor.update(player)
|
mcl_armor.update(player)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function mcl_death_drop.register_dropped_list(inv, listname, drop)
|
||||||
|
table.insert(mcl_death_drop.registered_dropped_lists, {inv = inv, listname = listname, drop = drop})
|
||||||
|
end
|
||||||
|
|
||||||
|
mcl_death_drop.register_dropped_list("PLAYER", "main", true)
|
||||||
|
mcl_death_drop.register_dropped_list("PLAYER", "craft", true)
|
||||||
|
mcl_death_drop.register_dropped_list("PLAYER", "armor", true)
|
||||||
|
|
||||||
|
minetest.register_on_dieplayer(function(player)
|
||||||
|
mcl_death_drop.handler(player)
|
||||||
end)
|
end)
|
||||||
|
|
Loading…
Reference in New Issue