Made custom chat event cancellable
This commit is contained in:
parent
888086f427
commit
15ece1a3dc
2 changed files with 6 additions and 5 deletions
|
@ -46,7 +46,7 @@ public class ChatProcessing {
|
||||||
"dark_purple" }; // TODO
|
"dark_purple" }; // TODO
|
||||||
private static boolean pingedconsole = false;
|
private static boolean pingedconsole = false;
|
||||||
|
|
||||||
// Returns e.setCancelled
|
// Returns e.setCancelled for custom event
|
||||||
public static boolean ProcessChat(Channel channel, CommandSender sender, String message) {
|
public static boolean ProcessChat(Channel channel, CommandSender sender, String message) {
|
||||||
long processstart = System.nanoTime();
|
long processstart = System.nanoTime();
|
||||||
if (PluginMain.essentials == null)
|
if (PluginMain.essentials == null)
|
||||||
|
@ -398,6 +398,6 @@ public class ChatProcessing {
|
||||||
DebugCommand.SendDebugMessage(
|
DebugCommand.SendDebugMessage(
|
||||||
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
|
"-- Full ChatProcessing time: " + (System.nanoTime() - processstart) / 1000000f + " ms");
|
||||||
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
|
DebugCommand.SendDebugMessage("-- ChatFormatter.Combine time: " + combinetime / 1000000f + " ms");
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,14 +63,14 @@ public class PlayerListener implements Listener {
|
||||||
|
|
||||||
public final static String[] LaughStrings = new String[] { "xd", "lel", "lawl", "kek", "lmao", "hue", "hah" };
|
public final static String[] LaughStrings = new String[] { "xd", "lel", "lawl", "kek", "lmao", "hue", "hah" };
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
public void onPlayerChat(AsyncPlayerChatEvent event) {
|
||||||
if (event.isCancelled())
|
if (event.isCancelled())
|
||||||
return;
|
return;
|
||||||
TBMCChatAPI.SendChatMessage(
|
TBMCChatAPI.SendChatMessage(
|
||||||
TBMCPlayer.getPlayer(event.getPlayer()).asPluginPlayer(ChatPlayer.class).CurrentChannel,
|
TBMCPlayer.getPlayer(event.getPlayer()).asPluginPlayer(ChatPlayer.class).CurrentChannel,
|
||||||
event.getPlayer(), event.getMessage());
|
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)
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
@ -339,7 +339,7 @@ public class PlayerListener implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onPlayerTBMCChat(TBMCChatEvent e) {
|
public void onPlayerTBMCChat(TBMCChatEvent e) {
|
||||||
try {
|
try {
|
||||||
ChatProcessing.ProcessChat(e.getChannel(), e.getSender(), e.getMessage());
|
e.setCancelled(ChatProcessing.ProcessChat(e.getChannel(), e.getSender(), e.getMessage()));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
for (Player p : Bukkit.getOnlinePlayers())
|
for (Player p : Bukkit.getOnlinePlayers())
|
||||||
p.sendMessage("§c!§r["
|
p.sendMessage("§c!§r["
|
||||||
|
@ -347,6 +347,7 @@ public class PlayerListener implements Listener {
|
||||||
? ((Player) e.getSender()).getDisplayName() : e.getSender().getName())
|
? ((Player) e.getSender()).getDisplayName() : e.getSender().getName())
|
||||||
+ "> " + e.getMessage());
|
+ "> " + e.getMessage());
|
||||||
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex);
|
TBMCCoreAPI.SendException("An error occured while processing a chat message!", ex);
|
||||||
|
e.setCancelled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue