From 82ca509878c65df3c479bbfb3b538e42996a62a2 Mon Sep 17 00:00:00 2001 From: ryanhamshire Date: Wed, 24 Sep 2014 17:18:12 -0700 Subject: [PATCH] Workaround for getTargetBlock deprecation. --- .../GriefPrevention/DatabaseDataStore.java | 2 +- .../GriefPrevention/PlayerEventHandler.java | 36 +++++++++++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/me/ryanhamshire/GriefPrevention/DatabaseDataStore.java b/src/me/ryanhamshire/GriefPrevention/DatabaseDataStore.java index 73280bc..c40a968 100644 --- a/src/me/ryanhamshire/GriefPrevention/DatabaseDataStore.java +++ b/src/me/ryanhamshire/GriefPrevention/DatabaseDataStore.java @@ -176,7 +176,7 @@ public class DatabaseDataStore extends DataStore } 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()); } } diff --git a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java index 9586067..121b98e 100644 --- a/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java +++ b/src/me/ryanhamshire/GriefPrevention/PlayerEventHandler.java @@ -53,6 +53,7 @@ import org.bukkit.event.player.PlayerLoginEvent.Result; import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; +import org.bukkit.util.BlockIterator; class PlayerEventHandler implements Listener { @@ -990,11 +991,11 @@ class PlayerEventHandler implements Listener if(clickedBlock == null || clickedBlock.getType() == Material.SNOW) { //try to find a far away non-air block along line of sight - HashSet transparentMaterials = new HashSet(); - transparentMaterials.add(Byte.valueOf((byte)Material.AIR.getId())); - transparentMaterials.add(Byte.valueOf((byte)Material.SNOW.getId())); - transparentMaterials.add(Byte.valueOf((byte)Material.LONG_GRASS.getId())); - clickedBlock = player.getTargetBlock(transparentMaterials, 250); + clickedBlock = getTargetBlock(player, 250, + Material.AIR, + Material.SNOW, + Material.LONG_GRASS); + GriefPrevention.sendMessage(player, TextMode.Info, clickedBlock.getType().name()); } } 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; + } }