Cancel chat event

This commit is contained in:
Jesse Boyd 2016-03-25 15:56:11 +11:00
parent 2816ceae72
commit 1252e004a0

View File

@ -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) { public void onChat(AsyncPlayerChatEvent event) {
System.out.println("CHAT EVENT!!!");
Player player = event.getPlayer(); Player player = event.getPlayer();
PlotPlayer plr = BukkitUtil.getPlayer(player); PlotPlayer plr = BukkitUtil.getPlayer(player);
Location loc = plr.getLocation(); Location loc = plr.getLocation();
PlotArea area = loc.getPlotArea(); PlotArea area = loc.getPlotArea();
if (area == null || (!area.PLOT_CHAT && !plr.getAttribute("chat"))) { if (area == null || (!area.PLOT_CHAT && !plr.getAttribute("chat"))) {
System.out.printf("AREA: " + area + " | " + area.PLOT_CHAT + " | " + plr.getAttribute("chat"));
return; return;
} }
Plot plot = area.getPlotAbs(loc); Plot plot = area.getPlotAbs(loc);
if (plot == null) { if (plot == null) {
System.out.println("PLOT IS NULL!!!");
return; return;
} }
event.setCancelled(true);
String message = event.getMessage(); String message = event.getMessage();
String format = C.PLOT_CHAT_FORMAT.s(); String format = C.PLOT_CHAT_FORMAT.s();
String sender = event.getPlayer().getDisplayName(); String sender = event.getPlayer().getDisplayName();
@ -558,18 +556,21 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) { for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
PlotPlayer pp = entry.getValue(); PlotPlayer pp = entry.getValue();
if (pp.getAttribute("chatspy")) { if (pp.getAttribute("chatspy")) {
System.out.println("CHAT SPY!");
String spy = event.getFormat(); String spy = event.getFormat();
spy = String.format(spy, sender, message); spy = String.format(spy, sender, message);
pp.sendMessage(spy); pp.sendMessage(spy);
} else if (plot.equals(pp.getCurrentPlot())) { } else if (plot.equals(pp.getCurrentPlot())) {
System.out.println("IN PLOT!");
recipients.add(((BukkitPlayer) pp).player); recipients.add(((BukkitPlayer) pp).player);
} }
} }
format = format.replaceAll("%plot_id%", id.x + ";" + id.y).replaceAll("%sender%", "%s").replaceAll("%msg%", "%s"); String full = format.replaceAll("%plot_id%", id.x + ";" + id.y).replaceAll("%sender%", sender).replaceAll("%msg%", message);
format = ChatColor.translateAlternateColorCodes('&', format); full = ChatColor.translateAlternateColorCodes('&', full);
event.setFormat(format); // 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) @EventHandler(priority = EventPriority.LOWEST)