listeners

This commit is contained in:
boy0001 2015-02-21 18:25:28 +11:00
parent 7514d3c5db
commit e3f7db4906

View File

@ -52,7 +52,9 @@ import com.intellectualcrafters.plot.events.PlayerEnterPlotEvent;
import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent; import com.intellectualcrafters.plot.events.PlayerLeavePlotEvent;
import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.flag.FlagManager;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.Permissions;
import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerFunctions; import com.intellectualcrafters.plot.util.bukkit.BukkitPlayerFunctions;
import com.intellectualcrafters.plot.util.bukkit.BukkitUtil; import com.intellectualcrafters.plot.util.bukkit.BukkitUtil;
import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
@ -107,13 +109,14 @@ public class PlotPlusListener extends PlotListener implements Listener {
} }
event.setCancelled(true); event.setCancelled(true);
final Plot plot = MainUtil.getPlot(BukkitUtil.getLocation(player)); final Plot plot = MainUtil.getPlot(BukkitUtil.getLocation(player));
PlotPlayer pp = BukkitUtil.getPlayer(player);
if (plot == null) { if (plot == null) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOT_IN_PLOT); MainUtil.sendMessage(pp, C.NOT_IN_PLOT);
return; return;
} }
UUID uuid = UUIDHandler.getUUID(player); UUID uuid = UUIDHandler.getUUID(player);
if (!plot.isAdded(uuid)) { if (!plot.isAdded(uuid)) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NO_PLOT_PERMS); MainUtil.sendMessage(pp, C.NO_PLOT_PERMS);
return; return;
} }
final Set<Player> plotPlayers = new HashSet<>(); final Set<Player> plotPlayers = new HashSet<>();
@ -135,7 +138,7 @@ public class PlotPlusListener extends PlotListener implements Listener {
} }
for (final Player p : plotPlayers) { for (final Player p : plotPlayers) {
p.playEffect(p.getLocation(), Effect.RECORD_PLAY, meta.getMaterial()); p.playEffect(p.getLocation(), Effect.RECORD_PLAY, meta.getMaterial());
BukkitPlayerFunctions.sendMessage(p, C.RECORD_PLAY.s().replaceAll("%player", player.getName()).replaceAll("%name", meta.toString())); MainUtil.sendMessage(pp, C.RECORD_PLAY.s().replaceAll("%player", player.getName()).replaceAll("%name", meta.toString()));
} }
} }
@ -208,14 +211,16 @@ public class PlotPlusListener extends PlotListener implements Listener {
return; return;
} }
final Player trespasser = event.getPlayer(); final Player trespasser = event.getPlayer();
if (UUIDHandler.getUUID(player).equals(UUIDHandler.getUUID(trespasser))) { PlotPlayer pt = BukkitUtil.getPlayer(trespasser);
PlotPlayer pp = BukkitUtil.getPlayer(player);
if (pp.getUUID().equals(pt.getUUID())) {
return; return;
} }
if (BukkitMain.hasPermission(trespasser, "plots.flag.notify-enter.bypass")) { if (Permissions.hasPermission(pt, "plots.flag.notify-enter.bypass")) {
return; return;
} }
if (player.isOnline()) { if (player.isOnline()) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOTIFY_ENTER.s().replace("%player", trespasser.getName()).replace("%plot", plot.getId().toString())); MainUtil.sendMessage(pp, C.NOTIFY_ENTER.s().replace("%player", trespasser.getName()).replace("%plot", plot.getId().toString()));
} }
} }
} }
@ -223,26 +228,31 @@ public class PlotPlusListener extends PlotListener implements Listener {
@EventHandler @EventHandler
public void onPlayerQuit(final PlayerQuitEvent event) { public void onPlayerQuit(final PlayerQuitEvent event) {
if (feedRunnable.containsKey(player.getName())) { Player player = event.getPlayer();
feedRunnable.remove(player.getName()); String name = player.getName();
if (feedRunnable.containsKey(name)) {
feedRunnable.remove(name);
} }
if (healRunnable.containsKey(player.getName())) { if (healRunnable.containsKey(name)) {
healRunnable.remove(player.getName()); healRunnable.remove(name);
} }
} }
@EventHandler @EventHandler
public void onPlotLeave(final PlayerLeavePlotEvent event) { public void onPlotLeave(final PlayerLeavePlotEvent event) {
event.getPlayer().playEffect(player.getLocation(), Effect.RECORD_PLAY, 0); Player leaver = event.getPlayer();
leaver.playEffect(leaver.getLocation(), Effect.RECORD_PLAY, 0);
final Plot plot = event.getPlot(); final Plot plot = event.getPlot();
if (FlagManager.getPlotFlag(plot, "farewell") != null) { if (FlagManager.getPlotFlag(plot, "farewell") != null) {
event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX_FAREWELL.s().replaceAll("%id%", plot.id + "") + FlagManager.getPlotFlag(plot, "farewell").getValueString())); event.getPlayer().sendMessage(ChatColor.translateAlternateColorCodes('&', C.PREFIX_FAREWELL.s().replaceAll("%id%", plot.id + "") + FlagManager.getPlotFlag(plot, "farewell").getValueString()));
} }
if (feedRunnable.containsKey(player.getName())) { PlotPlayer pl = BukkitUtil.getPlayer(leaver);
feedRunnable.remove(player.getName()); String name = pl.getName();
if (feedRunnable.containsKey(leaver)) {
feedRunnable.remove(leaver);
} }
if (healRunnable.containsKey(player.getName())) { if (healRunnable.containsKey(leaver)) {
healRunnable.remove(player.getName()); healRunnable.remove(leaver);
} }
if (booleanFlag(plot, "notify-leave", false)) { if (booleanFlag(plot, "notify-leave", false)) {
if (plot.hasOwner()) { if (plot.hasOwner()) {
@ -250,15 +260,15 @@ public class PlotPlusListener extends PlotListener implements Listener {
if (player == null) { if (player == null) {
return; return;
} }
final Player trespasser = event.getPlayer(); PlotPlayer pp = BukkitUtil.getPlayer(player);
if (UUIDHandler.getUUID(player).equals(UUIDHandler.getUUID(trespasser))) { if (pp.getUUID().equals(pl.getUUID())) {
return; return;
} }
if (BukkitMain.hasPermission(trespasser, "plots.flag.notify-leave.bypass")) { if (Permissions.hasPermission(pl, "plots.flag.notify-leave.bypass")) {
return; return;
} }
if (player.isOnline()) { if (player.isOnline()) {
MainUtil.sendMessage(BukkitUtil.getPlayer(player), C.NOTIFY_LEAVE.s().replace("%player", trespasser.getName()).replace("%plot", plot.getId().toString())); MainUtil.sendMessage(pp, C.NOTIFY_LEAVE.s().replace("%player", pl.getName()).replace("%plot", plot.getId().toString()));
} }
} }
} }