Snowballs not coming out

Discussion in 'Plugin Development' started by BrushPainter, Mar 6, 2014.

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

    BrushPainter

    Hey everyone, I'm trying to add a command to give the sender a 3-burst paintball gun. The code works, no errors or anything just that when the player types /pbgun they get the gun with all the item metas etc. but when they right click snow balls don't come out/shoot.

    Here is my current code:

    Code:java
    1. package me.BrushPainter.PaintballGuns;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.entity.Snowball;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. import java.util.ArrayList;
    19.  
    20. public class Main extends JavaPlugin implements Listener
    21. {
    22.  
    23. public void onEnable() {
    24.  
    25. getLogger().info("PaintballGuns Enabled");
    26.  
    27. }
    28.  
    29. public void onDisable() {
    30.  
    31. getLogger().info("PaintballGuns Disabled");
    32.  
    33. }
    34.  
    35. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    36.  
    37. if(cmd.getName().equalsIgnoreCase("pbgun")){
    38. if (sender instanceof Player) {
    39. Player pl = (Player) sender;
    40.  
    41. ItemStack is = new ItemStack(Material.GOLD_BARDING);
    42. ItemMeta im = is.getItemMeta();
    43. im.setDisplayName(ChatColor.GOLD + "" +ChatColor.BOLD + "3-Burst Paintball Gun");
    44. is.setItemMeta(im);
    45. pl.getInventory().addItem(is);
    46.  
    47. pl.sendMessage(ChatColor.YELLOW + "You have received a paintball gun, right click to use it.");
    48.  
    49. } else {
    50.  
    51. sender.sendMessage(ChatColor.RED + "An error has occured! - BrushPainter");
    52.  
    53. }
    54.  
    55. }
    56.  
    57.  
    58. return false;
    59.  
    60.  
    61.  
    62. }
    63.  
    64.  
    65. ArrayList<String> cooldownis = new ArrayList<String>();
    66. ArrayList<String> cooldownis1 = new ArrayList<String>();
    67. ArrayList<String> cooldownis2 = new ArrayList<String>();
    68.  
    69. @EventHandler
    70. public void onInteract(final PlayerInteractEvent e)
    71. {
    72. ItemStack is = new ItemStack(Material.GOLD_BARDING);
    73. ItemMeta im = is.getItemMeta();
    74. im.setDisplayName(ChatColor.GOLD + "" +ChatColor.BOLD + "3-Burst Paintball Gun");
    75. is.setItemMeta(im);
    76.  
    77. ItemStack is1 = new ItemStack(Material.IRON_BARDING);
    78. ItemMeta im1 = is1.getItemMeta();
    79. im1.setDisplayName(ChatColor.GRAY + "" +ChatColor.BOLD + "Semi-auto Paintball Gun");
    80. is1.setItemMeta(im1);
    81.  
    82. ItemStack is2 = new ItemStack(Material.DIAMOND_BARDING);
    83. ItemMeta im2 = is2.getItemMeta();
    84. im2.setDisplayName(ChatColor.BLUE + "" +ChatColor.BOLD + "Fully-auto Paintball Gun");
    85. if(e.getAction() == Action.RIGHT_CLICK_AIR)
    86. {
    87. if(e.getPlayer().getItemInHand().equals(is))
    88. {
    89. if (cooldownis.contains(e.getPlayer().getName()))
    90. {
    91. e.getPlayer().launchProjectile(Snowball.class);
    92. e.getPlayer().launchProjectile(Snowball.class);
    93. e.getPlayer().launchProjectile(Snowball.class);
    94. cooldownis.add(e.getPlayer().getName());
    95.  
    96. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    97. {
    98.  
    99. @Override
    100. public void run()
    101. {
    102. cooldownis.remove(e.getPlayer().getName());
    103. }
    104. }, 35L);
    105. }else
    106. {
    107. }
    108. }
    109.  
    110.  
    111.  
    112. if(e.getPlayer().getItemInHand().equals(is1))
    113. {
    114. if (cooldownis1.contains(e.getPlayer().getName()))
    115. {
    116. e.getPlayer().launchProjectile(Snowball.class);
    117. cooldownis1.add(e.getPlayer().getName());
    118.  
    119. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    120. {
    121.  
    122. @Override
    123. public void run()
    124. {
    125. cooldownis1.remove(e.getPlayer().getName());
    126. }
    127. }, 15L);
    128. }else
    129. {
    130. }
    131. }
    132.  
    133.  
    134.  
    135. if(e.getPlayer().getItemInHand().equals(is2))
    136. {
    137. if (cooldownis2.contains(e.getPlayer().getName()))
    138. {
    139. e.getPlayer().launchProjectile(Snowball.class);
    140. cooldownis2.add(e.getPlayer().getName());
    141.  
    142. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    143. {
    144.  
    145. @Override
    146. public void run()
    147. {
    148. cooldownis2.remove(e.getPlayer().getName());
    149. }
    150. }, 4L);
    151. }else
    152. {
    153. }
    154. }
    155. }
    156. }
    157. }



    If you have any idea why please help me as soon as possible, I would really like to have the plugin ready by the morning.

    Thanks in advance guys - Brush:)
     
  2. Offline

    timtower Moderator Moderator

  3. Offline

    BrushPainter

    timtower I know that this sound super nooby but can you give me an example of what you mean? I don't really understand. Thanks for the reply by the way. :)
     
  4. Offline

    MrInspector

    Code:java
    1. Bukkit.getPluginManager().registerEvents(this, this);
    2. // in your onEnable
     
  5. Offline

    BrushPainter

    MrInspector Oh god, thanks so much... I can't believe I didn't know what that was haha. -.- Thanks a lot though.

    MrInspector timtower The paintball gun is still not firing snowballs, it doesn't do anything when I right click. Here is my new code:

    Code:java
    1. package me.BrushPainter.PaintballGuns;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.entity.Snowball;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. import java.util.ArrayList;
    19.  
    20. public class Main extends JavaPlugin implements Listener
    21. {
    22.  
    23. public void onEnable() {
    24. Bukkit.getPluginManager().registerEvents(this, this);
    25. getLogger().info("PaintballGuns Enabled");
    26.  
    27. }
    28.  
    29. public void onDisable() {
    30.  
    31. getLogger().info("PaintballGuns Disabled");
    32.  
    33. }
    34.  
    35. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    36.  
    37. if(cmd.getName().equalsIgnoreCase("pbgun")){
    38. if (sender instanceof Player) {
    39. Player pl = (Player) sender;
    40.  
    41. ItemStack is = new ItemStack(Material.GOLD_BARDING);
    42. ItemMeta im = is.getItemMeta();
    43. im.setDisplayName(ChatColor.GOLD + "" +ChatColor.BOLD + "3-Burst Paintball Gun");
    44. is.setItemMeta(im);
    45. pl.getInventory().addItem(is);
    46.  
    47. pl.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "[" + ChatColor.RESET + "" + ChatColor.WHITE + "Clear" + ChatColor.DARK_AQUA + "Realms" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "] " + ChatColor.RESET + "" + ChatColor.GRAY + "You have received a paintball gun, right click to use it.");
    48.  
    49. } else {
    50.  
    51. sender.sendMessage(ChatColor.RED + "An error has occured! - BrushPainter");
    52.  
    53. }
    54.  
    55. }
    56.  
    57.  
    58. return false;
    59.  
    60.  
    61.  
    62. }
    63.  
    64.  
    65. ArrayList<String> cooldownis = new ArrayList<String>();
    66. ArrayList<String> cooldownis1 = new ArrayList<String>();
    67. ArrayList<String> cooldownis2 = new ArrayList<String>();
    68.  
    69. @EventHandler
    70. public void onInteract(final PlayerInteractEvent e)
    71. {
    72. ItemStack is = new ItemStack(Material.GOLD_BARDING);
    73. ItemMeta im = is.getItemMeta();
    74. im.setDisplayName(ChatColor.GOLD + "" +ChatColor.BOLD + "3-Burst Paintball Gun");
    75. is.setItemMeta(im);
    76.  
    77. ItemStack is1 = new ItemStack(Material.IRON_BARDING);
    78. ItemMeta im1 = is1.getItemMeta();
    79. im1.setDisplayName(ChatColor.GRAY + "" +ChatColor.BOLD + "Semi-auto Paintball Gun");
    80. is1.setItemMeta(im1);
    81.  
    82. ItemStack is2 = new ItemStack(Material.DIAMOND_BARDING);
    83. ItemMeta im2 = is2.getItemMeta();
    84. im2.setDisplayName(ChatColor.BLUE + "" +ChatColor.BOLD + "Fully-auto Paintball Gun");
    85. if(e.getAction() == Action.RIGHT_CLICK_AIR)
    86. {
    87. if(e.getPlayer().getItemInHand().equals(is))
    88. {
    89. if (cooldownis.contains(e.getPlayer().getName()))
    90. {
    91. e.getPlayer().launchProjectile(Snowball.class);
    92. e.getPlayer().launchProjectile(Snowball.class);
    93. e.getPlayer().launchProjectile(Snowball.class);
    94. cooldownis.add(e.getPlayer().getName());
    95.  
    96. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    97. {
    98.  
    99. @Override
    100. public void run()
    101. {
    102. cooldownis.remove(e.getPlayer().getName());
    103. }
    104. }, 35L);
    105. }else
    106. {
    107. }
    108. }
    109.  
    110.  
    111.  
    112. if(e.getPlayer().getItemInHand().equals(is1))
    113. {
    114. if (cooldownis1.contains(e.getPlayer().getName()))
    115. {
    116. e.getPlayer().launchProjectile(Snowball.class);
    117. cooldownis1.add(e.getPlayer().getName());
    118.  
    119. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    120. {
    121.  
    122. @Override
    123. public void run()
    124. {
    125. cooldownis1.remove(e.getPlayer().getName());
    126. }
    127. }, 15L);
    128. }else
    129. {
    130. }
    131. }
    132.  
    133.  
    134.  
    135. if(e.getPlayer().getItemInHand().equals(is2))
    136. {
    137. if (cooldownis2.contains(e.getPlayer().getName()))
    138. {
    139. e.getPlayer().launchProjectile(Snowball.class);
    140. cooldownis2.add(e.getPlayer().getName());
    141.  
    142. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    143. {
    144.  
    145. @Override
    146. public void run()
    147. {
    148. cooldownis2.remove(e.getPlayer().getName());
    149. }
    150. }, 4L);
    151. }else
    152. {
    153. }
    154. }
    155. }
    156. }
    157. }


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

    MrInspector

    Any errors in console?

    I'm pretty tired right now + sick so you could try to ask someone else right now. :(

    sorry
     
  7. Offline

    timtower Moderator Moderator

    BrushPainter Probably something wrong in the checks, don't check if the item is equal to another item but try getting the name of the item, strip the color and then compare that.
     
  8. Offline

    BrushPainter

    MrInspector None that I see and okay man I hope you feel better. It sucks to be sick...
     
    MrInspector likes this.
  9. Offline

    MrInspector

    Tell me about it! I've been sick 10 times this year already. (not kidding, it feels like hell)
     
  10. Offline

    BrushPainter

    timtower So I should just strip the color from the name and then that's it?

    MrInspector Wow man that's terrible, the year just started.

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

    timtower Moderator Moderator

    And check if the names match, probably better than comparing the entire item.
     
  12. Offline

    BrushPainter

    timtower I'm getting really confused about what to delete and what to add, I don't want to ruin my code that I have so far. :(

    timtower Here's what I have so far after stripping the color.

    Code:java
    1. package me.BrushPainter.PaintballGuns;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.entity.Snowball;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. import java.util.ArrayList;
    19.  
    20. public class Main extends JavaPlugin implements Listener
    21. {
    22.  
    23. public void onEnable() {
    24. Bukkit.getPluginManager().registerEvents(this, this);
    25. getLogger().info("PaintballGuns Enabled");
    26.  
    27. }
    28.  
    29. public void onDisable() {
    30.  
    31. getLogger().info("PaintballGuns Disabled");
    32.  
    33. }
    34.  
    35. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    36.  
    37. if(cmd.getName().equalsIgnoreCase("pbgun")){
    38. if (sender instanceof Player) {
    39. Player pl = (Player) sender;
    40.  
    41. ItemStack is = new ItemStack(Material.GOLD_BARDING);
    42. ItemMeta im = is.getItemMeta();
    43. im.setDisplayName("3-Burst Paintball Gun");
    44. is.setItemMeta(im);
    45. pl.getInventory().addItem(is);
    46.  
    47. pl.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "[" + ChatColor.RESET + "" + ChatColor.WHITE + "Clear" + ChatColor.DARK_AQUA + "Realms" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "] " + ChatColor.RESET + "" + ChatColor.GRAY + "You have received a paintball gun, right click to use it.");
    48.  
    49. } else {
    50.  
    51. sender.sendMessage(ChatColor.RED + "An error has occured! - BrushPainter");
    52.  
    53. }
    54.  
    55. }
    56.  
    57.  
    58. return false;
    59.  
    60.  
    61.  
    62. }
    63.  
    64.  
    65. ArrayList<String> cooldownis = new ArrayList<String>();
    66. ArrayList<String> cooldownis1 = new ArrayList<String>();
    67. ArrayList<String> cooldownis2 = new ArrayList<String>();
    68.  
    69. @EventHandler
    70. public void onInteract(final PlayerInteractEvent e)
    71. {
    72. ItemStack is = new ItemStack(Material.GOLD_BARDING);
    73. ItemMeta im = is.getItemMeta();
    74. im.setDisplayName(ChatColor.GOLD + "" +ChatColor.BOLD + "3-Burst Paintball Gun");
    75. is.setItemMeta(im);
    76.  
    77. ItemStack is1 = new ItemStack(Material.IRON_BARDING);
    78. ItemMeta im1 = is1.getItemMeta();
    79. im1.setDisplayName(ChatColor.GRAY + "" +ChatColor.BOLD + "Semi-auto Paintball Gun");
    80. is1.setItemMeta(im1);
    81.  
    82. ItemStack is2 = new ItemStack(Material.DIAMOND_BARDING);
    83. ItemMeta im2 = is2.getItemMeta();
    84. im2.setDisplayName(ChatColor.BLUE + "" +ChatColor.BOLD + "Fully-auto Paintball Gun");
    85. if(e.getAction() == Action.RIGHT_CLICK_AIR)
    86. {
    87. if(e.getPlayer().getItemInHand().equals(is))
    88. {
    89. if (cooldownis.contains(e.getPlayer().getName()))
    90. {
    91. e.getPlayer().launchProjectile(Snowball.class);
    92. e.getPlayer().launchProjectile(Snowball.class);
    93. e.getPlayer().launchProjectile(Snowball.class);
    94. cooldownis.add(e.getPlayer().getName());
    95.  
    96. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    97. {
    98.  
    99. @Override
    100. public void run()
    101. {
    102. cooldownis.remove(e.getPlayer().getName());
    103. }
    104. }, 35L);
    105. }else
    106. {
    107. }
    108. }
    109.  
    110.  
    111.  
    112. if(e.getPlayer().getItemInHand().equals(is1))
    113. {
    114. if (cooldownis1.contains(e.getPlayer().getName()))
    115. {
    116. e.getPlayer().launchProjectile(Snowball.class);
    117. cooldownis1.add(e.getPlayer().getName());
    118.  
    119. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    120. {
    121.  
    122. @Override
    123. public void run()
    124. {
    125. cooldownis1.remove(e.getPlayer().getName());
    126. }
    127. }, 15L);
    128. }else
    129. {
    130. }
    131. }
    132.  
    133.  
    134.  
    135. if(e.getPlayer().getItemInHand().equals(is2))
    136. {
    137. if (cooldownis2.contains(e.getPlayer().getName()))
    138. {
    139. e.getPlayer().launchProjectile(Snowball.class);
    140. cooldownis2.add(e.getPlayer().getName());
    141.  
    142. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    143. {
    144.  
    145. @Override
    146. public void run()
    147. {
    148. cooldownis2.remove(e.getPlayer().getName());
    149. }
    150. }, 4L);
    151. }else
    152. {
    153. }
    154. }
    155. }
    156. }
    157. }


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

    timtower Moderator Moderator

    Don't delete, comment out.
    And I will change the code for you to what I meant
     
  14. Offline

    BrushPainter

    timtower Thank you so much, and I never thought of that, that is a great idea for the future. It's 2:42 AM where I am, I have to catch some sleep, I will get back to you tomorrow morning, thanks a lot for all the help, I really appreciate it man. :)
     
  15. Offline

    timtower Moderator Moderator

    Have a good night ;)
    I will edit this post when done
    Code:java
    1.  
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.entity.Snowball;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. import java.util.ArrayList;
    19.  
    20. public class Main extends JavaPlugin implements Listener
    21. {
    22.  
    23. public void onEnable() {
    24. Bukkit.getPluginManager().registerEvents(this, this);
    25. getLogger().info("PaintballGuns Enabled");
    26.  
    27. }
    28.  
    29. public void onDisable() {
    30.  
    31. getLogger().info("PaintballGuns Disabled");
    32.  
    33. }
    34.  
    35. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    36.  
    37. if(cmd.getName().equalsIgnoreCase("pbgun")){
    38. if (sender instanceof Player) {
    39. Player pl = (Player) sender;
    40. ItemStack is = new ItemStack(Material.GOLD_BARDING);
    41. ItemMeta im = is.getItemMeta();
    42. im.setDisplayName(ChatColor.GOLD + "" +ChatColor.BOLD + "3-Burst Paintball Gun");
    43. is.setItemMeta(im);
    44. pl.getInventory().addItem(is);
    45. pl.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "[" + ChatColor.RESET + "" + ChatColor.WHITE + "Clear" + ChatColor.DARK_AQUA + "Realms" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "] " + ChatColor.RESET + "" + ChatColor.GRAY + "You have received a paintball gun, right click to use it.");
    46. } else {
    47. sender.sendMessage(ChatColor.RED + "An error has occured! - BrushPainter");
    48. }
    49. }
    50. return false;
    51. }
    52.  
    53.  
    54. ArrayList<String> cooldownis = new ArrayList<String>();
    55. ArrayList<String> cooldownis1 = new ArrayList<String>();
    56. ArrayList<String> cooldownis2 = new ArrayList<String>();
    57.  
    58. @EventHandler
    59. public void onInteract(final PlayerInteractEvent e)
    60. {
    61. /*ItemStack is = new ItemStack(Material.GOLD_BARDING);
    62.   ItemMeta im = is.getItemMeta();
    63.   im.setDisplayName(ChatColor.GOLD + "" +ChatColor.BOLD + "3-Burst Paintball Gun");
    64.   is.setItemMeta(im);
    65.  
    66.   ItemStack is1 = new ItemStack(Material.IRON_BARDING);
    67.   ItemMeta im1 = is1.getItemMeta();
    68.   im1.setDisplayName(ChatColor.GRAY + "" +ChatColor.BOLD + "Semi-auto Paintball Gun");
    69.   is1.setItemMeta(im1);
    70.  
    71.   ItemStack is2 = new ItemStack(Material.DIAMOND_BARDING);
    72.   ItemMeta im2 = is2.getItemMeta();
    73.   im2.setDisplayName(ChatColor.BLUE + "" +ChatColor.BOLD + "Fully-auto Paintball Gun");*/
    74. if(e.getAction() == Action.RIGHT_CLICK_AIR)
    75. {
    76. String itemName = "";
    77. ItemStack item = e.getPlayer().getItemInHand();
    78. if(!item.hasItemMeta())return;
    79. ItemMeta meta = item.getItemMeta();
    80. if(!meta.hasDisplayName())return;
    81. itemName = ChatColor.stripColor(meta.getDisplayName());
    82. if(itemName.contains("3-Burst Paintball Gun"))
    83. {
    84. if (cooldownis.contains(e.getPlayer().getName()))
    85. {
    86. e.getPlayer().launchProjectile(Snowball.class);
    87. e.getPlayer().launchProjectile(Snowball.class);
    88. e.getPlayer().launchProjectile(Snowball.class);
    89. cooldownis.add(e.getPlayer().getName());
    90.  
    91. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    92. {
    93. @Override
    94. public void run()
    95. {
    96. cooldownis.remove(e.getPlayer().getName());
    97. }
    98. }, 35L);
    99. }else
    100. {
    101. }
    102. }
    103.  
    104. if(itemName.contains("Semi-auto Paintball Gun"))
    105. {
    106. if (cooldownis1.contains(e.getPlayer().getName()))
    107. {
    108. e.getPlayer().launchProjectile(Snowball.class);
    109. cooldownis1.add(e.getPlayer().getName());
    110.  
    111. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    112. {
    113. @Override
    114. public void run()
    115. {
    116. cooldownis1.remove(e.getPlayer().getName());
    117. }
    118. }, 15L);
    119. }else
    120. {
    121. }
    122. }
    123.  
    124. if(itemName.contains("Fully-auto Paintball Gun"))
    125. {
    126. if (cooldownis2.contains(e.getPlayer().getName()))
    127. {
    128. e.getPlayer().launchProjectile(Snowball.class);
    129. cooldownis2.add(e.getPlayer().getName());
    130.  
    131. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    132. {
    133.  
    134. @Override
    135. public void run()
    136. {
    137. cooldownis2.remove(e.getPlayer().getName());
    138. }
    139. }, 4L);
    140. }else
    141. {
    142. }
    143. }
    144. }
    145. }
    146. }
     
  16. Offline

    BrushPainter

    timtower 97waterpolo That code still isn't working for me, I really really appreciate the effort you put in and your patience though. :) But nothing at all happens when I right click still. :confused: Not too sure what to do. Could it be because my command which is giving the ItemStack is below the actual part that makes it shoot snowballs? If so how would I fix this?
     
  17. Offline

    97WaterPolo

    BrushPainter
    Sorry, you are right, move the item stacks and their litres outside the event.
     
  18. Offline

    timtower Moderator Moderator

    BrushPainter found the issue: you check if people are in the cooldown then shoot, it should be the opposite.if not in.cooldown then shoot.
     
  19. Offline

    BrushPainter

    timtower So I have to do something like this for all 3?

    Code:java
    1. if(itemName.contains("Fully-auto Paintball Gun"))
    2. {
    3. if (cooldownis2.add(e.getPlayer().getName()))
    4. {
    5. e.getPlayer().launchProjectile(Snowball.class);
    6. cooldownis2.contains(e.getPlayer().getName());
    7.  
    8. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    9. {
    10.  
    11. @Override
    12. public void run()
    13. {
    14. cooldownis2.remove(e.getPlayer().getName());
    15. }
    16. }, 4L);
    17. }else
    18. {
    19. }


    97waterpolo Mind showing me how? I kind of thought that was the problem all along but I wasn't sure how to do it, if I put the code for the snowballs firing out of the horse armor it gives me tons upon tons of errors.

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

    timtower Moderator Moderator

    BrushPainter More like this:
    Code:java
    1.  
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.entity.Snowball;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. import java.util.ArrayList;
    19.  
    20. public class Main extends JavaPlugin implements Listener
    21. {
    22.  
    23. public void onEnable() {
    24. Bukkit.getPluginManager().registerEvents(this, this);
    25. getLogger().info("PaintballGuns Enabled");
    26.  
    27. }
    28.  
    29. public void onDisable() {
    30.  
    31. getLogger().info("PaintballGuns Disabled");
    32.  
    33. }
    34.  
    35. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    36.  
    37. if(cmd.getName().equalsIgnoreCase("pbgun")){
    38. if (sender instanceof Player) {
    39. Player pl = (Player) sender;
    40. ItemStack is = new ItemStack(Material.GOLD_BARDING);
    41. ItemMeta im = is.getItemMeta();
    42. im.setDisplayName(ChatColor.GOLD + "" +ChatColor.BOLD + "3-Burst Paintball Gun");
    43. is.setItemMeta(im);
    44. pl.getInventory().addItem(is);
    45. pl.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "[" + ChatColor.RESET + "" + ChatColor.WHITE + "Clear" + ChatColor.DARK_AQUA + "Realms" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "] " + ChatColor.RESET + "" + ChatColor.GRAY + "You have received a paintball gun, right click to use it.");
    46. } else {
    47. sender.sendMessage(ChatColor.RED + "An error has occured! - BrushPainter");
    48. }
    49. }
    50. return false;
    51. }
    52.  
    53.  
    54. ArrayList<String> cooldownis = new ArrayList<String>();
    55. ArrayList<String> cooldownis1 = new ArrayList<String>();
    56. ArrayList<String> cooldownis2 = new ArrayList<String>();
    57.  
    58. @EventHandler
    59. public void onInteract(final PlayerInteractEvent e)
    60. {
    61. /*ItemStack is = new ItemStack(Material.GOLD_BARDING);
    62. ItemMeta im = is.getItemMeta();
    63. im.setDisplayName(ChatColor.GOLD + "" +ChatColor.BOLD + "3-Burst Paintball Gun");
    64. is.setItemMeta(im);
    65.  
    66. ItemStack is1 = new ItemStack(Material.IRON_BARDING);
    67. ItemMeta im1 = is1.getItemMeta();
    68. im1.setDisplayName(ChatColor.GRAY + "" +ChatColor.BOLD + "Semi-auto Paintball Gun");
    69. is1.setItemMeta(im1);
    70.  
    71. ItemStack is2 = new ItemStack(Material.DIAMOND_BARDING);
    72. ItemMeta im2 = is2.getItemMeta();
    73. im2.setDisplayName(ChatColor.BLUE + "" +ChatColor.BOLD + "Fully-auto Paintball Gun");*/
    74. if(e.getAction() == Action.RIGHT_CLICK_AIR)
    75. {
    76. String itemName = "";
    77. ItemStack item = e.getPlayer().getItemInHand();
    78. if(!item.hasItemMeta())return;
    79. ItemMeta meta = item.getItemMeta();
    80. if(!meta.hasDisplayName())return;
    81. itemName = ChatColor.stripColor(meta.getDisplayName());
    82. if(itemName.contains("3-Burst Paintball Gun"))
    83. {
    84. if (!cooldownis.contains(e.getPlayer().getName()))
    85. {
    86. e.getPlayer().launchProjectile(Snowball.class);
    87. e.getPlayer().launchProjectile(Snowball.class);
    88. e.getPlayer().launchProjectile(Snowball.class);
    89. cooldownis.add(e.getPlayer().getName());
    90.  
    91. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    92. {
    93. @Override
    94. public void run()
    95. {
    96. cooldownis.remove(e.getPlayer().getName());
    97. }
    98. }, 35L);
    99. }else
    100. {
    101. }
    102. }
    103.  
    104. if(itemName.contains("Semi-auto Paintball Gun"))
    105. {
    106. if (!cooldownis1.contains(e.getPlayer().getName()))
    107. {
    108. e.getPlayer().launchProjectile(Snowball.class);
    109. cooldownis1.add(e.getPlayer().getName());
    110.  
    111. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    112. {
    113. @Override
    114. public void run()
    115. {
    116. cooldownis1.remove(e.getPlayer().getName());
    117. }
    118. }, 15L);
    119. }else
    120. {
    121. }
    122. }
    123.  
    124. if(itemName.contains("Fully-auto Paintball Gun"))
    125. {
    126. if (!cooldownis2.contains(e.getPlayer().getName()))
    127. {
    128. e.getPlayer().launchProjectile(Snowball.class);
    129. cooldownis2.add(e.getPlayer().getName());
    130.  
    131. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    132. {
    133.  
    134. @Override
    135. public void run()
    136. {
    137. cooldownis2.remove(e.getPlayer().getName());
    138. }
    139. }, 4L);
    140. }else
    141. {
    142. }
    143. }
    144. }
    145. }
    146. }
     
  21. Offline

    97WaterPolo

    BrushPainter
    Will do when home if you still need help. I think Tim got it though
     
  22. Offline

    BrushPainter

    timtower Ok but are you sure that it would work because I am not getting any errors with it but if you think about it, in the command I shouldn't have to use
    Code:java
    1. ItemStack is = new ItemStack(Material.GOLD_BARDING);
    2. ItemMeta im = is.getItemMeta();
    3. im.setDisplayName(ChatColor.GOLD + "" +ChatColor.BOLD + "3-Burst Paintball Gun");
    4. is.setItemMeta(im);
    5. pl.getInventory().addItem(is);
    6. pl.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "[" + ChatColor.RESET + "" + ChatColor.WHITE + "Clear" + ChatColor.DARK_AQUA + "Realms" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "] " + ChatColor.RESET + "" + ChatColor.GRAY + "You have received a paintball gun, right click to use it.");
    7. } else {
    8. sender.sendMessage(ChatColor.RED + "An error has occured! - BrushPainter");
    9. }
    10. }
    11. return false;
    12. }


    I should really only have to use
    Code:java
    1. pl.getInventory().addItem(is);
    to give the player the gun. But the problem is right now my code is just giving the player an itemStack renamed, not a itemStack that can shoot snowballs.

    97waterpolo Ok thanks, I think I found another problem in my above post though. Not too sure. :confused:

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

    timtower Moderator Moderator

    BrushPainter You probably want to add debug lines then, find what the current itemname is, what should it be, is this the same etc
     
  24. Offline

    BrushPainter

    timtower I am going to do one gun at a time for now, I duplicated my files in Eclipse for this, but I think I am going to try this now:

    Code:java
    1. package me.BrushPainter.PaintballGuns;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Material;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.entity.Snowball;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.player.PlayerInteractEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.inventory.meta.ItemMeta;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. import java.util.ArrayList;
    19.  
    20. public class Main extends JavaPlugin implements Listener
    21. {
    22.  
    23. public void onEnable() {
    24. Bukkit.getPluginManager().registerEvents(this, this);
    25. getLogger().info("PaintballGuns Enabled");
    26.  
    27. }
    28.  
    29. public void onDisable() {
    30.  
    31. getLogger().info("PaintballGuns Disabled");
    32.  
    33. }
    34.  
    35. ArrayList<String> cooldownis = new ArrayList<String>();
    36. @EventHandler
    37. public void onInteract(final PlayerInteractEvent e)
    38. {
    39. if(e.getAction() == Action.RIGHT_CLICK_AIR)
    40. {
    41. String itemName = "";
    42. ItemStack item = e.getPlayer().getItemInHand();
    43. if(!item.hasItemMeta())return;
    44. ItemMeta meta = item.getItemMeta();
    45. if(!meta.hasDisplayName())return;
    46. itemName = ChatColor.stripColor(meta.getDisplayName());
    47. if(itemName.contains("3-Burst Paintball Gun"))
    48. {
    49. if (cooldownis.contains(e.getPlayer().getName()))
    50. {
    51. e.getPlayer().launchProjectile(Snowball.class);
    52. e.getPlayer().launchProjectile(Snowball.class);
    53. e.getPlayer().launchProjectile(Snowball.class);
    54. cooldownis.add(e.getPlayer().getName());
    55.  
    56. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    57. {
    58. @Override
    59. public void run()
    60. {
    61. cooldownis.remove(e.getPlayer().getName());
    62. }
    63. }, 35L);
    64. }else
    65. {
    66. }
    67. }
    68. }
    69. }
    70.  
    71. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    72.  
    73. if(cmd.getName().equalsIgnoreCase("pbgun")){
    74. if (sender instanceof Player) {
    75. Player pl = (Player) sender;
    76. ItemStack is = new ItemStack(Material.GOLD_BARDING);
    77. ItemMeta im = is.getItemMeta();
    78. im.setDisplayName(ChatColor.GOLD + "" +ChatColor.BOLD + "3-Burst Paintball Gun");
    79. is.setItemMeta(im);
    80.  
    81. pl.getInventory().addItem(is);
    82. pl.sendMessage(ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "[" + ChatColor.RESET + "" + ChatColor.WHITE + "Clear" + ChatColor.DARK_AQUA + "Realms" + ChatColor.DARK_GRAY + "" + ChatColor.BOLD + "] " + ChatColor.RESET + "" + ChatColor.GRAY + "You have received a paintball gun, right click to use it.");
    83. } else {
    84. sender.sendMessage(ChatColor.RED + "An error has occured! - BrushPainter");
    85. }
    86. }
    87. return false;
    88. }
    89. }
     
  25. Offline

    timtower Moderator Moderator

    BrushPainter That won't work anyways, now you check if the player is in the cooldown, if so: then shoot, if not: do nothing
     
  26. Offline

    BrushPainter

    timtower It worked!!! :) I just did what you said, I changed it to:
    Code:java
    1. if (cooldownis.add(e.getPlayer().getName()))
    2. {
    3. e.getPlayer().launchProjectile(Snowball.class);
    4. e.getPlayer().launchProjectile(Snowball.class);
    5. e.getPlayer().launchProjectile(Snowball.class);
    6. cooldownis.conatins(e.getPlayer().getName());
    7.  
    8. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    9. {
    10. @Override
    11. public void run()
    12. {
    13. cooldownis.remove(e.getPlayer().getName());
     
  27. Offline

    timtower Moderator Moderator

    BrushPainter That is not what I said...
    Code:java
    1. if (!cooldownis.contains(e.getPlayer().getName()))
    2. {
    3. e.getPlayer().launchProjectile(Snowball.class);
    4. e.getPlayer().launchProjectile(Snowball.class);
    5. e.getPlayer().launchProjectile(Snowball.class);
    6. cooldownis.add(e.getPlayer().getName());
    7.  
    8. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
    9. {
    10. @Override
    11. public void run()
    12. {
    13. cooldownis.remove(e.getPlayer().getName());
    This is what I meant
     
  28. Offline

    BrushPainter

    timtower Oh okay, I will try it now!

    EDIT: It worked!! Thank you soo much man for all your time and patience, I can't thank you enough!!! :D
     
  29. Offline

    97WaterPolo

    BrushPainter

    Made a very stupid mistake on my part, thanks for pointing it out Tim. It is suppose to be "if (!cooldownis.contains(player.getName()))" it checks to make sure they are not on the could own. That could be the cause of all the problem.
     
  30. Offline

    BrushPainter

    97waterpolo timtower I can't thank you guys enough for all your help! Thank you, thank you, thank you! :D :D :D

    97waterpolo timtower Do you guys know how I can only allow the plugin to function in a certain world? I use MultiWorld, I tried checking the API but I'm not too sure what to look for or how to add it. If not it's ok I guess, anyway thanks a lot guys! :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
    Konkz and timtower like this.
Thread Status:
Not open for further replies.

Share This Page