Made custom chat event cancellable
This commit is contained in:
parent
908b62217a
commit
3285380ece
2 changed files with 26 additions and 2 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue