Class BlockDamage

java.lang.Object
me.deecaad.weaponmechanics.weapon.explode.BlockDamage
All Implemented Interfaces:
me.deecaad.core.file.Serializer<BlockDamage>

public class BlockDamage extends Object implements me.deecaad.core.file.Serializer<BlockDamage>
  • 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

      public BlockDamage.BreakMode getDefaultMode()
    • setDefaultMode

      public void setDefaultMode(BlockDamage.BreakMode defaultMode)
    • getBlocks

      public Map<org.bukkit.block.BlockType,BlockDamage.DamageConfig> getBlocks()
    • setBlocks

      public void setBlocks(Map<org.bukkit.block.BlockType,BlockDamage.DamageConfig> blocks)
    • getBreakMode

      public BlockDamage.BreakMode getBreakMode(org.bukkit.block.Block block)
    • getBreakMode

      @NotNull public BlockDamage.BreakMode getBreakMode(@NotNull org.bukkit.block.BlockType material)
      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 -1 if 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, or null if 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()
      Returns true if at least 1 block can be broken through the damage(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 pass false, 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 null
      isRegenerate - Use true if you want to have perfect regeneration.
      Returns:
      The DamageData wrapping the block, or null if no damage was applied.
    • getKeyword

      public String getKeyword()
      Specified by:
      getKeyword in interface me.deecaad.core.file.Serializer<BlockDamage>
    • letPassThrough

      public boolean letPassThrough(@NotNull String key)
      Specified by:
      letPassThrough in interface me.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:
      serialize in interface me.deecaad.core.file.Serializer<BlockDamage>
      Throws:
      me.deecaad.core.file.SerializerException