From 1ea87b8354b8db5f505618f4b3126200e8f5f8f2 Mon Sep 17 00:00:00 2001 From: NewGarbo Date: Wed, 18 Nov 2015 09:37:32 +0000 Subject: [PATCH] Fixed an NPE when destroying a Clan's Home --- .../mineplex/game/clans/clans/ClansGame.java | 28 ++++++++++++------- .../clans/clans/commands/ClansCommand.java | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java index dee2134d2..5746e68da 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansGame.java @@ -382,7 +382,7 @@ public class ClansGame extends MiniPlugin } // Allow Clan's Home - if (event.getClickedBlock().getLocation().equals(home)) + if (event.getClickedBlock().getLocation().distance(home) <= 2 && event.getClickedBlock().getType().equals(Material.BED_BLOCK)) { return; } @@ -398,11 +398,19 @@ public class ClansGame extends MiniPlugin // Block is not Trust Allowed else if (!_clans.getClanBlocks().allowInteract(event.getClickedBlock().getTypeId()) || access != ClanRelation.ALLY_TRUST) { + Location home = event.getClickedBlock() == null ? null : _clans.getClanUtility().getClanByClanName(_clans.getClanUtility().getClaim(event.getClickedBlock().getLocation()).Owner).getHome(); + + // Allow Clan's Home + if (event.getClickedBlock().getLocation().distance(home) <= 2 && event.getClickedBlock().getType().equals(Material.BED_BLOCK)) + { + return; + } + // Disallow event.setCancelled(true); // Inform - UtilPlayer.message(player, F.main("Clans", "You cannot use items in " + _clans.getClanUtility().getOwnerStringRel(event.getClickedBlock().getLocation(), player) + "." + mimic)); + UtilPlayer.message(player, F.main("Clans", "You cannot use items in " + _clans.getClanUtility().getOwnerStringRel(event.getClickedBlock().getLocation(), player) + "'s Territory." + mimic)); return; } @@ -419,7 +427,7 @@ public class ClansGame extends MiniPlugin event.setCancelled(true); // Inform - UtilPlayer.message(player, F.main("Clans", "You cannot place blocks in " + _clans.getClanUtility().getOwnerStringRel(event.getClickedBlock().getRelative(event.getBlockFace()).getLocation(), player) + "." + mimic)); + UtilPlayer.message(player, F.main("Clans", "You cannot place blocks in " + _clans.getClanUtility().getOwnerStringRel(event.getClickedBlock().getRelative(event.getBlockFace()).getLocation(), player) + "'s Territory." + mimic)); return; } @@ -635,7 +643,7 @@ public class ClansGame extends MiniPlugin return; } - if (UtilMath.offset(block.getLocation(), blockClan.getHome()) > 3) + if (UtilMath.offset(block.getLocation(), blockClan.getHome()) > 2) { return; } @@ -647,14 +655,14 @@ public class ClansGame extends MiniPlugin if (!blockClan.equals(userClan)) { - if (blockClan.isAlly(userClan)) + if (userClan != null && blockClan.isAlly(userClan)) { UtilPlayer.message(player, F.main("Clans", "You cannot remove an Ally's Clan Home.")); } else { UtilPlayer.message(player, F.main("Clans", "You have destroyed " + F.elem(blockClan.getName()) + "'s Clan Home!")); - removeHome(userClan); + removeHome(blockClan, blockClan.getHome()); } return; @@ -664,7 +672,7 @@ public class ClansGame extends MiniPlugin { event.setCancelled(true); - removeHome(userClan); + removeHome(blockClan, blockClan.getHome()); UtilPlayer.message(player, F.main("Clans", "You have removed your Clan Home.")); } @@ -675,15 +683,15 @@ public class ClansGame extends MiniPlugin } } - private void removeHome(ClanInfo clan) + private void removeHome(ClanInfo clan, Location clanHome) { - clan.getHome().getBlock().setType(Material.AIR); + clanHome.getBlock().setType(Material.AIR); for (int x2 = -1; x2 < 1; x2++) { for (int z2 = -1; z2 < 1; z2++) { - Block block = clan.getHome().clone().add(x2, 0, z2).getBlock(); + Block block = clanHome.clone().add(x2, 0, z2).getBlock(); if (block.getType().equals(Material.BED_BLOCK)) { block.setType(Material.AIR); diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java index 074072f5d..3e99c092e 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansCommand.java @@ -829,7 +829,7 @@ public class ClansCommand extends CommandBase Location home = clan.getHome(); - if (!(home.getBlock().getType().equals(Material.BED) && home.add(0,1,0).getBlock().getType().equals(Material.AIR))) + if (!(home.getBlock().getType().equals(Material.BED_BLOCK) && home.add(0,1,0).getBlock().getType().equals(Material.AIR))) { UtilPlayer.message(caller, F.main("Clans", "Your Clan's bed has been destroyed, or is obstructed.")); return;