Skip to content

Commit

Permalink
Bugfix: don't error out on //flora → //bonemeal alias if bonemeal mod…
Browse files Browse the repository at this point in the history
… isn't installed

Also add worldeditadditions_core.command_exists to check both WEA and WEW for whether a command exists or not
  • Loading branch information
sbrl committed Dec 13, 2023
1 parent 74a8996 commit 873ff4b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion worldeditadditions_commands/aliases.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
23 changes: 23 additions & 0 deletions worldeditadditions_core/core/command_exists.lua
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion worldeditadditions_core/core/register_command.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
1 change: 1 addition & 0 deletions worldeditadditions_core/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 873ff4b

Please sign in to comment.