diff --git a/chatcommands.lua b/chatcommands.lua index 6fe809d..692211f 100644 --- a/chatcommands.lua +++ b/chatcommands.lua @@ -4,12 +4,10 @@ local channel_invitation_string = "|#${channel_name}| Channel invite from (${fro .. "which you can send messages to the channel via #${channel_name}: message" local channel_invited_string = "|#${channel_name}| Invite sent to ${to_player}" local channel_deleted_string = "|#${channel_name}| Channel deleted" -local channel_joined_string = "|#${channel_name}| Joined channel" local channel_left_string = "|#${channel_name}| Left channel" local channel_already_deleted_string = "|#${channel_name}| Channel seems to have already " .. "been deleted, will unregister channel from your list of channels" -local join_channel_sound = "beerchat_chirp" -- Sound when you join a channel local leave_channel_sound = "beerchat_chirp" -- Sound when you leave a channel local channel_invite_sound = "beerchat_chirp" -- Sound when sending/ receiving an invite to a channel @@ -181,19 +179,7 @@ local join_channel = { end end - if not beerchat.execute_callbacks('before_join', name, channel_name) then - return false - end - - beerchat.add_player_channel(name, channel_name) - - if beerchat.enable_sounds then - minetest.sound_play(join_channel_sound, - { to_player = name, gain = beerchat.sounds_default_gain }) - end - minetest.chat_send_player(name, beerchat.format_message(channel_joined_string, - { channel_name = channel_name })) - return true + return beerchat.join_channel(name, channel_name) end } diff --git a/common.lua b/common.lua index f0c5157..c524821 100644 --- a/common.lua +++ b/common.lua @@ -47,6 +47,19 @@ beerchat.fix_player_channel = function(name, notify) beerchat.set_player_channel(name, beerchat.main_channel_name) end +beerchat.join_channel = function(name, channel, set_default) + if not beerchat.execute_callbacks('before_join', name, channel) then + return false + end + (set_default and beerchat.set_player_channel or beerchat.add_player_channel)(name, channel) + if beerchat.enable_sounds then + minetest.sound_play("beerchat_chirp", { to_player = name, gain = beerchat.sounds_default_gain }) + end + local msg = beerchat.format_message("|#${channel_name}| Joined channel", { channel_name = channel }) + minetest.chat_send_player(name, msg) + return true +end + beerchat.has_player_muted_player = function(name, other_name) local cb_result = beerchat.execute_callbacks('before_check_muted', name, other_name) if cb_result ~= nil then diff --git a/plugin/hash.lua b/plugin/hash.lua index fb84c40..abf1520 100644 --- a/plugin/hash.lua +++ b/plugin/hash.lua @@ -3,33 +3,40 @@ -- e.g. #my-channel: hello everyone in my channel! local function switch_channel(name, channel) + local skip_sound if not beerchat.is_player_subscribed_to_channel(name, channel) then - minetest.chat_send_player(name, "You need to join this channel in order to be able to switch to it") - else - if not beerchat.execute_callbacks('before_switch_chan', name, - beerchat.currentPlayerChannel[name], channel) then + if beerchat.channels[channel].password and beerchat.channels[channel].password ~= "" then + minetest.chat_send_player(name, "Channel is protected, you need to join this channel with /jc command") + return + elseif not beerchat.join_channel(name, channel) then return end - beerchat.set_player_channel(name, channel) - if channel == beerchat.main_channel_name then - minetest.chat_send_player(name, - "Switched to channel " .. channel .. ", messages will now be sent to this channel" - ) - else - minetest.chat_send_player(name, - "Switched to channel " .. channel .. ", messages will now be sent to this channel. " - .. "To switch back to the main channel, type #" .. beerchat.main_channel_name - ) - end - if beerchat.enable_sounds then - minetest.sound_play( - beerchat.channel_management_sound, - { - to_player = name, - gain = beerchat.sounds_default_gain - } - ) - end + -- Skip channel switch sound because beerchat.join_channel will also play sound + skip_sound = true + end + if not beerchat.execute_callbacks('before_switch_chan', name, + beerchat.currentPlayerChannel[name], channel) then + return + end + beerchat.set_player_channel(name, channel) + if channel == beerchat.main_channel_name then + minetest.chat_send_player(name, + "Switched to channel " .. channel .. ", messages will now be sent to this channel" + ) + else + minetest.chat_send_player(name, + "Switched to channel " .. channel .. ", messages will now be sent to this channel. " + .. "To switch back to the main channel, type #" .. beerchat.main_channel_name + ) + end + if not skip_sound and beerchat.enable_sounds then + minetest.sound_play( + beerchat.channel_management_sound, + { + to_player = name, + gain = beerchat.sounds_default_gain + } + ) end end