mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Clean up our block listener some.
This commit is contained in:
parent
0c52b3016c
commit
4f8b66f94d
@ -68,6 +68,13 @@ public enum AbilityType {
|
||||
null),
|
||||
|
||||
LEAF_BLOWER(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null),
|
||||
|
||||
BLOCK_CRACKER(
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
@ -144,7 +151,6 @@ public enum AbilityType {
|
||||
* @return true if the player has permissions, false otherwise
|
||||
*/
|
||||
public boolean getPermissions(Player player) {
|
||||
|
||||
switch (this) {
|
||||
case BERSERK:
|
||||
return Permissions.berserk(player);
|
||||
@ -152,6 +158,9 @@ public enum AbilityType {
|
||||
case BLAST_MINING:
|
||||
return Permissions.remoteDetonation(player);
|
||||
|
||||
case BLOCK_CRACKER:
|
||||
return Permissions.blockCracker(player);
|
||||
|
||||
case GIGA_DRILL_BREAKER:
|
||||
return Permissions.gigaDrillBreaker(player);
|
||||
|
||||
@ -189,6 +198,9 @@ public enum AbilityType {
|
||||
case BERSERK:
|
||||
return (BlockUtils.affectedByGigaDrillBreaker(blockState) || blockState.getType() == Material.SNOW);
|
||||
|
||||
case BLOCK_CRACKER:
|
||||
return BlockUtils.affectedByBlockCracker(blockState);
|
||||
|
||||
case GIGA_DRILL_BREAKER:
|
||||
return BlockUtils.affectedByGigaDrillBreaker(blockState);
|
||||
|
||||
|
@ -28,14 +28,12 @@ import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.datatypes.skills.ToolType;
|
||||
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
|
||||
import com.gmail.nossr50.events.fake.FakeBlockDamageEvent;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerAnimationEvent;
|
||||
import com.gmail.nossr50.runnables.StickyPistonTrackerTask;
|
||||
import com.gmail.nossr50.skills.excavation.ExcavationManager;
|
||||
import com.gmail.nossr50.skills.herbalism.HerbalismManager;
|
||||
import com.gmail.nossr50.skills.mining.MiningManager;
|
||||
import com.gmail.nossr50.skills.repair.Repair;
|
||||
import com.gmail.nossr50.skills.smelting.SmeltingManager;
|
||||
import com.gmail.nossr50.skills.unarmed.UnarmedManager;
|
||||
import com.gmail.nossr50.skills.woodcutting.WoodcuttingManager;
|
||||
import com.gmail.nossr50.util.BlockUtils;
|
||||
import com.gmail.nossr50.util.ItemUtils;
|
||||
@ -72,9 +70,11 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
|
||||
for (Block b : blocks) {
|
||||
if (b.getRelative(direction).hasMetadata(mcMMO.blockMetadataKey)) {
|
||||
mcMMO.getPlaceStore().setTrue(b.getRelative(direction));
|
||||
b.getRelative(direction).removeMetadata(mcMMO.blockMetadataKey, plugin);
|
||||
Block nextBlock = b.getRelative(direction);
|
||||
|
||||
if (nextBlock.hasMetadata(mcMMO.blockMetadataKey)) {
|
||||
mcMMO.getPlaceStore().setTrue(nextBlock);
|
||||
nextBlock.removeMetadata(mcMMO.blockMetadataKey, plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,15 +106,14 @@ public class BlockListener implements Listener {
|
||||
}
|
||||
|
||||
BlockState blockState = event.getBlock().getState();
|
||||
int blockId = blockState.getTypeId();
|
||||
|
||||
/* Check if the blocks placed should be monitored so they do not give out XP in the future */
|
||||
if (BlockUtils.shouldBeWatched(blockState)) {
|
||||
mcMMO.getPlaceStore().setTrue(blockState);
|
||||
}
|
||||
|
||||
if (Repair.anvilMessagesEnabled && (blockId == Repair.repairAnvilId || blockId == Repair.salvageAnvilId)) {
|
||||
UserManager.getPlayer(player).getRepairManager().placedAnvilCheck(blockId);
|
||||
if (Repair.anvilMessagesEnabled && BlockUtils.isMcMMOAnvil(blockState)) {
|
||||
UserManager.getPlayer(player).getRepairManager().placedAnvilCheck(blockState.getTypeId());
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,41 +322,31 @@ public class BlockListener implements Listener {
|
||||
ItemStack heldItem = player.getItemInHand();
|
||||
Block block = event.getBlock();
|
||||
BlockState blockState = block.getState();
|
||||
HerbalismManager herbalismManager = mcMMOPlayer.getHerbalismManager();
|
||||
|
||||
/*
|
||||
* ABILITY TRIGGER CHECKS
|
||||
*
|
||||
* We don't need to check permissions here because they've already been checked for the ability to even activate.
|
||||
*/
|
||||
if (herbalismManager.canGreenTerraBlock(blockState)) {
|
||||
if (herbalismManager.processGreenTerra(blockState)) {
|
||||
if (mcMMOPlayer.getAbilityMode(AbilityType.GREEN_TERRA) && BlockUtils.canMakeMossy(blockState)) {
|
||||
if (mcMMOPlayer.getHerbalismManager().processGreenTerra(blockState)) {
|
||||
blockState.update(true);
|
||||
}
|
||||
}
|
||||
else if (mcMMOPlayer.getAbilityMode(AbilityType.BERSERK)) {
|
||||
else if (mcMMOPlayer.getAbilityMode(AbilityType.BERSERK) && heldItem.getType() == Material.AIR) {
|
||||
if (SkillUtils.triggerCheck(player, block, AbilityType.BERSERK)) {
|
||||
if (heldItem.getType() == Material.AIR) {
|
||||
plugin.getServer().getPluginManager().callEvent(new FakePlayerAnimationEvent(player));
|
||||
|
||||
event.setInstaBreak(true);
|
||||
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch());
|
||||
}
|
||||
event.setInstaBreak(true);
|
||||
player.playSound(block.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch());
|
||||
}
|
||||
// Another perm check for the cracked blocks activation
|
||||
else if (BlockUtils.affectedByBlockCracker(blockState)) {
|
||||
UnarmedManager unarmedManager = mcMMOPlayer.getUnarmedManager();
|
||||
|
||||
if (unarmedManager.canUseBlockCracker() && SkillUtils.blockBreakSimulate(block, player, false) && unarmedManager.blockCrackerCheck(blockState)) {
|
||||
else if (Permissions.blockCracker(player) && SkillUtils.triggerCheck(player, block, AbilityType.BLOCK_CRACKER)) {
|
||||
if (mcMMOPlayer.getUnarmedManager().blockCrackerCheck(blockState)) {
|
||||
blockState.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (BlockUtils.isLeaves(blockState)) {
|
||||
if (mcMMOPlayer.getWoodcuttingManager().canUseLeafBlower(heldItem) && SkillUtils.blockBreakSimulate(block, player, true)) {
|
||||
event.setInstaBreak(true);
|
||||
player.playSound(blockState.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch());
|
||||
}
|
||||
else if (mcMMOPlayer.getWoodcuttingManager().canUseLeafBlower(heldItem) && SkillUtils.triggerCheck(player, block, AbilityType.LEAF_BLOWER)) {
|
||||
event.setInstaBreak(true);
|
||||
player.playSound(blockState.getLocation(), Sound.ITEM_PICKUP, Misc.POP_VOLUME, Misc.getPopPitch());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,7 @@ import org.bukkit.material.CocoaPlant;
|
||||
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
|
||||
import org.bukkit.material.NetherWarts;
|
||||
|
||||
import com.gmail.nossr50.config.Config;
|
||||
import com.gmail.nossr50.skills.repair.Repair;
|
||||
|
||||
public final class BlockUtils {
|
||||
private BlockUtils() {}
|
||||
@ -306,9 +306,9 @@ public final class BlockUtils {
|
||||
* @param blockState The {@link BlockState} of the block to check
|
||||
* @return true if the block is an mcMMO anvil, false otherwise
|
||||
*/
|
||||
private static boolean isMcMMOAnvil(BlockState blockState) {
|
||||
public static boolean isMcMMOAnvil(BlockState blockState) {
|
||||
int blockId = blockState.getTypeId();
|
||||
|
||||
return blockId == Config.getInstance().getRepairAnvilId() || blockId == Config.getInstance().getSalvageAnvilId();
|
||||
return blockId == Repair.repairAnvilId || blockId == Repair.salvageAnvilId;
|
||||
}
|
||||
}
|
||||
|
@ -347,6 +347,7 @@ public class SkillUtils {
|
||||
|
||||
switch (ability) {
|
||||
case BERSERK:
|
||||
case BLOCK_CRACKER:
|
||||
case LEAF_BLOWER:
|
||||
if (!ability.blockCheck(block.getState())) {
|
||||
activate = false;
|
||||
|
Loading…
Reference in New Issue
Block a user