[SEVERE] Wrong method arguments used for event type registered

Discussion in 'Plugin Development' started by Jok3r539, Mar 8, 2012.

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

    Jok3r539

    The title shows what I see in my console, This is my code for the event, I do not see what I am doing wrong... I'm kind of thinking that its the arrow to the left of it in the comment, I have to use that for something but what?
     
  2. Offline

    billofbong

    There is no player argument for EventHandler.
    Code:
    @EventHandler
    public void onPlayerDamage(EntityDamageEvent event){
    String strPlayer = event.getPlayer.getName();
    if(event.getEntity() instanceof Player) {
                    Player p = (Player) event.getEntity();
                    if(plugin.getConfig().get(strPlayer, "GOD") != null){
                   event.setCancelled(true);
                   If(event.isCancelled()) return;
                   player.setHealth(20);
                   player.setFoodLevel(20);
                    }
            }
    }
     
  3. Offline

    Jok3r539

    It still gives me the title of the thread, but Im gonna test it...

    Nope... doesnt work... :(

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

    Njol

    You have some errors/problems in the code, here's a better version:
    Code:
    @EventHandler(ignoreCancelled = true)
    public void onPlayerDamage(EntityDamageEvent event){
    if(event.getEntity() instanceof Player) {
                    Player p = (Player) event.getEntity();
                    if(plugin.getConfig().get(p.getName(), "GOD") != null){
                  event.setCancelled(true);
                  p.setHealth(20);
                  p.setFoodLevel(20);
                    }
            }
    }
     
  5. Offline

    Jok3r539

    Ok why is this line: Player p = (Player) event.getEntity();, even in there? p is not used anywhere!! EDIT: Im doing it wrong you think I have player in that class so im going to use:
     
  6. Offline

    Njol

    It is used 3 times, but i overlooked that you had two variables for the same thing (the other being player).
    Code:
    @EventHandler(ignoreCancelled = true)
    public void onPlayerDamage(EntityDamageEvent event){
    if(event.getEntity() instanceof Player) {
                    Player p = (Player) event.getEntity();
                    if(plugin.getConfig().get(p.getName(), "GOD") != null){// used here
                  event.setCancelled(true);
                  p.setHealth(20); //here
                  p.setFoodLevel(20); //and here
                    }
            }
    }
     
  7. Offline

    Jok3r539

    Ok thanks, Im going to test it now!
     
Thread Status:
Not open for further replies.

Share This Page