Shooting fireballs?

Discussion in 'Plugin Development' started by harrybridgen, Mar 7, 2014.

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

    harrybridgen

    Hello, Im new to coding and I have a problem, everything in the plugin works ok, but when I try to right click with the book, it doesn't shoot the fireball. Any help?
    Code:java
    1. package lolwut.harrymoo.testplugin;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.Material;
    5. import org.bukkit.command.Command;
    6. import org.bukkit.command.CommandSender;
    7. import org.bukkit.entity.Fireball;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.block.Action;
    11. import org.bukkit.event.player.PlayerInteractEvent;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.inventory.PlayerInventory;
    14. import org.bukkit.plugin.java.JavaPlugin;
    15.  
    16. public class Main extends JavaPlugin {
    17.  
    18. public void onEnable() {
    19. getLogger().info("Plugin enabled!");
    20. }
    21. public void onDisable() {
    22. getLogger().info("Plugin Disabled!");
    23. }
    24. public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    25. if (label.equalsIgnoreCase("fireball")) {
    26. Player player = (Player) sender;
    27. PlayerInventory inventory = player.getInventory();
    28. inventory.addItem(new ItemStack(Material.BOOK));
    29. player.sendMessage(ChatColor.GOLD + "Fireball!");
    30. }
    31. return false;
    32. }
    33. @EventHandler
    34. public void OnEvt(PlayerInteractEvent event) {
    35. Player player = event.getPlayer();
    36. if (player.getItemInHand().getType() == Material.BOOK && event.getAction() == Action.RIGHT_CLICK_AIR) {
    37. player.launchProjectile(Fireball.class);
    38. }
    39. }
    40. }
     
  2. Offline

    IkBenHarm

    harrybridgen
    this is what i used to shoot a fireball:

    Code:
                        Location spawnAt = player.getEyeLocation().toVector().add(player.getEyeLocation().getDirection().multiply(3)).toLocation(player.getWorld());
                        Fireball fireball = player.getWorld().spawn(spawnAt, Fireball.class);
     
  3. Offline

    harrybridgen

    IkBenHarm ok, i'll try it out.
    Edit: nothing
     
  4. Offline

    IkBenHarm

    harrybridgen
    ohno, wait. this was it. Sorry

    Code:
    double pitch = ((player.getLocation().getPitch() + 90) * Math.PI) / 180;
                        double yaw = ((player.getLocation().getYaw() + 90) * Math.PI) / 180;
     
                        double x = Math.sin(pitch) * Math.cos(yaw);
                        double y = Math.sin(pitch) * Math.sin(yaw);
                        double z = Math.cos(pitch);
     
                        Vector vector = new Vector(x, z, y);
                       
                        Location spawnAt = player.getEyeLocation().toVector().add(player.getEyeLocation().getDirection().multiply(3)).toLocation(player.getWorld());
                        Fireball fireball = player.getWorld().spawn(spawnAt, Fireball.class);
                        fireball.setDirection(vector.multiply(10));
    for that vector thing you might aswell use player.getlookingdirection

    harrybridgen
    you might wanna change getItemInHand().getType ==
    to
    getItemInHand().getType().equals

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

    harrybridgen

    IkBenHarm Nothing again. I think there is a problem with my code
    Code:java
    1. @EventHandler
    2. public void OnEvt (PlayerInteractEvent event) {
    3. Player player = event.getPlayer();
    4. if (player.getItemInHand().getType() == Material.BOOK && event.getAction() == Action.RIGHT_CLICK_AIR) {


    just gives me errors and shit

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

    IkBenHarm

    harrybridgen
    mh, try removing the book check and see if its shoots a fireball then. if it does, you know where the error is
     
  7. Offline

    d3v1n302418

    harrybridgen Okay, nothing he said is of value here. You need to let your main class implement listener
    Code:java
    1. public class <classname> extends JavaPlugin implements Listener

    then you need to register events in your onEnable.
    Code:java
    1. Bukkit.getPluginManager().registerEvents(this, this);
     
  8. Offline

    harrybridgen

    d3v1n302418 How do I use
    Code:java
    1. Bukkit.getPluginManager().registerEvents(this, this);
     
  9. Offline

    IkBenHarm

    d3v1n302418
    whoops... *Using a drill to nail myself at the wall right now*
     
  10. Offline

    harrybridgen

    IkBenHarm And no, still nothing.
     
  11. Offline

    IkBenHarm

  12. Offline

    harrybridgen

    How do I use IkBenHarm
    Code:
    Bukkit.getPluginManager().registerEvents(this, this);
    Where do I put it?
     
  13. Offline

    IkBenHarm

  14. Offline

    harrybridgen

  15. Offline

    Barinade

    Using the main class as your listener #swag
     
  16. Offline

    d3v1n302418

    Barinade Dude, he's a beginner, chill out. :confused:
     
Thread Status:
Not open for further replies.

Share This Page