Enchantment API mining?

Discussion in 'Programming Help' started by Banbeucmas, Nov 20, 2015.

  1. Banbeucmas

    Banbeucmas New Member

    hi, i am a person who new to spigot (bukkit) coding, basicly, i have done with dependencies [EnchantmentAPI, WorldGuard]
    the plugin allows when a pickaxe apply 3x3 mining enchantment, it breaks the block in a plus area like this


    X: Block didnt break
    O:Block that break
    P:Block that player mined

    The proplem is, when the pickaxe is mining next to a block with the build flag deny protected, it still break that block (including Bedrocks)

    Here is the code, hoping someone to fix it

    Code (Text):
    package me.banbeucmas;

    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.entity.Player;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockEvent;
    import org.bukkit.plugin.Plugin;

    import com.rit.sucy.CustomEnchantment;
    import com.sk89q.worldguard.bukkit.WorldGuardPlugin;

    public class threebythree extends CustomEnchantment
        private WorldGuardPlugin getWorldGuard() {
            Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");

            if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
                return null;

            return (WorldGuardPlugin) plugin;
        static final Material[] threebythree = new Material[]
            public threebythree()
                super("3x3 Mining", threebythree, 1);
                this.max = 1;
                this.base = 50;
                this.interval = 10;
            public void applyToolEffect(Player player, Block block,int EnchantLevel, BlockEvent event)
                if (!(event instanceof BlockBreakEvent)) {
                if (getWorldGuard().canBuild(player, block.getRelative(0, -1, 0)))
                Block loc1 = block.getRelative(BlockFace.EAST, 1);
                Block loc2 = block.getRelative(BlockFace.WEST, 1);
                Block loc3 = block.getRelative(BlockFace.UP, 0);
                Block loc4 = block.getRelative(BlockFace.NORTH, 1);
                Block loc5 = block.getRelative(BlockFace.SOUTH, 1);

    P.S: Since i am new to coding you might say i need to learn more on JAva and bukkit plugin, I KNOW, give me some time to learn, almost everyone cant be good at something at the beginning

    Btw, i have read the worldguard api documentation, so some code maybe copied (almost, cuz i only understood 1%)
  2. PseudoKnight

    PseudoKnight Well-Known Member Developer

    I don't know how the enchantment plugin API works, but typically you'd listen for BlockBreakEvent at a higher priority and ignore cancelled events.
  3. PseudoKnight

    PseudoKnight Well-Known Member Developer

  4. Banbeucmas

    Banbeucmas New Member

    So that's mean I need to find another way ( with out the BlockBreakEvent, block will break instantly) or is there a way to lower the priority or set ignoreCancelled = false?
  5. PseudoKnight

    PseudoKnight Well-Known Member Developer

    Oh wait, I see what you're doing. You want to individually check every block, not just the original block. But what you're doing is just checking the block below the original block. You need to loop through each block and if WorldGuardPlugin.inst().canBuild(player, location) break that block. You don't need to check the original block, since WorldGuard will already do that.
  6. Banbeucmas

    Banbeucmas New Member

    Thks a million times, you helped me a lot!