From 9eb5535c75a1ee8dfcce9cb6f72b9642af094513 Mon Sep 17 00:00:00 2001 From: GJ Date: Thu, 8 Mar 2012 16:30:50 -0500 Subject: [PATCH] Fixed the NPE PlayerInteractEvent. --- .../java/com/gmail/nossr50/BlockChecks.java | 120 ++++++++++++++++++ src/main/java/com/gmail/nossr50/Combat.java | 8 +- .../nossr50/listeners/mcPlayerListener.java | 2 +- 3 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/gmail/nossr50/BlockChecks.java diff --git a/src/main/java/com/gmail/nossr50/BlockChecks.java b/src/main/java/com/gmail/nossr50/BlockChecks.java new file mode 100644 index 000000000..022365eb1 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/BlockChecks.java @@ -0,0 +1,120 @@ +package com.gmail.nossr50; + +import org.bukkit.Material; +import org.bukkit.block.Block; + +import com.gmail.nossr50.config.LoadProperties; + +public class BlockChecks { + + /** + * Checks to see if a block type awards XP. + * + * @param material {@link Block} type to check + * @return true if the block type awards XP, false otherwise + */ + public static boolean shouldBeWatched(Material material) { + switch (material) { + case BROWN_MUSHROOM: + case CACTUS: + case CLAY: + case COAL_ORE: + case DIAMOND_ORE: + case DIRT: + case ENDER_STONE: + case GLOWING_REDSTONE_ORE: + case GLOWSTONE: + case GOLD_ORE: + case GRASS: + case GRAVEL: + case IRON_ORE: + case JACK_O_LANTERN: + case LAPIS_ORE: + case LOG: + case MELON_BLOCK: + case MOSSY_COBBLESTONE: + case MYCEL: + case NETHERRACK: + case OBSIDIAN: + case PUMPKIN: + case RED_MUSHROOM: + case RED_ROSE: + case REDSTONE_ORE: + case SAND: + case SANDSTONE: + case SOUL_SAND: + case STONE: + case SUGAR_CANE_BLOCK: + case VINE: + case WATER_LILY: + case YELLOW_FLOWER: + return true; + + default: + return false; + } + } + + /** + * Check if a block should allow for the activation of abilities. + * + * @param material Type of {@link Block} to check + * @return true if the block should allow ability activation, false otherwise + */ + public static boolean abilityBlockCheck(Material material) { + switch (material) { + case BED_BLOCK: + case BREWING_STAND: + case BOOKSHELF: + case BURNING_FURNACE: + case CAKE_BLOCK: + case CHEST: + case DISPENSER: + case ENCHANTMENT_TABLE: + case FENCE_GATE: + case FURNACE: + case IRON_DOOR_BLOCK: + case JUKEBOX: + case LEVER: + case NOTE_BLOCK: + case STONE_BUTTON: + case TRAP_DOOR: + case WALL_SIGN: + case WOODEN_DOOR: + case WORKBENCH: + return false; + + default: + break; + } + + if (Material.getMaterial(LoadProperties.anvilID).equals(material)) { + return false; + } + else { + return true; + } + } + + /** + * Check if a block type is an ore. + * + * @param material The type of {@link Block} to check + * @return true if the Block is an ore, false otherwise + */ + public static boolean isOre(Material material) { + switch (material) { + case COAL_ORE: + case DIAMOND_ORE: + case GLOWING_REDSTONE_ORE: + case GOLD_ORE: + case IRON_ORE: + case LAPIS_ORE: + case REDSTONE_ORE: + return true; + + default: + return false; + } + } +} diff --git a/src/main/java/com/gmail/nossr50/Combat.java b/src/main/java/com/gmail/nossr50/Combat.java index 45b0f08d2..daba5777b 100644 --- a/src/main/java/com/gmail/nossr50/Combat.java +++ b/src/main/java/com/gmail/nossr50/Combat.java @@ -99,16 +99,16 @@ public class Combat { } else if (itemInHand.getType().equals(Material.BONE) && mcPermissions.getInstance().taming(attacker) && targetType.equals(EntityType.WOLF)) { Wolf wolf = (Wolf) target; - String message = "Combat.BeastLore" + " "; + String message = mcLocale.getString("Combat.BeastLore") + " "; int health = wolf.getHealth(); event.setCancelled(true); if (wolf.isTamed()) { - message.concat(mcLocale.getString("Combat.BeastLoreOwner", new Object[] {Taming.getOwnerName(wolf)}) + " "); - message.concat(mcLocale.getString("Combat.BeastLoreHealthWolfTamed", new Object[] {health})); + message = message.concat(mcLocale.getString("Combat.BeastLoreOwner", new Object[] {Taming.getOwnerName(wolf)}) + " "); + message = message.concat(mcLocale.getString("Combat.BeastLoreHealthWolfTamed", new Object[] {health})); } else { - message.concat(mcLocale.getString("Combat.BeastLoreHealthWolf", new Object[] {health})); + message = message.concat(mcLocale.getString("Combat.BeastLoreHealthWolf", new Object[] {health})); } attacker.sendMessage(message); diff --git a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java index a913ed1bf..d3e5feeab 100644 --- a/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/mcPlayerListener.java @@ -158,7 +158,7 @@ public class mcPlayerListener implements Listener Block block = event.getClickedBlock(); ItemStack is = player.getItemInHand(); Material mat; - if (block.equals(null)) { + if (block == null) { mat = Material.AIR; } else {