My event isnt being called?

Discussion in 'Plugin Development' started by callum2904, Jul 25, 2014.

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

    callum2904

    Code:java
    1. public class EntityDamageByEntityListener implements Listener {
    2.  
    3. @SuppressWarnings("deprecation")
    4. @EventHandler
    5. public void damageByEntity(EntityDamageByEntityEvent event) {
    6. Bukkit.broadcastMessage(ChatColor.RED + "Event Has been called!");
    7. if (event.getDamager() instanceof Player && event.getEntity() instanceof Player) {
    8.  
    9. Player damager = (Player) event.getDamager();
    10. Player entity = (Player) event.getEntity();
    11. //
    12. Chat.sendMessage(damager, "Both are players!");
    13. if (damager.getItemInHand().getType() == Material.STICK
    14. && ChatColor.stripColor(damager.getItemInHand().getItemMeta().getDisplayName())
    15. .equalsIgnoreCase("Arrest Batton")) {
    16. //
    17. Chat.sendMessage(damager, "Has arrest batton!");
    18. if (damager.hasPermission("roleplay.arrest") || damager.isOp()) {
    19. //
    20. Chat.sendMessage(damager, "Player has permission");
    21. if(Variables.getVars().isWanted(entity.getUniqueId())){
    22. //
    23. Chat.sendMessage(damager, "Player is wanted!");
    24. if (!Variables.getVars().isArrested(entity.getUniqueId())) {
    25. //
    26. Chat.sendMessage(damager, "Has not already been arrested!");
    27. User user = Main.getInstance().getEssentials().getUser(entity);
    28. try {
    29. //
    30. Chat.sendMessage(damager, "Can send to jail!");
    31. Main.getInstance().getEssentials().getJails().sendToJail(user, "Jail");
    32. Variables.getVars().addArrested(entity.getUniqueId());
    33. user.setHealth(user.getMaxHealth());
    34.  
    35. if (Variables.getVars().hasBounty(entity.getUniqueId())) {
    36. if (Economy.getMoney(entity.getName())
    37. - Variables.getVars().getBounty(entity.getUniqueId()) >= 0) {
    38. Economy.setMoney(
    39. entity.getName(),
    40. Economy.getMoney(entity.getName())
    41. - Variables.getVars().getBounty(
    42. entity.getUniqueId()));
    43. } else {
    44. Economy.setMoney(entity.getName(), 0);
    45. }
    46. Economy.setMoney(
    47. damager.getName(),
    48. Economy.getMoney(damager.getName())
    49. + Variables.getVars().getBounty(
    50. entity.getUniqueId()));
    51. Chat.sendMessage(
    52. damager,
    53. "You have arrested "
    54. + ChatColor.GREEN
    55. + entity.getName()
    56. + ChatColor.WHITE
    57. + ". "
    58. + ChatColor.RED
    59. + "Bounty gained $"
    60. + Variables.getVars().getBounty(
    61. entity.getUniqueId()));
    62. Chat.sendMessage(
    63. entity,
    64. "You have arrested "
    65. + ChatColor.GREEN
    66. + entity.getName()
    67. + ChatColor.WHITE
    68. + ". "
    69. + ChatColor.RED
    70. + "Bounty lost $"
    71. + Variables.getVars().getBounty(
    72. entity.getUniqueId()));
    73. Variables.getVars().removeBonty(entity.getUniqueId());
    74. } else {
    75. Chat.sendMessage(damager, "You have arrested " + ChatColor.GREEN
    76. + entity.getName() + ChatColor.WHITE + ".");
    77. Chat.sendMessage(entity, "You have been arrested by " + ChatColor.GREEN
    78. + damager.getName() + ChatColor.WHITE + ".");
    79. }
    80. } catch (Exception e) {
    81. e.printStackTrace();
    82. }
    83. }
    84. }
    85. event.setCancelled(true);
    86. Variables.getVars().setWanted(entity.getUniqueId(), false);
    87. }
    88. } else if (damager.getItemInHand().getType() == Material.STICK
    89. && ChatColor.stripColor(damager.getItemInHand().getItemMeta().getDisplayName())
    90. .equalsIgnoreCase("UnArrest Batton")) {
    91. if (damager.hasPermission("roleplay.unarrest")) {
    92. if (Variables.getVars().isArrested(entity.getUniqueId())) {
    93. damager.sendMessage("unarrested!");
    94. User user = Main.getInstance().getEssentials().getUser(entity);
    95. user.setJailed(false);
    96. user.teleport(Bukkit.getWorld("world").getSpawnLocation());
    97. Variables.getVars().removeArrested(entity.getUniqueId());
    98. Chat.sendMessage(damager,
    99. "You have unarrested " + ChatColor.GREEN + entity.getName()
    100. + ChatColor.WHITE + ".");
    101. Chat.sendMessage(entity, "You have been unarrested by " + ChatColor.GREEN
    102. + damager.getName() + ChatColor.WHITE + ".");
    103. }
    104. event.setCancelled(true);
    105. }
    106. }else{
    107. Variables.getVars().addBounty(damager.getUniqueId(), 25);
    108. if(event.getDamage() > 4.0){
    109. Chat.sendMessage(damager, "You are wanted for your crimes!");
    110. Variables.getVars().setWanted(damager.getUniqueId(), true);
    111. }
    112. }
    113. }
    114. }
    115.  
    116. }


    That is my entitydamagebyentitylistener class which i call using
    Code:java
    1. public void onEnable(){
    2. plugin = this;
    3. essentials = (Essentials) getServer().getPluginManager().getPlugin("Essentials");
    4.  
    5. // if (!Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays")) {
    6. // getLogger().severe("*** HolographicDisplays is not installed or not enabled. ***");
    7. // getLogger().severe("*** This plugin will be disabled. ***");
    8. // this.setEnabled(false);
    9. // return;
    10. // }
    11. //
    12. // useHolographicDisplays = Bukkit.getPluginManager().isPluginEnabled("HolographicDisplays");
    13.  
    14. PluginManager pm = getServer().getPluginManager();
    15. pm.registerEvents(new EntityDamageByEntityListener(), this);
    16. pm.registerEvents(new PlayerJoinListener(), this);
    17. pm.registerEvents(new PlayerQuitListener(), this);
    18. pm.registerEvents(new PlayerSpawnListener(), this);
    19. pm.registerEvents(new PlayerDeathListener(), this);
    20.  
    21. }


    that is my on enable where you see i call the other listener but when i hit another player with the stick, without or anything it doesnt even broadcast that the event has been called!!!!
     
  2. Offline

    Saladoc

    Is there something in the server log indicating an error?
     
  3. Offline

    Lazertx

    Do you have essentials installed because that may be why it doesn't get to registering your event classes. If so are any entities being hit to trigger the event?
     
  4. Offline

    callum2904

    No errors, no logs, essentials is installed.
    EDIT: Its now working some times i think it may be a lag issue but i dont get why it would always call the event

    Sorry for wasting your time i was being an idiot and saving it to the wrong folder hahah

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

    Lazertx

    It's cool glade that you figured it out good luck with your plugin.
     
Thread Status:
Not open for further replies.

Share This Page