Solved Event Error or what? [Need Help]

Discussion in 'Plugin Development' started by Josh014, Jan 20, 2014.

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

    Josh014

    Hey,

    So I don't know if this is an error but I'm making an damage event but it can't pass the event. It gets spammend in my console and even some events what I don't use get spammed in the console.

    Error or...? (This is just a small part of it. It get spammed more and more):
    Code:
    [20:49:59 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:49:59 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:00 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:00 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:00 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:00 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:00 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:00 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:00 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:00 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:00 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:00 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:03 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:03 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:03 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:03 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:04 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    [20:50:05 ERROR]: Could not pass event EntityDamageByBlockEvent to Teams v1.0
    >
    Code gameDamageListener:
    Code:java
    1. package teams.listeners;
    2.  
    3. import org.bukkit.Effect;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    8. import org.bukkit.event.entity.EntityDamageEvent;
    9.  
    10. import teams.main.Effects;
    11. import teams.main.Team;
    12. import teams.main.main;
    13.  
    14. public class gameDamageListener extends main implements Listener{
    15. public static main plugin;
    16.  
    17. public gameDamageListener(main instance){
    18. plugin = instance;
    19. }
    20.  
    21. //@EventHandler \/
    22. @EventHandler
    23. public void onPlayerDamageByTeam(EntityDamageByEntityEvent event) {
    24. Player player = (Player) event.getEntity();
    25. Player teammate = (Player) event.getDamager();
    26.  
    27.  
    28. if (player instanceof Player
    29. && teammate instanceof Player) {
    30.  
    31. if (!Team.isInTeam(player)) {
    32. return;
    33. }
    34.  
    35. if (Team.isInTeamBlue(player)) {
    36.  
    37. if (Team.isInTeamBlue(teammate)) {
    38.  
    39. event.setCancelled(true);
    40.  
    41. } else {
    42.  
    43. event.setCancelled(false);
    44.  
    45. }
    46.  
    47. }
    48.  
    49. if (Team.isInTeamRed(player)) {
    50.  
    51. if (Team.isInTeamRed(teammate)) {
    52.  
    53. event.setCancelled(true);
    54.  
    55. } else {
    56.  
    57. event.setCancelled(false);
    58.  
    59. }
    60.  
    61. }
    62.  
    63.  
    64.  
    65. }
    66.  
    67. }
    68.  
    69. @EventHandler
    70. public void onPlayerDamage(EntityDamageEvent event) {
    71. Player player = (Player) event.getEntity();
    72.  
    73. if (player instanceof Player) {
    74.  
    75. Effects.playEffect(player.getLocation(), Effect.STEP_SOUND, 152);
    76.  
    77. }
    78.  
    79. }
    80.  
    81.  
    82. }
    83.  


    Code in main class to register the event:
    Code:java
    1. pm.registerEvents(new gameDamageListener(this), this);


    Thank you,
     
  2. Offline

    xTrollxDudex

    Josh014
    Assuming that main is your main class, you can't make a subclass or a new instance of JavaPlugin more than once.
     
    Jaker232 likes this.
  3. Offline

    Josh014

    xTrollxDudex
    So basically I need to remove "extends main"?

    xTrollxDudex
    Alright I removed the extends main part and it is solved. Thank you :). I never thought it was that simple ._.

    Edit:

    Nevermind after some testing I got the problem again...

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

    xMrPoi

    Also, you automatically try to cast the entity to a player and get their team. Your checks should be before that

    Code:java
    1. @EventHandler
    2. public void onTeamHit(EntityDamageEvent event){
    3. if(!(event.getEntity() instanceof Player && event.getEntity().getDamager() instanceof Player)) return;
    4. //do the rest of your checks
    5. }
     
    Josh014 likes this.
  5. Offline

    Josh014

    xMrPoi
    Ah.. Okay lemme test :)

    xMrPoi
    Thank you :). But now back to the main problem that's the spam I get in my console...

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

    xMrPoi

    Josh014 oh I thought removing the "extends main" fixed it.
     
  7. Offline

    Josh014

    xMrPoi
    In the first few it looked like it was fixed but as soon as I turned into gamemode 1 I got all those messages. I tried to check if a player is in creative and then return that but that didn't work..
     
  8. Offline

    xMrPoi

    Josh014 idk man sorry. Maybe I can remember to look at it when I get back to my computer and not my phone
     
  9. Offline

    Josh014

    xMrPoi
    Alright man, thank you for correcting my code with the teams!
     
  10. Offline

    Josh014

  11. Offline

    Josh014

  12. Offline

    Tirelessly

    Josh014 Is that the full error message? And can you post your new code?
     
  13. Offline

    Josh014

    Tirelessly yes that's the full error.

    new Code:
    Code:java
    1. @EventHandler
    2. public void onPlayerDamage(EntityDamageEvent event) {
    3. Player player = (Player) event.getEntity();
    4. Location loc = player.getLocation();
    5.  
    6. if (!(player instanceof Player)
    7. || player.getGameMode() == GameMode.CREATIVE) return;
    8.  
    9. Effects.playEffect(loc, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
    10. Effects.playEffect(loc, Effect.STEP_SOUND, Material.REDSTONE_WIRE);
    11.  
    12. }


    Edit:
    The error gets only spammed in the chat while I am in Gamemode Creative. So I tried to make a return statement but it didn't really work.
     
  14. Offline

    Tirelessly

    Josh014 I want the whole class. Also, you can't cast event.getEntity to Player before checking if it is a Player.
     
  15. Offline

    Josh014

    Tirelessly
    Whole class:
    Code:java
    1. package teams.listeners;
    2.  
    3. import org.bukkit.Effect;
    4. import org.bukkit.GameMode;
    5. import org.bukkit.Location;
    6. import org.bukkit.Material;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.entity.EntityDamageByEntityEvent;
    11. import org.bukkit.event.entity.EntityDamageEvent;
    12.  
    13. import teams.main.Effects;
    14. import teams.main.Team;
    15. import teams.main.main;
    16.  
    17. public class gameDamageListener implements Listener{
    18. public static main plugin;
    19.  
    20. public gameDamageListener(main instance){
    21. plugin = instance;
    22. }
    23.  
    24. //@EventHandler \/
    25. @EventHandler
    26. public void onPlayerDamageByTeam(EntityDamageByEntityEvent event) {
    27. Player player = (Player) event.getEntity();
    28. Player teammate = (Player) event.getDamager();
    29.  
    30. if(!(player instanceof Player && teammate instanceof Player))
    31. return;
    32.  
    33. if (!Team.isInTeam(player)) {
    34. return;
    35. }
    36.  
    37. if (Team.isInTeamBlue(player)) {
    38.  
    39. if (Team.isInTeamBlue(teammate)) {
    40.  
    41. event.setCancelled(true);
    42.  
    43. } else {
    44.  
    45. event.setCancelled(false);
    46.  
    47. }
    48.  
    49. }
    50.  
    51. if (Team.isInTeamRed(player)) {
    52.  
    53. if (Team.isInTeamRed(teammate)) {
    54.  
    55. event.setCancelled(true);
    56.  
    57. } else {
    58.  
    59. event.setCancelled(false);
    60.  
    61. }
    62.  
    63. }
    64.  
    65.  
    66.  
    67. }
    68.  
    69. @EventHandler
    70. public void onPlayerDamage(EntityDamageEvent event) {
    71. Player player = (Player) event.getEntity();
    72. Location loc = player.getLocation();
    73.  
    74. if (!(player instanceof Player)
    75. || player.getGameMode() == GameMode.CREATIVE) return;
    76.  
    77. Effects.playEffect(loc, Effect.STEP_SOUND, Material.REDSTONE_BLOCK);
    78. Effects.playEffect(loc, Effect.STEP_SOUND, Material.REDSTONE_WIRE);
    79.  
    80. }
    81.  
    82.  
    83. }
    84.  
     
  16. Offline

    Tirelessly

    Josh014 Fix what I just said in both of your listeners.
     
  17. Offline

    Josh014

    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page