From 873ff4bef899e674c18f7cceedcba8ec128a36d8 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Wed, 13 Dec 2023 22:15:27 +0000 Subject: [PATCH] =?UTF-8?q?Bugfix:=20don't=20error=20out=20on=20//flora=20?= =?UTF-8?q?=20=E2=86=92=20//bonemeal=20alias=20if=20bonemeal=20mod=20isn't?= =?UTF-8?q?=20installed=20Also=20add=20worldeditadditions=5Fcore.command?= =?UTF-8?q?=5Fexists=20to=20check=20both=20WEA=20and=20WEW=20for=20whether?= =?UTF-8?q?=20a=20command=20exists=20or=20not?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +++ worldeditadditions_commands/aliases.lua | 5 +++- .../core/command_exists.lua | 23 +++++++++++++++++++ .../core/register_command.lua | 2 +- worldeditadditions_core/init.lua | 1 + 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 worldeditadditions_core/core/command_exists.lua diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f80436..66b436a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ Note to self: See the bottom of this file for the release template text. - Added [`//nodeapply`](https://worldeditadditions.mooncarrot.space/Reference/#nodeapply), a generalisation of [`//airapply`](https://worldeditadditions.mooncarrot.space/Reference/#airapply) that works with a defined list of nodes. Check out [the reference](https://worldeditadditions.mooncarrot.space/Reference/#nodeapply) - it has some cool tricks to it! (thanks for suggesting, @kliv91 from the Discord server!) - Added [`//ngroups`](https://worldeditadditions.mooncarrot.space/Reference/#ngroups), which lists the groups that a given node is a member of. Useful when paired with [`//nodeapply`](https://worldeditadditions.mooncarrot.space/Reference/#nodeapply)! +### Bugfixes and changes +- Don't warn on failed registration of `//flora` → [`//bonemeal`](https://worldeditadditions.mooncarrot.space/Reference/#bonemeal) if the `bonemeal` mod isn't installed (e.g. in MineClone2) - thanks @VorTechnix in #106 + ## v1.14.5: The multipoint update, hotfix 5 (1st August 2023) - Fix a bug where creative players in survival couldn't punch out position markers diff --git a/worldeditadditions_commands/aliases.lua b/worldeditadditions_commands/aliases.lua index ebe0402..b5e5df5 100644 --- a/worldeditadditions_commands/aliases.lua +++ b/worldeditadditions_commands/aliases.lua @@ -7,7 +7,10 @@ wea_c.register_alias("conv", "convolve") wea_c.register_alias("naturalise", "layers") wea_c.register_alias("naturalize", "layers") -wea_c.register_alias("flora", "bonemeal") +if wea_c.command_exists("/bonemeal") then + -- No need to log here, since we notify the server admin in the server logs in the dofile() for the main //bonemeal command + wea_c.register_alias("flora", "bonemeal") +end -- Measure Tools wea_c.register_alias("mcount", "count") diff --git a/worldeditadditions_core/core/command_exists.lua b/worldeditadditions_core/core/command_exists.lua new file mode 100644 index 0000000..56b7978 --- /dev/null +++ b/worldeditadditions_core/core/command_exists.lua @@ -0,0 +1,23 @@ +--- WorldEditAdditions chat command registration +-- @namespace worldeditadditions_core +local wea_c = worldeditadditions_core + + +--- Returns whether a WorldEditAdditions (or WorldEdit) command exists with the given name. +-- Note that this does NOT check for general Minetest chat commands - only commands registered through WorldEditAdditions or WorldEdit, if WorldEdit is currently loaded - the eventual plan is to make it an optional dependency. +-- @param cmdname string The name of the command to check for. Remember to remove the first forward slash! In other words if you would normally type `//layers` in-game, then you'd call `worldeditadditions.command_exists("/layers")`. +-- @param only_wea bool If true, then only check for WorldEditAdditions commands and not commands from related compatible mods such as WorldEdit. +-- @returns bool Whether a WorldEdit/WorldEditAdditions command exists with the given name. +local function command_exists(cmdname, only_wea) + if only_wea == nil then only_wea = false end + if wea_c.registered_commands[cmdname] ~= nil then + return true + end + if only_wea == true then return false end + if worldedit.registered_commands[cmdname] ~= nil then + return true + end + return false +end + +return command_exists \ No newline at end of file diff --git a/worldeditadditions_core/core/register_command.lua b/worldeditadditions_core/core/register_command.lua index e6a829b..6ae81fb 100644 --- a/worldeditadditions_core/core/register_command.lua +++ b/worldeditadditions_core/core/register_command.lua @@ -5,7 +5,7 @@ -- ██ ██ ███████ ██████ ██ ███████ ██ ███████ ██ ██ --- WorldEditAdditions chat command registration --- @module worldeditadditions_core +-- @namespace worldeditadditions_core local wea_c = worldeditadditions_core local run_command = dofile(wea_c.modpath.."/core/run_command.lua") diff --git a/worldeditadditions_core/init.lua b/worldeditadditions_core/init.lua index ae3030f..85409b3 100644 --- a/worldeditadditions_core/init.lua +++ b/worldeditadditions_core/init.lua @@ -61,6 +61,7 @@ wea_c.setting_handler = dofile(wea_c.modpath.."/utils/setting_handler.lua") -- A wea_c.pos = dofile(modpath.."/core/pos.lua") -- AFTER EventEmitter wea_c.register_command = dofile(modpath.."/core/register_command.lua") +wea_c.command_exists = dofile(modpath.."/core/command_exists.lua") wea_c.fetch_command_def = dofile(modpath.."/core/fetch_command_def.lua") wea_c.register_alias = dofile(modpath.."/core/register_alias.lua") wea_c.entities = dofile(modpath.."/core/entities/init.lua") -- AFTER pos