From 9ae4f0220574b8841ec263af573aa0ae2f48ba99 Mon Sep 17 00:00:00 2001 From: manuelgu Date: Sat, 28 May 2016 01:16:01 +0200 Subject: [PATCH] Fix forcefield flag --- .../bukkit/listeners/ForceFieldListener.java | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java index ed08bfa7e..3c80a7a8c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/ForceFieldListener.java @@ -5,15 +5,14 @@ import com.intellectualcrafters.plot.flag.Flags; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; -import com.plotsquared.bukkit.events.PlayerEnterPlotEvent; import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.util.BukkitUtil; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.util.Vector; - import java.util.HashSet; import java.util.Set; import java.util.UUID; @@ -53,7 +52,7 @@ public class ForceFieldListener implements Listener { return null; } - public Vector calculateVelocity(PlotPlayer pp, PlotPlayer e) { + private Vector calculateVelocity(PlotPlayer pp, PlotPlayer e) { Location playerLocation = pp.getLocationFull(); Location oPlayerLocation = e.getLocation(); double playerX = playerLocation.getX(); @@ -84,29 +83,27 @@ public class ForceFieldListener implements Listener { } @EventHandler - public void onPlotEntry(PlayerEnterPlotEvent event) { + public void onPlotEntry(PlayerMoveEvent event) { Player player = event.getPlayer(); PlotPlayer pp = BukkitUtil.getPlayer(player); - Plot plot = event.getPlot(); + Plot plot = pp.getCurrentPlot(); if (plot == null) { return; } Optional forcefield = plot.getFlag(Flags.FORCEFIELD); if (forcefield.isPresent() && forcefield.get()) { - if (!plot.getFlag(Flags.FORCEFIELD).or(false)) { - UUID uuid = pp.getUUID(); - if (plot.isAdded(uuid)) { - Set players = getNearbyPlayers(player, plot); - for (PlotPlayer oPlayer : players) { - ((BukkitPlayer) oPlayer).player.setVelocity(calculateVelocity(pp, oPlayer)); - } - } else { - PlotPlayer oPlayer = hasNearbyPermitted(player, plot); - if (oPlayer == null) { - return; - } - player.setVelocity(calculateVelocity(oPlayer, pp)); + UUID uuid = pp.getUUID(); + if (plot.isAdded(uuid)) { + Set players = getNearbyPlayers(player, plot); + for (PlotPlayer oPlayer : players) { + ((BukkitPlayer) oPlayer).player.setVelocity(calculateVelocity(pp, oPlayer)); } + } else { + PlotPlayer oPlayer = hasNearbyPermitted(player, plot); + if (oPlayer == null) { + return; + } + player.setVelocity(calculateVelocity(oPlayer, pp)); } } }