Deving a plugin for a friend ~ need help ~ stop mobs from attacking a player

Discussion in 'Plugin Development' started by Pencil, Aug 4, 2011.

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


    Alright so a friend got me back into Minecraft and I might start playing again and start to be active again, but first I have to finish his plugin request.

    Basically I have a Mob mounted on a player, and want it to stop attacking.

    I tried this:

    package net.creepcraft.iPencil;
    import org.bukkit.entity.Entity;
    import org.bukkit.event.entity.EntityListener;
    import org.bukkit.event.entity.EntityTargetEvent;
    public class MobMountsEntityListener extends EntityListener {
        private MobMounts plugin;
        public MobMountsEntityListener(MobMounts plugin) {
            this.plugin = plugin;
        public void onEntityTarget(EntityTargetEvent e)
                Entity mob = e.getEntity();
                Entity target = e.getTarget();
                Entity passenger = target.getPassenger();
                if ((mob != null) && (passenger != null)){
    I was hoping I could write it like that, I was hoping to do it:

    Entity mob = e.getEntity(); get the mob that triggered the event
    Entity passenger = target.getPassenger(); get the passenger of the player, the mob that triggered the event
    if ((mob != null) && (passenger != null)){ check if the mob exists (gonna remove it in a sec, it was a use earlier but i rewrote it so now it doesn't anymore) and checks if the player has a passenger (as in a mob that is mounted on the player), if it has one then cancel the event.

    Now the problem is that it simply doesn't work, the mob still attacks me when it's mounted.

    After thinking this over a few times i noticed that it could never work, as the event only gets called once, the first time the mob targets me and doesn't get called again when it gets mounted.

    Is there like an event that calls when something mounts something ? Or how else would I remove the mobs target and stop it from attacking me?

    Any help would be appreciated :) If my post makes absolutely no sense, it's 4 AM in the morning and I have to wake up in 3 hours for work :D
  2. Offline


    Seems silly to ask, but I suppose we'll start with square one:
    Did you register the event?

    Wait, you mention it gets you're monitoring it.
    Disregard that.

    Have you tried storing any player that has your specified entity attached to them into an ArrayList, and then checking in onEntityDamageByEntity to see if the damager was their passenger?

    You could probably cancel it from there and achieve the same effect
  3. Offline


    Yup, I did register it, this is just my EntityListener :)

    That would probably work for most of the mobs however the problem is that I want the Skeleton to actually still shoot people, however I'll probably have to manually check for close players nearby and make the mob target them D:. When I get home in ~8 hours I'll try the damage version. I wonder why I didn't think of it myelf :p I was probably too focused on getting the Entity Target working :D Anyways thanks alot :)
  4. Offline


    Hmz, just realised, it wont work that way because a Creeper would already be boom'd once the damage occurs, so it's probably a bad idea D:
  5. Offline


    Out of curiosity, what are your exact intents with this? I'm not too sure what you *need* to be done, so it's difficult to suggest relevant solutions
  6. Offline


    Pretty easy :D. I have an entity mounted on a player, and I want it to stop attacking me, aswell as moving (which is a bit harder to do :confused:).

    I was wondering, I've seen *by accident* when using a plugin like MobDisguise, that a mob gets spawned that doesn't move nor attack or show any signs of activity. Is it possible to spawn one of those and use it as a mount on the player?

    I'm kind of stuck here :/, as I can't use the damage event :(. Any chance I could add you on skype or msn? ^^
  7. Offline

    Connor Mahaffey

    I see the problem.

    "target" is the entity the mob is targetting, aka, you riding him (the target is the passenger).
    Then you say that the "passenger" is the target's passenger. The passenger is the target.

    So Entity passenger = mob.getPassenger(); NOT Entity passenger = target.getPassenger();

    Right now passenger would always be null, and thus the event never cancels.
  8. Offline


    Note: @desmin88 fixed this bug I believe.
  9. Offline


    Nope, it's right xD

    I'm not riding the mob, the mob is ontop of me. I explained it here .

    Basically mob is the monster that triggered the event, then it gets the target of that monster, and checks if that player has a monster mounted on it. So I guess it should work. But I think the problem is that the onTarget event only gets called once, and if the monster is already targeting me it doesn't get called again :/

    Yep I know it's fixed, I just thought I could use something like them for this :)
Thread Status:
Not open for further replies.

Share This Page