Class BlockDamage
java.lang.Object
me.deecaad.weaponmechanics.weapon.explode.BlockDamage
- All Implemented Interfaces:
me.deecaad.core.file.Serializer<BlockDamage>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDetermines whether a block is broken, cracked, or skip damage.static final recordHolds data from config for a material. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor for serializersBlockDamage(double dropBlockChance, int damage, int defaultBlockDurability, org.bukkit.Material defaultMask, BlockDamage.BreakMode defaultMode, Map<org.bukkit.block.BlockType, BlockDamage.DamageConfig> blocks) Constructor with arguments. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturnstrueif at least 1 block can be broken through thedamage(Block, Player, boolean)method.damage(org.bukkit.block.Block block, org.bukkit.entity.Player player, boolean isRegenerate) Applies damage to te given block.Map<org.bukkit.block.BlockType, BlockDamage.DamageConfig> getBreakMode(org.bukkit.block.Block block) getBreakMode(org.bukkit.block.BlockType material) Returns the behavior of the given material.intintorg.bukkit.MaterialdoubleintgetDurability(org.bukkit.block.Block block) intgetDurability(org.bukkit.block.BlockType material) Returns the number of hits before the block is broken, or-1if the block should not be broken.org.bukkit.MaterialgetMask(org.bukkit.block.Block block) org.bukkit.MaterialgetMask(org.bukkit.block.BlockType material) Returns the block the given material should be replaced with, ornullif the block shouldn't be replaced.booleanletPassThrough(String key) serialize(me.deecaad.core.file.SerializeData data) voidsetBlocks(Map<org.bukkit.block.BlockType, BlockDamage.DamageConfig> blocks) voidsetDamage(int damage) voidsetDefaultBlockDurability(int defaultBlockDurability) voidsetDefaultMask(org.bukkit.Material defaultMask) voidsetDefaultMode(BlockDamage.BreakMode defaultMode) voidsetDropBlockChance(double dropBlockChance) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.deecaad.core.file.Serializer
canUsePathTo, getName, getParentKeywords, getWikiLink, shouldSerialize, tryPathTo, useLater
-
Constructor Details
-
BlockDamage
public BlockDamage()Default constructor for serializers -
BlockDamage
public BlockDamage(double dropBlockChance, int damage, int defaultBlockDurability, org.bukkit.Material defaultMask, BlockDamage.BreakMode defaultMode, Map<org.bukkit.block.BlockType, BlockDamage.DamageConfig> blocks) Constructor with arguments.- Parameters:
dropBlockChance- The [0, 1] chance to drop broken blocks as items.damage- The damage (usually 1) each hit.defaultBlockDurability- The default health any block has.defaultMask- The default mask (usually AIR) any block has.defaultMode- The default breaking mode any block has.blocks- Per-block overrides.
-
-
Method Details
-
getDropBlockChance
public double getDropBlockChance() -
setDropBlockChance
public void setDropBlockChance(double dropBlockChance) -
getDamage
public int getDamage() -
setDamage
public void setDamage(int damage) -
getDefaultBlockDurability
public int getDefaultBlockDurability() -
setDefaultBlockDurability
public void setDefaultBlockDurability(int defaultBlockDurability) -
getDefaultMask
public org.bukkit.Material getDefaultMask() -
setDefaultMask
public void setDefaultMask(org.bukkit.Material defaultMask) -
getDefaultMode
-
setDefaultMode
-
getBlocks
-
setBlocks
-
getBreakMode
-
getBreakMode
Returns the behavior of the given material. Should it break? Should it crack? Or should it ignore all damage?- Parameters:
material- The non-null material to check.- Returns:
- The non-null break mode of the material.
-
getDurability
public int getDurability(@NotNull org.bukkit.block.Block block) -
getDurability
public int getDurability(@NotNull org.bukkit.block.BlockType material) Returns the number of hits before the block is broken, or-1if the block should not be broken.- Parameters:
material- The non-null material to check.- Returns:
- The number of hits before the block breaks.
-
getMask
@NotNull public org.bukkit.Material getMask(@NotNull org.bukkit.block.Block block) -
getMask
public org.bukkit.Material getMask(org.bukkit.block.BlockType material) Returns the block the given material should be replaced with, ornullif the block shouldn't be replaced.- Parameters:
material- The non-null material to check.- Returns:
- The nullable material to use as a mask.
-
canBreakBlocks
public boolean canBreakBlocks()Returnstrueif at least 1 block can be broken through thedamage(Block, Player, boolean)method. Useful for checking if a weapon can be used for griefing.- Returns:
- true if blocks can be broken.
-
damage
@Nullable public BlockDamageData.DamageData damage(org.bukkit.block.Block block, @Nullable org.bukkit.entity.Player player, boolean isRegenerate) Applies damage to te given block. Any previous damage that was applied is STACKED to see if the block should be broken. Depending on the block, damage might be skipped, the block may be cracked, or the block may break.Regeneration is not handled automatically. You have to check the return value and handle regeneration in a schedules task. If you pass
true, blocks will be broken WITHOUT block updates. If you passfalse, blocks will be broken and neighboring blocks will be updated (making accurate regeneration impossible).boolean regenerate = true; BlockDamageData.DamageData data = BlockDamage#damage(block, null, regenerate); if (regenerate) { if (blockDamage.isBreak() && data.isBroken()) { new BukkitRunnable() { public void run() { data.regenerate(); data.remove(); } }.runTaskLater(plugin, 200L); // 10 seconds } } else if (data.isBroken()) { data.remove(); }- Parameters:
block- The non-null block to damage.player- The nullable player who is breaking block, explosions should always give nullisRegenerate- Use true if you want to have perfect regeneration.- Returns:
- The DamageData wrapping the block, or null if no damage was applied.
-
getKeyword
- Specified by:
getKeywordin interfaceme.deecaad.core.file.Serializer<BlockDamage>
-
letPassThrough
- Specified by:
letPassThroughin interfaceme.deecaad.core.file.Serializer<BlockDamage>
-
serialize
@NotNull public BlockDamage serialize(@NotNull me.deecaad.core.file.SerializeData data) throws me.deecaad.core.file.SerializerException - Specified by:
serializein interfaceme.deecaad.core.file.Serializer<BlockDamage>- Throws:
me.deecaad.core.file.SerializerException
-