mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 22:16:22 +00:00
ping ping ping ping ping ping ping ping ping ping ping
This commit is contained in:
4 files changed
+155
-1
No files matched your search
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 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.config;
|
||||
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
|
||||
@ConfigSerializable
|
||||
public class PingSettings {
|
||||
|
||||
@Comment("The color your name will be when another player mentions you.")
|
||||
private TextColor highlightTextColor = NamedTextColor.YELLOW;
|
||||
|
||||
private String prefix = "@";
|
||||
|
||||
private boolean playSound = false;
|
||||
private Key name = Key.key("block.anvil.use");
|
||||
private Sound.Source source = Sound.Source.MASTER;
|
||||
private float volume = 1.0f; // 0.0 -> infinity
|
||||
private float pitch = 1.0f; // 0.0 -> 2.0
|
||||
|
||||
public TextColor highlightTextColor() {
|
||||
return this.highlightTextColor;
|
||||
}
|
||||
|
||||
public boolean playSound() {
|
||||
return this.playSound;
|
||||
}
|
||||
|
||||
public Key name() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public String prefix() {
|
||||
return this.prefix;
|
||||
}
|
||||
|
||||
public Sound.Source source() {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
public float volume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public float pitch() {
|
||||
return this.pitch;
|
||||
}
|
||||
|
||||
public Sound sound() {
|
||||
return Sound.sound(this.name, this.source, this.volume, this.pitch);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -58,6 +58,9 @@ public class PrimaryConfig {
|
||||
""")
|
||||
private Map<String, String> customPlaceholders = Map.of();
|
||||
|
||||
@Comment("Various settings related to pinging players in channels.")
|
||||
private PingSettings pingSettings = new PingSettings();
|
||||
|
||||
public Locale defaultLocale() {
|
||||
return this.defaultLocale;
|
||||
}
|
||||
@@ -82,6 +85,10 @@ public class PrimaryConfig {
|
||||
return this.customPlaceholders;
|
||||
}
|
||||
|
||||
public PingSettings pings() {
|
||||
return this.pingSettings;
|
||||
}
|
||||
|
||||
public enum StorageType {
|
||||
JSON,
|
||||
MYSQL,
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* CarbonChat
|
||||
*
|
||||
* Copyright (c) 2021 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 java.util.regex.Pattern;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.events.CarbonChatEvent;
|
||||
import net.draycia.carbon.api.users.CarbonPlayer;
|
||||
import net.draycia.carbon.api.util.KeyedRenderer;
|
||||
import net.draycia.carbon.api.util.RenderedMessage;
|
||||
import net.draycia.carbon.common.config.PrimaryConfig;
|
||||
import net.kyori.adventure.audience.MessageType;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
|
||||
import static net.draycia.carbon.api.util.KeyedRenderer.keyedRenderer;
|
||||
import static net.kyori.adventure.key.Key.key;
|
||||
|
||||
@DefaultQualifier(NonNull.class)
|
||||
public class PingHandler {
|
||||
|
||||
private final Key muteKey = key("carbon", "pings");
|
||||
private final KeyedRenderer renderer;
|
||||
|
||||
@Inject
|
||||
public PingHandler(final CarbonChat carbonChat, final PrimaryConfig primaryConfig) {
|
||||
this.renderer = keyedRenderer(this.muteKey, (sender, recipient, message, originalMessage) -> {
|
||||
if (!(recipient instanceof CarbonPlayer recipientPlayer)) {
|
||||
return new RenderedMessage(message, MessageType.CHAT);
|
||||
}
|
||||
|
||||
final String prefix = primaryConfig.pings().prefix();
|
||||
|
||||
return new RenderedMessage(message.replaceText(TextReplacementConfig.builder()
|
||||
.match(Pattern.compile(Pattern.quote(prefix + recipientPlayer.username()), Pattern.CASE_INSENSITIVE))
|
||||
.replacement(matchedText -> {
|
||||
if (primaryConfig.pings().playSound()) {
|
||||
recipient.playSound(primaryConfig.pings().sound());
|
||||
}
|
||||
|
||||
return matchedText.color(primaryConfig.pings().highlightTextColor());
|
||||
})
|
||||
.build()), MessageType.CHAT);
|
||||
});
|
||||
|
||||
carbonChat.eventHandler().subscribe(CarbonChatEvent.class, 1, false, event -> {
|
||||
event.renderers().add(0, this.renderer);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import net.draycia.carbon.common.listeners.DeafenHandler;
|
||||
import net.draycia.carbon.common.listeners.IgnoreHandler;
|
||||
import net.draycia.carbon.common.listeners.ItemLinkHandler;
|
||||
import net.draycia.carbon.common.listeners.MuteHandler;
|
||||
import net.draycia.carbon.common.listeners.PingHandler;
|
||||
|
||||
public final class ListenerUtils {
|
||||
|
||||
@@ -33,7 +34,7 @@ public final class ListenerUtils {
|
||||
}
|
||||
|
||||
public static final List<Class<?>> LISTENER_CLASSES = List.of(DeafenHandler.class, IgnoreHandler.class,
|
||||
ItemLinkHandler.class, MuteHandler.class);
|
||||
ItemLinkHandler.class, MuteHandler.class, PingHandler.class);
|
||||
|
||||
public static void registerCommonListeners(final Injector injector) {
|
||||
for (final var listenerClass : LISTENER_CLASSES) {
|
||||
|
||||
Reference in new issue
Block a user