LEFT Clicking a blazerod will throw a fireball

Discussion in 'Plugin Development' started by Curtis3321, Mar 21, 2013.

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

    Curtis3321

    Hello,

    i need some help.

    How can i make it so, when a player LEFT clicks with blazerod in there hand, it will shoot a fireball, but if they dont have the permission it will cancel?

    Help ;)

    I am not a very good at starting code so :(
     
  2. Offline

    xmarinusx

    Listen for PlayerInteractEvent and shoot a fire ball if they have permission(player.hasPermission("Your permission node here"))
    If you want some more detailled code just reply.
     
    Curtis3321 likes this.
  3. Offline

    Curtis3321

    Um, can i get more detailed code?
     
  4. Offline

    xmarinusx

    Code:java
    1.  
    2. @EventHandler
    3. public void onPlayerInterace(PlayerInteractEvent event){
    4. Action action = event.getAction();
    5. Player player = event.getPlayer();
    6. if(action.equals(Action.LEFT_CLICK_BLOCK) || action.equals(Action.LEFT_CLICK_AIR)){
    7. if(player.hasPermission("your.node.here")){
    8. if(player.getInventory().getItemInHand().getType() == Material.BLAZE_ROD){
    9. player.launchProjectile(Fireball.class).setVelocity(player.getLocation().getDirection().normalize().multiply(2));//Try some different numbers for the speed.
    10. }
    11. }
    12. }
    13. }

    I haven't tested it but it didn't give any errors, just tell me if it doesn't work.
     
  5. Offline

    Curtis3321

    Thanks, i have 1 more requests. How do i add a cooldown to it? Like 20 seconds or w/e
     
  6. Offline

    xmarinusx

  7. Offline

    CoderCloud

    I would create a hashmap with the playername and the time when the player fired a fireball. if he wants to shoot again you just compare the time in the map with the current time.
    Then you dont need multiple threads.
     
  8. Offline

    xmarinusx

    Owh, he meant that! That would be easier indeed. I thought he meant it would take 20 seconds until the fireball fires:p.
     
  9. Offline

    CoderCloud

    I think he meant that. Maybe you are right and I'm wrong. :eek:
     
Thread Status:
Not open for further replies.

Share This Page