[CODE]: Remove all damage when using Ender Pearls to teleport

Discussion in 'Plugin Development' started by Minken, Dec 13, 2012.

Thread Status:
Not open for further replies.
  1. The topic says it all. I've been looking for code to get rid of the damage when teleporting with Ender Pearls, it ended up that I fixed it myself, with inspiration from @np98765


    Code:
        // set this one outside any function, but inside the class
        boolean doNotDamageThePlayerOnEnderPearlUse = false;
     
        @EventHandler
        public void onProjectileLaunch(ProjectileLaunchEvent event)
        {
            doNotDamageThePlayerOnEnderPearlUse = true;
        }
     
        @EventHandler
        public void onProjectileHitEvent (ProjectileHitEvent event)
        {
            if (!(event.getEntity().getShooter() instanceof Player)) { return; }
     
            if (event.getEntity().toString().contentEquals("CraftEnderPearl"))
            {
                doNotDamageThePlayerOnEnderPearlUse = true;
                Player player = (Player) event.getEntity().getShooter();
                Location hitlocation = event.getEntity().getLocation();
                player.teleport(hitlocation);
            }
        }
     
        @EventHandler
        public void onEntityDamageEvent (EntityDamageEvent event)
        {
            if (!(event.getEntity() instanceof Player)) { return; }
     
            if (doNotDamageThePlayerOnEnderPearlUse == true)
            {
                event.setCancelled(true);
                doNotDamageThePlayerOnEnderPearlUse = false;
            }
        }
    
    Honestly, I'm not sure if every part of the code is needed. I just know it works with Bukkit-1.4.5-R0.2-b2488 :) Feel free to comment with code improvements and/or feedback. Thanks.

    Edit: I've just noticed that it does NOT work if you throw more than one Ender Pearl at the time. But it works fine if you just throw one Ender Pearl at once.

    Hmm, I've noticed that I sometimes got damage anyway. I don't know why. Perhaps I shouldn't throw an Ender Pearl to the underside of a high stairway to heaven. Looking for code improvements by the community!

    Help me improve the code, community :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  2. Offline

    Tehmaker

    Shorten your variables..... Also, try just checking for the damager as being an enderpearl, then remove it.
     
  3. Offline

    AmoebaMan

    Listen for the teleport, catch it, cancel it, and warp the player yourself.
     
  4. Offline

    Spootyman619

    We are trying to launch a server and for some reason enderpearl damage is disabled...players can be damaged by throwing them but the player throwing and teleporting recieves no damage. I can list my mods if you wanna help me here! I created a thread but no one has responded. We did not download any mods to prevent enderpearl damage and it seems to be some other mod though we have torn through most of the yml files and we cant find shit! HELP PLEASE!
     
  5. Offline

    Crunkle

    Here you go, kiddos. Please give full credits if used.
     
  6. Offline

    evilmidget38

    Rofl at your licensing. Are you seriously attempting to try and copyright that?
     
  7. Offline

    Crunkle

    I'm not trying to "copyright that" at all. My "/snippets/" directory does that to all my snippets automatically.
    The EPDamage.java is actually just a PHP script (through the magic of an access file and PHP's mod_rewrite) fetching the snippet from a .txt document in a folder which is then put in format using a template.

    I simply did the PHP script to make all my sources look pretty and aligned correctly. This way, I can quickly and easily drag and drop a .txt document and the .java link will automatically have everything for distribution.

    Think of it as standard procedure so I can have all my snippets in a folder...

    I'm slightly unsure as to why you're extremely ignorant about it.
     
Thread Status:
Not open for further replies.

Share This Page