Cleanup & a few memory leak fixes.

This commit is contained in:
GJ 2012-03-08 18:09:31 -05:00
parent bce418bee8
commit d393e4d124
3 changed files with 288 additions and 253 deletions

View File

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

View File

@ -10,7 +10,7 @@ public class BlockChecks {
/** /**
* Checks to see if a block type awards XP. * 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 * @return true if the block type awards XP, false otherwise
*/ */
public static boolean shouldBeWatched(Material material) { public static boolean shouldBeWatched(Material material) {
@ -58,7 +58,7 @@ public class BlockChecks {
/** /**
* Check if a block should allow for the activation of abilities. * 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 * @return true if the block should allow ability activation, false otherwise
*/ */
public static boolean abilityBlockCheck(Material material) { public static boolean abilityBlockCheck(Material material) {
@ -99,7 +99,7 @@ public class BlockChecks {
/** /**
* Check if a block type is an ore. * 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 * @return true if the Block is an ore, false otherwise
*/ */
public static boolean isOre(Material material) { public static boolean isOre(Material material) {
@ -117,4 +117,45 @@ public class BlockChecks {
return false; 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);
}
} }

View File

@ -31,151 +31,143 @@ import com.gmail.nossr50.locale.mcLocale;
import com.gmail.nossr50.skills.*; import com.gmail.nossr50.skills.*;
import com.gmail.nossr50.events.FakeBlockBreakEvent; import com.gmail.nossr50.events.FakeBlockBreakEvent;
public class mcBlockListener implements Listener public class mcBlockListener implements Listener {
{
private final mcMMO plugin; private final mcMMO plugin;
public mcBlockListener(final mcMMO plugin) public mcBlockListener(final mcMMO plugin) {
{
this.plugin = plugin; this.plugin = plugin;
} }
/**
* Monitor BlockPlace events.
*
* @param event The event to monitor
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) public void onBlockPlace(BlockPlaceEvent event) {
{
//Setup some basic variables
Block block; Block block;
Player player = event.getPlayer(); Player player = event.getPlayer();
//When blocks are placed on snow this event reports the wrong block. //When blocks are placed on snow this event reports the wrong block.
if (event.getBlockReplacedState() != null && event.getBlockReplacedState().getType().equals(Material.SNOW)) if (event.getBlockReplacedState() != null && event.getBlockReplacedState().getType().equals(Material.SNOW)) {
block = event.getBlockAgainst(); block = event.getBlockAgainst();
else }
else {
block = event.getBlock(); block = event.getBlock();
}
int id = block.getTypeId(); int id = block.getTypeId();
Material mat = block.getType(); Material mat = block.getType();
//Check if the blocks placed should be monitored so they do not give out XP in the future //Check if the blocks placed should be monitored so they do not give out XP in the future
if(BlockChecks.shouldBeWatched(mat)) if (BlockChecks.shouldBeWatched(mat)) {
{ BlockChecks.watchBlock(mat, block, plugin);
//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) if (id == LoadProperties.anvilID && LoadProperties.anvilmessages) {
plugin.changeQueue.push(block);
}
if(id == LoadProperties.anvilID && LoadProperties.anvilmessages)
{
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
if(!PP.getPlacedAnvil())
{ if (!PP.getPlacedAnvil()) {
if(LoadProperties.spoutEnabled) if (LoadProperties.spoutEnabled) {
{
SpoutPlayer sPlayer = SpoutManager.getPlayer(player); SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
if(sPlayer.isSpoutCraftEnabled())
sPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to repair!", Material.IRON_BLOCK); if (sPlayer.isSpoutCraftEnabled()) {
sPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to repair!", Material.getMaterial(id));
}
}
else {
event.getPlayer().sendMessage(mcLocale.getString("mcBlockListener.PlacedAnvil"));
} }
else
event.getPlayer().sendMessage(mcLocale.getString("mcBlockListener.PlacedAnvil")); //$NON-NLS-1$
PP.togglePlacedAnvil(); PP.togglePlacedAnvil();
} }
} }
} }
/**
* Monitor BlockBreak events.
*
* @param event The event to monitor
*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) public void onBlockBreak(BlockBreakEvent event) {
{
Player player = event.getPlayer(); Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
Block block = event.getBlock(); Block block = event.getBlock();
int id = block.getTypeId(); Material mat = block.getType();
ItemStack inhand = player.getItemInHand(); ItemStack inhand = player.getItemInHand();
if(event instanceof FakeBlockBreakEvent) if(event instanceof FakeBlockBreakEvent) {
return; return;
}
/* /*
* HERBALISM * HERBALISM
*/ */
//Green Terra //Green Terra
if(PP.getHoePreparationMode() && mcPermissions.getInstance().herbalismAbility(player) && ((id == 59 && block.getData() == (byte) 0x07) || Herbalism.canBeGreenTerra(block))) if (PP.getHoePreparationMode() && mcPermissions.getInstance().herbalismAbility(player) && ((mat.equals(Material.CROPS) && block.getData() == (byte) 0x7) || Herbalism.canBeGreenTerra(block))) {
Skills.abilityCheck(player, SkillType.HERBALISM); Skills.abilityCheck(player, SkillType.HERBALISM);
}
//Wheat && Triple drops //Wheat && Triple drops
if(PP.getGreenTerraMode() && Herbalism.canBeGreenTerra(block)) if (PP.getGreenTerraMode() && Herbalism.canBeGreenTerra(block)) {
Herbalism.herbalismProcCheck(block, player, event, plugin); Herbalism.herbalismProcCheck(block, player, event, plugin);
}
if(mcPermissions.getInstance().herbalism(player) && block.getData() != (byte) 5) if (mcPermissions.getInstance().herbalism(player) && block.getData() != (byte) 5) {
Herbalism.herbalismProcCheck(block, player, event, plugin); Herbalism.herbalismProcCheck(block, player, event, plugin);
}
/* /*
* MINING * MINING
*/ */
if(mcPermissions.getInstance().mining(player))
{ if (mcPermissions.getInstance().mining(player) && Mining.canBeSuperBroken(block)) {
if(LoadProperties.miningrequirespickaxe && ItemChecks.isMiningPick(inhand)) if (LoadProperties.miningrequirespickaxe && ItemChecks.isMiningPick(inhand)) {
Mining.miningBlockCheck(player, block, plugin); Mining.miningBlockCheck(player, block, plugin);
else if(!LoadProperties.miningrequirespickaxe) }
else if (!LoadProperties.miningrequirespickaxe) {
Mining.miningBlockCheck(player, block, plugin); Mining.miningBlockCheck(player, block, plugin);
} }
}
/* /*
* WOOD CUTTING * WOOD CUTTING
*/ */
if(mcPermissions.getInstance().woodcutting(player) && id == 17) if(mcPermissions.getInstance().woodcutting(player) && mat.equals(Material.LOG)) {
{ if (LoadProperties.woodcuttingrequiresaxe && ItemChecks.isAxe(inhand)) {
if(LoadProperties.woodcuttingrequiresaxe && ItemChecks.isAxe(inhand))
WoodCutting.woodcuttingBlockCheck(player, block, plugin); WoodCutting.woodcuttingBlockCheck(player, block, plugin);
else if(!LoadProperties.woodcuttingrequiresaxe) }
else if (!LoadProperties.woodcuttingrequiresaxe) {
WoodCutting.woodcuttingBlockCheck(player, block, plugin); WoodCutting.woodcuttingBlockCheck(player, block, plugin);
}
if(PP.getTreeFellerMode()) if (PP.getTreeFellerMode()) {
WoodCutting.treeFeller(event, plugin); WoodCutting.treeFeller(event, plugin);
} }
}
/* /*
* EXCAVATION * EXCAVATION
*/ */
if(Excavation.canBeGigaDrillBroken(block) && mcPermissions.getInstance().excavation(player) && block.getData() != (byte) 5)
if (Excavation.canBeGigaDrillBroken(block) && mcPermissions.getInstance().excavation(player) && block.getData() != (byte) 0x5)
{ {
if(LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand)) if(LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand)) {
Excavation.excavationProcCheck(block, player); Excavation.excavationProcCheck(block, player);
else if(!LoadProperties.excavationRequiresShovel) }
else if(!LoadProperties.excavationRequiresShovel) {
Excavation.excavationProcCheck(block, player); Excavation.excavationProcCheck(block, player);
} }
}
//Change the byte back when broken //Change the byte back when broken
if(block.getData() == 5 && BlockChecks.shouldBeWatched(block.getType())) if (block.getData() == (byte) 0x5 && BlockChecks.shouldBeWatched(mat)) {
{ block.setData((byte) 0x0);
block.setData((byte) 0); }
if(plugin.misc.blockWatchList.contains(block)) else if(plugin.misc.blockWatchList.contains(block)) {
plugin.misc.blockWatchList.remove(block); plugin.misc.blockWatchList.remove(block);
} }
} }