Call events for console recipient

This commit is contained in:
Draycia committed 2020-11-17 04:17:17 -08:00
1 parent f1703b6b1d
commit d98cd88d56
6 files changed
+28 -31

No files matched your search

@@ -184,43 +184,35 @@ public class CarbonChatChannel implements TextChannel {
CarbonEvents.post(newEvent);
final PlayerUser targetUser = newEvent.target();
final CarbonUser targetUser = newEvent.target();
if (targetUser != null) {
users.put(targetUser, newEvent.component());
}
}
// TODO: ChatFormatEvent ConsoleUser support for target, specify ConsoleUser as target
final ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(user, null, this, preFormatEvent.format(),
final ConsoleUser consoleUser = this.carbonChat.userService().consoleUser();
final ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(user, consoleUser, this, preFormatEvent.format(),
preFormatEvent.message());
CarbonEvents.post(consoleFormatEvent);
final TextColor channelColor = this.channelColor(user);
final TextColor targetColor;
if (channelColor != null) {
targetColor = channelColor;
} else {
targetColor = NamedTextColor.WHITE;
}
final TextComponent consoleFormat = (TextComponent) this.carbonChat.messageProcessor().processMessage(consoleFormatEvent.format(),
"displayname", displayName,
"color", "<" + targetColor.asHexString() + ">",
"color", "<" + channelColor.asHexString() + ">",
"playercolor", "<" + user.customChatColor(),
"phase", Long.toString(System.currentTimeMillis() % 25),
"message", consoleFormatEvent.message());
final ChatComponentEvent consoleEvent = new ChatComponentEvent(user, null, this, consoleFormat,
final ChatComponentEvent consoleEvent = new ChatComponentEvent(user, consoleUser, this, consoleFormat,
consoleFormatEvent.message());
CarbonEvents.post(consoleEvent);
if (!consoleEvent.cancelled()) {
final ConsoleUser consoleUser = this.carbonChat.userService().consoleUser();
if (consoleUser != null) {
users.put(consoleUser, consoleEvent.component());
}
@@ -2,6 +2,7 @@ package net.draycia.carbon.common.listeners.events;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.events.ChatFormatEvent;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.users.PlayerUser;
import net.kyori.event.PostOrders;
@@ -9,13 +10,13 @@ public class IgnoredPlayerHandler {
public IgnoredPlayerHandler() {
CarbonEvents.register(ChatFormatEvent.class, PostOrders.FIRST, false, event -> {
final PlayerUser target = event.target();
final CarbonUser target = event.target();
if (target == null) {
if (!(target instanceof PlayerUser)) {
return;
}
if (target.ignoringUser(event.sender())) {
if (((PlayerUser) target).ignoringUser(event.sender())) {
event.cancelled(true);
}
});
@@ -5,6 +5,7 @@ import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.events.ChatComponentEvent;
import net.draycia.carbon.api.events.ChatFormatEvent;
import net.draycia.carbon.api.events.misc.CarbonEvents;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.users.PlayerUser;
import net.kyori.adventure.sound.Sound;
import net.kyori.event.PostOrders;
@@ -19,9 +20,9 @@ public class PingHandler {
return;
}
final PlayerUser target = event.target();
final CarbonUser target = event.target();
if (target == null) {
if (!(target instanceof PlayerUser)) {
return;
}
@@ -40,7 +41,7 @@ public class PingHandler {
}
}
final Sound sound = target.pingOptions().pingSound();
final Sound sound = ((PlayerUser) target).pingOptions().pingSound();
if (sound != null) {
target.playSound(sound);
@@ -54,9 +55,9 @@ public class PingHandler {
return;
}
final PlayerUser target = event.target();
final CarbonUser target = event.target();
if (target == null) {
if (!(target instanceof PlayerUser)) {
return;
}