event cannot be resolved

Discussion in 'Plugin Development' started by MehrPvM, Jun 8, 2013.

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

    MehrPvM

    Hi, I'm trying to make a death listener but I've got an error where I have underlined it below, this is my whole class file and this is the error: 'event cannot be resolved'

    event.getPlayer();

    Code:
    package me.MehrPvM.Event;
     
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class deathlistener implements Listener{
     
        public static Main plugin;
        Player player = event.getPlayer();
     
     
        public deathlistener(Main instance){
            plugin = instance;
        }
     
        @EventHandler(priority=EventPriority.NORMAL)
        public void onPlayerDeath(PlayerDeathEvent event) {
            String playerName = player.getName();
            Bukkit.broadcastMessage(playerName + " has died!");
     
            }
    }
    Thanks
     
  2. Offline

    chasechocolate

    That variable must be inside an event method. In your case, move that inside the "onPlayerDeath()" method.
     
  3. Offline

    MehrPvM

    chasechocolate But then the 'getPlayer' from the same code is errored, saying : 'the method player() is undefined for the type PlayerDeathEvent'
     
  4. Offline

    Wingzzz

    Well that error doesn't match up with your code oddly. If you put Player player = event.getPlayer(); and it says 'the method player() is undefined for the type PlayerDeathEvent'... then somewhere something is wrong because it's talking about a different method.
     
  5. Offline

    Zaane

    This should work:

    String playerName = event.getEntity().getName();
     
  6. Offline

    MehrPvM

    Works Zaane, thanks. And Wired it's exactly the same.
     
Thread Status:
Not open for further replies.

Share This Page