Not working

Discussion in 'Plugin Development' started by iWareWolf, Feb 18, 2014.

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

    iWareWolf

    This class is supposed to have a multiuse bow that can shoot high velocity arrows or exploding arrows, but nothing is working. I have registered it in.

    Code:java
    1. package org.wolfempire.witherdefense.listener;
    2.  
    3. import java.util.Arrays;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Location;
    7. import org.bukkit.Material;
    8. import org.bukkit.entity.Arrow;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.entity.EntityShootBowEvent;
    14. import org.bukkit.event.entity.ProjectileHitEvent;
    15. import org.bukkit.event.player.PlayerInteractEvent;
    16. import org.bukkit.inventory.meta.ItemMeta;
    17. import org.bukkit.metadata.FixedMetadataValue;
    18. import org.bukkit.scheduler.BukkitRunnable;
    19. import org.wolfempire.witherdefense.WitherDefense;
    20.  
    21. public class TacticalArcher implements Listener {
    22.  
    23. WitherDefense plugin;
    24.  
    25. public TacticalArcher(WitherDefense plugin) {
    26. this.plugin = plugin;
    27. }
    28.  
    29. @EventHandler
    30. public void onInteract(PlayerInteractEvent e) {
    31. if (e.getPlayer().getInventory().getItemInHand() != null) {
    32. if (e.getPlayer().getInventory().getItemInHand().getType().equals(Material.BOW)) {
    33. if (e.getPlayer().getInventory().getItemInHand().getItemMeta().hasLore()) {
    34. if (e.getAction().equals(Action.LEFT_CLICK_AIR) || e.getAction().equals(Action.LEFT_CLICK_BLOCK)) {
    35. if (e.getPlayer().getInventory().getItemInHand().getItemMeta().getLore().contains(ChatColor.RESET + ""
    36. + ChatColor.AQUA + "Piercing Shot")) {
    37. ItemMeta bowMeta = e.getPlayer().getInventory().getItemInHand().getItemMeta();
    38. bowMeta.setLore(Arrays.asList(ChatColor.RESET + "" + ChatColor.AQUA + "Current Type:", ChatColor.RESET + ""
    39. + ChatColor.AQUA + "Explosive Shot", "Left Click to switch Type"));
    40. e.getPlayer().updateInventory();
    41. }
    42. if (e.getPlayer().getInventory().getItemInHand().getItemMeta().getLore().contains(ChatColor.RESET + ""
    43. + ChatColor.AQUA + "Explosive Shot")) {
    44. ItemMeta bowMeta = e.getPlayer().getInventory().getItemInHand().getItemMeta();
    45. bowMeta.setLore(Arrays.asList(ChatColor.RESET + "" + ChatColor.AQUA + "Current Type:", ChatColor.RESET + ""
    46. + ChatColor.AQUA + "Piercing Shot", "Left Click to switch Type"));
    47. e.getPlayer().updateInventory();
    48. }
    49. }
    50. }
    51. }
    52. }
    53. }
    54.  
    55. @EventHandler
    56. public void onShoot(EntityShootBowEvent e) {
    57. if (e.getEntity() instanceof Player) {
    58. Player shooter = (Player) e.getEntity();
    59. if (e.getProjectile() instanceof Arrow) {
    60. if (shooter.getInventory().getItemInHand() != null) {
    61. if (shooter.getInventory().getItemInHand().getType().equals(Material.BOW)) {
    62. if (shooter.getInventory().getItemInHand().getItemMeta().hasLore()) {
    63. if (shooter.getInventory().getItemInHand().getItemMeta().getLore().contains(ChatColor.RESET + ""
    64. + ChatColor.AQUA + "Piercing Shot")) {
    65. e.getProjectile().setVelocity(e.getProjectile().getVelocity().multiply(1.25));
    66. }
    67. if (shooter.getInventory().getItemInHand().getItemMeta().getLore().contains(ChatColor.RESET + ""
    68. + ChatColor.AQUA + "Explosive Shot")) {
    69. if (shooter.getLevel() == 1) {
    70. e.getProjectile().setMetadata("Explosive Shot", new FixedMetadataValue(plugin, true));
    71. shooter.setExp(0F);
    72. new Cooldown(shooter) {
    73. }.runTaskTimer(plugin, 0L, 1L);
    74. } else {
    75. e.setCancelled(true);
    76. }
    77. }
    78. }
    79. }
    80. }
    81. }
    82. }
    83. }
    84.  
    85. @EventHandler
    86. public void onHit(ProjectileHitEvent e) {
    87. if (e.getEntity() instanceof Arrow) {
    88. if (e.getEntity().hasMetadata("Explosive Shot")) {
    89. Location loc = e.getEntity().getLocation();
    90. Bukkit.getWorld("world").createExplosion(loc.getX(), loc.getBlockY(), loc.getBlockZ(), 3L, false, false);
    91. }
    92. }
    93. }
    94. }
    95.  
    96. class Cooldown extends BukkitRunnable {
    97.  
    98. Player player;
    99.  
    100. public Cooldown(Player player) {
    101. this.player = player;
    102. }
    103.  
    104. @Override
    105. public void run() {
    106. if (player.getLevel() != 1) {
    107. player.giveExp(2);
    108. } else {
    109. this.cancel();
    110. }
    111. }
    112. }
    113.  
     
  2. Offline

    Drew1080

    iWareWolf
    Okay if you have already registered your event's then does this throw a stacktrace when run it on the server?
     
  3. Offline

    iWareWolf

  4. Offline

    xTrollxDudex

Thread Status:
Not open for further replies.

Share This Page