Gun Shooting help.

Discussion in 'Plugin Development' started by BeastCraft3, Jul 29, 2014.

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

    BeastCraft3

    I got this code by a friend but im wondering why it wont shoot the clay_ball. Heres the code
    Code:java
    1. package CrankPhilsWarPlugin;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Material;
    7. import org.bukkit.Sound;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandExecutor;
    10. import org.bukkit.command.CommandSender;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.block.Action;
    15. import org.bukkit.event.player.PlayerInteractEvent;
    16. import org.bukkit.inventory.ItemStack;
    17. import org.bukkit.inventory.meta.ItemMeta;
    18.  
    19. public class Awp implements Listener, CommandExecutor {
    20.  
    21. public Awp(Main main) {
    22. main.getServer().getPluginManager().registerEvents(this, main);
    23. }
    24.  
    25. ItemStack Awp = new ItemStack(Material.STONE_AXE);{
    26. ItemMeta Awpmeta = Awp.getItemMeta();
    27. ArrayList<String> cc = new ArrayList<String>();
    28. Awpmeta.setDisplayName(ChatColor.RED + "AWP");
    29. cc.add(ChatColor.GREEN + "Sniper");
    30. Awpmeta.setLore(cc);
    31. Awp.setItemMeta(Awpmeta);
    32. }
    33.  
    34. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    35. if(!(sender instanceof Player)) {
    36. sender.sendMessage("Only players can use this command.");
    37. return true;
    38. }
    39. if(label.equalsIgnoreCase("awp")) {
    40. Player p = (Player) sender;
    41. if(p.hasPermission("gun.Awp")) {
    42. p.getInventory().addItem(new ItemStack(Awp));
    43. } else {
    44. p.sendMessage("You dont got permission to preform this command.");
    45. }
    46. }
    47. return false;
    48. }
    49.  
    50. @EventHandler
    51. public void onPlayerInteract(PlayerInteractEvent e){
    52. if(e.getAction() == Action.RIGHT_CLICK_AIR){
    53. Player p = e.getPlayer();
    54. if(p.getInventory().getItemInHand().getType() == Material.STONE_AXE){
    55. ItemStack i = p.getInventory().getItemInHand();
    56. if(i.getDurability() < 1562){
    57. i.setDurability((short)(i.getDurability() + 52.1));
    58. p.playSound(p.getLocation(), Sound.WITHER_HURT, 1, 2);
    59. }else{
    60. p.sendMessage(ChatColor.RED + "Left click to reload!");
    61. }
    62. }
    63. }else if(e.getAction() == Action.LEFT_CLICK_AIR){
    64. Player p = e.getPlayer();
    65. if(p.getInventory().getItemInHand().getType() == Material.STONE_AXE){
    66. ItemStack i = p.getInventory().getItemInHand();
    67. if(i.getDurability() > 52.1){
    68. for(int x = 0 ; x <= 44 ; x++){
    69. ItemStack im = p.getInventory().getItem(x);
    70. if(im.getType() == Material.CLAY_BALL){
    71. im.setAmount(im.getAmount() - 1);
    72. i.setDurability((short) (i.getDurability() - 52.1));
    73. p.playSound(p.getLocation(), Sound.DOOR_OPEN, 1, 2);
    74. break;
    75. }
    76. }
    77. }else{
    78. p.sendMessage(ChatColor.RED + "Ammo full!");
    79. }
    80. }
    81. }
    82. }
    83.  
    84.  
    85.  
    86. }
    87.  
     
  2. Offline

    Flamedek

    BeastCraft3 Wheres the code that should shoot it? It just checks if the inventory contains a clay ball, does durability and plays a sound but thats it.
    Nothing there that shoots it
     
  3. Offline

    BeastCraft3

    Flamedek
    hmm, Where should I place it?
     
  4. Offline

    Flamedek

    BeastCraft3 To not change the rest you could do it after you found the clayball but before the break. So for example after line 73 in your code here
     
  5. Offline

    BeastCraft3

    Flamedek
    Would the code look like this?
    Code:java
    1. Fireball f = e.getPlayer().launchProjectile(Fireball.class);


    EDIT: I want it to shoot the clay_ball. do you know how to do that?
     
  6. Offline

    Flamedek

    BeastCraft3 well a clay_ball isnt an entity so... you could launch a dropped item which represents a clay bal, but its still an item so idk what happens with people being able to pick it up mid air.
    Sticking to an entity like a fireball is probably easiest.. What you did looks good, just test it out
     
  7. Offline

    BeastCraft3

    Flamedek
    Thank you, I changed the fireball to an arrow. And sorry for nagging but do you know how to make the arrow go 250 blocks?
     
  8. Offline

    Flamedek

    BeastCraft3 multiply its velocity by a lot of times. use getVector().multiply to get the new vector, and setVelocity(vector) to apply
     
  9. Offline

    BeastCraft3

    Flamedek
    Emm. I cant find the right method for getVector. Where should I write it? After this?:
    Code:java
    1. Arrow a = e.getPlayer().launchProjectile(Arrow.class);
     
  10. Offline

    Flamedek

    BeastCraft3 Its just getVelocity my bad, and yes just after that I think
     
Thread Status:
Not open for further replies.

Share This Page