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,269 +31,261 @@ 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) {
{ Block block;
//Setup some basic variables Player player = event.getPlayer();
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)) {
//When blocks are placed on snow this event reports the wrong block. block = event.getBlockAgainst();
if (event.getBlockReplacedState() != null && event.getBlockReplacedState().getType().equals(Material.SNOW)) }
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;
if (id == LoadProperties.anvilID && LoadProperties.anvilmessages) {
switch(mat) PlayerProfile PP = Users.getProfile(player);
{
case CACTUS: if (!PP.getPlacedAnvil()) {
case GLOWING_REDSTONE_ORE: if (LoadProperties.spoutEnabled) {
case JACK_O_LANTERN: SpoutPlayer sPlayer = SpoutManager.getPlayer(player);
case LOG:
case PUMPKIN: if (sPlayer.isSpoutCraftEnabled()) {
case REDSTONE_ORE: sPlayer.sendNotification("[mcMMO] Anvil Placed", "Right click to repair!", Material.getMaterial(id));
case SUGAR_CANE_BLOCK: }
case VINE: }
shouldBeChanged = false; //We don't want these added to changeQueue else {
plugin.misc.blockWatchList.add(block); event.getPlayer().sendMessage(mcLocale.getString("mcBlockListener.PlacedAnvil"));
break; }
case BROWN_MUSHROOM:
case RED_MUSHROOM: PP.togglePlacedAnvil();
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();
}
}
} }
/**
* 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(); Material mat = block.getType();
int id = block.getTypeId(); 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
if(PP.getGreenTerraMode() && Herbalism.canBeGreenTerra(block)) //Wheat && Triple drops
Herbalism.herbalismProcCheck(block, player, event, plugin); 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);
if (mcPermissions.getInstance().herbalism(player) && block.getData() != (byte) 5) {
/* Herbalism.herbalismProcCheck(block, player, event, plugin);
* MINING }
*/
if(mcPermissions.getInstance().mining(player)) /*
{ * MINING
if(LoadProperties.miningrequirespickaxe && ItemChecks.isMiningPick(inhand)) */
Mining.miningBlockCheck(player, block, plugin);
else if(!LoadProperties.miningrequirespickaxe) if (mcPermissions.getInstance().mining(player) && Mining.canBeSuperBroken(block)) {
Mining.miningBlockCheck(player, block, plugin); if (LoadProperties.miningrequirespickaxe && ItemChecks.isMiningPick(inhand)) {
} Mining.miningBlockCheck(player, block, plugin);
}
/* else if (!LoadProperties.miningrequirespickaxe) {
* WOOD CUTTING Mining.miningBlockCheck(player, block, plugin);
*/ }
}
if(mcPermissions.getInstance().woodcutting(player) && id == 17)
{ /*
if(LoadProperties.woodcuttingrequiresaxe && ItemChecks.isAxe(inhand)) * WOOD CUTTING
WoodCutting.woodcuttingBlockCheck(player, block, plugin); */
else if(!LoadProperties.woodcuttingrequiresaxe)
WoodCutting.woodcuttingBlockCheck(player, block, plugin); if(mcPermissions.getInstance().woodcutting(player) && mat.equals(Material.LOG)) {
if (LoadProperties.woodcuttingrequiresaxe && ItemChecks.isAxe(inhand)) {
if(PP.getTreeFellerMode()) WoodCutting.woodcuttingBlockCheck(player, block, plugin);
WoodCutting.treeFeller(event, plugin); }
} else if (!LoadProperties.woodcuttingrequiresaxe) {
WoodCutting.woodcuttingBlockCheck(player, block, plugin);
/* }
* EXCAVATION
*/ if (PP.getTreeFellerMode()) {
if(Excavation.canBeGigaDrillBroken(block) && mcPermissions.getInstance().excavation(player) && block.getData() != (byte) 5) WoodCutting.treeFeller(event, plugin);
{ }
if(LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand)) }
Excavation.excavationProcCheck(block, player);
else if(!LoadProperties.excavationRequiresShovel) /*
Excavation.excavationProcCheck(block, player); * EXCAVATION
} */
//Change the byte back when broken if (Excavation.canBeGigaDrillBroken(block) && mcPermissions.getInstance().excavation(player) && block.getData() != (byte) 0x5)
if(block.getData() == 5 && BlockChecks.shouldBeWatched(block.getType())) {
{ if(LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand)) {
block.setData((byte) 0); Excavation.excavationProcCheck(block, player);
if(plugin.misc.blockWatchList.contains(block)) }
plugin.misc.blockWatchList.remove(block); 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) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockDamage(BlockDamageEvent event) public void onBlockDamage(BlockDamageEvent event)
{ {
Player player = event.getPlayer(); Player player = event.getPlayer();
PlayerProfile PP = Users.getProfile(player); PlayerProfile PP = Users.getProfile(player);
ItemStack inhand = player.getItemInHand(); ItemStack inhand = player.getItemInHand();
Block block = event.getBlock(); Block block = event.getBlock();
int id = block.getTypeId(); int id = block.getTypeId();
Material mat = block.getType(); Material mat = block.getType();
/* /*
* ABILITY PREPARATION CHECKS * ABILITY PREPARATION CHECKS
*/ */
if(BlockChecks.abilityBlockCheck(mat)) if(BlockChecks.abilityBlockCheck(mat))
{ {
if(PP.getHoePreparationMode() && Herbalism.canBeGreenTerra(block)) if(PP.getHoePreparationMode() && Herbalism.canBeGreenTerra(block))
Skills.abilityCheck(player, SkillType.HERBALISM); Skills.abilityCheck(player, SkillType.HERBALISM);
if(PP.getAxePreparationMode() && mat.equals(Material.LOG) && mcPermissions.getInstance().woodCuttingAbility(player)) if(PP.getAxePreparationMode() && mat.equals(Material.LOG) && mcPermissions.getInstance().woodCuttingAbility(player))
Skills.abilityCheck(player, SkillType.WOODCUTTING); Skills.abilityCheck(player, SkillType.WOODCUTTING);
if(PP.getPickaxePreparationMode() && Mining.canBeSuperBroken(block)) if(PP.getPickaxePreparationMode() && Mining.canBeSuperBroken(block))
Skills.abilityCheck(player, SkillType.MINING); Skills.abilityCheck(player, SkillType.MINING);
if(PP.getShovelPreparationMode() && Excavation.canBeGigaDrillBroken(block)) if(PP.getShovelPreparationMode() && Excavation.canBeGigaDrillBroken(block))
Skills.abilityCheck(player, SkillType.EXCAVATION); Skills.abilityCheck(player, SkillType.EXCAVATION);
} }
if(PP.getFistsPreparationMode() && (Excavation.canBeGigaDrillBroken(block) || mat.equals(Material.SNOW))) if(PP.getFistsPreparationMode() && (Excavation.canBeGigaDrillBroken(block) || mat.equals(Material.SNOW)))
Skills.abilityCheck(player, SkillType.UNARMED); Skills.abilityCheck(player, SkillType.UNARMED);
/* /*
* TREE FELLER STUFF * TREE FELLER STUFF
*/ */
if(LoadProperties.spoutEnabled && mat.equals(Material.LOG) && PP.getTreeFellerMode()) if(LoadProperties.spoutEnabled && mat.equals(Material.LOG) && PP.getTreeFellerMode())
SpoutStuff.playSoundForPlayer(SoundEffect.FIZZ, player, block.getLocation()); SpoutStuff.playSoundForPlayer(SoundEffect.FIZZ, player, block.getLocation());
/* /*
* GREEN TERRA STUFF * GREEN TERRA STUFF
*/ */
if(PP.getGreenTerraMode() && mcPermissions.getInstance().herbalismAbility(player)) if(PP.getGreenTerraMode() && mcPermissions.getInstance().herbalismAbility(player))
Herbalism.greenTerra(player, block); Herbalism.greenTerra(player, block);
/* /*
* GIGA DRILL BREAKER CHECKS * GIGA DRILL BREAKER CHECKS
*/ */
if(PP.getGigaDrillBreakerMode() && Excavation.canBeGigaDrillBroken(block) && m.blockBreakSimulate(block, player, true) && mcPermissions.getInstance().excavationAbility(player)) if(PP.getGigaDrillBreakerMode() && Excavation.canBeGigaDrillBroken(block) && m.blockBreakSimulate(block, player, true) && mcPermissions.getInstance().excavationAbility(player))
{ {
if(LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand)) if(LoadProperties.excavationRequiresShovel && ItemChecks.isShovel(inhand))
{ {
event.setInstaBreak(true); event.setInstaBreak(true);
Excavation.gigaDrillBreaker(player, block); Excavation.gigaDrillBreaker(player, block);
} }
else if(!LoadProperties.excavationRequiresShovel) else if(!LoadProperties.excavationRequiresShovel)
{ {
event.setInstaBreak(true); event.setInstaBreak(true);
Excavation.gigaDrillBreaker(player, block); Excavation.gigaDrillBreaker(player, block);
} }
} }
/* /*
* BERSERK MODE CHECKS * BERSERK MODE CHECKS
*/ */
if(PP.getBerserkMode() if(PP.getBerserkMode()
&& m.blockBreakSimulate(block, player, true) && m.blockBreakSimulate(block, player, true)
&& player.getItemInHand().getTypeId() == 0 && player.getItemInHand().getTypeId() == 0
&& (Excavation.canBeGigaDrillBroken(block) || id == 78) && (Excavation.canBeGigaDrillBroken(block) || id == 78)
&& mcPermissions.getInstance().unarmedAbility(player)) && mcPermissions.getInstance().unarmedAbility(player))
{ {
event.setInstaBreak(true); event.setInstaBreak(true);
if(LoadProperties.spoutEnabled) if(LoadProperties.spoutEnabled)
SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation()); SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
} }
/* /*
* SUPER BREAKER CHECKS * SUPER BREAKER CHECKS
*/ */
if(PP.getSuperBreakerMode() if(PP.getSuperBreakerMode()
&& Mining.canBeSuperBroken(block) && Mining.canBeSuperBroken(block)
&& m.blockBreakSimulate(block, player, true) && m.blockBreakSimulate(block, player, true)
&& mcPermissions.getInstance().miningAbility(player)) && mcPermissions.getInstance().miningAbility(player))
{ {
if(LoadProperties.miningrequirespickaxe) if(LoadProperties.miningrequirespickaxe)
{ {
if(ItemChecks.isMiningPick(inhand)){ if(ItemChecks.isMiningPick(inhand)){
event.setInstaBreak(true); event.setInstaBreak(true);
Mining.SuperBreakerBlockCheck(player, block, plugin); Mining.SuperBreakerBlockCheck(player, block, plugin);
} }
} else { } else {
event.setInstaBreak(true); event.setInstaBreak(true);
Mining.SuperBreakerBlockCheck(player, block, plugin); Mining.SuperBreakerBlockCheck(player, block, plugin);
} }
} }
/* /*
* LEAF BLOWER CHECKS * LEAF BLOWER CHECKS
*/ */
if(id == 18 if(id == 18
&& mcPermissions.getInstance().woodCuttingAbility(player) && mcPermissions.getInstance().woodCuttingAbility(player)
&& PP.getSkillLevel(SkillType.WOODCUTTING) >= 100 && PP.getSkillLevel(SkillType.WOODCUTTING) >= 100
&& m.blockBreakSimulate(block, player, true)) && m.blockBreakSimulate(block, player, true))
{ {
if(LoadProperties.woodcuttingrequiresaxe) if(LoadProperties.woodcuttingrequiresaxe)
{ {
if(ItemChecks.isAxe(inhand)){ if(ItemChecks.isAxe(inhand)){
event.setInstaBreak(true); event.setInstaBreak(true);
WoodCutting.leafBlower(player, block); WoodCutting.leafBlower(player, block);
} }
} }
else if(inhand.getTypeId() != 359) else if(inhand.getTypeId() != 359)
{ {
event.setInstaBreak(true); event.setInstaBreak(true);
WoodCutting.leafBlower(player, block); WoodCutting.leafBlower(player, block);
} }
} }
} }
@EventHandler @EventHandler