Rename chat event

This commit is contained in:
Draycia committed 2020-07-01 13:52:42 -07:00
1 parent 554775ba13
commit 2d14d42f64
3 files changed
+11 -9

No files matched your search

@@ -1,6 +1,7 @@
package net.draycia.simplechat.channels; package net.draycia.simplechat.channels;
import net.draycia.simplechat.SimpleChat; import net.draycia.simplechat.SimpleChat;
import net.draycia.simplechat.events.ChatFormatEvent;
import net.draycia.simplechat.storage.ChatUser; import net.draycia.simplechat.storage.ChatUser;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor; import net.kyori.adventure.text.format.TextColor;
@@ -118,7 +119,7 @@ public abstract class ChatChannel {
} }
/** /**
* Parses the specified message, calls a {@link net.draycia.simplechat.events.ChannelChatEvent}, and sends the message to everyone who can view this channel. * Parses the specified message, calls a {@link ChatFormatEvent}, and sends the message to everyone who can view this channel.
* @param user The player who is saying the message. * @param user The player who is saying the message.
* @param message The message to be sent. * @param message The message to be sent.
*/ */
@@ -3,7 +3,7 @@ package net.draycia.simplechat.channels.impls;
import me.clip.placeholderapi.PlaceholderAPI; import me.clip.placeholderapi.PlaceholderAPI;
import net.draycia.simplechat.SimpleChat; import net.draycia.simplechat.SimpleChat;
import net.draycia.simplechat.channels.ChatChannel; import net.draycia.simplechat.channels.ChatChannel;
import net.draycia.simplechat.events.ChannelChatEvent; import net.draycia.simplechat.events.ChatFormatEvent;
import net.draycia.simplechat.storage.ChatUser; import net.draycia.simplechat.storage.ChatUser;
import net.draycia.simplechat.util.DiscordWebhook; import net.draycia.simplechat.util.DiscordWebhook;
import net.kyori.adventure.audience.Audience; import net.kyori.adventure.audience.Audience;
@@ -178,16 +178,16 @@ public class SimpleChatChannel extends ChatChannel {
} }
// Call custom chat event // Call custom chat event
ChannelChatEvent event = new ChannelChatEvent(user, this, messageFormat, message); ChatFormatEvent formatEvent = new ChatFormatEvent(user, this, messageFormat, message);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(formatEvent);
if (event.isCancelled()) { if (formatEvent.isCancelled()) {
return; return;
} }
// Parse placeholders // Parse placeholders
messageFormat = PlaceholderAPI.setPlaceholders(user.asOfflinePlayer(), event.getFormat()); messageFormat = PlaceholderAPI.setPlaceholders(user.asOfflinePlayer(), formatEvent.getFormat());
// Convert legacy color codes to Mini color codes // Convert legacy color codes to Mini color codes
Component component = LegacyComponentSerializer.legacy('&').deserialize(messageFormat); Component component = LegacyComponentSerializer.legacy('&').deserialize(messageFormat);
@@ -197,7 +197,7 @@ public class SimpleChatChannel extends ChatChannel {
Component formattedMessage = MiniMessage.instance().parse(messageFormat, "color", "<" + color.toString() + ">", Component formattedMessage = MiniMessage.instance().parse(messageFormat, "color", "<" + color.toString() + ">",
"phase", Long.toString(System.currentTimeMillis() % 25), "server", "phase", Long.toString(System.currentTimeMillis() % 25), "server",
simpleChat.getConfig().getString("server-name", "Server"), simpleChat.getConfig().getString("server-name", "Server"),
"message", event.getMessage()); "message", formatEvent.getMessage());
// Handle item linking placeholders // Handle item linking placeholders
if (formattedMessage instanceof TextComponent && user.isOnline()) { if (formattedMessage instanceof TextComponent && user.isOnline()) {
@@ -7,7 +7,7 @@ import org.bukkit.event.Event;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class ChannelChatEvent extends Event implements Cancellable { public class ChatFormatEvent extends Event implements Cancellable {
private static final HandlerList HANDLERS_LIST = new HandlerList(); private static final HandlerList HANDLERS_LIST = new HandlerList();
private boolean isCancelled = false; private boolean isCancelled = false;
@@ -17,7 +17,7 @@ public class ChannelChatEvent extends Event implements Cancellable {
private String format; private String format;
private String message; private String message;
public ChannelChatEvent(ChatUser user, ChatChannel chatChannel, String format, String message) { public ChatFormatEvent(ChatUser user, ChatChannel chatChannel, String format, String message) {
super(true); super(true);
this.user = user; this.user = user;
@@ -73,4 +73,5 @@ public class ChannelChatEvent extends Event implements Cancellable {
public void setMessage(String message) { public void setMessage(String message) {
this.message = message; this.message = message;
} }
} }