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