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