Custom death messages?

Discussion in 'Plugin Development' started by AppleMC, Feb 18, 2013.

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

    CubixCoders

    Well all the deaths are returning "Lava death" btw.. Are you getting an error inthe console? If so please show
     
  2. Offline

    AppleMC

    Uhhh not all deaths are returning lava.. i have different death paths for each
     

    Attached Files:

  3. Offline

    AppleMC

  4. Offline

    xavierarmadillo

    Code:
        @EventHandler
        public void onEntityDeath(EntityDeathEvent event) {
     
            Entity victim = event.getEntity();
            DamageCause damage = null;
            String Victim = "", Killer = "", Cause = "";
            boolean byPlayer = false;
            boolean flipIt = false;
     
            if (victim.getLastDamageCause() != null) {
                damage = victim.getLastDamageCause().getCause();
            } else {
                return;
            }
     
            // Determine the victim of the death
            // ############################################################################
            if (victim instanceof Player) {
                // Get the player display name
                Victim = ((Player) victim).getDisplayName();
            } else {
                // Format the victim to a readable form
                Victim = victim.getType().getName().toLowerCase().replace("_", " ");
     
                if (victim instanceof Wolf) {
                    Wolf wolf = (Wolf) victim;
                    if (wolf.getOwner() != null) {
                        Player ply = (Player) wolf.getOwner();
                        Victim = Victim.concat(" owned by ").concat(
                                ply.getDisplayName());
                    }
                }
     
                // Concat the appropriate article before the noun.
                if (Victim.matches("[aeiou].*?")) {
                    Victim = "An ".concat(Victim);
                } else {
                    Victim = "A ".concat(Victim);
                }
            }
     
            // Determine the cause of the death
            // ############################################################################
            if (damage.equals(DamageCause.ENTITY_ATTACK)) {
                // The killer was another entity.
                // Determine the entity
                Entity killer = event.getEntity().getKiller();
     
                if (killer instanceof Player) {
     
                    byPlayer = true;
                    Killer = " from ".concat(event.getEntity().getKiller()
                            .getDisplayName());
     
                    ItemStack item = event.getEntity().getKiller().getItemInHand();
     
                    String theCause = item.getType().toString().toLowerCase();
     
                    if (theCause.equals("air")) {
                        Cause = " attacking with their awesome fist";
                    } else {
     
                        if (theCause.matches("[aeiou].*?")) {
                            Cause = " attacking them with an ".concat(theCause
                                    .replace("_", " "));
                        } else {
                            Cause = " attacking them with a ".concat(theCause
                                    .replace("_", " "));
                        }
                    }
     
                } else {
     
                    if (victim.getLastDamageCause() instanceof EntityDamageByEntityEvent) {
     
                        EntityDamageByEntityEvent eEvent = (EntityDamageByEntityEvent) victim
                                .getLastDamageCause();
                        String entityName = eEvent.getDamager().getType().getName()
                                .toLowerCase();
     
                        if (entityName.matches("[aeiou].*?")) {
                            Killer = " by an ".concat(entityName);
                        } else {
                            Killer = " by a ".concat(entityName);
                        }
     
                        if (eEvent.getDamager() instanceof Wolf) {
                            Wolf wolf = (Wolf) eEvent.getDamager();
                            if (wolf.getOwner() != null) {
                                Player ply = (Player) wolf.getOwner();
                                Killer = Killer.concat(" owned by ").concat(
                                        ply.getDisplayName());
                            }
                        }
     
                        Cause = " by being attacked";
                        flipIt = true;
     
                    } else {
                        // unknown
                        Cause = " unknown";
                    }
                }
            } else if (damage.equals(DamageCause.BLOCK_EXPLOSION)) {
                Cause = " from an explosion";
            } else if (damage.equals(DamageCause.CONTACT)) {
                Cause = " from kissing a cactus";
            } else if (damage.equals(DamageCause.CUSTOM)) {
                Cause = " from something custom";
            } else if (damage.equals(DamageCause.DROWNING)
                    || damage.equals(DamageCause.SUFFOCATION)) {
                Cause = " from not taking a breath";
            } else if (damage.equals(DamageCause.ENTITY_EXPLOSION)) {
                Cause = " by playing with a creeper";
            } else if (damage.equals(DamageCause.FALL)) {
                Cause = " by bungee jumping without a cord";
            } else if (damage.equals(DamageCause.FALLING_BLOCK)) {
                Cause = " by being smooshed";
            } else if (damage.equals(DamageCause.FIRE)
                    || damage.equals(DamageCause.FIRE_TICK)) {
                Cause = " after jumping into a campfire";
            } else if (damage.equals(DamageCause.LAVA)) {
                Cause = " from swimming in lava";
            } else if (damage.equals(DamageCause.LIGHTNING)) {
                Cause = " by flying a kite in an electrical storm";
            } else if (damage.equals(DamageCause.MAGIC)) {
                Cause = " by playing with magic";
            } else if (damage.equals(DamageCause.MELTING)) {
                Cause = " from thawing.";
            } else if (damage.equals(DamageCause.POISON)) {
                Cause = " by drinking poison";
            } else if (damage.equals(DamageCause.PROJECTILE)) {
                Cause = " from being shot";
            } else if (damage.equals(DamageCause.STARVATION)) {
                Cause = " because they didn't go grocery shopping";
            } else if (damage.equals(DamageCause.SUICIDE)) {
                Cause = " by taking the easy way out";
            } else if (damage.equals(DamageCause.VOID)) {
                Cause = " by falling into the abyss";
            } else if (damage.equals(DamageCause.WITHER)) {
                Cause = " because they danced with the wither";
            }
     
            String toSend = Victim.concat(" died").concat(Killer).concat(Cause)
                    .concat(".");
     
            if (flipIt) {
                toSend = Victim.concat(" died").concat(Cause).concat(Killer)
                        .concat(".");
            }
     
            if (!lastMessage.equals(toSend) || byPlayer) {
     
                long time = (new Date().getTime() - lastTime.getTime()) / 1000;
     
                if (time > 15 || byPlayer) {
                    lastMessage = toSend;
                    lastTime = new Date();
                    sendToAll(ChatColor.WHITE + toSend);
                }
            }
        }
     
  5. Offline

    alexlyn1

    use the DamageCause will work better.
     
  6. Offline

    Cycryl

    i think if you wanted to use colorcodes in the config you can do
    \u00A7 + Colorcode
    e.g: \u00A74Hi acts like ChatColor.RED + "Hi"
     
Thread Status:
Not open for further replies.

Share This Page