From 2240696c98633b3658535a3d1cbc6b0bd56b6280 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Tue, 18 Nov 2014 10:00:15 +0100 Subject: [PATCH] Get PS from Location rather than Entity to minimize the risk for hitting a velocityX NaN bug. --- .../cmd/CmdFactionsAccessAbstract.java | 2 +- .../factions/cmd/CmdFactionsHome.java | 2 +- .../factions/cmd/CmdFactionsMap.java | 5 ++++- .../factions/cmd/CmdFactionsSeeChunkOld.java | 2 +- .../factions/cmd/CmdFactionsSetAuto.java | 2 +- .../factions/cmd/CmdFactionsSetCircle.java | 2 +- .../factions/cmd/CmdFactionsSetFill.java | 2 +- .../factions/cmd/CmdFactionsSetOne.java | 2 +- .../factions/cmd/CmdFactionsSetSquare.java | 2 +- .../factions/engine/EngineMain.java | 20 +++++++++---------- 10 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessAbstract.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessAbstract.java index 22e14b09..31c29308 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessAbstract.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsAccessAbstract.java @@ -41,7 +41,7 @@ public abstract class CmdFactionsAccessAbstract extends FactionsCommand @Override public void perform() { - chunk = PS.valueOf(me).getChunk(true); + chunk = PS.valueOf(me.getLocation()).getChunk(true); ta = BoardColl.get().getTerritoryAccessAt(chunk); hostFaction = ta.getHostFaction(); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsHome.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsHome.java index a0f76820..7eabc79f 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsHome.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsHome.java @@ -89,7 +89,7 @@ public class CmdFactionsHome extends FactionsCommandHome } - Faction factionHere = BoardColl.get().getFactionAt(PS.valueOf(me)); + Faction factionHere = BoardColl.get().getFactionAt(PS.valueOf(me.getLocation())); Location locationHere = me.getLocation().clone(); // if player is not in a safe zone or their own faction territory, only allow teleport if no enemies are nearby diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMap.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMap.java index 32036eb2..4a001590 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMap.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMap.java @@ -2,6 +2,8 @@ package com.massivecraft.factions.cmd; import java.util.List; +import org.bukkit.Location; + import com.massivecraft.factions.Const; import com.massivecraft.factions.Perm; import com.massivecraft.factions.entity.BoardColl; @@ -61,7 +63,8 @@ public class CmdFactionsMap extends FactionsCommand public void showMap(int width, int height) { - List message = BoardColl.get().getMap(msenderFaction, PS.valueOf(me), me.getLocation().getYaw(), width, height); + Location location = me.getLocation(); + List message = BoardColl.get().getMap(msenderFaction, PS.valueOf(location), location.getYaw(), width, height); sendMessage(message); } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java index 1017dfbd..0d8461f0 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSeeChunkOld.java @@ -37,7 +37,7 @@ public class CmdFactionsSeeChunkOld extends FactionsCommand { // Args World world = me.getWorld(); - PS chunk = PS.valueOf(me).getChunk(true); + PS chunk = PS.valueOf(me.getLocation()).getChunk(true); int chunkX = chunk.getChunkX(); int chunkZ = chunk.getChunkZ(); diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java index 0d679fd6..83b2c784 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetAuto.java @@ -57,7 +57,7 @@ public class CmdFactionsSetAuto extends FactionsCommand msg("Now auto-setting %s land.", newFaction.describeTo(msender)); // Chunks - final PS chunk = PS.valueOf(me).getChunk(true); + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); Set chunks = Collections.singleton(chunk); // Apply / Inform diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java index 5771ebee..5a9f4efa 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetCircle.java @@ -37,7 +37,7 @@ public class CmdFactionsSetCircle extends CmdFactionsSetXRadius public Set getChunks() { // Common Startup - final PS chunk = PS.valueOf(me).getChunk(true); + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); final Set chunks = new LinkedHashSet(); chunks.add(chunk); // The center should come first for pretty messages diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetFill.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetFill.java index f70f19a6..c64f4c3c 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetFill.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetFill.java @@ -41,7 +41,7 @@ public class CmdFactionsSetFill extends CmdFactionsSetXSimple public Set getChunks() { // Common Startup - final PS chunk = PS.valueOf(me).getChunk(true); + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); final Set chunks = new LinkedHashSet(); // What faction (aka color) resides there? diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetOne.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetOne.java index 669259e7..d7cd87c3 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetOne.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetOne.java @@ -32,7 +32,7 @@ public class CmdFactionsSetOne extends CmdFactionsSetXSimple @Override public Set getChunks() { - final PS chunk = PS.valueOf(me).getChunk(true); + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); final Set chunks = Collections.singleton(chunk); return chunks; } diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java index c3e2fa96..8793aad5 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsSetSquare.java @@ -37,7 +37,7 @@ public class CmdFactionsSetSquare extends CmdFactionsSetXRadius public Set getChunks() { // Common Startup - final PS chunk = PS.valueOf(me).getChunk(true); + final PS chunk = PS.valueOf(me.getLocation()).getChunk(true); final Set chunks = new LinkedHashSet(); chunks.add(chunk); // The center should come first for pretty messages diff --git a/src/main/java/com/massivecraft/factions/engine/EngineMain.java b/src/main/java/com/massivecraft/factions/engine/EngineMain.java index 10a97e0e..f03afb5d 100644 --- a/src/main/java/com/massivecraft/factions/engine/EngineMain.java +++ b/src/main/java/com/massivecraft/factions/engine/EngineMain.java @@ -728,7 +728,7 @@ public class EngineMain extends EngineAbstract MPlayer mplayer = MPlayer.get(player); // ... and powerloss can happen here ... - Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player)); + Faction faction = BoardColl.get().getFactionAt(PS.valueOf(player.getLocation())); if (!faction.getFlag(MFlag.getFlagPowerloss())) { @@ -829,7 +829,7 @@ public class EngineMain extends EngineAbstract if (eattacker != null && eattacker.equals(edefender)) return true; // ... gather defender PS and faction information ... - PS defenderPs = PS.valueOf(defender); + PS defenderPs = PS.valueOf(defender.getLocation()); Faction defenderPsFaction = BoardColl.get().getFactionAt(defenderPs); // ... PVP flag may cause a damage block ... @@ -863,7 +863,7 @@ public class EngineMain extends EngineAbstract if (MConf.get().playersWhoBypassAllProtection.contains(attacker.getName())) return true; // ... gather attacker PS and faction information ... - PS attackerPs = PS.valueOf(attacker); + PS attackerPs = PS.valueOf(attacker.getLocation()); Faction attackerPsFaction = BoardColl.get().getFactionAt(attackerPs); // ... PVP flag may cause a damage block ... @@ -1017,7 +1017,7 @@ public class EngineMain extends EngineAbstract } // ... if there is a faction at the players location ... - PS ps = PS.valueOf(player).getChunk(true); + PS ps = PS.valueOf(player.getLocation()).getChunk(true); Faction factionAtPs = BoardColl.get().getFactionAt(ps); if (factionAtPs.isNone()) return; // TODO: An NPE can arise here? Why? @@ -1093,7 +1093,7 @@ public class EngineMain extends EngineAbstract if (target == null) return; // ... at a place where monsters are forbidden ... - PS ps = PS.valueOf(target); + PS ps = PS.valueOf(target.getLocation()); Faction faction = BoardColl.get().getFactionAt(ps); if (faction.getFlag(MFlag.getFlagMonsters())) return; @@ -1120,7 +1120,7 @@ public class EngineMain extends EngineAbstract Entity entity = event.getEntity(); // ... and the faction there has explosions disabled ... - Faction faction = BoardColl.get().getFactionAt(PS.valueOf(entity)); + Faction faction = BoardColl.get().getFactionAt(PS.valueOf(entity.getLocation())); if (faction.isExplosionsAllowed()) return; // ... then cancel. @@ -1286,7 +1286,7 @@ public class EngineMain extends EngineAbstract @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) public void blockBuild(HangingPlaceEvent event) { - if (canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getEntity()), true)) return; + if (canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getEntity().getLocation()), true)) return; event.setCancelled(true); } @@ -1300,7 +1300,7 @@ public class EngineMain extends EngineAbstract Entity breaker = entityEvent.getRemover(); if (! (breaker instanceof Player)) return; - if ( ! canPlayerBuildAt(breaker, PS.valueOf(event.getEntity()), true)) + if ( ! canPlayerBuildAt(breaker, PS.valueOf(event.getEntity().getLocation()), true)) { event.setCancelled(true); } @@ -1320,7 +1320,7 @@ public class EngineMain extends EngineAbstract Player player = (Player)edamager; // ... and the player can't build there ... - if (canPlayerBuildAt(player, PS.valueOf(itemFrame), true)) return; + if (canPlayerBuildAt(player, PS.valueOf(itemFrame.getLocation()), true)) return; // ... then cancel the event. event.setCancelled(true); @@ -1493,7 +1493,7 @@ public class EngineMain extends EngineAbstract MPlayer me = MPlayer.get(player); if (me.isUsingAdminMode()) return true; - PS ps = PS.valueOf(entity); + PS ps = PS.valueOf(entity.getLocation()); EntityType type = entity.getType(); if (MConf.get().entityTypesContainer.contains(type) && ! MPerm.getPermContainer().has(me, ps, verboose)) return false;