onDeath(PlayerDeathEvent event) error

Discussion in 'Plugin Development' started by daniel_svs, Jan 14, 2021.

  1. Offline

    daniel_svs

    i am very new to java and don't know much, it's giving me an error on the onDeath(PlayerDeathEvent event) part

    here is my code

    Code:
    package tld.example.myplugin;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.Sound;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.PlayerDeathEvent;
    
    public class death implements CommandExecutor {
       
        @SuppressWarnings("unused")
       
        private Main plugin;
       
        public death(Main plugin) {
            this.plugin = plugin;
            plugin.getCommand("death").setExecutor(this);
        }
    
        @Override
        public boolean onCommand(CommandSender sender    , Command cmd, String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage("only players can use this command");
                return true;
            }
             @EventHandler
                public void onDeath(PlayerDeathEvent event) {
                    Location deathLocation = event.getEntity().getLocation();
    
                    int x = (int) deathLocation.getX();
                    int y = (int) deathLocation.getY();
                    int z = (int) deathLocation.getZ();
                    String world = deathLocation.getWorld().getName();
             }
            return true;
    }
    }
    
     
  2. Offline

    Kars

    You put the EventHandler function inside of another function. You can't do that.
     
  3. Offline

    Strahan

    Also you really should follow naming conventions and call the class Death instead.

    Further I hope you aren't creating those x/y/z/world variables for the sake of saving the location to a config or something, because Location implements ConfigurationSerializable so manual serialization is not necessary.
     
  4. Offline

    marcelo.mb

    @daniel_svs If you do not have any questions left, please mark the thread as solved.
     

Share This Page