فهرست منبع

Cleanup & a few memory leak fixes.

GJ 13 سال پیش
والد
کامیت
d393e4d124
3فایلهای تغییر یافته به همراه288 افزوده شده و 253 حذف شده
  1. 3 1
      Changelog.txt
  2. 44 3
      src/main/java/com/gmail/nossr50/BlockChecks.java
  3. 241 249
      src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java

+ 3 - 1
Changelog.txt

@@ -14,9 +14,11 @@ Version 2.0.00-dev
  + Added bookshelves to list of blocks that don't trigger abilities.
  = Fixed ClassCastException from Taming preventDamage checks
  = Fixed issue with Blast Mining not seeing TNT for detonation due to snow
+ = Fixed issue with block interaction returning NPEs
+ = Fixed issue where every block broken had a mining check applied
+ = Fixed issue where blocks weren't being removed from the watchlist
  ! Changed Call of the Wild to activate on left-click rather than right-click
  ! Changed Blast Mining to track based on Entity ID vs. Location
- = Attempted fix of block interaction returning NPE's
 
 Version 1.3.02
  + Added in game guides for Mining, Excavation, and Acrobatics. Simply type /skillname ? to access them

+ 44 - 3
src/main/java/com/gmail/nossr50/BlockChecks.java

@@ -10,7 +10,7 @@ public class BlockChecks {
     /**
      * Checks to see if a block type awards XP.
      *
-     * @param material {@link Block} type to check
+     * @param material The type of Block to check
      * @return true if the block type awards XP, false otherwise
      */
     public static boolean shouldBeWatched(Material material) {
@@ -58,7 +58,7 @@ public class BlockChecks {
     /**
      * Check if a block should allow for the activation of abilities.
      *
-     * @param material Type of {@link Block} to check
+     * @param material The type of Block to check
      * @return true if the block should allow ability activation, false otherwise
      */
     public static boolean abilityBlockCheck(Material material) {
@@ -99,7 +99,7 @@ public class BlockChecks {
     /**
      * Check if a block type is an ore.
      *
-     * @param material The type of {@link Block} to check
+     * @param material The type of Block to check
      * @return true if the Block is an ore, false otherwise
      */
     public static boolean isOre(Material material) {
@@ -117,4 +117,45 @@ public class BlockChecks {
             return false;
         }
     }
+
+    /**
+     * Adds the block the the appropriate watchlist.
+     *
+     * @param material the type of Block to watch
+     * @param block the Block to watch
+     * @param plugin mcMMO plugin instance
+     */
+    public static void watchBlock(Material material, Block block, mcMMO plugin) {
+
+        boolean addToChangeQueue = true;
+        
+        switch (material) {
+        case CACTUS:
+        case GLOWING_REDSTONE_ORE:
+        case JACK_O_LANTERN:
+        case LOG:
+        case PUMPKIN:
+        case REDSTONE_ORE:
+        case SUGAR_CANE_BLOCK:
+        case VINE:
+            addToChangeQueue = false; //We don't want these added to changeQueue - these use their data
+            plugin.misc.blockWatchList.add(block);
+            break;
+
+        case BROWN_MUSHROOM:
+        case RED_MUSHROOM:
+        case RED_ROSE:
+        case YELLOW_FLOWER:
+        case WATER_LILY:
+            addToChangeQueue = false; //We don't want these added to chaneQueue - they're already being added to the fast queue
+            plugin.fastChangeQueue.push(block);
+            break;
+
+        default:
+            break;
+        }
+
+        if(addToChangeQueue)
+            plugin.changeQueue.push(block);
+    }
 }

+ 241 - 249
src/main/java/com/gmail/nossr50/listeners/mcBlockListener.java

@@ -31,269 +31,261 @@ import com.gmail.nossr50.locale.mcLocale;
 import com.gmail.nossr50.skills.*;
 import com.gmail.nossr50.events.FakeBlockBreakEvent;
 
-public class mcBlockListener implements Listener 
-{
+public class mcBlockListener implements Listener {
     private final mcMMO plugin;
 
-    public mcBlockListener(final mcMMO plugin) 
-    {
+    public mcBlockListener(final mcMMO plugin) {
         this.plugin = plugin;
     }
-    
+
+    /**
+     * Monitor BlockPlace events.
+     *
+     * @param event The event to monitor
+     */
     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
-    public void onBlockPlace(BlockPlaceEvent event) 
-    {
-    	//Setup some basic variables
-    	Block block;
-    	Player player = event.getPlayer();
-    	
-    	//When blocks are placed on snow this event reports the wrong block.
-    	if (event.getBlockReplacedState() != null && event.getBlockReplacedState().getType().equals(Material.SNOW)) 
-    		block = event.getBlockAgainst();
-    	else 
-    		block = event.getBlock();
-    	
-    	int id = block.getTypeId();
-    	Material mat = block.getType();
-    	
-    	//Check if the blocks placed should be monitored so they do not give out XP in the future
-    	if(BlockChecks.shouldBeWatched(mat))
-    	{	
-    		//Only needed for blocks that use their block data (wood, pumpkins, etc.)
-    	    boolean shouldBeChanged = true;
-    	    
-    		switch(mat)
-    		{
-    		case CACTUS:
-    		case GLOWING_REDSTONE_ORE:
-    		case JACK_O_LANTERN:
-    		case LOG:
-    		case PUMPKIN:
-    		case REDSTONE_ORE:
-    		case SUGAR_CANE_BLOCK:
-    		case VINE:
-    		    shouldBeChanged = false; //We don't want these added to changeQueue
-    			plugin.misc.blockWatchList.add(block);
-    			break;
-    		case BROWN_MUSHROOM:
-    		case RED_MUSHROOM:
-    		case RED_ROSE:
-    		case YELLOW_FLOWER:
-    		case WATER_LILY:
-    			plugin.fastChangeQueue.push(block);
-    			break;
-    		}
-    		
-    		if(shouldBeChanged)
-    		    plugin.changeQueue.push(block); 			
-    	}
-    	
-    	if(id == LoadProperties.anvilID && LoadProperties.anvilmessages)
-    	{
-    		PlayerProfile PP = Users.getProfile(player);
-    		if(!PP.getPlacedAnvil())
-    		{
-    			if(LoadProperties.spoutEnabled)
-    			{
-    				SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
-    				if(sPlayer.isSpoutCraftEnabled())
-    					sPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to repair!", Material.IRON_BLOCK);
-	    		}
-	    		else
-	    			event.getPlayer().sendMessage(mcLocale.getString("mcBlockListener.PlacedAnvil")); //$NON-NLS-1$
-    			
-    			PP.togglePlacedAnvil();
-    		}
-    	}
+    public void onBlockPlace(BlockPlaceEvent event) {
+        Block block;
+        Player player = event.getPlayer();
+
+        //When blocks are placed on snow this event reports the wrong block.
+        if (event.getBlockReplacedState() != null && event.getBlockReplacedState().getType().equals(Material.SNOW)) {
+            block = event.getBlockAgainst();
+        }
+        else {
+            block = event.getBlock();
+        }
+
+        int id = block.getTypeId();
+        Material mat = block.getType();
+
+        //Check if the blocks placed should be monitored so they do not give out XP in the future
+        if (BlockChecks.shouldBeWatched(mat)) {
+            BlockChecks.watchBlock(mat, block, plugin);
+        }
+
+        if (id == LoadProperties.anvilID && LoadProperties.anvilmessages) {
+            PlayerProfile PP = Users.getProfile(player);
+
+            if (!PP.getPlacedAnvil()) {
+                if (LoadProperties.spoutEnabled) {
+                    SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
+
+                    if (sPlayer.isSpoutCraftEnabled()) {
+                        sPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to repair!", Material.getMaterial(id));
+                    }
+                }
+                else {
+                    event.getPlayer().sendMessage(mcLocale.getString("mcBlockListener.PlacedAnvil"));
+                }
+
+                PP.togglePlacedAnvil();
+            }
+        }
     }
 
+    /**
+     * Monitor BlockBreak events.
+     *
+     * @param event The event to monitor
+     */
     @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
-    public void onBlockBreak(BlockBreakEvent event) 
-    {
-    	Player player = event.getPlayer();
-    	PlayerProfile PP = Users.getProfile(player);
-    	Block block = event.getBlock();
-    	int id = block.getTypeId();
-    	ItemStack inhand = player.getItemInHand();
-    	
-    	if(event instanceof FakeBlockBreakEvent) 
-    		return;
-    	
-    	/*
-    	 * HERBALISM
-    	 */
-    	
-    	//Green Terra
-   		if(PP.getHoePreparationMode() && mcPermissions.getInstance().herbalismAbility(player) && ((id == 59 && block.getData() == (byte) 0x07) || Herbalism.canBeGreenTerra(block)))
-   			Skills.abilityCheck(player, SkillType.HERBALISM);
-   		
-   		//Wheat && Triple drops
-   		if(PP.getGreenTerraMode() && Herbalism.canBeGreenTerra(block))
-   			Herbalism.herbalismProcCheck(block, player, event, plugin);
-    	
-    	if(mcPermissions.getInstance().herbalism(player) && block.getData() != (byte) 5)
-			Herbalism.herbalismProcCheck(block, player, event, plugin);
-    	
-    	/*
-    	 * MINING
-    	 */
-    	if(mcPermissions.getInstance().mining(player))
-    	{
-    		if(LoadProperties.miningrequirespickaxe && ItemChecks.isMiningPick(inhand))
-    			Mining.miningBlockCheck(player, block, plugin);
-    		else if(!LoadProperties.miningrequirespickaxe)
-    			Mining.miningBlockCheck(player, block, plugin);
-    	}
-    	
-    	/*
-   		 * WOOD CUTTING
-   		 */
-    	
-   		if(mcPermissions.getInstance().woodcutting(player) && id == 17)
-   		{
-   			if(LoadProperties.woodcuttingrequiresaxe && ItemChecks.isAxe(inhand))
-				WoodCutting.woodcuttingBlockCheck(player, block, plugin);
-   			else if(!LoadProperties.woodcuttingrequiresaxe)
-    			WoodCutting.woodcuttingBlockCheck(player, block, plugin);
-   			
-   			if(PP.getTreeFellerMode())
-   			    WoodCutting.treeFeller(event, plugin);
-    	}
-   		
-    	/*
-    	 * EXCAVATION
-    	 */
-    	if(Excavation.canBeGigaDrillBroken(block) && mcPermissions.getInstance().excavation(player) && block.getData() != (byte) 5)
-    	{
-    		if(LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand))
-    			Excavation.excavationProcCheck(block, player);
-    		else if(!LoadProperties.excavationRequiresShovel)
-    			Excavation.excavationProcCheck(block, player);
-    	}
-    	
-    	//Change the byte back when broken
-    	if(block.getData() == 5 && BlockChecks.shouldBeWatched(block.getType()))
-    	{
-    		block.setData((byte) 0);
-    		if(plugin.misc.blockWatchList.contains(block))
-    			plugin.misc.blockWatchList.remove(block);
-    	}
+    public void onBlockBreak(BlockBreakEvent event) {
+        Player player = event.getPlayer();
+        PlayerProfile PP = Users.getProfile(player);
+        Block block = event.getBlock();
+        Material mat = block.getType();
+        ItemStack inhand = player.getItemInHand();
+
+        if(event instanceof FakeBlockBreakEvent) {
+            return;
+        }
+
+        /*
+         * HERBALISM
+         */
+
+        //Green Terra
+        if (PP.getHoePreparationMode() && mcPermissions.getInstance().herbalismAbility(player) && ((mat.equals(Material.CROPS) && block.getData() == (byte) 0x7) || Herbalism.canBeGreenTerra(block))) {
+            Skills.abilityCheck(player, SkillType.HERBALISM);
+        }
+
+        //Wheat && Triple drops
+        if (PP.getGreenTerraMode() && Herbalism.canBeGreenTerra(block)) {
+            Herbalism.herbalismProcCheck(block, player, event, plugin);
+        }
+
+        if (mcPermissions.getInstance().herbalism(player) && block.getData() != (byte) 5) {
+            Herbalism.herbalismProcCheck(block, player, event, plugin);
+        }
+
+        /*
+         * MINING
+         */
+
+        if (mcPermissions.getInstance().mining(player) && Mining.canBeSuperBroken(block)) {
+            if (LoadProperties.miningrequirespickaxe && ItemChecks.isMiningPick(inhand)) {
+                Mining.miningBlockCheck(player, block, plugin);
+            }
+            else if (!LoadProperties.miningrequirespickaxe) {
+                Mining.miningBlockCheck(player, block, plugin);
+            }
+        }
+
+        /*
+         * WOOD CUTTING
+         */
+
+        if(mcPermissions.getInstance().woodcutting(player) && mat.equals(Material.LOG)) {
+            if (LoadProperties.woodcuttingrequiresaxe && ItemChecks.isAxe(inhand)) {
+                WoodCutting.woodcuttingBlockCheck(player, block, plugin);
+            }
+            else if (!LoadProperties.woodcuttingrequiresaxe) {
+                WoodCutting.woodcuttingBlockCheck(player, block, plugin);
+            }
+
+            if (PP.getTreeFellerMode()) {
+                WoodCutting.treeFeller(event, plugin);
+            }
+        }
+
+        /*
+         * EXCAVATION
+         */
+
+        if (Excavation.canBeGigaDrillBroken(block) && mcPermissions.getInstance().excavation(player) && block.getData() != (byte) 0x5)
+        {
+            if(LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand)) {
+                Excavation.excavationProcCheck(block, player);
+            }
+            else if(!LoadProperties.excavationRequiresShovel) {
+                Excavation.excavationProcCheck(block, player);
+            }
+        }
+
+        //Change the byte back when broken
+        if (block.getData() == (byte) 0x5 && BlockChecks.shouldBeWatched(mat)) {
+            block.setData((byte) 0x0);
+        }
+        else if(plugin.misc.blockWatchList.contains(block)) {
+            plugin.misc.blockWatchList.remove(block);
+        }
     }
 
     @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
     public void onBlockDamage(BlockDamageEvent event) 
     {
-    	Player player = event.getPlayer();
-    	PlayerProfile PP = Users.getProfile(player);
-    	ItemStack inhand = player.getItemInHand();
-    	Block block = event.getBlock();
-    	int id = block.getTypeId();
-    	Material mat = block.getType();
+        Player player = event.getPlayer();
+        PlayerProfile PP = Users.getProfile(player);
+        ItemStack inhand = player.getItemInHand();
+        Block block = event.getBlock();
+        int id = block.getTypeId();
+        Material mat = block.getType();
 
-    	/*
-    	 * ABILITY PREPARATION CHECKS
-    	 */
-    	if(BlockChecks.abilityBlockCheck(mat))
-    	{
-	   		if(PP.getHoePreparationMode() && Herbalism.canBeGreenTerra(block))
-	   			Skills.abilityCheck(player, SkillType.HERBALISM);
-	    	if(PP.getAxePreparationMode() && mat.equals(Material.LOG) && mcPermissions.getInstance().woodCuttingAbility(player))
-	    		Skills.abilityCheck(player, SkillType.WOODCUTTING);
-	    	if(PP.getPickaxePreparationMode() && Mining.canBeSuperBroken(block))
-	    		Skills.abilityCheck(player, SkillType.MINING);
-	    	if(PP.getShovelPreparationMode() && Excavation.canBeGigaDrillBroken(block))
-	    		Skills.abilityCheck(player, SkillType.EXCAVATION);
-    	}
-    	
-    	if(PP.getFistsPreparationMode() && (Excavation.canBeGigaDrillBroken(block) || mat.equals(Material.SNOW)))
-    		Skills.abilityCheck(player, SkillType.UNARMED);
-    	
-    	/*
-    	 * TREE FELLER STUFF
-    	 */
-    	if(LoadProperties.spoutEnabled && mat.equals(Material.LOG) && PP.getTreeFellerMode())
-    		SpoutStuff.playSoundForPlayer(SoundEffect.FIZZ, player, block.getLocation());
-    	
-    	/*
-    	 * GREEN TERRA STUFF
-    	 */
-    	if(PP.getGreenTerraMode() && mcPermissions.getInstance().herbalismAbility(player))
-   			Herbalism.greenTerra(player, block);
-    	
-    	/*
-    	 * GIGA DRILL BREAKER CHECKS
-    	 */
-    	if(PP.getGigaDrillBreakerMode() && Excavation.canBeGigaDrillBroken(block) && m.blockBreakSimulate(block, player, true) && mcPermissions.getInstance().excavationAbility(player))
-    	{	
-    		if(LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand))
-    		{
-    			event.setInstaBreak(true);
-    			Excavation.gigaDrillBreaker(player, block);
-    		}
-    		else if(!LoadProperties.excavationRequiresShovel)
-    		{
-    			event.setInstaBreak(true);
-    			Excavation.gigaDrillBreaker(player, block);
-    		}
-    	}
-    	/*
-    	 * BERSERK MODE CHECKS
-    	 */
-    	if(PP.getBerserkMode() 
-    		&& m.blockBreakSimulate(block, player, true) 
-    		&& player.getItemInHand().getTypeId() == 0 
-    		&& (Excavation.canBeGigaDrillBroken(block) || id == 78)
-    		&& mcPermissions.getInstance().unarmedAbility(player))
-    	{
-    		event.setInstaBreak(true);
-			
-    		if(LoadProperties.spoutEnabled)
-    			SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
-    	}
-    	
-    	/*
-    	 * SUPER BREAKER CHECKS
-    	 */
-    	if(PP.getSuperBreakerMode() 
-    		&& Mining.canBeSuperBroken(block)
-    		&& m.blockBreakSimulate(block, player, true)
-    		&& mcPermissions.getInstance().miningAbility(player))
-    	{
-    		if(LoadProperties.miningrequirespickaxe)
-    		{
-    			if(ItemChecks.isMiningPick(inhand)){
-    			    
-    				event.setInstaBreak(true);
-    				Mining.SuperBreakerBlockCheck(player, block, plugin);
-    			}
-    		} else {
-    			event.setInstaBreak(true);
-    			Mining.SuperBreakerBlockCheck(player, block, plugin);
-    		}
-    	}
-    	
-    	/*
-    	 * LEAF BLOWER CHECKS
-    	 */
-    	if(id == 18 
-    		&& mcPermissions.getInstance().woodCuttingAbility(player) 
-    		&& PP.getSkillLevel(SkillType.WOODCUTTING) >= 100 
-    		&& m.blockBreakSimulate(block, player, true))
-    	{	
-    		if(LoadProperties.woodcuttingrequiresaxe)
-    		{
-    			if(ItemChecks.isAxe(inhand)){
-    				event.setInstaBreak(true);
-    				WoodCutting.leafBlower(player, block);
-    			}
-    		}
-    		else if(inhand.getTypeId() != 359)
-    		{
-    			event.setInstaBreak(true);
-    			WoodCutting.leafBlower(player, block);
-    		}
-    		
-    	}
+        /*
+         * ABILITY PREPARATION CHECKS
+         */
+        if(BlockChecks.abilityBlockCheck(mat))
+        {
+               if(PP.getHoePreparationMode() && Herbalism.canBeGreenTerra(block))
+                   Skills.abilityCheck(player, SkillType.HERBALISM);
+            if(PP.getAxePreparationMode() && mat.equals(Material.LOG) && mcPermissions.getInstance().woodCuttingAbility(player))
+                Skills.abilityCheck(player, SkillType.WOODCUTTING);
+            if(PP.getPickaxePreparationMode() && Mining.canBeSuperBroken(block))
+                Skills.abilityCheck(player, SkillType.MINING);
+            if(PP.getShovelPreparationMode() && Excavation.canBeGigaDrillBroken(block))
+                Skills.abilityCheck(player, SkillType.EXCAVATION);
+        }
+        
+        if(PP.getFistsPreparationMode() && (Excavation.canBeGigaDrillBroken(block) || mat.equals(Material.SNOW)))
+            Skills.abilityCheck(player, SkillType.UNARMED);
+        
+        /*
+         * TREE FELLER STUFF
+         */
+        if(LoadProperties.spoutEnabled && mat.equals(Material.LOG) && PP.getTreeFellerMode())
+            SpoutStuff.playSoundForPlayer(SoundEffect.FIZZ, player, block.getLocation());
+        
+        /*
+         * GREEN TERRA STUFF
+         */
+        if(PP.getGreenTerraMode() && mcPermissions.getInstance().herbalismAbility(player))
+               Herbalism.greenTerra(player, block);
+        
+        /*
+         * GIGA DRILL BREAKER CHECKS
+         */
+        if(PP.getGigaDrillBreakerMode() && Excavation.canBeGigaDrillBroken(block) && m.blockBreakSimulate(block, player, true) && mcPermissions.getInstance().excavationAbility(player))
+        {    
+            if(LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand))
+            {
+                event.setInstaBreak(true);
+                Excavation.gigaDrillBreaker(player, block);
+            }
+            else if(!LoadProperties.excavationRequiresShovel)
+            {
+                event.setInstaBreak(true);
+                Excavation.gigaDrillBreaker(player, block);
+            }
+        }
+        /*
+         * BERSERK MODE CHECKS
+         */
+        if(PP.getBerserkMode() 
+            && m.blockBreakSimulate(block, player, true) 
+            && player.getItemInHand().getTypeId() == 0 
+            && (Excavation.canBeGigaDrillBroken(block) || id == 78)
+            && mcPermissions.getInstance().unarmedAbility(player))
+        {
+            event.setInstaBreak(true);
+            
+            if(LoadProperties.spoutEnabled)
+                SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
+        }
+        
+        /*
+         * SUPER BREAKER CHECKS
+         */
+        if(PP.getSuperBreakerMode() 
+            && Mining.canBeSuperBroken(block)
+            && m.blockBreakSimulate(block, player, true)
+            && mcPermissions.getInstance().miningAbility(player))
+        {
+            if(LoadProperties.miningrequirespickaxe)
+            {
+                if(ItemChecks.isMiningPick(inhand)){
+                    
+                    event.setInstaBreak(true);
+                    Mining.SuperBreakerBlockCheck(player, block, plugin);
+                }
+            } else {
+                event.setInstaBreak(true);
+                Mining.SuperBreakerBlockCheck(player, block, plugin);
+            }
+        }
+        
+        /*
+         * LEAF BLOWER CHECKS
+         */
+        if(id == 18 
+            && mcPermissions.getInstance().woodCuttingAbility(player) 
+            && PP.getSkillLevel(SkillType.WOODCUTTING) >= 100 
+            && m.blockBreakSimulate(block, player, true))
+        {    
+            if(LoadProperties.woodcuttingrequiresaxe)
+            {
+                if(ItemChecks.isAxe(inhand)){
+                    event.setInstaBreak(true);
+                    WoodCutting.leafBlower(player, block);
+                }
+            }
+            else if(inhand.getTypeId() != 359)
+            {
+                event.setInstaBreak(true);
+                WoodCutting.leafBlower(player, block);
+            }
+            
+        }
     }
     
     @EventHandler