Grenadelauncher plugin

Discussion in 'Plugin Development' started by The_IcATaRiX, Jan 21, 2014.

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

    The_IcATaRiX

    Hey guys!

    I basically wanted to code a grenadelauncher but i don't really know how to start.. :(
    It's a PlayerInteractEvent so if you right-click a dispenser (the dispenser is in your inventory) it shoots a FIREWORK_CHARGE with a velocity of like 2-3. I would love if someone could give me the code which does that :) (I know the rest (how to create a explosion etc.))

    Thanks for helping
    - The_IcATaRiX
     
  2. Offline

    phildachil

    Watch this video:
     
  3. Offline

    The_IcATaRiX

    I don't want a fireball.. I want to drop a item with a velocity on right clicking a dispenser :)
    and this item should be a FIREWORK_CHARGE

    but thanks for the try of help^^
     
  4. Offline

    Deleted user

    The_IcATaRiX

    player.dropItem(), get the item that dropped. Set said item's direction to the player's direction. Set velocity to over 90- set the velocity to like 3 or something.
     
  5. Offline

    Cammeritz

    Try this:

    Code:java
    1. package xxx;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Location;
    5. import org.bukkit.Material;
    6. import org.bukkit.World;
    7. import org.bukkit.entity.Entity;
    8. import org.bukkit.entity.Fireball;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.entity.EntityExplodeEvent;
    12. import org.bukkit.event.entity.ProjectileHitEvent;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14.  
    15. public class CLASSNAME implements Listener {
    16. @EventHandler
    17. public void onBall(PlayerInteractEvent ev){
    18. final Player p = ev.getPlayer();
    19. if(p.getItemInHand().getType() == Material.DISPENSER){
    20. Fireball ball = p.launchProjectile(Fireball.class);
    21. ball.setVelocity(p.getEyeLocation().getDirection().multiply(4));
    22. ball.setShooter(p);
    23. }
    24. }
    25.  
    26.  
    27. @EventHandler
    28. public void onExplode(ProjectileHitEvent ev)
    29. {
    30. Entity entity = ev.getEntity();
    31.  
    32. if ((entity instanceof Fireball)) {
    33. Fireball b = (Fireball)entity;
    34. Entity shooter = b.getShooter();
    35.  
    36. if ((shooter instanceof Player)) {
    37. Player p = (Player)shooter;
    38. World wa = p.getWorld();
    39. Location l = b.getLocation();
    40. //p.getWorld().createExplosion(b.getLocation(), 5.0F);
    41. wa.createExplosion(l.getX(), l.getY(), l.getZ(), 5.0F, false, false);
    42.  
    43. }
    44. }
    45. }
    46. @EventHandler
    47. public void onBUMM(EntityExplodeEvent ev){
    48. ev.setCancelled(true);
    49. }
    50. }
    51.  


    I used this in my own plugin (just with other items and effects) :) I hope i helped you

    The_IcATaRiX

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  6. Offline

    The_IcATaRiX

    Cammeritz
    zombiekiller753

    I finally got this code to spawn the item, it works perfectly and the velocity is awesome! The only problem is that i can only shoot the item in the directions north, east, west and south and not directly where the player is looking at, like northeast. :(

    Code:java
    1. @EventHandler
    2. private void onPlayerInteract(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (!(e.getAction() == Action.RIGHT_CLICK_AIR)) return;
    5. if (!(e.getItem().getType() == Material.DISPENSER)) return;
    6.  
    7. p.getWorld().dropItem(p.getLocation(),new ItemStack(Material.FIREWORK_CHARGE));
    8.  
    9. Item item = p.getWorld().dropItem(p.getLocation(),new ItemStack(Material.FIREWORK_CHARGE));
    10.  
    11. item.setVelocity(p.getLocation().getDirection().multiply(2.8D));
    12. }
     
  7. Offline

    Deleted user

    The_IcATaRiX

    You can't?

    getDirection().multiply() should send it flying in whatever direction the player's looking at
     
  8. Offline

    The_IcATaRiX

    zombiekiller753
    No it doesnt work.. I'm looking to northeast but it shoots the item to east. :(

    EDIT: I noticed that when i jump and shoot it shoots the firework_charge to the players direction!
    But i also want that to happen if the player is not jumping xD
     
  9. Offline

    Cammeritz


    Don't use dropitem :O
     
  10. Offline

    The_IcATaRiX

    Cammeritz
    I got this code now:
    Code:java
    1. @EventHandler
    2. private void onPlayerInteract(PlayerInteractEvent e) {
    3. Player p = e.getPlayer();
    4. if (!(e.getAction() == Action.RIGHT_CLICK_AIR)) return;
    5. if (!(e.getItem().getType() == Material.DISPENSER)) return;
    6.  
    7. Item item = p.getWorld().dropItem(p.getLocation(),new ItemStack(Material.FIREWORK_CHARGE));
    8.  
    9. item.setVelocity(p.getLocation().getDirection().multiply(2.8D));


    I already removed the senseless itemspawn because I noticed that if I right-click the dispenser it spawns two firework_charges but it didn't change anything. I still can only shoot in the 4 main directions.
    Can you tell me what else I should use for dropitem? Or what do you mean :D

    Does noone have a clue? :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  11. Offline

    Cammeritz

    The_IcATaRiX Replace dropitem with:

    Code:java
    1. Player p = event.getPlayer;
    2. Fireball ball = p.launchProjectile(Fireball.class);
    3. ball.setVelocity(p.getEyeLocation().getDirection().multiply(4));
    4. ball.setShooter(p);
     
  12. Offline

    werter318

    Cammeritz Wait what??? why... he doesn't want to have a fireball.
     
Thread Status:
Not open for further replies.

Share This Page