mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 14:38:49 +00:00
Add option to play sounds when receiving party chat messages (#588)
This commit is contained in:
1 parent
620bd57c46
commit
a58c745725
3 files changed
+71
No files matched your search
@@ -77,6 +77,7 @@ import net.draycia.carbon.common.listeners.Listener;
|
|||||||
import net.draycia.carbon.common.listeners.MessagePacketHandler;
|
import net.draycia.carbon.common.listeners.MessagePacketHandler;
|
||||||
import net.draycia.carbon.common.listeners.MuteHandler;
|
import net.draycia.carbon.common.listeners.MuteHandler;
|
||||||
import net.draycia.carbon.common.listeners.PartyChatSpyHandler;
|
import net.draycia.carbon.common.listeners.PartyChatSpyHandler;
|
||||||
|
import net.draycia.carbon.common.listeners.PartyPingHandler;
|
||||||
import net.draycia.carbon.common.listeners.PingHandler;
|
import net.draycia.carbon.common.listeners.PingHandler;
|
||||||
import net.draycia.carbon.common.listeners.RadiusListener;
|
import net.draycia.carbon.common.listeners.RadiusListener;
|
||||||
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
import net.draycia.carbon.common.messages.CarbonMessageRenderer;
|
||||||
@@ -228,6 +229,7 @@ public final class CarbonCommonModule extends AbstractModule {
|
|||||||
listeners.addBinding().to(MessagePacketHandler.class);
|
listeners.addBinding().to(MessagePacketHandler.class);
|
||||||
listeners.addBinding().to(MuteHandler.class);
|
listeners.addBinding().to(MuteHandler.class);
|
||||||
listeners.addBinding().to(PartyChatSpyHandler.class);
|
listeners.addBinding().to(PartyChatSpyHandler.class);
|
||||||
|
listeners.addBinding().to(PartyPingHandler.class);
|
||||||
listeners.addBinding().to(PingHandler.class);
|
listeners.addBinding().to(PingHandler.class);
|
||||||
listeners.addBinding().to(RadiusListener.class);
|
listeners.addBinding().to(RadiusListener.class);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -289,6 +289,16 @@ public class PrimaryConfig {
|
|||||||
public boolean enabled = true;
|
public boolean enabled = true;
|
||||||
|
|
||||||
public int expireInvitesAfterSeconds = 45;
|
public int expireInvitesAfterSeconds = 45;
|
||||||
|
|
||||||
|
public boolean playSound = false;
|
||||||
|
|
||||||
|
@Comment("Sound for receiving a party message")
|
||||||
|
public @Nullable Sound messageSound = Sound.sound(
|
||||||
|
Key.key("entity.experience_orb.pickup"),
|
||||||
|
Sound.Source.MASTER,
|
||||||
|
1.0F,
|
||||||
|
1.0F
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum StorageType {
|
public enum StorageType {
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* CarbonChat
|
||||||
|
*
|
||||||
|
* Copyright (c) 2024 Josua Parks (Vicarious)
|
||||||
|
* Contributors
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package net.draycia.carbon.common.listeners;
|
||||||
|
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
import net.draycia.carbon.api.event.CarbonEventHandler;
|
||||||
|
import net.draycia.carbon.api.event.events.CarbonChatEvent;
|
||||||
|
import net.draycia.carbon.common.channels.PartyChatChannel;
|
||||||
|
import net.draycia.carbon.common.config.ConfigManager;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
|
import net.kyori.adventure.identity.Identity;
|
||||||
|
import net.kyori.adventure.sound.Sound;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||||
|
|
||||||
|
@DefaultQualifier(NonNull.class)
|
||||||
|
public class PartyPingHandler implements Listener {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public PartyPingHandler(final CarbonEventHandler events, final ConfigManager configManager) {
|
||||||
|
events.subscribe(CarbonChatEvent.class, 100, false, event -> {
|
||||||
|
if (!(event.chatChannel() instanceof PartyChatChannel)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final @Nullable Sound sound = configManager.primaryConfig().partyChat().messageSound;
|
||||||
|
|
||||||
|
if (configManager.primaryConfig().partyChat().playSound && sound != null) {
|
||||||
|
for (final Audience recipient : event.recipients()) {
|
||||||
|
// Don't ping the message sender
|
||||||
|
if (event.sender().uuid().equals(recipient.get(Identity.UUID).orElse(null))) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
recipient.playSound(sound);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in new issue
Block a user