From 11aef273bad083815f5405074a704fa4d64f5a00 Mon Sep 17 00:00:00 2001 From: Thanos paravantis Date: Tue, 19 Apr 2016 18:25:04 +0300 Subject: [PATCH] Fix NPE on Volley Pig --- .../type/ChallengeMiniOneInTheQuiver.java | 2 +- .../challenge/type/ChallengeVolleyPig.java | 41 ++++++++++++++++--- 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeMiniOneInTheQuiver.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeMiniOneInTheQuiver.java index dcad99909..02e49a206 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeMiniOneInTheQuiver.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeMiniOneInTheQuiver.java @@ -88,7 +88,7 @@ public class ChallengeMiniOneInTheQuiver extends Challenge } else if ((absX <= getArenaSize() - 1 || absZ <= getArenaSize() - 1)) { - if (((absX == getArenaSize() - 2 || absZ == getArenaSize() - 2) || (absX == getArenaSize() - 4 || absZ == getArenaSize() - 4)) && UtilMath.r(7) == 0 && canPlaceBarrier(block.getRelative(BlockFace.UP)) && !Data.isSpawnLocation(block.getLocation())) + if (((absX == getArenaSize() - 2 || absZ == getArenaSize() - 2) || (absX == getArenaSize() - 4 || absZ == getArenaSize() - 4)) && UtilMath.r(8) == 0 && canPlaceBarrier(block.getRelative(BlockFace.UP)) && !Data.isSpawnLocation(block.getLocation())) { generateBarrier(block); } diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeVolleyPig.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeVolleyPig.java index 4f1e9d26d..cce566cde 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeVolleyPig.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/games/mineware/challenge/type/ChallengeVolleyPig.java @@ -17,6 +17,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.event.player.PlayerQuitEvent; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.LeatherArmorMeta; import org.bukkit.potion.PotionEffect; @@ -76,7 +77,9 @@ public class ChallengeVolleyPig extends Challenge for (int z = -9; z <= 9; z++) { if (z == 0) + { continue; + } spawns.add(getCenter().add(x + 0.5, 1.1, z + 0.5)); } @@ -106,7 +109,6 @@ public class ChallengeVolleyPig extends Challenge } } } - } @Override @@ -116,8 +118,8 @@ public class ChallengeVolleyPig extends Challenge spawnPig(); addPlayersOnTeam(); + equipKnockbackStick(); equipTeamHelmets(); - startMainTask(); } @@ -126,7 +128,10 @@ public class ChallengeVolleyPig extends Challenge { Host.DamagePvE = false; - _pig.remove(); + if (_pig != null) + { + _pig.remove(); + } } @SuppressWarnings("deprecation") @@ -224,7 +229,22 @@ public class ChallengeVolleyPig extends Challenge @SuppressWarnings("deprecation") private void addPlayersOnTeam() { - ItemStack stick = new ItemBuilder(Material.STICK).addEnchantment(Enchantment.KNOCKBACK, 1).build(); + // int half = getPlayersAlive().size() / 2; + // int current = 0; + // + // for (Player player : getPlayersAlive()) + // { + // if (current < half) + // { + // _blueTeam.add(player); + // } + // else + // { + // _redTeam.add(player); + // } + // + // current++; + // } for (Player player : getPlayersAlive()) { @@ -242,8 +262,6 @@ public class ChallengeVolleyPig extends Challenge _redTeam.add(player); } } - - player.getInventory().setItem(Settings.getLockedSlot(), stick); } } @@ -267,6 +285,17 @@ public class ChallengeVolleyPig extends Challenge { player.getInventory().setHelmet(helmet); } + + } + + private void equipKnockbackStick() + { + ItemStack stick = new ItemBuilder(Material.STICK) + .addEnchantment(Enchantment.KNOCKBACK, 1) + .addItemFlags(ItemFlag.HIDE_ENCHANTS) + .build(); + + setItem(Settings.getLockedSlot(), stick); } private void knockback(Player player)