Made custom chat event cancellable

This commit is contained in:
Norbi Peti 2016-12-18 12:57:57 +01:00
parent 888086f427
commit 15ece1a3dc
2 changed files with 6 additions and 5 deletions

View file

@ -46,7 +46,7 @@ public class ChatProcessing {
"dark_purple" }; // TODO
private static boolean pingedconsole = false;
// Returns e.setCancelled
// Returns e.setCancelled for custom event
public static boolean ProcessChat(Channel channel, CommandSender sender, String message) {
long processstart = System.nanoTime();
if (PluginMain.essentials == null)
@ -398,6 +398,6 @@ public class ChatProcessing {
DebugCommand.SendDebugMessage(
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
return true;
return false;
}
}

View file

@ -63,14 +63,14 @@ public class PlayerListener implements Listener {
public final static String[] LaughStrings = new String[] { "xd", "lel", "lawl", "kek", "lmao", "hue", "hah" };
@EventHandler
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerChat(AsyncPlayerChatEvent event) {
if (event.isCancelled())
return;
TBMCChatAPI.SendChatMessage(
TBMCPlayer.getPlayer(event.getPlayer()).asPluginPlayer(ChatPlayer.class).CurrentChannel,
event.getPlayer(), event.getMessage());
event.setCancelled(true);
event.setCancelled(true); // The custom event should only be cancelled when muted or similar
}
@EventHandler(priority = EventPriority.HIGHEST)
@ -339,7 +339,7 @@ public class PlayerListener implements Listener {
@EventHandler
public void onPlayerTBMCChat(TBMCChatEvent e) {
try {
ChatProcessing.ProcessChat(e.getChannel(), e.getSender(), e.getMessage());
e.setCancelled(ChatProcessing.ProcessChat(e.getChannel(), e.getSender(), e.getMessage()));
} catch (Exception ex) {
for (Player p : Bukkit.getOnlinePlayers())
p.sendMessage("§c!§r["
@ -347,6 +347,7 @@ public class PlayerListener implements Listener {
? ((Player) e.getSender()).getDisplayName() : e.getSender().getName())
+ "> " + e.getMessage());
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex);
e.setCancelled(true);
}
}
}