mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-04 06:28:53 +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
@@ -2,6 +2,7 @@ package net.draycia.carbon.api.events;
|
|||||||
|
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.events.misc.CarbonEvent;
|
import net.draycia.carbon.api.events.misc.CarbonEvent;
|
||||||
|
import net.draycia.carbon.api.users.CarbonUser;
|
||||||
import net.draycia.carbon.api.users.PlayerUser;
|
import net.draycia.carbon.api.users.PlayerUser;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.event.Cancellable;
|
import net.kyori.event.Cancellable;
|
||||||
@@ -12,12 +13,12 @@ public class ChatComponentEvent implements CarbonEvent, Cancellable {
|
|||||||
|
|
||||||
private boolean isCancelled = false;
|
private boolean isCancelled = false;
|
||||||
private final @NonNull PlayerUser sender;
|
private final @NonNull PlayerUser sender;
|
||||||
private final @Nullable PlayerUser target;
|
private final @Nullable CarbonUser target;
|
||||||
private @NonNull ChatChannel chatChannel;
|
private @NonNull ChatChannel chatChannel;
|
||||||
private @NonNull TextComponent component;
|
private @NonNull TextComponent component;
|
||||||
private final @NonNull String originalMessage;
|
private final @NonNull String originalMessage;
|
||||||
|
|
||||||
public ChatComponentEvent(final @NonNull PlayerUser sender, final @Nullable PlayerUser target,
|
public ChatComponentEvent(final @NonNull PlayerUser sender, final @Nullable CarbonUser target,
|
||||||
final @NonNull ChatChannel chatChannel, final @NonNull TextComponent component,
|
final @NonNull ChatChannel chatChannel, final @NonNull TextComponent component,
|
||||||
final @NonNull String originalMessage) {
|
final @NonNull String originalMessage) {
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ public class ChatComponentEvent implements CarbonEvent, Cancellable {
|
|||||||
return this.sender;
|
return this.sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable PlayerUser target() {
|
public @Nullable CarbonUser target() {
|
||||||
return this.target;
|
return this.target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.draycia.carbon.api.events;
|
|||||||
|
|
||||||
import net.draycia.carbon.api.channels.ChatChannel;
|
import net.draycia.carbon.api.channels.ChatChannel;
|
||||||
import net.draycia.carbon.api.events.misc.CarbonEvent;
|
import net.draycia.carbon.api.events.misc.CarbonEvent;
|
||||||
|
import net.draycia.carbon.api.users.CarbonUser;
|
||||||
import net.draycia.carbon.api.users.PlayerUser;
|
import net.draycia.carbon.api.users.PlayerUser;
|
||||||
import net.kyori.event.Cancellable;
|
import net.kyori.event.Cancellable;
|
||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
@@ -11,12 +12,12 @@ public class ChatFormatEvent implements CarbonEvent, Cancellable {
|
|||||||
|
|
||||||
private boolean isCancelled = false;
|
private boolean isCancelled = false;
|
||||||
private final @NonNull PlayerUser sender;
|
private final @NonNull PlayerUser sender;
|
||||||
private final @Nullable PlayerUser target;
|
private final @Nullable CarbonUser target;
|
||||||
private @NonNull ChatChannel chatChannel;
|
private @NonNull ChatChannel chatChannel;
|
||||||
private @NonNull String format;
|
private @NonNull String format;
|
||||||
private @NonNull String message;
|
private @NonNull String message;
|
||||||
|
|
||||||
public ChatFormatEvent(final @NonNull PlayerUser sender, final @Nullable PlayerUser target,
|
public ChatFormatEvent(final @NonNull PlayerUser sender, final @Nullable CarbonUser target,
|
||||||
final @NonNull ChatChannel chatChannel, final @NonNull String format,
|
final @NonNull ChatChannel chatChannel, final @NonNull String format,
|
||||||
final @NonNull String message) {
|
final @NonNull String message) {
|
||||||
|
|
||||||
@@ -42,7 +43,7 @@ public class ChatFormatEvent implements CarbonEvent, Cancellable {
|
|||||||
return this.sender;
|
return this.sender;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @Nullable PlayerUser target() {
|
public @Nullable CarbonUser target() {
|
||||||
return this.target;
|
return this.target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-3
@@ -3,6 +3,7 @@ package net.draycia.carbon.bukkit.listeners.events;
|
|||||||
import me.clip.placeholderapi.PlaceholderAPI;
|
import me.clip.placeholderapi.PlaceholderAPI;
|
||||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||||
import net.draycia.carbon.api.events.ChatFormatEvent;
|
import net.draycia.carbon.api.events.ChatFormatEvent;
|
||||||
|
import net.draycia.carbon.api.users.CarbonUser;
|
||||||
import net.draycia.carbon.api.users.PlayerUser;
|
import net.draycia.carbon.api.users.PlayerUser;
|
||||||
import net.kyori.event.PostOrders;
|
import net.kyori.event.PostOrders;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@@ -12,14 +13,14 @@ public class RelationalPlaceholderHandler {
|
|||||||
|
|
||||||
public RelationalPlaceholderHandler() {
|
public RelationalPlaceholderHandler() {
|
||||||
CarbonEvents.register(ChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
CarbonEvents.register(ChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||||
final PlayerUser targetUser = event.target();
|
final CarbonUser targetUser = event.target();
|
||||||
|
|
||||||
if (targetUser == null) {
|
if (!(targetUser instanceof PlayerUser)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Player sender = Bukkit.getPlayer(event.sender().uuid());
|
final Player sender = Bukkit.getPlayer(event.sender().uuid());
|
||||||
final Player target = Bukkit.getPlayer(targetUser.uuid());
|
final Player target = Bukkit.getPlayer(((PlayerUser) targetUser).uuid());
|
||||||
|
|
||||||
if (sender == null || target == null) {
|
if (sender == null || target == null) {
|
||||||
return;
|
return;
|
||||||
|
|||||||
+6
-14
@@ -184,43 +184,35 @@ public class CarbonChatChannel implements TextChannel {
|
|||||||
|
|
||||||
CarbonEvents.post(newEvent);
|
CarbonEvents.post(newEvent);
|
||||||
|
|
||||||
final PlayerUser targetUser = newEvent.target();
|
final CarbonUser targetUser = newEvent.target();
|
||||||
|
|
||||||
if (targetUser != null) {
|
if (targetUser != null) {
|
||||||
users.put(targetUser, newEvent.component());
|
users.put(targetUser, newEvent.component());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: ChatFormatEvent ConsoleUser support for target, specify ConsoleUser as target
|
final ConsoleUser consoleUser = this.carbonChat.userService().consoleUser();
|
||||||
final ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(user, null, this, preFormatEvent.format(),
|
|
||||||
|
final ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(user, consoleUser, this, preFormatEvent.format(),
|
||||||
preFormatEvent.message());
|
preFormatEvent.message());
|
||||||
|
|
||||||
CarbonEvents.post(consoleFormatEvent);
|
CarbonEvents.post(consoleFormatEvent);
|
||||||
|
|
||||||
final TextColor channelColor = this.channelColor(user);
|
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(),
|
final TextComponent consoleFormat = (TextComponent) this.carbonChat.messageProcessor().processMessage(consoleFormatEvent.format(),
|
||||||
"displayname", displayName,
|
"displayname", displayName,
|
||||||
"color", "<" + targetColor.asHexString() + ">",
|
"color", "<" + channelColor.asHexString() + ">",
|
||||||
"playercolor", "<" + user.customChatColor(),
|
"playercolor", "<" + user.customChatColor(),
|
||||||
"phase", Long.toString(System.currentTimeMillis() % 25),
|
"phase", Long.toString(System.currentTimeMillis() % 25),
|
||||||
"message", consoleFormatEvent.message());
|
"message", consoleFormatEvent.message());
|
||||||
|
|
||||||
final ChatComponentEvent consoleEvent = new ChatComponentEvent(user, null, this, consoleFormat,
|
final ChatComponentEvent consoleEvent = new ChatComponentEvent(user, consoleUser, this, consoleFormat,
|
||||||
consoleFormatEvent.message());
|
consoleFormatEvent.message());
|
||||||
|
|
||||||
CarbonEvents.post(consoleEvent);
|
CarbonEvents.post(consoleEvent);
|
||||||
|
|
||||||
if (!consoleEvent.cancelled()) {
|
if (!consoleEvent.cancelled()) {
|
||||||
final ConsoleUser consoleUser = this.carbonChat.userService().consoleUser();
|
|
||||||
|
|
||||||
if (consoleUser != null) {
|
if (consoleUser != null) {
|
||||||
users.put(consoleUser, consoleEvent.component());
|
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.misc.CarbonEvents;
|
||||||
import net.draycia.carbon.api.events.ChatFormatEvent;
|
import net.draycia.carbon.api.events.ChatFormatEvent;
|
||||||
|
import net.draycia.carbon.api.users.CarbonUser;
|
||||||
import net.draycia.carbon.api.users.PlayerUser;
|
import net.draycia.carbon.api.users.PlayerUser;
|
||||||
import net.kyori.event.PostOrders;
|
import net.kyori.event.PostOrders;
|
||||||
|
|
||||||
@@ -9,13 +10,13 @@ public class IgnoredPlayerHandler {
|
|||||||
|
|
||||||
public IgnoredPlayerHandler() {
|
public IgnoredPlayerHandler() {
|
||||||
CarbonEvents.register(ChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target.ignoringUser(event.sender())) {
|
if (((PlayerUser) target).ignoringUser(event.sender())) {
|
||||||
event.cancelled(true);
|
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.ChatComponentEvent;
|
||||||
import net.draycia.carbon.api.events.ChatFormatEvent;
|
import net.draycia.carbon.api.events.ChatFormatEvent;
|
||||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||||
|
import net.draycia.carbon.api.users.CarbonUser;
|
||||||
import net.draycia.carbon.api.users.PlayerUser;
|
import net.draycia.carbon.api.users.PlayerUser;
|
||||||
import net.kyori.adventure.sound.Sound;
|
import net.kyori.adventure.sound.Sound;
|
||||||
import net.kyori.event.PostOrders;
|
import net.kyori.event.PostOrders;
|
||||||
@@ -19,9 +20,9 @@ public class PingHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final PlayerUser target = event.target();
|
final CarbonUser target = event.target();
|
||||||
|
|
||||||
if (target == null) {
|
if (!(target instanceof PlayerUser)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ public class PingHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Sound sound = target.pingOptions().pingSound();
|
final Sound sound = ((PlayerUser) target).pingOptions().pingSound();
|
||||||
|
|
||||||
if (sound != null) {
|
if (sound != null) {
|
||||||
target.playSound(sound);
|
target.playSound(sound);
|
||||||
@@ -54,9 +55,9 @@ public class PingHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final PlayerUser target = event.target();
|
final CarbonUser target = event.target();
|
||||||
|
|
||||||
if (target == null) {
|
if (!(target instanceof PlayerUser)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user