ENTITY_ATTACK Broken...

Discussion in 'Spigot Plugin Development' started by Jacko2k18, Jan 13, 2019.

  1. Code (Java):
    package me.iceslayzpvp.DeathMessages;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Arrow;
    import org.bukkit.entity.Creeper;
    import org.bukkit.entity.LivingEntity;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Skeleton;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageByEntityEvent;
    import org.bukkit.event.entity.EntityDamageEvent;
    import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
    import org.bukkit.event.entity.PlayerDeathEvent;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener {
     
        public void onEnable() {
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
            getConfig().options().copyDefaults(true);
            saveConfig();
        }
     
        @EventHandler
       
        public void onPlayerDeath(PlayerDeathEvent event, CommandSender sender, EntityDamageEvent damageEvent) {

            String prefix = getConfig().getString("Prefix");
            if (event.getEntity().getLastDamageCause() instanceof EntityDamageByEntityEvent) {
                EntityDamageByEntityEvent nEvent = (EntityDamageByEntityEvent) event
                        .getEntity().getLastDamageCause();
                if ((nEvent.getDamager() instanceof Creeper)) {
                   
                   
                    event.setDeathMessage(ChatColor.translateAlternateColorCodes('&', prefix + " &8>> &b &cYou are such a ssssss... Dead person &6" + event.getEntity().getDisplayName() +  "&c you got blown up... Idiot."));
                }
                if ((nEvent.getDamager() instanceof Arrow)) {
                    Arrow arrow = (Arrow) nEvent.getDamager();
                    if (arrow.getShooter() instanceof Skeleton) {
                        event.setDeathMessage(ChatColor.translateAlternateColorCodes('&', prefix + " &8>> &b" + event.getEntity().getDisplayName() + " &cwas shot by a &6Skeleton"));
                    }
                    if (arrow.getShooter() instanceof Player) {
                       
                        event.setDeathMessage(ChatColor.translateAlternateColorCodes('&', prefix + " &8>> &b" + event.getEntity().getDisplayName() + " &cwas shot by &6" + event.getEntity().getKiller().getDisplayName()));
                       
                    }
                }
            } else {
               
               
                DamageCause cause = event.getEntity().getLastDamageCause()
                        .getCause();
               

               
                if (cause.toString().equals("LAVA")) {
                    event.setDeathMessage(ChatColor.translateAlternateColorCodes('&', prefix + " &8>> &b" + event.getEntity().getDisplayName() + " &cgot devoured by a pool of lava."));
                }
               
                if(cause.toString().equals("ENTITY_ATTACK")) {
                     event.setDeathMessage(ChatColor.translateAlternateColorCodes('&', prefix + " &8>> &b" + event.getEntity().getDisplayName() + " &cgot owned by " + event.getEntity().getDisplayName()));
                }
                if (cause.toString().equals("DROWNING")) {
                    event.setDeathMessage(ChatColor.translateAlternateColorCodes('&', prefix + " &8>> &b" + event.getEntity().getDisplayName() + " &ctried to swim but failed..."));
                }
               
                if(cause.toString().equals("FALL")) {
                   
                    event.setDeathMessage(ChatColor.translateAlternateColorCodes('&', prefix + " &8>> &b" + event.getEntity().getDisplayName() + " &cdied to a fall!"));
                   
                }
            }
        }
       
       
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (cmd.getName().equalsIgnoreCase("deathmessages")) {
                    Player p = (Player)sender;
                   
                    p.sendMessage(ChatColor.translateAlternateColorCodes('&', "&aYou are running version 1.0 of _IceSlayzPvP_'s DeathMessages Plugin!"));
                   
                    return true;
            }
            Player p = (Player)sender;
            if(cmd.getName().equalsIgnoreCase("deathprefix") && p.hasPermission("icecmds.setprefix")) {
                if (args.length == 0) {
                        sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Prefix") + " &8&l>>&r " + ChatColor.RED + "You need to specify a prefix."));
                        return false;
                }
                StringBuilder str = new StringBuilder();
                for (int i = 0; i < args.length; i++) {
                        str.append(args[i] + " ");
                }
                String setmotd = str.toString();
                getConfig().set("Prefix", setmotd);
                saveConfig();
                sender.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Prefix") + "&8&l>> &aPrefix set to : " + setmotd));
                return true;
            }else if(label.equalsIgnoreCase("blockedprefix") && (!p.hasPermission("icecmds.setprefix"))) {
                p.sendMessage(ChatColor.translateAlternateColorCodes('&', getConfig().getString("Prefix") + " &8&l>> &cYou don't have permission to do this! (ICECMDS.SETPREFIX)"));
            }
           
            return false;
    }
         
       
       
       

    }
    I have this code for my death message plugin and the ENTITY_ATTACK won't work it wont broadcast or nothing...
     
  2. md_5

    Administrator Developer

    public void onPlayerDeath(PlayerDeathEvent event, CommandSender sender, EntityDamageEvent damageEvent) {


    That is not what an event handler looks like.

    I suggest you go back to a tutorial. There should only be a single parameter.
     
  3. I took it out command sender and entity damage event
     
  4. It still doesn't work :(
     
  5. Anyone know whats wrong?
     
  6. md_5

    Administrator Developer

    Add print statements to see what code is executing
     
  7. Go back to the basic. Not saying this to be rude but your understanding of how events work is non existent. You will be much better off going and creating some super simple event based plugins (even something as basic as send the player a message when they click a grass block) and building up from there.