diff --git a/common/src/main/java/net/draycia/carbon/common/CarbonCommonModule.java b/common/src/main/java/net/draycia/carbon/common/CarbonCommonModule.java index fff49e90..5fd73cb7 100644 --- a/common/src/main/java/net/draycia/carbon/common/CarbonCommonModule.java +++ b/common/src/main/java/net/draycia/carbon/common/CarbonCommonModule.java @@ -77,6 +77,7 @@ import net.draycia.carbon.common.listeners.Listener; import net.draycia.carbon.common.listeners.MessagePacketHandler; import net.draycia.carbon.common.listeners.MuteHandler; 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.RadiusListener; 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(MuteHandler.class); listeners.addBinding().to(PartyChatSpyHandler.class); + listeners.addBinding().to(PartyPingHandler.class); listeners.addBinding().to(PingHandler.class); listeners.addBinding().to(RadiusListener.class); } diff --git a/common/src/main/java/net/draycia/carbon/common/config/PrimaryConfig.java b/common/src/main/java/net/draycia/carbon/common/config/PrimaryConfig.java index b500330f..cc613f24 100644 --- a/common/src/main/java/net/draycia/carbon/common/config/PrimaryConfig.java +++ b/common/src/main/java/net/draycia/carbon/common/config/PrimaryConfig.java @@ -289,6 +289,16 @@ public class PrimaryConfig { public boolean enabled = true; 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 { diff --git a/common/src/main/java/net/draycia/carbon/common/listeners/PartyPingHandler.java b/common/src/main/java/net/draycia/carbon/common/listeners/PartyPingHandler.java new file mode 100644 index 00000000..96a9fd94 --- /dev/null +++ b/common/src/main/java/net/draycia/carbon/common/listeners/PartyPingHandler.java @@ -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 . + */ +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); + } + } + }); + } + +}