add 'cheat-commands' rule
This commit is contained in:
parent
2e24d60404
commit
5e9b290aea
@ -52,6 +52,22 @@ function submit(text)
|
||||
add_to_history(text)
|
||||
setup_variables()
|
||||
|
||||
text = text:trim()
|
||||
local name
|
||||
for s in text:gmatch("%S+") do
|
||||
name = s
|
||||
break
|
||||
end
|
||||
if name == nil then
|
||||
name = text
|
||||
end
|
||||
if not rules.get("cheat-commands") and table.has(console.cheats, name) then
|
||||
console.log("cheat commands are disabled")
|
||||
document.prompt.text = ""
|
||||
document.prompt.focused = true
|
||||
return
|
||||
end
|
||||
|
||||
document.log.caret = -1
|
||||
local status, result = pcall(console.execute, text)
|
||||
if result then
|
||||
|
||||
@ -28,17 +28,17 @@ console.add_command(
|
||||
function(args, kwargs)
|
||||
local name = args[1]
|
||||
if #name == 0 then
|
||||
|
||||
local commands = console.get_commands_list()
|
||||
table.sort(commands)
|
||||
local str = "Available commands:"
|
||||
|
||||
for i,k in ipairs(commands) do
|
||||
str = str .. "\n " .. build_scheme(console.get_command_info(k))
|
||||
if rules.get("cheat-commands") or not table.has(console.cheats, k) then
|
||||
str = str .. "\n " .. build_scheme(console.get_command_info(k))
|
||||
end
|
||||
end
|
||||
|
||||
return str .. "\nuse 'help <command>'"
|
||||
|
||||
end
|
||||
|
||||
local command = console.get_command_info(name)
|
||||
@ -255,3 +255,13 @@ console.add_command(
|
||||
return "registered rules:\n" .. names
|
||||
end
|
||||
)
|
||||
|
||||
console.cheats = {
|
||||
"blocks.fill",
|
||||
"tp",
|
||||
"fragment.place",
|
||||
"time.set",
|
||||
"time.daycycle",
|
||||
"entity.despawn",
|
||||
"player.respawn"
|
||||
}
|
||||
|
||||
@ -103,6 +103,9 @@ function time.post_runnable(runnable)
|
||||
table.insert(__post_runnables, runnable)
|
||||
end
|
||||
|
||||
--- Console library extension ---
|
||||
console.cheats = {}
|
||||
|
||||
local log_element = Document.new("core:console").log
|
||||
function console.log(...)
|
||||
local args = {...}
|
||||
@ -205,9 +208,10 @@ function _rules.listen(name, handler)
|
||||
end
|
||||
|
||||
function _rules.create(name, value, handler)
|
||||
print(name, value, handler)
|
||||
_rules.set(name, value)
|
||||
return _rules.listen(name, handler)
|
||||
if handler ~= nil then
|
||||
return _rules.listen(name, handler)
|
||||
end
|
||||
end
|
||||
|
||||
function _rules.unlisten(name, id)
|
||||
@ -218,6 +222,8 @@ end
|
||||
function _rules.clear()
|
||||
_rules.rules = {}
|
||||
_rules.nextid = 1
|
||||
|
||||
_rules.create("cheat-commands", true)
|
||||
end
|
||||
|
||||
function __vc_create_hud_rules()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user