Cleanup listeners a bit more. Also fix bug in recent dev builds where

placed blocks were not properly tracked.
This commit is contained in:
GJ 2013-01-25 12:33:48 -05:00
parent a35af4dbe6
commit a7be57241c
10 changed files with 70 additions and 78 deletions

View File

@ -32,6 +32,7 @@ import com.gmail.nossr50.skills.Skills;
import com.gmail.nossr50.skills.ToolType; import com.gmail.nossr50.skills.ToolType;
import com.gmail.nossr50.skills.excavation.Excavation; import com.gmail.nossr50.skills.excavation.Excavation;
import com.gmail.nossr50.skills.herbalism.Herbalism; import com.gmail.nossr50.skills.herbalism.Herbalism;
import com.gmail.nossr50.skills.mining.Mining;
import com.gmail.nossr50.skills.mining.MiningManager; import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.repair.Repair; import com.gmail.nossr50.skills.repair.Repair;
import com.gmail.nossr50.skills.repair.Salvage; import com.gmail.nossr50.skills.repair.Salvage;
@ -97,7 +98,7 @@ public class BlockListener implements Listener {
/** /**
* Monitor BlockPlace events. * Monitor BlockPlace events.
* *
* @param event The event to monitor * @param event The event to watch
*/ */
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
@ -114,18 +115,16 @@ public class BlockListener implements Listener {
mcMMO.placeStore.setTrue(block); mcMMO.placeStore.setTrue(block);
} }
if (Config.getInstance().getRepairAnvilMessagesEnabled()) { if (Repair.anvilMessagesEnabled) {
int id = block.getTypeId(); int blockID = block.getTypeId();
if (id == Config.getInstance().getRepairAnvilId()) { if (blockID == Repair.anvilID) {
Repair.placedAnvilCheck(player, id); Repair.placedAnvilCheck(player, blockID);
} }
else if (id == Config.getInstance().getSalvageAnvilId()) { else if (blockID == Salvage.anvilID) {
Salvage.placedAnvilCheck(player, id); Salvage.placedAnvilCheck(player, blockID);
} }
} }
} }
/** /**
@ -140,58 +139,54 @@ public class BlockListener implements Listener {
} }
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.hasMetadata("NPC")) return; // Check if this player is a Citizens NPC
PlayerProfile profile = Users.getProfile(player); PlayerProfile profile = Users.getProfile(player);
if (profile == null) { if (Misc.isNPCPlayer(player, profile)) {
return; return;
} }
Block block = event.getBlock(); Block block = event.getBlock();
ItemStack inHand = player.getItemInHand(); ItemStack heldItem = player.getItemInHand();
Config configInstance = Config.getInstance();
/* HERBALISM */ /* HERBALISM */
if (BlockChecks.canBeGreenTerra(block)) { if (BlockChecks.canBeGreenTerra(block)) {
/* Green Terra */ Skills.abilityCheck(player, SkillType.HERBALISM); //Green Terra
if (profile.getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(player)) {
Skills.abilityCheck(player, SkillType.HERBALISM);
}
/* Triple drops */
if (profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
Herbalism.herbalismProcCheck(block, player, event, plugin);
}
/*
* We don't check the block store here because herbalism has too many unusual edge cases.
* Instead, we check it inside the drops handler.
*/
if (Permissions.herbalism(player)) { if (Permissions.herbalism(player)) {
Herbalism.herbalismProcCheck(block, player, event, plugin); Herbalism.herbalismProcCheck(block, player, event, plugin); //Double drops
if (profile.getAbilityMode(AbilityType.GREEN_TERRA)) {
Herbalism.herbalismProcCheck(block, player, event, plugin); //Triple drops
}
} }
} }
/* MINING */ /* MINING */
else if (BlockChecks.canBeSuperBroken(block) && Permissions.mining(player)) { else if (BlockChecks.canBeSuperBroken(block) && Permissions.mining(player) && !mcMMO.placeStore.isTrue(block)) {
if (Mining.requiresTool) {
if (ItemChecks.isPickaxe(heldItem)) {
MiningManager miningManager = new MiningManager(player); MiningManager miningManager = new MiningManager(player);
if (configInstance.getMiningRequiresTool()) {
if (ItemChecks.isPickaxe(inHand)) {
miningManager.miningBlockCheck(block); miningManager.miningBlockCheck(block);
} }
} }
else { else {
MiningManager miningManager = new MiningManager(player);
miningManager.miningBlockCheck(block); miningManager.miningBlockCheck(block);
} }
} }
/* WOOD CUTTING */ /* WOOD CUTTING */
else if (BlockChecks.isLog(block) && Permissions.woodcutting(player) && !mcMMO.placeStore.isTrue(block)) { else if (BlockChecks.isLog(block) && Permissions.woodcutting(player) && !mcMMO.placeStore.isTrue(block)) {
if (profile.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.treeFeller(player) && ItemChecks.isAxe(inHand)) { if (profile.getAbilityMode(AbilityType.TREE_FELLER) && Permissions.treeFeller(player) && ItemChecks.isAxe(heldItem)) {
Woodcutting.beginTreeFeller(event); Woodcutting.beginTreeFeller(event);
} }
else { else {
if (configInstance.getWoodcuttingRequiresTool()) { if (Woodcutting.requiresTool) {
if (ItemChecks.isAxe(inHand)) { if (ItemChecks.isAxe(heldItem)) {
Woodcutting.beginWoodcutting(player, block); Woodcutting.beginWoodcutting(player, block);
} }
} }
@ -203,8 +198,8 @@ public class BlockListener implements Listener {
/* EXCAVATION */ /* EXCAVATION */
else if (BlockChecks.canBeGigaDrillBroken(block) && Permissions.excavation(player) && !mcMMO.placeStore.isTrue(block)) { else if (BlockChecks.canBeGigaDrillBroken(block) && Permissions.excavation(player) && !mcMMO.placeStore.isTrue(block)) {
if (configInstance.getExcavationRequiresTool()) { if (Excavation.requiresTool) {
if (ItemChecks.isShovel(inHand)) { if (ItemChecks.isShovel(heldItem)) {
Excavation.excavationProcCheck(block, player); Excavation.excavationProcCheck(block, player);
} }
} }
@ -213,12 +208,17 @@ public class BlockListener implements Listener {
} }
} }
//Remove metadata when broken /* Remove metadata from placed watched blocks */
if (BlockChecks.shouldBeWatched(block)) { if (BlockChecks.shouldBeWatched(block) && mcMMO.placeStore.isTrue(block)) {
mcMMO.placeStore.setFalse(block); mcMMO.placeStore.setFalse(block);
} }
} }
/**
* Handle BlockBreak events where the event is modified.
*
* @param event The event to modify
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreakHigher(BlockBreakEvent event) { public void onBlockBreakHigher(BlockBreakEvent event) {
if (event instanceof FakeBlockBreakEvent) { if (event instanceof FakeBlockBreakEvent) {
@ -227,21 +227,16 @@ public class BlockListener implements Listener {
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getBlock(); Block block = event.getBlock();
ItemStack inHand = player.getItemInHand(); ItemStack heldItem = player.getItemInHand();
if (Misc.isNPCPlayer(player)) { if (Misc.isNPCPlayer(player)) {
return; return;
} }
if (mcMMO.placeStore.isTrue(block)) { if (Permissions.hylianLuck(player) && ItemChecks.isSword(heldItem)) {
mcMMO.placeStore.setFalse(block);
return;
}
if (Permissions.hylianLuck(player) && ItemChecks.isSword(inHand)) {
Herbalism.hylianLuck(block, player, event); Herbalism.hylianLuck(block, player, event);
} }
else if (BlockChecks.canBeFluxMined(block) && ItemChecks.isPickaxe(inHand) && !inHand.containsEnchantment(Enchantment.SILK_TOUCH)) { else if (BlockChecks.canBeFluxMined(block) && ItemChecks.isPickaxe(heldItem) && !heldItem.containsEnchantment(Enchantment.SILK_TOUCH) && Permissions.fluxMining(player) && !mcMMO.placeStore.isTrue(block)) {
SmeltingManager smeltingManager = new SmeltingManager(player); SmeltingManager smeltingManager = new SmeltingManager(player);
smeltingManager.fluxMining(event); smeltingManager.fluxMining(event);
} }

View File

@ -422,19 +422,15 @@ public class Skills {
*/ */
public static void abilityCheck(Player player, SkillType type) { public static void abilityCheck(Player player, SkillType type) {
PlayerProfile profile = Users.getProfile(player); PlayerProfile profile = Users.getProfile(player);
if (profile == null) {
return;
}
ToolType tool = type.getTool(); ToolType tool = type.getTool();
AbilityType ability = type.getAbility();
if (!profile.getToolPreparationMode(tool)) { if (!profile.getToolPreparationMode(tool) || !ability.getPermissions(player)) {
return; return;
} }
profile.setToolPreparationMode(tool, false); profile.setToolPreparationMode(tool, false);
AbilityType ability = type.getAbility();
/* Axes and Woodcutting are odd because they share the same tool. /* Axes and Woodcutting are odd because they share the same tool.
* We show them the too tired message when they take action. * We show them the too tired message when they take action.
*/ */
@ -532,15 +528,11 @@ public class Skills {
* @param xp the amount of XP to gain * @param xp the amount of XP to gain
*/ */
public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) { public static void xpProcessing(Player player, PlayerProfile profile, SkillType type, int xp) {
if (type.getPermissions(player)) { if ((type.getMaxLevel() < profile.getSkillLevel(type) + 1) || (Misc.getPowerLevelCap() < Users.getPlayer(player).getPowerLevel() + 1)) {
if (Users.getPlayer(player) == null)
return;
if ((type.getMaxLevel() < profile.getSkillLevel(type) + 1) || (Misc.getPowerLevelCap() < Users.getPlayer(player).getPowerLevel() + 1))
return; return;
}
Users.getPlayer(player).addXP(type, xp); Users.getPlayer(player).addXP(type, xp);
xpCheckSkill(type, player, profile); xpCheckSkill(type, player, profile);
} }
}
} }

View File

@ -27,6 +27,7 @@ import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class Excavation { public class Excavation {
public static boolean requiresTool = Config.getInstance().getExcavationRequiresTool();
/** /**
* Check to see if treasures were found. * Check to see if treasures were found.

View File

@ -106,9 +106,6 @@ public class Herbalism {
* @param plugin mcMMO plugin instance * @param plugin mcMMO plugin instance
*/ */
public static void herbalismProcCheck(final Block block, Player player, BlockBreakEvent event, mcMMO plugin) { public static void herbalismProcCheck(final Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
if (player == null)
return;
final PlayerProfile profile = Users.getProfile(player); final PlayerProfile profile = Users.getProfile(player);
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM); int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
@ -557,7 +554,7 @@ public class Herbalism {
if (chance > Misc.getRandom().nextInt(activationChance)) { if (chance > Misc.getRandom().nextInt(activationChance)) {
Location location = block.getLocation(); Location location = block.getLocation();
int dropNumber = Misc.getRandom().nextInt(3); int dropNumber = Misc.getRandom().nextInt(3);
ItemStack item = null; ItemStack item;
switch (block.getType()) { switch (block.getType()) {
case DEAD_BUSH: case DEAD_BUSH:
@ -584,6 +581,11 @@ public class Herbalism {
case RED_ROSE: case RED_ROSE:
case YELLOW_FLOWER: case YELLOW_FLOWER:
if (mcMMO.placeStore.isTrue(block)) {
mcMMO.placeStore.setFalse(block);
return;
}
if (dropNumber == 0) { if (dropNumber == 0) {
item = new ItemStack(Material.POTATO); item = new ItemStack(Material.POTATO);
} }
@ -594,7 +596,6 @@ public class Herbalism {
item = new ItemStack(Material.APPLE); item = new ItemStack(Material.APPLE);
} }
mcMMO.placeStore.setFalse(block);
break; break;
case FLOWER_POT: case FLOWER_POT:
@ -610,10 +611,6 @@ public class Herbalism {
break; break;
default: default:
break;
}
if (item == null) {
return; return;
} }

View File

@ -26,6 +26,8 @@ public class Mining {
public static double doubleDropsMaxChance = advancedConfig.getMiningDoubleDropChance(); public static double doubleDropsMaxChance = advancedConfig.getMiningDoubleDropChance();
public static boolean doubleDropsDisabled = config.miningDoubleDropsDisabled(); public static boolean doubleDropsDisabled = config.miningDoubleDropsDisabled();
public static boolean requiresTool = Config.getInstance().getMiningRequiresTool();
public static final int DIAMOND_TOOL_TIER = 4; public static final int DIAMOND_TOOL_TIER = 4;
public static final int IRON_TOOL_TIER = 3; public static final int IRON_TOOL_TIER = 3;
public static final int STONE_TOOL_TIER = 2; public static final int STONE_TOOL_TIER = 2;

View File

@ -112,12 +112,7 @@ public class MiningManager extends SkillManager{
* @param block The block being broken * @param block The block being broken
*/ */
public void miningBlockCheck(Block block) { public void miningBlockCheck(Block block) {
if (mcMMO.placeStore.isTrue(block)) {
return;
}
MiningBlockEventHandler eventHandler = new MiningBlockEventHandler(this, block); MiningBlockEventHandler eventHandler = new MiningBlockEventHandler(this, block);
eventHandler.processXPGain(); eventHandler.processXPGain();
if (!Permissions.miningDoubleDrops(player)) { if (!Permissions.miningDoubleDrops(player)) {

View File

@ -34,6 +34,7 @@ public class Repair {
public static boolean arcaneForgingDowngrades = advancedConfig.getArcaneForgingDowngradeEnabled(); public static boolean arcaneForgingDowngrades = advancedConfig.getArcaneForgingDowngradeEnabled();
public static boolean arcaneForgingEnchantLoss = advancedConfig.getArcaneForgingEnchantLossEnabled(); public static boolean arcaneForgingEnchantLoss = advancedConfig.getArcaneForgingEnchantLossEnabled();
public static boolean anvilMessagesEnabled = Config.getInstance().getRepairAnvilMessagesEnabled();
public static int anvilID = Config.getInstance().getRepairAnvilId(); public static int anvilID = Config.getInstance().getRepairAnvilId();
/** /**

View File

@ -3,6 +3,7 @@ package com.gmail.nossr50.skills.smelting;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -10,14 +11,17 @@ import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillType; import com.gmail.nossr50.skills.SkillType;
import com.gmail.nossr50.skills.mining.Mining; import com.gmail.nossr50.skills.mining.Mining;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
public class FluxMiningEventHandler { public class FluxMiningEventHandler {
private SmeltingManager manager; private SmeltingManager manager;
private Player player;
private BlockBreakEvent event; private BlockBreakEvent event;
private Block block; private Block block;
protected FluxMiningEventHandler(SmeltingManager manager, BlockBreakEvent event) { protected FluxMiningEventHandler(SmeltingManager manager, BlockBreakEvent event) {
this.manager = manager; this.manager = manager;
this.player = manager.getPlayer();
this.event = event; this.event = event;
this.block = event.getBlock(); this.block = event.getBlock();
} }
@ -43,10 +47,13 @@ public class FluxMiningEventHandler {
} }
Location location = block.getLocation(); Location location = block.getLocation();
int chance = (int) ((Mining.doubleDropsMaxChance / Mining.doubleDropsMaxLevel) * (Misc.skillCheck(manager.getProfile().getSkillLevel(SkillType.MINING), Mining.doubleDropsMaxLevel)));
Misc.dropItem(location, item); Misc.dropItem(location, item);
if (Permissions.secondSmelt(player)) {
int chance = (int) ((Mining.doubleDropsMaxChance / Mining.doubleDropsMaxLevel) * (Misc.skillCheck(manager.getProfile().getSkillLevel(SkillType.MINING), Mining.doubleDropsMaxLevel)));
Misc.randomDropItem(location, item, chance); Misc.randomDropItem(location, item, chance);
} }
}
protected void eventCancellationAndProcessing() { protected void eventCancellationAndProcessing() {
event.setCancelled(true); event.setCancelled(true);
@ -54,6 +61,6 @@ public class FluxMiningEventHandler {
} }
protected void sendAbilityMessage() { protected void sendAbilityMessage() {
manager.getPlayer().sendMessage(LocaleLoader.getString("Smelting.FluxMining.Success")); player.sendMessage(LocaleLoader.getString("Smelting.FluxMining.Success"));
} }
} }

View File

@ -56,7 +56,7 @@ public class SmeltingManager extends SkillManager {
} }
public void fluxMining(BlockBreakEvent event) { public void fluxMining(BlockBreakEvent event) {
if (skillLevel < Smelting.fluxMiningUnlockLevel || !Permissions.fluxMining(player)) { if (skillLevel < Smelting.fluxMiningUnlockLevel) {
return; return;
} }

View File

@ -29,6 +29,8 @@ public abstract class Woodcutting {
public static final boolean DOUBLE_DROP_DISABLED = Config.getInstance().woodcuttingDoubleDropsDisabled(); public static final boolean DOUBLE_DROP_DISABLED = Config.getInstance().woodcuttingDoubleDropsDisabled();
public static final int TREE_FELLER_THRESHOLD = Config.getInstance().getTreeFellerThreshold(); public static final int TREE_FELLER_THRESHOLD = Config.getInstance().getTreeFellerThreshold();
public static boolean requiresTool = Config.getInstance().getWoodcuttingRequiresTool();
/** /**
* Begins the Tree Feller ability * Begins the Tree Feller ability
* *