From 3285380ece673c31d135938eeca322d62b16ae59 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 18 Dec 2016 12:57:35 +0100 Subject: [PATCH] Made custom chat event cancellable --- src/main/java/buttondevteam/lib/TBMCChatEvent.java | 14 +++++++++++++- .../java/buttondevteam/lib/chat/TBMCChatAPI.java | 14 +++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/main/java/buttondevteam/lib/TBMCChatEvent.java b/src/main/java/buttondevteam/lib/TBMCChatEvent.java index 2f00575..21c84b3 100644 --- a/src/main/java/buttondevteam/lib/TBMCChatEvent.java +++ b/src/main/java/buttondevteam/lib/TBMCChatEvent.java @@ -1,17 +1,19 @@ package buttondevteam.lib; import org.bukkit.command.CommandSender; +import org.bukkit.event.Cancellable; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import buttondevteam.lib.chat.Channel; -public class TBMCChatEvent extends Event { +public class TBMCChatEvent extends Event implements Cancellable { private static final HandlerList handlers = new HandlerList(); private Channel channel; private CommandSender sender; private String message; + private boolean cancelled; public TBMCChatEvent(CommandSender sender, Channel channel, String message) { this.sender = sender; @@ -44,4 +46,14 @@ public class TBMCChatEvent extends Event { return handlers; } + @Override + public boolean isCancelled() { + return cancelled; + } + + @Override + public void setCancelled(boolean cancelled) { + this.cancelled = cancelled; + } + } diff --git a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java index 3a4c71d..8965942 100644 --- a/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java +++ b/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java @@ -189,8 +189,20 @@ public class TBMCChatAPI { return true; } - public static void SendChatMessage(Channel channel, CommandSender sender, String message) { + /** + * Sends a chat message to Minecraft + * + * @param channel + * The channel to send to + * @param sender + * The sender to send from + * @param message + * The message to send + * @return The event cancelled state + */ + public static boolean SendChatMessage(Channel channel, CommandSender sender, String message) { TBMCChatEvent event = new TBMCChatEvent(sender, channel, message); Bukkit.getPluginManager().callEvent(event); + return event.isCancelled(); } }