Adding Fortune to 3x3 Pickaxe

Discussion in 'Plugin Development' started by iAmReprisal, May 5, 2017.

Thread Status:
Not open for further replies.
  1. Offline

    iAmReprisal

    Hello,

    I was wondering how I would add Fortune drops to this Pickaxe.
    It's not giving me Fortune drops for every single block that breaks.

    CODE:

    Code:
    package me.reprisal;
    
    import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
    
    import org.bukkit.ChatColor;
    import org.bukkit.block.Block;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.Plugin;
    
    import com.sk89q.worldedit.Vector;
    import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    import com.sk89q.worldguard.protection.ApplicableRegionSet;
    import com.sk89q.worldguard.protection.flags.DefaultFlag;
    import com.sk89q.worldguard.protection.managers.RegionManager;
    
    public class AlephPickaxe implements Listener {
       
        private CEParadox main;
        public AlephPickaxe(CEParadox main) {
            this.main = main;
        }
       
        private WorldGuardPlugin getWorldGuard() {
           
            Plugin plugin = main.getServer().getPluginManager().getPlugin("WorldGuard");
    
            if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
                return null;
            }
            return (WorldGuardPlugin) plugin;
        }
       
        @SuppressWarnings("deprecation")
        @EventHandler
        public void blockBreak(BlockBreakEvent e) {
    
            Player player = e.getPlayer();
            Block b = e.getBlock();
           
            ItemStack i = player.getItemInHand();
            ItemMeta lore = i.getItemMeta();
           
            if(!(i == null) && (i.hasItemMeta() && (lore.hasLore() && (lore.getLore().contains(ChatColor.GRAY + "Aleph I"))))) {
                Block block;
                for (int xOff = -1; xOff <= 1; ++xOff) {
                    for (int yOff = -1; yOff <= 1; ++yOff) {
                        for (int zOff = -1; zOff <= 1; ++zOff) {
                            block = b.getRelative(xOff, yOff, zOff);
                            WorldGuardPlugin worldGuard = getWorldGuard();
                            Vector pt = toVector(block);
                            RegionManager regionManager = worldGuard.getRegionManager(player.getWorld());
                            ApplicableRegionSet set = regionManager.getApplicableRegions(pt);
                            if (set.allows(DefaultFlag.BLOCK_BREAK)) {
                                block.breakNaturally();
                            }
                        }
                    }
                }
            }
        }
    
    }
    

    Any help would be greatly appreciated!


    Thanks!

    -Reprisal
     
  2. Online

    timtower Administrator Administrator Moderator

    @iAmReprisal Break naturally with an item parameter.
    Not sure how good it works though.
     
  3. Offline

    ipodtouch0218

    @timtower
    Doesn't Block#breakNaturally cause a BlockBreakEvent? If so, the 3x3 area would become 5x5, then 7x7, expanding all the way up from infinity.
     
  4. Online

    timtower Administrator Administrator Moderator

    @ipodtouch0218 Plugin needs to trigger that as far as I know. I do not know for sure though.
     
  5. Offline

    Zombie_Striker

    @ipodtouch0218
    No. It does not. That event only is called when a Player breaks a block, not just when any block is broken.
     
    ipodtouch0218 likes this.
  6. Offline

    iAmReprisal

    Is there any way of getting Fortune to work on this?
     
  7. Offline

    Caderape2

    @iAmReprisal
    for each block, you may get the drops and multiply the amount
     
    iAmReprisal likes this.
  8. Offline

    iAmReprisal

    @Caderape2
    How could I get each drop?


    Sent from my iPhone using Tapatalk
     
  9. Offline

    Caderape2

    @iAmReprisal
    that return a list of itemstack. You can iterate it. You may check first id it's not null
     
Thread Status:
Not open for further replies.

Share This Page