Change chat priority

This commit is contained in:
Jesse Boyd 2016-03-25 15:07:35 +11:00
parent f74e7bb4cb
commit 2816ceae72

View File

@ -27,6 +27,16 @@ import com.plotsquared.bukkit.object.BukkitLazyBlock;
import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.object.BukkitPlayer;
import com.plotsquared.bukkit.util.BukkitUtil; import com.plotsquared.bukkit.util.BukkitUtil;
import com.plotsquared.listener.PlayerBlockEventType; import com.plotsquared.listener.PlayerBlockEventType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
@ -107,17 +117,6 @@ import org.bukkit.projectiles.BlockProjectileSource;
import org.bukkit.projectiles.ProjectileSource; import org.bukkit.projectiles.ProjectileSource;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
/** /**
* Player Events involving plots * Player Events involving plots
* *
@ -534,17 +533,20 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
} }
} }
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, 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;
} }
String message = event.getMessage(); String message = event.getMessage();
@ -553,14 +555,16 @@ public class PlayerEvents extends com.plotsquared.listener.PlotListener implemen
PlotId id = plot.getId(); PlotId id = plot.getId();
Set<Player> recipients = event.getRecipients(); Set<Player> recipients = event.getRecipients();
recipients.clear(); recipients.clear();
for (Player p : Bukkit.getOnlinePlayers()) { for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
PlotPlayer pp = BukkitUtil.getPlayer(p); 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())) {
recipients.add(p); 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 = format.replaceAll("%plot_id%", id.x + ";" + id.y).replaceAll("%sender%", "%s").replaceAll("%msg%", "%s");