Get Type for Block not working

Discussion in 'Plugin Development' started by Vex102, Apr 12, 2020.

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

    Vex102

    I'm trying to get the type and the remove all the stuff in the line to an anvil if it's that block but it's not working it only does it to one block
    Code:
    package me.vergo.main.events;
    
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.UUID;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    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.Action;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.plugin.Plugin;
    
    import me.vergo.main.Main;
    
    
    public class VeinMiningEvent implements Listener
    {
    
        public static ArrayList<UUID> targ = new ArrayList<UUID>();
       
        @EventHandler
        public void playerInteractEvent(PlayerInteractEvent e)
        {
            Player p = e.getPlayer();
            if(e.getAction() == Action.RIGHT_CLICK_AIR  || e.getAction() == Action.RIGHT_CLICK_BLOCK)
            {
                for(int i = 0; i<targ.size(); i++)
                {
                    if(targ.get(i).equals(p.getUniqueId()))
                    {
                        if(p.getItemInHand() != null)
                        {
                            if(p.getItemInHand().hasItemMeta())
                            {
    
                                if(p.getItemInHand().getItemMeta().hasLore())
                                {
                                    ItemMeta meta = p.getItemInHand().getItemMeta();
                                    List<String> lore = meta.getLore();
                                    lore.add(ChatColor.LIGHT_PURPLE + "Vein Miner");
                                    meta.setLore(lore);
                                    p.getItemInHand().setItemMeta(meta);
                                    p.setItemInHand(p.getItemInHand());
                                    targ.remove(i);
                                }else {
                                    ItemMeta meta = p.getItemInHand().getItemMeta();
                                    ArrayList<String> lore = new ArrayList<String>();
                                    lore.add(ChatColor.LIGHT_PURPLE + "Vein Miner");
                                    meta.setLore(lore);
                                    p.getItemInHand().setItemMeta(meta);
                                    p.setItemInHand(p.getItemInHand());
                                    targ.remove(i);
                                }
                            }else {
                                ItemMeta meta = p.getItemInHand().getItemMeta();
                                ArrayList<String> lore = new ArrayList<String>();
                                lore.add(ChatColor.LIGHT_PURPLE + "Vein Miner");
                                meta.setLore(lore);
                                p.getItemInHand().setItemMeta(meta);
                                p.setItemInHand(p.getItemInHand());
                                targ.remove(i);
                            }
                        }
                    }
                }
            }
        }
       
       
        private HashMap<UUID, Long> cooldown = new HashMap<UUID, Long>();
        private Plugin plugin = Main.getPlugin(Main.class);
    
        @EventHandler
        public void onBlockBreak(BlockBreakEvent e)
        {
            Player p = e.getPlayer();
            ItemStack item = e.getPlayer().getItemInHand();
            Block block = e.getBlock();
            Block prevBlock = null;
            int cooldowntime = plugin.getConfig().getInt("Cooldown");
    
            if(item.hasItemMeta())
            {
                p.sendMessage("Test1");
                if(item.getItemMeta().hasLore())
                {
                    p.sendMessage("Test2");
                    List<String> lore = item.getItemMeta().getLore();
                    for(int i =0; i<lore.size(); i++)
                    {
                        p.sendMessage("Test3");
                        if(lore.get(i).equalsIgnoreCase(ChatColor.LIGHT_PURPLE + "Vein Miner"))
                        {
                            p.sendMessage("Test4");
                            if(cooldown.containsKey(p.getUniqueId()))
                            {
                                p.sendMessage("Test5");
                                long secondsleft = ((cooldown.get(p.getUniqueId())/1000) + cooldowntime) - (System.currentTimeMillis() / 1000);
                                if(secondsleft <= 0)
                                {
                                    prevBlock = block;
                                    p.sendMessage("Test9");
                                   
                                    //block.getWorld().getBlockAt(block.getLocation()).setType(Material.ANVIL);
                                    p.sendMessage("Block"  + block.getWorld().getBlockAt((int)block.getX()+1,(int)block.getY()-1,(int)block.getZ()).getType());
                                //    if(block.getWorld().getBlockAt((int)block.getX()+1,(int)block.getY(),(int)block.getZ()).getType() == block.getType())
                                //    {
                                //        block.getWorld().getBlockAt((int)block.getX()+1,(int)block.getY(),(int)block.getZ()).setType(Material.ANVIL);
                                //    }
                                   
    [COLOR=#ff0080]                                for(int a = 0; a<15; a++)
                                    {
                                        p.sendMessage("Block"  + block.getWorld().getBlockAt((int)block.getX()+a,(int)block.getY(),(int)block.getZ()).getType());
                                        if(block.getWorld().getBlockAt((int)block.getX()+a,(int)block.getY(),(int)block.getZ()).getType() == prevBlock.getType())
                                        {
                                            p.sendMessage("Block1: "  + block.getWorld().getBlockAt((int)block.getX()+a,(int)block.getY(),(int)block.getZ()).getType());
                                            p.sendMessage("Test20");
                                            block.getWorld().getBlockAt((int)block.getX()+a,(int)block.getY(),(int)block.getZ()).setType(Material.ANVIL);
                                        }[/COLOR]
                                        e.setCancelled(true);
                                    }
    
                                   
                                    cooldown.remove(p.getUniqueId());
                                }else {
    
                                }
                            }else {
                                p.sendMessage("Test6");
                                cooldown.put(p.getUniqueId(), System.currentTimeMillis());
                            }
           
                        }
                    }
                }
            }
           
        }
       
    
       
       
    }
     
    Last edited by a moderator: Apr 12, 2020
  2. Offline

    Kars

    Which function.
     
Thread Status:
Not open for further replies.

Share This Page