From 1252e004a0f82298dfbfaabdc6f4bdeebcee7496 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Fri, 25 Mar 2016 15:56:11 +1100 Subject: [PATCH] Cancel chat event --- .../bukkit/listeners/PlayerEvents.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 554147136..9d8673f0a 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -533,22 +533,20 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) public void onChat(AsyncPlayerChatEvent event) { - System.out.println("CHAT EVENT!!!"); Player player = event.getPlayer(); PlotPlayer plr = BukkitUtil.getPlayer(player); Location loc = plr.getLocation(); PlotArea area = loc.getPlotArea(); if (area == null || (!area.PLOT_CHAT && !plr.getAttribute("chat"))) { - System.out.printf("AREA: " + area + " | " + area.PLOT_CHAT + " | " + plr.getAttribute("chat")); return; } Plot plot = area.getPlotAbs(loc); if (plot == null) { - System.out.println("PLOT IS NULL!!!"); return; } + event.setCancelled(true); String message = event.getMessage(); String format = C.PLOT_CHAT_FORMAT.s(); String sender = event.getPlayer().getDisplayName(); @@ -558,18 +556,21 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen for (Entry entry : UUIDHandler.getPlayers().entrySet()) { PlotPlayer pp = entry.getValue(); if (pp.getAttribute("chatspy")) { - System.out.println("CHAT SPY!"); String spy = event.getFormat(); spy = String.format(spy, sender, message); pp.sendMessage(spy); } else if (plot.equals(pp.getCurrentPlot())) { - System.out.println("IN PLOT!"); recipients.add(((BukkitPlayer) pp).player); } } - format = format.replaceAll("%plot_id%", id.x + ";" + id.y).replaceAll("%sender%", "%s").replaceAll("%msg%", "%s"); - format = ChatColor.translateAlternateColorCodes('&', format); - event.setFormat(format); + String full = format.replaceAll("%plot_id%", id.x + ";" + id.y).replaceAll("%sender%", sender).replaceAll("%msg%", message); + full = ChatColor.translateAlternateColorCodes('&', full); +// format = format.replaceAll("%plot_id%", id.x + ";" + id.y).replaceAll("%sender%", "%s").replaceAll("%msg%", "%s"); +// format = ChatColor.translateAlternateColorCodes('&', format); + for (Player receiver : recipients) { + receiver.sendMessage(full); + } +// event.setFormat(format); } @EventHandler(priority = EventPriority.LOWEST)