mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Call events for console recipient
This commit is contained in:
1 parent
f1703b6b1d
commit
d98cd88d56
6 files changed
+28
-31
No files matched your search
+6
-14
@@ -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());
|
||||
}
|
||||
|
||||
+4
-3
@@ -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);
|
||||
}
|
||||
});
|
||||
|
||||
+6
-5
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user