Workaround for getTargetBlock deprecation.

This commit is contained in:
ryanhamshire 2014-09-24 17:18:12 -07:00
parent ddc34f1ae1
commit 82ca509878
2 changed files with 31 additions and 7 deletions

View File

@ -176,7 +176,7 @@ public class DatabaseDataStore extends DataStore
} }
catch(Exception ex) catch(Exception ex)
{ {
GriefPrevention.AddLogEntry("Failed to look up UUID for player " + ownerName + "."); GriefPrevention.AddLogEntry("This owner entry is not a UUID: " + ownerName + ".");
GriefPrevention.AddLogEntry(" Converted land claim to administrative @ " + lesserBoundaryCorner.toString()); GriefPrevention.AddLogEntry(" Converted land claim to administrative @ " + lesserBoundaryCorner.toString());
} }
} }

View File

@ -53,6 +53,7 @@ import org.bukkit.event.player.PlayerLoginEvent.Result;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.util.BlockIterator;
class PlayerEventHandler implements Listener class PlayerEventHandler implements Listener
{ {
@ -990,11 +991,11 @@ class PlayerEventHandler implements Listener
if(clickedBlock == null || clickedBlock.getType() == Material.SNOW) if(clickedBlock == null || clickedBlock.getType() == Material.SNOW)
{ {
//try to find a far away non-air block along line of sight //try to find a far away non-air block along line of sight
HashSet<Byte> transparentMaterials = new HashSet<Byte>(); clickedBlock = getTargetBlock(player, 250,
transparentMaterials.add(Byte.valueOf((byte)Material.AIR.getId())); Material.AIR,
transparentMaterials.add(Byte.valueOf((byte)Material.SNOW.getId())); Material.SNOW,
transparentMaterials.add(Byte.valueOf((byte)Material.LONG_GRASS.getId())); Material.LONG_GRASS);
clickedBlock = player.getTargetBlock(transparentMaterials, 250); GriefPrevention.sendMessage(player, TextMode.Info, clickedBlock.getType().name());
} }
} }
catch(Exception e) //an exception intermittently comes from getTargetBlock(). when it does, just ignore the event catch(Exception e) //an exception intermittently comes from getTargetBlock(). when it does, just ignore the event
@ -1792,5 +1793,28 @@ class PlayerEventHandler implements Listener
} }
} }
} }
} }
static Block getTargetBlock(Player player, int maxDistance, Material... passthroughMaterials) throws IllegalStateException
{
BlockIterator iterator = new BlockIterator(player.getLocation(), player.getEyeHeight(), maxDistance);
Block result = player.getLocation().getBlock().getRelative(BlockFace.UP);
while (iterator.hasNext())
{
result = iterator.next();
boolean passthrough = false;
for(Material passthroughMaterial : passthroughMaterials)
{
if(result.getType().equals(passthroughMaterial))
{
passthrough = true;
break;
}
}
if(!passthrough) return result;
}
return result;
}
} }