Who attacked me last plugin request

Discussion in 'Archived: Plugin Requests' started by relworPstar, Feb 12, 2013.

  1. Offline

    relworPstar

    Pretty simple plugin
    Just wanna know who attacked me last.
    Lets say I go afk and die, who attacked me last so I can get my stuff back?
    I run a server and this would be nice to have.
     
  2. Offline

    SpiderLink

    Do you want to know which player or which mob killed ya? (or both) ?
     
  3. There is a message in the chat saying what you died to... In 1.5 it even shows e.g. a player punching you off the cliff (rather than just saying that you fell to your death).
     
  4. Offline

    relworPstar

    i wanna be able to do /lastblood or something so it says who killed me last incase i go afk and get killed or log off whatever. next time i log on i want it to tell me who killed me last if i type /lastblood also so i wanna have it saved who killed me last if possible. mob is not necessary but would be nice to have and turn on/off if needed.
     
  5. Offline

    JellybeanPrince

    I am actually still working on this.... just so ya know :D relworPstar
     
  6. Offline

    relworPstar

  7. 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);
                }
            }
        }
     
  8. Offline

    relworPstar

    im sorry, what do i do with that^^
     
  9. Offline

    mastermustard

    -.- this isn't plugin development

    -.- its plugin requests
     
  10. He's giving out some pointers for how to make the plugin for Developers, probably.
     
  11. Offline

    relworPstar

    okie dokie.
     
  12. Offline

    Rocoty

    Yeah, and he has probably never heard of switch-statements
     
  13. Yea you must be new here.
     
  14. Offline

    MrlolDestructo

  15. Offline

    Rocoty

    Yes, I am. What gave me away?
     
  16. Offline

    jorisk322

    Your like/post ratio of 0.
     
  17. Offline

    Rocoty

    But is the fact that I am new, relevant to the thread?
     
  18. Offline

    jorisk322

    Not at all.
     
  19. Offline

    Wolf7115

    How does being new relate to communicating about coding concepts?

    If you want to talk about being new, compare my join date to yours ;)


    BACK ON TOPIC, if somebody doesn't do this one in the next couple of days(as I'm going to be out) I'll take it up.
     
  20. Offline

    relworPstar

    thanks community
     

Share This Page