I can't get the target block

Discussion in 'Plugin Development' started by ProjectGames0, Nov 24, 2015.

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

    ProjectGames0

    Hey, I'm trying to make a thor kit, but I can't get the target block to make the lightning

    Could you guys help me? Please, I will need it today

    Code:
        @SuppressWarnings("deprecation")
        @EventHandler
        public void abThor(PlayerInteractEvent e){
             final Player p = (Player) e.getPlayer();
           
            if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
               
                if(p.getItemInHand().getType() == Material.WOOD_AXE){
                   
                    if(Main.thorc.contains(p.getName())){
                        p.sendMessage(ChatColor.RED + "O Thor está em cooldown");
                    }else{
                       
                        p.getWorld().strikeLightning(p.getTargetBlock(null, 20).getLocation());
                        Main.thorc.add(p.getName());
                       
                        Main.plugin.getServer().getScheduler().scheduleAsyncDelayedTask(Main.plugin, new Runnable() {
                            public void run() {
                                Main.thorc.remove(p.getName());
                            }
                        },  20);
                    }
                   
                }
            }
        }
    The error is in: p.getWorld().strikeLightning(p.getTargetBlock(null, 20).getLocation());
     
  2. Offline

    Chloe-chan

    What is the error ?
     
  3. Offline

    ProjectGames0

    error.png
    It doesn't work
     
  4. Offline

    mcdorli

    Cast the null to a Set<Byte>, because this method can take two types of containers, and null can be either of those

    Edit: to a HashSet<Byte> or a Set<Material>, these are the two options.
     
  5. Offline

    ProjectGames0

    Sorry, I didn't understand, What do I have to do?
     
  6. Offline

    mcdorli

    Cast, do you know what casting means?
     
  7. Offline

    Lordloss

    You should know some basic Java if you want to learn the bukkit API..
     
  8. Offline

    VinexAx789

    @ProjectGames0
    Here's the spoon feed :D
    p.getWorld().strikeLightning(p.getTargetBlock((HashSet<Byte>) null, 20).getLocation());
     
  9. Offline

    mcdorli

    Why are you proud of that?
     
    VinexAx789 likes this.
  10. Offline

    VinexAx789

    @mcdorli He's not going to get much farther without knowing how to cast so it's ok. :D
    As long as I get a thank you your fine
    @ProjectGames0
     
  11. Offline

    mcdorli

    Maybe link him a page about cating? This only does, that he won't learn it, because he can just copy and paste it.
     
    VinexAx789 and Zombie_Striker like this.
  12. Offline

    Zombie_Striker

    @VinexAx789
    Yeah, If he doesn't have a basic understand of Java, you should definitely just spoonfeed him code. Surely he will just look at it and understand exactly what everything means
    </sarcasm>

    Please don't spoonfeed.
     
    VinexAx789 likes this.
  13. Offline

    mcdorli

    You forgot to add a <sarcasm> tag before your sentence, this xml code would throw an error.
     
  14. Offline

    ProjectGames0

    Thank you guys!
    Now it's working

    I'll try to learn more about Java, and about casting. :)
     
    VinexAx789 likes this.
Thread Status:
Not open for further replies.

Share This Page