Fixed an NPE when destroying a Clan's Home

This commit is contained in:
NewGarbo 2015-11-18 09:37:32 +00:00
parent 03764ad480
commit 1ea87b8354
2 changed files with 19 additions and 11 deletions

View File

@ -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);

View File

@ -829,7 +829,7 @@ public class ClansCommand extends CommandBase<ClansManager>
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;